Caffe2 - C++ API
A deep learning, cross platform ML framework
conv_op_shared.cc
1 #include "conv_op_shared.h"
2 #include "caffe2/core/context.h"
3 #include "caffe2/core/flags.h"
4 #include "caffe2/core/workspace.h"
5 
6 C10_DEFINE_bool(
7  caffe2_force_shared_col_buffer,
8  false,
9  "Always use the shared col buffer");
10 
11 namespace caffe2 {
12 
13 template <>
14 void createSharedBuffer<CPUContext>(Workspace* ws) {
15  auto* mutexPtr = ws->CreateBlob("__CAFFE2_SHARED_CONV_BUFFER_CPU_MUTEX__")
16  ->GetMutable<std::unique_ptr<std::mutex>>();
17  mutexPtr->reset(new std::mutex());
18  ws->CreateBlob("__CAFFE2_SHARED_CONV_BUFFER_CPU__");
19 }
20 
21 template <>
22 void runWithSharedBuffer<CPUContext>(
23  Workspace* ws,
24  std::function<void(Tensor* buffer)> f) {
25  auto* mutexBlob = ws->GetBlob("__CAFFE2_SHARED_CONV_BUFFER_CPU_MUTEX__");
26  CAFFE_ENFORCE(mutexBlob, "Must call createSharedBuffer() first");
27 
28  auto* mutexPtr = mutexBlob->GetMutable<std::unique_ptr<std::mutex>>();
29  std::lock_guard<std::mutex> g(**mutexPtr);
30  auto* buffer = BlobGetMutableTensor(
31  ws->GetBlob("__CAFFE2_SHARED_CONV_BUFFER_CPU__"), CPU);
32  f(buffer);
33 }
34 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13