CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
TritonData< IO > * data_
void copyInput(const void *values, size_t offset) override
virtual void close()
virtual void copyInput(const void *values, size_t offset)
TritonCpuShmResource(TritonData< IO > *data, const std::string &name, size_t size)
~TritonCpuShmResource() override
virtual void set()
void copyInput(const void *values, size_t offset) override
TritonMemResource(TritonData< IO > *data, const std::string &name, size_t size)
const uint8_t * copyOutput() override
~TritonHeapResource() override
TritonHeapResource(TritonData< IO > *data, const std::string &name, size_t size)
void set() override
virtual const uint8_t * copyOutput()
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
const uint8_t * copyOutput() override
virtual ~TritonMemResource()
tuple size
Write out results.
size_t size() const