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, unsigned entry) {}
24  //used for output
25  virtual void copyOutput() {}
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, unsigned entry) override {}
43  void copyOutput() override {}
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, unsigned entry) override {}
54  void copyOutput() override {}
55 
56 protected:
57  size_t sizeOrig_;
58 };
59 
64 
65 //avoid "explicit specialization after instantiation" error
66 template <>
67 void TritonInputHeapResource::copyInput(const void* values, size_t offset, unsigned entry);
68 template <>
69 void TritonInputCpuShmResource::copyInput(const void* values, size_t offset, unsigned entry);
70 template <>
72 template <>
74 
75 #ifdef TRITON_ENABLE_GPU
76 #include "cuda_runtime_api.h"
77 
78 template <typename IO>
79 class TritonGpuShmResource : public TritonMemResource<IO> {
80 public:
81  TritonGpuShmResource(TritonData<IO>* data, const std::string& name, size_t size);
82  ~TritonGpuShmResource() override;
83  void close() override;
84  void copyInput(const void* values, size_t offset, unsigned entry) override {}
85  void copyOutput() override {}
86 
87 protected:
88  int deviceId_;
89  std::shared_ptr<cudaIpcMemHandle_t> handle_;
90 };
91 
92 using TritonInputGpuShmResource = TritonGpuShmResource<triton::client::InferInput>;
93 using TritonOutputGpuShmResource = TritonGpuShmResource<triton::client::InferRequestedOutput>;
94 
95 //avoid "explicit specialization after instantiation" error
96 template <>
97 void TritonInputGpuShmResource::copyInput(const void* values, size_t offset, unsigned entry);
98 template <>
99 void TritonOutputGpuShmResource::copyOutput();
100 #endif
101 
102 #endif
size
Write out results.
void copyInput(const void *values, size_t offset, unsigned entry) override
TritonData< IO > * data_
virtual void copyOutput()
virtual void close()
virtual void copyInput(const void *values, size_t offset, unsigned entry)
TritonCpuShmResource(TritonData< IO > *data, const std::string &name, size_t size)
TritonMemResource(TritonData< IO > *data, const std::string &name, size_t size)
void copyOutput() override
void copyInput(const void *values, size_t offset, unsigned entry) override
~TritonCpuShmResource() override
~TritonHeapResource() override
TritonHeapResource(TritonData< IO > *data, const std::string &name, size_t size)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void copyOutput() override
virtual ~TritonMemResource()
size_t size() const