提交 ddfa6cf0 编写于 作者: L liaogang

FIX: remove boost from memory folder

上级 adf8c95b
...@@ -32,7 +32,22 @@ detail::BuddyAllocator* GetCPUBuddyAllocator() { ...@@ -32,7 +32,22 @@ detail::BuddyAllocator* GetCPUBuddyAllocator() {
return a; return a;
} }
#ifndef PADDLE_ONLY_CPU // The following code are for CUDA. template <>
void* Alloc<platform::CPUPlace>(platform::CPUPlace place, size_t size) {
return GetCPUBuddyAllocator()->Alloc(size);
}
template <>
void Free<platform::CPUPlace>(platform::CPUPlace place, void* p) {
GetCPUBuddyAllocator()->Free(p);
}
template <>
size_t Used<platform::CPUPlace>(platform::CPUPlace place) {
return GetCPUBuddyAllocator()->Used();
}
#ifndef PADDLE_ONLY_CPU
detail::BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) { detail::BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) {
static detail::BuddyAllocator** as = NULL; static detail::BuddyAllocator** as = NULL;
...@@ -49,41 +64,22 @@ detail::BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) { ...@@ -49,41 +64,22 @@ detail::BuddyAllocator* GetGPUBuddyAllocator(int gpu_id) {
return as[gpu_id]; return as[gpu_id];
} }
#endif // PADDLE_ONLY_CPU template <>
void* Alloc<platform::GPUPlace>(platform::GPUPlace place, size_t size) {
return GetGPUBuddyAllocator(place.device)->Alloc(size);
}
void* Alloc(platform::Place pl, size_t size) { template <>
#ifndef PADDLE_ONLY_CPU void Free<platform::GPUPlace>(platform::GPUPlace place, void* p) {
if (paddle::platform::is_gpu_place(pl)) { GetGPUBuddyAllocator(place.device)->Free(p);
size_t gpu_id = boost::get<platform::GPUPlace>(pl).device;
return GetGPUBuddyAllocator(gpu_id)->Alloc(size);
}
#endif // PADDLE_ONLY_CPU
PADDLE_ASSERT(paddle::platform::is_cpu_place(pl));
return GetCPUBuddyAllocator()->Alloc(size);
} }
void Free(paddle::platform::Place pl, void* p) { template <>
#ifndef PADDLE_ONLY_CPU size_t Used<platform::GPUPlace>(platform::GPUPlace place) {
if (paddle::platform::is_gpu_place(pl)) { return GetGPUBuddyAllocator(place.device)->Used();
size_t gpu_id = boost::get<platform::GPUPlace>(pl).device;
GetGPUBuddyAllocator(gpu_id)->Free(p);
return;
}
#endif // PADDLE_ONLY_CPU
PADDLE_ASSERT(paddle::platform::is_cpu_place(pl));
GetCPUBuddyAllocator()->Free(p);
} }
size_t Used(paddle::platform::Place pl) {
#ifndef PADDLE_ONLY_CPU
if (paddle::platform::is_gpu_place(pl)) {
size_t gpu_id = boost::get<platform::GPUPlace>(pl).device;
return GetGPUBuddyAllocator(gpu_id)->Used();
}
#endif // PADDLE_ONLY_CPU #endif // PADDLE_ONLY_CPU
PADDLE_ASSERT(paddle::platform::is_cpu_place(pl));
return GetCPUBuddyAllocator()->Used();
}
} // namespace memory } // namespace memory
} // namespace paddle } // namespace paddle
...@@ -19,9 +19,14 @@ limitations under the License. */ ...@@ -19,9 +19,14 @@ limitations under the License. */
namespace paddle { namespace paddle {
namespace memory { namespace memory {
void* Alloc(paddle::platform::Place, size_t); template <class Place>
void Free(paddle::platform::Place, void*); void* Alloc(Place, size_t);
size_t Used(paddle::platform::Place);
template <class Place>
void Free(Place, void*);
template <class Place>
size_t Used(Place);
} // namespace memory } // namespace memory
} // namespace paddle } // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册