1 #include "caffe2/core/context_gpu.h" 2 #include "caffe2/operators/conv_op_shared.h" 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__");
15 void runWithSharedBuffer<CUDAContext>(
17 std::function<void(Tensor* buffer)> f) {
18 auto* mutexBlob = ws->GetBlob(
"__CAFFE2_SHARED_CONV_BUFFER_CUDA_MUTEX__");
19 CAFFE_ENFORCE(mutexBlob,
"Must call createSharedBuffer() first");
21 auto* mutexPtr = mutexBlob->GetMutable<std::unique_ptr<std::mutex>>();
22 std::lock_guard<std::mutex> g(**mutexPtr);
23 auto* buffer = BlobGetMutableTensor(
24 ws->GetBlob(
"__CAFFE2_SHARED_CONV_BUFFER_CUDA__"), CUDA);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...