From a0d80754c54c0e5f26085ff9274a87670a58fdb4 Mon Sep 17 00:00:00 2001 From: Huihuang Zheng Date: Tue, 17 Sep 2019 12:10:12 +0800 Subject: [PATCH] Add comments for CUDA Device Context Allocator related stuff (#19809) --- .../memory/allocation/cuda_device_context_allocation.h | 6 ++++++ .../memory/allocation/cuda_device_context_allocator.h | 6 ++++++ .../memory/allocation/cuda_device_context_allocator_pool.h | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/paddle/fluid/memory/allocation/cuda_device_context_allocation.h b/paddle/fluid/memory/allocation/cuda_device_context_allocation.h index cf0d8792d0..02011f88c1 100644 --- a/paddle/fluid/memory/allocation/cuda_device_context_allocation.h +++ b/paddle/fluid/memory/allocation/cuda_device_context_allocation.h @@ -20,6 +20,12 @@ namespace paddle { namespace memory { namespace allocation { +/** + * CUDADeviceContextAllocation is a wrapper of the underbeneath allocation. + * CUDADeviceContextAllocation adds a CUDA stream callback for the underbeneath + * allocation so that CUDADeviceContextAllocation can be used in a CUDA stream + * which deletes allocation in the callback. + */ class CUDADeviceContextAllocation : public Allocation { public: explicit CUDADeviceContextAllocation(AllocationPtr allocation); diff --git a/paddle/fluid/memory/allocation/cuda_device_context_allocator.h b/paddle/fluid/memory/allocation/cuda_device_context_allocator.h index e27cb72af6..34bd1176db 100644 --- a/paddle/fluid/memory/allocation/cuda_device_context_allocator.h +++ b/paddle/fluid/memory/allocation/cuda_device_context_allocator.h @@ -24,6 +24,12 @@ namespace paddle { namespace memory { namespace allocation { +/** + * CUDADeviceContextAllocator will allocate a CUDADeviceContextAllocation + * after waiting for a self-created event on the default stream. It does so to + * let the non-default stream be able to allocate GPU memory which will be + * released by stream callback + */ class CUDADeviceContextAllocator : public Allocator { public: explicit CUDADeviceContextAllocator(platform::CUDAPlace place, diff --git a/paddle/fluid/memory/allocation/cuda_device_context_allocator_pool.h b/paddle/fluid/memory/allocation/cuda_device_context_allocator_pool.h index 03b7c34f71..b423f226d9 100644 --- a/paddle/fluid/memory/allocation/cuda_device_context_allocator_pool.h +++ b/paddle/fluid/memory/allocation/cuda_device_context_allocator_pool.h @@ -24,6 +24,13 @@ namespace paddle { namespace memory { namespace allocation { +/** + * CUDADeviceContextAllocatorPool is a singletion stores mapping from + * CUDAPlace(s) to std::shared_ptr. When a + * CUDADeviceContext's compute stream isn't default stream, it can call this + * class to allocate GPU memory which will be released by a callback after + * stream execution. + */ class CUDADeviceContextAllocatorPool { public: static CUDADeviceContextAllocatorPool &Instance(); -- GitLab