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

CUDA pinned memory resource for fast host/device transfer memory. More...

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

Public Member Functions

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

Detailed Description

CUDA pinned memory resource for fast host/device transfer memory.

Provides CUDA pinned (page-locked) memory allocation that is accessible from host code but provides faster transfers to/from GPU devices. Focuses purely on memory allocation responsibilities without tensor-specific operations.

Constructor & Destructor Documentation

◆ CudaPinnedMemoryResource()

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

Constructs CUDA pinned 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::CudaPinnedMemoryResource::do_allocate ( std::size_t bytes,
std::size_t = alignof(std::max_align_t) )
inlineoverrideprotectedvirtual

Allocates CUDA pinned memory.

Uses cudaMallocHost to allocate page-locked memory that provides faster transfers between host and device while remaining host-accessible.

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

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

◆ do_deallocate()

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

Deallocates CUDA pinned memory.

Uses cudaFreeHost to properly release page-locked memory. Ensures operation occurs on the correct device.

Parameters
ptrPointer to pinned memory to deallocate The alignment argument is unused, and kept for interface compatibility.

The size argument is unused and therefore intentionally unnamed.

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

◆ do_is_equal()

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

Compares pinned memory resources for equality.

Pinned memory resources are equal if they are both CudaPinnedMemoryResource instances with the same device ID.

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

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


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