Mila
Deep Neural Network Library
|
A class that represents a dynamically-determined memory resource. More...
Public Member Functions | |
DynamicMemoryResource (Compute::DeviceType device_type=Compute::DeviceType::Cuda) | |
Constructs a DynamicMemoryResource based on the device type. | |
bool | is_device_accessible () const noexcept |
Checks if the memory resource is device-accessible. | |
bool | is_host_accessible () const noexcept |
Checks if the memory resource is host-accessible. | |
Protected Member Functions | |
void * | do_allocate (std::size_t size, std::size_t alignment) override |
Allocates memory of the specified size with the given alignment. | |
void | do_deallocate (void *ptr, std::size_t size, std::size_t alignment) override |
Deallocates previously allocated memory. | |
bool | do_is_equal (const std::pmr::memory_resource &other) const noexcept override |
Checks if this memory resource is equal to another memory resource. | |
Private Attributes | |
std::variant< Compute::CpuMemoryResource, Compute::CudaMemoryResource > | resource_variant_ |
A class that represents a dynamically-determined memory resource.
This class serves as an adapter between the runtime selection of memory resources (via DeviceContext) and the compile-time requirements of the Tensor class, which requires a specific memory resource type rather than a variant.
|
inlineexplicit |
Constructs a DynamicMemoryResource based on the device type.
device_type | The type of device to create the memory resource for. |
|
inlineoverrideprotected |
Allocates memory of the specified size with the given alignment.
This delegates to the appropriate memory resource based on the device type.
size | The size in bytes to allocate. |
alignment | The alignment requirement for the allocation. |
|
inlineoverrideprotected |
Deallocates previously allocated memory.
This delegates to the appropriate memory resource based on the device type.
ptr | Pointer to the memory to deallocate. |
size | The size in bytes of the allocation. |
alignment | The alignment of the allocation. |
|
inlineoverrideprotectednoexcept |
Checks if this memory resource is equal to another memory resource.
other | The other memory resource to compare with. |
|
inlinenoexcept |
Checks if the memory resource is device-accessible.
|
inlinenoexcept |
Checks if the memory resource is host-accessible.
|
private |