Skip to content

Commit 7ba7ad6

Browse files
committed
GPU Memory Manager support for PyCaffe
1 parent b044a77 commit 7ba7ad6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

python/caffe/_caffe.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "caffe/layers/memory_data_layer.hpp"
1919
#include "caffe/layers/python_layer.hpp"
2020
#include "caffe/sgd_solvers.hpp"
21+
#include "caffe/util/gpu_memory.hpp"
2122

2223
// Temporary solution for numpy < 1.7 versions: old macro, no promises.
2324
// You're strongly advised to upgrade to >= 1.7.
@@ -51,9 +52,25 @@ namespace caffe {
5152
typedef float Dtype;
5253
const int NPY_DTYPE = NPY_FLOAT32;
5354

55+
#ifndef CPU_ONLY
56+
shared_ptr<GPUMemory::Scope> gpu_memory_scope;
57+
#endif
58+
5459
// Selecting mode.
5560
void set_mode_cpu() { Caffe::set_mode(Caffe::CPU); }
56-
void set_mode_gpu() { Caffe::set_mode(Caffe::GPU); }
61+
void set_mode_gpu() {
62+
Caffe::set_mode(Caffe::GPU);
63+
#ifndef CPU_ONLY
64+
vector<int> gpus;
65+
int count = 0;
66+
CUDA_CHECK(cudaGetDeviceCount(&count));
67+
for (int i = 0; i < count; ++i) {
68+
gpus.push_back(i);
69+
}
70+
CHECK_GT(gpus.size(), 0);
71+
gpu_memory_scope.reset(new GPUMemory::Scope(gpus));
72+
#endif
73+
}
5774

5875
// For convenience, check that input files can be opened, and raise an
5976
// exception that boost will send to Python if not (caffe could still crash

0 commit comments

Comments
 (0)