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

CUDA managed memory resource for unified host/device accessible memory. More...

Inheritance diagram for Mila::Dnn::Compute::CudaManagedMemoryResource:
Collaboration diagram for Mila::Dnn::Compute::CudaManagedMemoryResource:

Public Member Functions

 CudaManagedMemoryResource (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
static constexpr bool is_device_accessible = DeviceAccessible::is_device_accessible
 Indicates managed memory is accessible from device code.
static constexpr bool is_host_accessible = HostAccessible::is_host_accessible
 Indicates managed memory is 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 alignment=alignof(std::max_align_t)) override
 Allocates CUDA managed memory.
void do_deallocate (void *ptr, std::size_t, std::size_t alignment=alignof(std::max_align_t)) override
 Deallocates CUDA managed memory.
bool do_is_equal (const std::pmr::memory_resource &other) const noexcept override
 Compares managed memory resources for equality.

Private Attributes

int device_id_ {-1}

Detailed Description

CUDA managed memory resource for unified host/device accessible memory.

Provides CUDA managed (unified) memory allocation that is accessible from both host and device code with automatic migration. Focuses purely on memory allocation responsibilities without tensor-specific operations or type conversions.

Constructor & Destructor Documentation

◆ CudaManagedMemoryResource()

Mila::Dnn::Compute::CudaManagedMemoryResource::CudaManagedMemoryResource ( 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
Here is the caller graph for this function:

Member Function Documentation

◆ do_allocate()

void * Mila::Dnn::Compute::CudaManagedMemoryResource::do_allocate ( std::size_t bytes,
std::size_t alignment = alignof(std::max_align_t) )
inlineoverrideprotectedvirtual

Allocates CUDA managed memory.

Uses cudaMallocManaged to allocate unified memory that can be accessed from both host and device code with automatic migration.

Parameters
bytesNumber of bytes to allocate
alignmentMemory alignment requirement (ignored by CUDA)
Returns
Pointer to allocated managed memory
Exceptions
std::bad_allocIf allocation fails

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

Here is the call graph for this function:

◆ do_deallocate()

void Mila::Dnn::Compute::CudaManagedMemoryResource::do_deallocate ( void * ptr,
std::size_t ,
std::size_t alignment = alignof(std::max_align_t) )
inlineoverrideprotectedvirtual

Deallocates CUDA managed memory.

Uses cudaFree to release managed memory. Ensures operation occurs on the correct device.

Parameters
ptrPointer to managed memory to deallocate
bytesSize of memory block (unused, kept for interface compatibility)
alignmentAlignment used during allocation (unused, kept for interface compatibility)

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

Here is the call graph for this function:

◆ do_is_equal()

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

Compares managed memory resources for equality.

Managed memory resources are equal if they are both CudaManagedMemoryResource instances with the same device ID.

Parameters
otherThe other memory resource to compare with
Returns
true if both are CudaManagedMemoryResource with same device ID

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

Here is the call graph for this function:

Member Data Documentation

◆ device_id_

int Mila::Dnn::Compute::CudaManagedMemoryResource::device_id_ {-1}
private

◆ device_type

DeviceType Mila::Dnn::Compute::CudaManagedMemoryResource::device_type = DeviceType::Cuda
staticconstexpr

◆ is_device_accessible

bool Mila::Dnn::Compute::CudaManagedMemoryResource::is_device_accessible = DeviceAccessible::is_device_accessible
staticconstexpr

Indicates managed memory is accessible from device code.

◆ is_host_accessible

bool Mila::Dnn::Compute::CudaManagedMemoryResource::is_host_accessible = HostAccessible::is_host_accessible
staticconstexpr

Indicates managed memory is accessible from host code.


The documentation for this class was generated from the following file: