|
Mila
Deep Neural Network Library
|
CUDA execution context specialization. More...
Public Member Functions | |
| CudaExecutionContext (const CudaExecutionContext &)=delete | |
| CudaExecutionContext (CudaExecutionContext &&)=delete | |
| CudaExecutionContext (DeviceId device_id) | |
| Constructs CUDA execution context for a specific device. | |
| ~CudaExecutionContext () | |
| Destructor with proper CUDA resource cleanup. | |
| cublasLtHandle_t | getCublasLtHandle () const |
| Gets a cuBLASLt handle for this context. | |
| void * | getCublasLtWorkspace () const noexcept |
| Gets the cuBLASLt workspace buffer. | |
| size_t | getCublasLtWorkspaceSize () const noexcept |
| Gets the cuBLASLt workspace buffer size in bytes. | |
| curandGenerator_t | getCurandGenerator () const |
| Gets the cuRAND generator bound to this context's stream. | |
| DeviceId | getDeviceId () const noexcept override |
| Gets the device identifier. | |
| void * | getDeviceScratchBuffer (size_t required_bytes) const |
| Gets the device scratch buffer shared by operations during forward passes. | |
| void * | getLoadStagingBuffer (size_t required_bytes) const |
| Gets or grows the device buffer a load fits full-precision weights through. | |
| void * | getPinnedStagingBuffer (size_t required_bytes) const |
| Gets or grows the pinned host staging buffer for Host->Device transfers. | |
| cudaStream_t | getStream () const noexcept |
| Gets the CUDA stream for asynchronous operations. | |
| CudaExecutionContext & | operator= (const CudaExecutionContext &)=delete |
| CudaExecutionContext & | operator= (CudaExecutionContext &&)=delete |
| void | releaseLoadStaging () noexcept override |
| Free the device buffer a load staged full-precision weights through. | |
| void | reserveScratch (std::size_t bytes) override |
| Allocate the forward scratch buffer at exactly the size a network reports. | |
| void | synchronize () override |
| Synchronizes the CUDA stream. | |
| Public Member Functions inherited from Mila::Dnn::Compute::IExecutionContext | |
| const ActivationObserver & | getActivationObserver () const noexcept |
| bool | hasActivationObserver () const noexcept |
| void | setActivationObserver (ActivationObserver observer) |
| Install the observer components publish their activations to. | |
Static Public Member Functions | |
| static constexpr size_t | getLoadStagingLimitBytes () noexcept |
| Largest staging request one fit of full-precision weights may make, in bytes. | |
CUDA execution context specialization.
Manages CUDA execution resources including streams and library handles. Each context owns an independent CUDA stream and owns the library handles used by callers bound to this context's stream.
Thread Safety:
|
inlineexplicit |
Constructs CUDA execution context for a specific device.
Creates an independent CUDA stream.
| device_id | CUDA device identifier. |
| std::invalid_argument | If device_id type is not Cuda. |
| std::runtime_error | If CUDA stream creation fails. |
|
inlinenodiscard |
Gets a cuBLASLt handle for this context.
Created lazily and owned by this context.
| std::runtime_error | If handle creation fails. |
|
inlinenodiscardnoexcept |
Gets the cuBLASLt workspace buffer.
Shared scratch memory for cuBLASLt algorithm execution. Allocated once at context creation, valid for the lifetime of this context. Size is kCublasLtWorkspaceSize bytes.
|
inlinenodiscardnoexcept |
Gets the cuBLASLt workspace buffer size in bytes.
|
inlinenodiscard |
Gets the cuRAND generator bound to this context's stream.
Created lazily, seeded from Core::RandomGenerator, and bound to this context's stream. Reuse across calls avoids per-call creation overhead.
| std::runtime_error | If generator creation or seeding fails. |
|
inlinenodiscardoverridevirtualnoexcept |
Gets the device identifier.
Implements Mila::Dnn::Compute::IExecutionContext.
|
inlinenodiscard |
Gets the device scratch buffer shared by operations during forward passes.
Used by operations that need a temporary device buffer during forward passes (e.g. FP8->BF16 weight dequantization before a cuBLASLt GEMM). Because all operations on this context share a single stream, the buffer can be safely reused across sequential ops – each op finishes before the next one writes to the buffer.
Once a network has reserved it, a request larger than the reservation throws: the reservation is the footprint's prediction, and exceeding it is a defect in that prediction. Before any reservation the buffer grows on demand. Freed in releaseResources().
| required_bytes | Minimum number of bytes required. |
| std::logic_error | If the request exceeds a reservation. |
| std::runtime_error | If allocation fails. |
|
inlinenodiscard |
Gets or grows the device buffer a load fits full-precision weights through.
Separate from the forward scratch: it lives only while a load runs, and the load frees it through releaseLoadStaging() when it returns. Grown on demand in between; the returned pointer is invalidated by a later call with a larger request.
| required_bytes | Minimum number of bytes required. |
| std::runtime_error | If allocation fails. |
|
inlinestaticnodiscardconstexprnoexcept |
Largest staging request one fit of full-precision weights may make, in bytes.
A tensor larger than this is fitted in row blocks that fit, which costs more copies and no more memory.
|
inlinenodiscard |
Gets or grows the pinned host staging buffer for Host->Device transfers.
Page-locked via cudaHostAlloc so cudaMemcpyAsync from it to device memory is a direct DMA transfer. Grown on demand, never shrunk. Freed in releaseResources().
| required_bytes | Minimum number of bytes required. |
| std::runtime_error | If allocation fails. |
|
inlinenodiscardnoexcept |
Gets the CUDA stream for asynchronous operations.
|
inlineoverridevirtualnoexcept |
Free the device buffer a load staged full-precision weights through.
A load that fits full-precision weights on the device stages each tensor through one buffer, which is needed only until the last tensor has landed. The model load calls this when it returns, so the buffer is not held for the model's lifetime. Safe to call when nothing was staged; a no-op for contexts that stage nothing.
Reimplemented from Mila::Dnn::Compute::IExecutionContext.
|
inlineoverridevirtual |
Allocate the forward scratch buffer at exactly the size a network reports.
| bytes | The largest scratch request any operation on this context makes. |
| std::runtime_error | If allocation fails. |
Reimplemented from Mila::Dnn::Compute::IExecutionContext.
|
inlineoverridevirtual |
Synchronizes the CUDA stream.
Blocks until all operations submitted to this context's stream complete.
| std::runtime_error | If stream synchronization fails. |
Implements Mila::Dnn::Compute::IExecutionContext.