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

CPU memory resource for host-accessible memory allocation. More...

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

Public Member Functions

 CpuMemoryResource (int device_id=0)
 Constructs CPU memory resource.
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::Cpu
static constexpr bool is_device_accessible = false
 Indicates CPU memory is not accessible from device code.
static constexpr bool is_host_accessible = HostAccessible::is_host_accessible
 Indicates CPU 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) override
 Allocates aligned CPU memory.
void do_deallocate (void *ptr, std::size_t, std::size_t) override
 Deallocates CPU memory using platform-specific functions.
bool do_is_equal (const std::pmr::memory_resource &other) const noexcept override
 Compares CPU memory resources for equality.

Detailed Description

CPU memory resource for host-accessible memory allocation.

Provides optimized CPU memory allocation with proper alignment support for tensor data. CPU memory allocation doesn't require device selection, so the device_id parameter is unused but maintained for interface consistency with other memory resource types.

Constructor & Destructor Documentation

◆ CpuMemoryResource()

Mila::Dnn::Compute::CpuMemoryResource::CpuMemoryResource ( int device_id = 0)
inlineexplicit

Constructs CPU memory resource.

Parameters
device_idDevice identifier (unused for CPU, maintained for interface consistency)
Note
CPU memory allocation doesn't require device selection
Parameter is kept for consistency with CUDA memory resources

Member Function Documentation

◆ do_allocate()

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

Allocates aligned CPU memory.

Uses platform-specific aligned allocation functions to ensure proper memory alignment for optimal CPU performance and SIMD operations.

Parameters
bytesNumber of bytes to allocate
alignmentMemory alignment requirement
Returns
Pointer to allocated memory
Exceptions
std::bad_allocIf allocation fails

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

◆ do_deallocate()

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

Deallocates CPU memory using platform-specific functions.

Properly releases memory allocated with platform-specific aligned allocation functions.

Parameters
ptrPointer to 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::CpuMemoryResource::do_is_equal ( const std::pmr::memory_resource & other) const
inlineoverrideprotectedvirtualnoexcept

Compares CPU memory resources for equality.

CPU memory resources are equal if they are both CpuMemoryResource instances, since they all manage the same underlying host memory pool.

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

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


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