Caffe2 - C++ API
A deep learning, cross platform ML framework
libshm.h
1 #pragma once
2 
3 #include <TH/TH.h>
4 
5 #ifdef __cplusplus
6 
7 void libshm_init(const char *manager_exec_path);
8 
9 // Superclass to run a constructor before THRefcountedMapAllocator
10 class THManagedMapAllocatorInit {
11 protected:
12  THManagedMapAllocatorInit(const char* manager_handle, const char* filename);
13  std::string manager_handle_;
14 };
15 
16 // Like a THRefcountedMapAllocator, but it also makes use of an external
17 // shared memory manager process to ensure that shared memory regions actually
18 // get freed in the end (even if processes lose the memory).
19 class THManagedMapAllocator : private THManagedMapAllocatorInit, public THRefcountedMapAllocator {
20 public:
21  THManagedMapAllocator(const char* manager_handle, const char* filename, int flags, ptrdiff_t size);
22 
23  void close() override;
24 
25  ~THManagedMapAllocator() { close(); }
26 
27  static at::DataPtr makeDataPtr(const char* manager_handle, const char* filename, int flags, ptrdiff_t size);
28  static THManagedMapAllocator* fromDataPtr(const at::DataPtr&);
29 
30  const char* manager_handle() const { return manager_handle_.c_str(); }
31 };
32 
33 #endif