CMS 3D CMS Logo

TritonMemResource.h
Go to the documentation of this file.
1 #ifndef HeterogeneousCore_SonicTriton_TritonMemResource
2 #define HeterogeneousCore_SonicTriton_TritonMemResource
3 
4 #include <string>
5 #include <memory>
6 
7 #include "grpc_client.h"
8 
9 //forward declaration
10 template <typename IO>
11 class TritonData;
12 
13 //base class for memory operations
14 template <typename IO>
15 class TritonMemResource {
16 public:
18  virtual ~TritonMemResource() {}
19  uint8_t* addr() { return addr_; }
20  size_t size() const { return size_; }
21  virtual void close() {}
22  //used for input
23  virtual void copyInput(const void* values, size_t offset) {}
24  //used for output
25  virtual const uint8_t* copyOutput() { return nullptr; }
26  virtual void set();
27 
28 protected:
29  //member variables
32  size_t size_;
33  uint8_t* addr_;
34  bool closed_;
35 };
36 
37 template <typename IO>
38 class TritonHeapResource : public TritonMemResource<IO> {
39 public:
41  ~TritonHeapResource() override {}
42  void copyInput(const void* values, size_t offset) override {}
43  const uint8_t* copyOutput() override { return nullptr; }
44  void set() override {}
45 };
46 
47 template <typename IO>
48 class TritonCpuShmResource : public TritonMemResource<IO> {
49 public:
51  ~TritonCpuShmResource() override;
52  void close() override;
53  void copyInput(const void* values, size_t offset) override {}
54  const uint8_t* copyOutput() override { return nullptr; }
55 };
56 
61 
62 //avoid "explicit specialization after instantiation" error
63 template <>
64 void TritonInputHeapResource::copyInput(const void* values, size_t offset);
65 template <>
66 void TritonInputCpuShmResource::copyInput(const void* values, size_t offset);
67 template <>
69 template <>
71 
72 #ifdef TRITON_ENABLE_GPU
73 #include "cuda_runtime_api.h"
74 
75 template <typename IO>
76 class TritonGpuShmResource : public TritonMemResource<IO> {
77 public:
78  TritonGpuShmResource(TritonData<IO>* data, const std::string& name, size_t size);
79  ~TritonGpuShmResource() override;
80  void close() override;
81  void copyInput(const void* values, size_t offset) override {}
82  const uint8_t* copyOutput() override { return nullptr; }
83 
84 protected:
85  int deviceId_;
86  std::shared_ptr<cudaIpcMemHandle_t> handle_;
87 };
88 
89 using TritonInputGpuShmResource = TritonGpuShmResource<triton::client::InferInput>;
90 using TritonOutputGpuShmResource = TritonGpuShmResource<triton::client::InferRequestedOutput>;
91 
92 //avoid "explicit specialization after instantiation" error
93 template <>
94 void TritonInputGpuShmResource::copyInput(const void* values, size_t offset);
95 template <>
96 const uint8_t* TritonOutputGpuShmResource::copyOutput();
97 #endif
98 
99 #endif
TritonMemResource::data_
TritonData< IO > * data_
Definition: TritonMemResource.h:30
TritonMemResource::size
size_t size() const
Definition: TritonMemResource.h:20
TritonMemResource::addr
uint8_t * addr()
Definition: TritonMemResource.h:19
TritonData
Definition: TritonData.h:45
TritonMemResource::size_
size_t size_
Definition: TritonMemResource.h:32
TritonMemResource
Definition: TritonData.h:21
TritonMemResource::addr_
uint8_t * addr_
Definition: TritonMemResource.h:33
TritonCpuShmResource::TritonCpuShmResource
TritonCpuShmResource(TritonData< IO > *data, const std::string &name, size_t size)
Definition: TritonMemResource.cc:54
TritonCpuShmResource::copyOutput
const uint8_t * copyOutput() override
Definition: TritonMemResource.h:54
TritonMemResource::close
virtual void close()
Definition: TritonMemResource.h:21
TritonMemResource::copyInput
virtual void copyInput(const void *values, size_t offset)
Definition: TritonMemResource.h:23
TritonMemResource::TritonMemResource
TritonMemResource(TritonData< IO > *data, const std::string &name, size_t size)
Definition: TritonMemResource.cc:15
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
TritonHeapResource::~TritonHeapResource
~TritonHeapResource() override
Definition: TritonMemResource.h:41
TritonMemResource::set
virtual void set()
Definition: TritonMemResource.cc:19
TritonHeapResource::copyOutput
const uint8_t * copyOutput() override
Definition: TritonMemResource.h:43
TritonCpuShmResource::close
void close() override
Definition: TritonMemResource.cc:88
TritonCpuShmResource::~TritonCpuShmResource
~TritonCpuShmResource() override
Definition: TritonMemResource.cc:83
TritonMemResource::copyOutput
virtual const uint8_t * copyOutput()
Definition: TritonMemResource.h:25
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TritonHeapResource::TritonHeapResource
TritonHeapResource(TritonData< IO > *data, const std::string &name, size_t size)
Definition: TritonMemResource.cc:25
TritonMemResource::closed_
bool closed_
Definition: TritonMemResource.h:34
TritonHeapResource::set
void set() override
Definition: TritonMemResource.h:44
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
TritonCpuShmResource::copyInput
void copyInput(const void *values, size_t offset) override
Definition: TritonMemResource.h:53
TritonMemResource::name_
std::string name_
Definition: TritonMemResource.h:31
TritonMemResource::~TritonMemResource
virtual ~TritonMemResource()
Definition: TritonMemResource.h:18
TritonHeapResource
Definition: TritonData.h:23
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
TritonHeapResource::copyInput
void copyInput(const void *values, size_t offset) override
Definition: TritonMemResource.h:42
TritonCpuShmResource
Definition: TritonData.h:25
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443