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  void closeSafe();
23  //used for input
24  virtual void copyInput(const void* values, size_t offset, unsigned entry) {}
25  //used for output
26  virtual void copyOutput() {}
27  virtual void set();
28 
29 protected:
30  //member variables
33  size_t size_;
34  uint8_t* addr_;
35  bool closed_;
36 };
37 
38 template <typename IO>
39 class TritonHeapResource : public TritonMemResource<IO> {
40 public:
42  ~TritonHeapResource() override {}
43  void copyInput(const void* values, size_t offset, unsigned entry) override {}
44  void copyOutput() override {}
45  void set() override {}
46 };
47 
48 template <typename IO>
49 class TritonCpuShmResource : public TritonMemResource<IO> {
50 public:
52  ~TritonCpuShmResource() override;
53  void close() override;
54  void copyInput(const void* values, size_t offset, unsigned entry) override {}
55  void copyOutput() override {}
56 
57 protected:
58  size_t sizeOrig_;
59 };
60 
65 
66 //avoid "explicit specialization after instantiation" error
67 template <>
68 void TritonInputHeapResource::copyInput(const void* values, size_t offset, unsigned entry);
69 template <>
70 void TritonInputCpuShmResource::copyInput(const void* values, size_t offset, unsigned entry);
71 template <>
73 template <>
75 
76 #ifdef TRITON_ENABLE_GPU
77 #include "cuda_runtime_api.h"
78 
79 template <typename IO>
80 class TritonGpuShmResource : public TritonMemResource<IO> {
81 public:
82  TritonGpuShmResource(TritonData<IO>* data, const std::string& name, size_t size);
83  ~TritonGpuShmResource() override;
84  void close() override;
85  void copyInput(const void* values, size_t offset, unsigned entry) override {}
86  void copyOutput() override {}
87 
88 protected:
89  int deviceId_;
90  std::shared_ptr<cudaIpcMemHandle_t> handle_;
91 };
92 
93 using TritonInputGpuShmResource = TritonGpuShmResource<triton::client::InferInput>;
94 using TritonOutputGpuShmResource = TritonGpuShmResource<triton::client::InferRequestedOutput>;
95 
96 //avoid "explicit specialization after instantiation" error
97 template <>
98 void TritonInputGpuShmResource::copyInput(const void* values, size_t offset, unsigned entry);
99 template <>
100 void TritonOutputGpuShmResource::copyOutput();
101 #endif
102 
103 #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
~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