|
Mila 0.13.48
Deep Neural Network Library
|
Clean memory resource abstraction for device-specific memory allocation. More...


Public Member Functions | |
| virtual | ~MemoryResource ()=default |
| Virtual destructor for proper cleanup of derived classes. | |
Static Public Attributes | |
| 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 | |
| virtual void * | do_allocate (std::size_t bytes, std::size_t alignment) override=0 |
| Allocates memory with specified size and alignment. | |
| virtual void | do_deallocate (void *ptr, std::size_t bytes, std::size_t alignment) override=0 |
| Deallocates previously allocated memory. | |
| virtual bool | do_is_equal (const std::pmr::memory_resource &other) const noexcept override=0 |
| Compares this memory resource with another for equality. | |
Clean memory resource abstraction for device-specific memory allocation.
This class extends std::pmr::memory_resource with device-awareness while maintaining clear separation of concerns. Memory resources are responsible only for allocation, deallocation, and basic memory operations. Tensor-specific operations like type conversion and fill operations are handled by separate tensor operation classes.
Device-specific implementations (CPU, CUDA) override these methods with optimized implementations appropriate for their memory types and access patterns.
|
virtualdefault |
Virtual destructor for proper cleanup of derived classes.
|
overrideprotectedpure virtual |
Allocates memory with specified size and alignment.
Pure virtual function that must be implemented by derived classes to provide device-specific memory allocation. Implementation should handle device-specific allocation strategies and error conditions.
| bytes | Number of bytes to allocate |
| alignment | Memory alignment requirement |
| std::bad_alloc | If allocation fails |
Implemented in Mila::Dnn::Compute::CpuMemoryResource, Mila::Dnn::Compute::CudaDeviceMemoryResource, Mila::Dnn::Compute::CudaManagedMemoryResource, Mila::Dnn::Compute::CudaPinnedMemoryResource, Mila::Dnn::Compute::MetalMemoryResource, Mila::Dnn::Compute::TrackedMemoryResource, and Mila::Dnn::Compute::VulkanMemoryResource.
|
overrideprotectedpure virtual |
Deallocates previously allocated memory.
Pure virtual function that must be implemented by derived classes to provide device-specific memory deallocation. Implementation should handle proper cleanup and device synchronization if necessary.
| ptr | Pointer to memory to deallocate |
| bytes | Size of memory block (may be used for debugging/validation) |
| alignment | Alignment that was used during allocation |
Implemented in Mila::Dnn::Compute::CpuMemoryResource, Mila::Dnn::Compute::CudaDeviceMemoryResource, Mila::Dnn::Compute::CudaManagedMemoryResource, Mila::Dnn::Compute::CudaPinnedMemoryResource, Mila::Dnn::Compute::MetalMemoryResource, Mila::Dnn::Compute::TrackedMemoryResource, and Mila::Dnn::Compute::VulkanMemoryResource.
|
overrideprotectedpure virtualnoexcept |
Compares this memory resource with another for equality.
Two memory resources are equal if they can be used interchangeably for allocation and deallocation. Typically this means they are the same type and manage the same underlying memory pool or device.
| other | The other memory resource to compare with |
Implemented in Mila::Dnn::Compute::CpuMemoryResource, Mila::Dnn::Compute::CudaDeviceMemoryResource, Mila::Dnn::Compute::CudaManagedMemoryResource, Mila::Dnn::Compute::CudaPinnedMemoryResource, Mila::Dnn::Compute::MetalMemoryResource, Mila::Dnn::Compute::TrackedMemoryResource, and Mila::Dnn::Compute::VulkanMemoryResource.
|
staticconstexpr |
Checks if the memory is accessible from device code.
Derived classes should override this to reflect their accessibility characteristics.
|
staticconstexpr |
Checks if the memory is accessible from host code.
Derived classes should override this to reflect their accessibility characteristics.