Caffe2 - C++ API
A deep learning, cross platform ML framework
conv_op_shared_gpu.cc
1 #include "caffe2/core/context_gpu.h"
2 #include "conv_op_shared.h"
3 
4 namespace caffe2 {
5 
6 template <>
7 void createSharedBuffer<CUDAContext>(Workspace* ws) {
8  auto* mutexPtr = ws->CreateBlob("__CAFFE2_SHARED_CONV_BUFFER_CUDA_MUTEX__")
9  ->GetMutable<std::unique_ptr<std::mutex>>();
10  mutexPtr->reset(new std::mutex());
11  ws->CreateBlob("__CAFFE2_SHARED_CONV_BUFFER_CUDA__");
12 }
13 
14 template <>
15 void runWithSharedBuffer(
16  Workspace* ws,
17  std::function<void(Tensor<CUDAContext>* buffer)> f) {
18  auto* mutexBlob = ws->GetBlob("__CAFFE2_SHARED_CONV_BUFFER_CUDA_MUTEX__");
19  CAFFE_ENFORCE(mutexBlob, "Must call createSharedBuffer() first");
20 
21  auto* mutexPtr = mutexBlob->GetMutable<std::unique_ptr<std::mutex>>();
22  std::lock_guard<std::mutex> g(**mutexPtr);
23  auto* buffer = ws->GetBlob("__CAFFE2_SHARED_CONV_BUFFER_CUDA__")
24  ->GetMutable<TensorCUDA>();
25  f(buffer);
26 }
27 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...