Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::Compute::CudaDeviceMemoryResource Class Referenceexport

CUDA device memory resource for GPU-accessible memory allocation. More...

Inheritance diagram for Mila::Dnn::Compute::CudaDeviceMemoryResource:
Mila::Dnn::Compute::MemoryResource

Public Member Functions

 CudaDeviceMemoryResource (int device_id)
 Constructs CUDA managed memory resource with device ID.
Public Member Functions inherited from Mila::Dnn::Compute::MemoryResource
virtual ~MemoryResource ()=default
 Virtual destructor for proper cleanup of derived classes.

Static Public Attributes

static constexpr DeviceType device_type = DeviceType::Cuda
 Device type constant for CUDA memory resources.
static constexpr bool is_device_accessible = DeviceAccessible::is_device_accessible
 Indicates CUDA device memory is accessible from device code.
static constexpr bool is_host_accessible = false
 Indicates CUDA device memory is not accessible from host code.
Static Public Attributes inherited from Mila::Dnn::Compute::MemoryResource
static constexpr bool is_device_accessible = false
 Checks if the memory is accessible from device code.
static constexpr bool is_host_accessible = true
 Checks if the memory is accessible from host code.

Protected Member Functions

void * do_allocate (std::size_t bytes, std::size_t) override
 Allocates memory on the CUDA device.
void do_deallocate (void *ptr, std::size_t, std::size_t) override
 Deallocates CUDA device memory.
bool do_is_equal (const std::pmr::memory_resource &other) const noexcept override
 Compares CUDA memory resources for equality.

Detailed Description

CUDA device memory resource for GPU-accessible memory allocation.

Provides optimized CUDA device memory allocation with proper device binding through device context integration. Focuses purely on memory allocation responsibilities without tensor-specific operations or type conversions.

Constructor & Destructor Documentation

◆ CudaDeviceMemoryResource()

Mila::Dnn::Compute::CudaDeviceMemoryResource::CudaDeviceMemoryResource ( int device_id)
inlineexplicit

Constructs CUDA managed memory resource with device ID.

Parameters
device_idCUDA device ID (0, 1, 2, etc.)
Exceptions
std::invalid_argumentIf device_id is invalid

Member Function Documentation

◆ do_allocate()

void * Mila::Dnn::Compute::CudaDeviceMemoryResource::do_allocate ( std::size_t bytes,
std::size_t  )
inlineoverrideprotectedvirtual

Allocates memory on the CUDA device.

Ensures allocation occurs on the correct device by activating the device context before calling cudaMalloc. Provides detailed error information on allocation failure.

Parameters
bytesNumber of bytes to allocate The alignment argument is ignored: CUDA allocations are already suitably aligned.
Returns
Pointer to allocated device memory
Exceptions
CudaBadAllocIf allocation fails

Implements Mila::Dnn::Compute::MemoryResource.

◆ do_deallocate()

void Mila::Dnn::Compute::CudaDeviceMemoryResource::do_deallocate ( void * ptr,
std::size_t ,
std::size_t  )
inlineoverrideprotectedvirtual

Deallocates CUDA device memory.

Ensures deallocation occurs on the correct device and provides detailed error information if deallocation fails.

Parameters
ptrPointer to device memory to deallocate

The size and alignment arguments are unused (kept for the memory-resource interface) and therefore intentionally unnamed.

Implements Mila::Dnn::Compute::MemoryResource.

◆ do_is_equal()

bool Mila::Dnn::Compute::CudaDeviceMemoryResource::do_is_equal ( const std::pmr::memory_resource & other) const
inlineoverrideprotectedvirtualnoexcept

Compares CUDA memory resources for equality.

CUDA memory resources are equal if they are both CudaDeviceMemoryResource instances. Device binding is handled at the tensor level through device context management.

Parameters
otherThe other memory resource to compare with
Returns
true if both are CudaDeviceMemoryResource instances

Implements Mila::Dnn::Compute::MemoryResource.


The documentation for this class was generated from the following file:
  • Mila/Src/Dnn/Compute/Devices/Cuda/CudaDeviceMemoryResource.ixx