|
18 | 18 |
|
19 | 19 | #include "caffe/util/device_alternate.hpp" |
20 | 20 |
|
21 | | -#ifdef USE_CNMEM |
22 | | -// cuMEM integration |
23 | | -#include <cnmem.h> |
24 | | -#endif |
25 | | - |
26 | 21 | // gflags 2.1 issue: namespace google was changed to gflags without warning. |
27 | 22 | // Luckily we will be able to use GFLAGS_GFLAGS_H_ to detect if it is version |
28 | 23 | // 2.1. If yes, we will add a temporary solution to redirect the namespace. |
@@ -70,6 +65,12 @@ private:\ |
70 | 65 | // is executed we will see a fatal log. |
71 | 66 | #define NOT_IMPLEMENTED LOG(FATAL) << "Not Implemented Yet" |
72 | 67 |
|
| 68 | +#include "CuMem.hpp" |
| 69 | + |
| 70 | +// bfomitchev: temporary, for better merge |
| 71 | +#define MemoryHandler CuMem |
| 72 | +#define MemoryHandlerActivator CuMemActivator |
| 73 | + |
73 | 74 | // See PR #1236 |
74 | 75 | namespace cv { class Mat; } |
75 | 76 |
|
@@ -184,67 +185,7 @@ class Caffe { |
184 | 185 | DISABLE_COPY_AND_ASSIGN(Caffe); |
185 | 186 | }; |
186 | 187 |
|
187 | | -class MemoryHandler { |
188 | | - public: |
189 | | - static MemoryHandler& Get(); |
190 | | -#ifndef CPU_ONLY |
191 | | - static void mallocGPU(void **ptr, size_t size, |
192 | | - cudaStream_t stream = cudaStreamDefault); |
193 | | - static void freeGPU(void *ptr, cudaStream_t = cudaStreamDefault); |
194 | | - static void registerStream(cudaStream_t stream); |
195 | | -#endif |
196 | | - static void setGPUs(const std::vector<int>& gpus) { Get().gpus_ = gpus; } |
197 | | - static void usePool() { Get().using_pool_ = true; } |
198 | | - static bool usingPool() { |
199 | | -#ifdef USE_CNMEM |
200 | | - return Get().using_pool_; |
201 | | -#else |
202 | | - return false; |
203 | | -#endif |
204 | | - } |
205 | | - static void getInfo(size_t *free_mem, size_t *used_mem); |
206 | | - static void destroy(); |
207 | | - ~MemoryHandler() { } |
208 | | - |
209 | | - private: |
210 | | - MemoryHandler() : using_pool_(false), initialized_(false) {} |
211 | | - static void Init(); |
212 | | - // static void Destroy(); |
213 | | -#ifndef CPU_ONLY |
214 | | - void allocate_memory(void **ptr, size_t size, cudaStream_t stream); |
215 | | - void free_memory(void *ptr, cudaStream_t stream); |
216 | | -#endif |
217 | | - DISABLE_COPY_AND_ASSIGN(MemoryHandler); |
218 | | - |
219 | | - bool using_pool_; |
220 | | - bool initialized_; |
221 | | - std::vector<int> gpus_; |
222 | | -}; |
223 | | - |
224 | | -class MemoryHandlerActivator { |
225 | | - public: |
226 | | - explicit MemoryHandlerActivator(const std::vector<int>& gpus) |
227 | | - : using_pool_(false) { |
228 | | - if (gpus.size() > 0) { |
229 | | - using_pool_ = true; |
230 | | - MemoryHandler::usePool(); |
231 | | - MemoryHandler::setGPUs(gpus); |
232 | | -#ifndef CPU_ONLY |
233 | | - void* temp; |
234 | | - MemoryHandler::mallocGPU(&temp, 4); |
235 | | - MemoryHandler::freeGPU(temp); |
236 | | -#endif |
237 | | - } |
238 | | - } |
239 | | - ~MemoryHandlerActivator() { |
240 | | - if (using_pool_) { |
241 | | - MemoryHandler::destroy(); |
242 | | - } |
243 | | - } |
244 | | - private: |
245 | | - int using_pool_; |
246 | | -}; |
247 | | - |
248 | 188 | } // namespace caffe |
249 | 189 |
|
250 | 190 | #endif // CAFFE_COMMON_HPP_ |
| 191 | + |
0 commit comments