A 64-byte-aligned bump-pointer allocator over a single contiguous block of device memory, obtained via a supplied IComputeBackend (expected to be a CUDABackend in practice, though this class itself doesn't hard-require that specific type).
More...
#include <DeviceMemoryArena.h>
A 64-byte-aligned bump-pointer allocator over a single contiguous block of device memory, obtained via a supplied IComputeBackend (expected to be a CUDABackend in practice, though this class itself doesn't hard-require that specific type).
◆ DeviceMemoryArena() [1/2]
| Deep::DeviceMemoryArena::DeviceMemoryArena |
( |
IComputeBackend * | backend, |
|
|
size_t | total_floats ) |
|
inline |
Allocates a single 64-byte-aligned device buffer large enough to hold total_floats floats, rounded up to the nearest 64-byte boundary.
- Parameters
-
| backend | The backend to allocate from (and later free through). Must outlive this DeviceMemoryArena. Passing a CPUBackend here would allocate host memory under a class named "device" – that's a caller contract, not something this class checks at runtime, mirroring Tensor's own backend/device pairing contract. |
| total_floats | Total number of floats this arena can hand out across all future AllocateFloats() calls combined. |
- Exceptions
-
| std::bad_alloc | if the underlying allocation fails. |
◆ ~DeviceMemoryArena()
| Deep::DeviceMemoryArena::~DeviceMemoryArena |
( |
| ) |
|
|
inline |
Frees the underlying device buffer via the same backend it was allocated from.
◆ DeviceMemoryArena() [2/2]
| Deep::DeviceMemoryArena::DeviceMemoryArena |
( |
const DeviceMemoryArena & | | ) |
|
|
delete |
Deleted: DeviceMemoryArena owns a single device allocation, so copying would risk a double-free.
◆ AllocateFloats()
| float * Deep::DeviceMemoryArena::AllocateFloats |
( |
size_t | num_floats | ) |
|
|
inline |
Allocates a 64-byte aligned chunk of floats from the arena.
- Parameters
-
| num_floats | Number of floats to allocate from the arena. The actual reservation is rounded up to the nearest 64-byte boundary, matching MemoryArena's own guarantee (the original version of this class had no such rounding at all). |
- Returns
- Pointer to the start of the allocated chunk, valid for the lifetime of this DeviceMemoryArena. 64-byte aligned.
- Exceptions
-
| std::runtime_error | if the requested allocation would exceed the arena's total capacity – the original version of this class had no bounds checking at all. |
- Warning
- Individual chunks are never freed independently; the entire arena is released at once in the destructor.
◆ GetCapacityBytes()
| size_t Deep::DeviceMemoryArena::GetCapacityBytes |
( |
| ) |
const |
|
inline |
Returns the arena's total capacity.
◆ GetUsedBytes()
| size_t Deep::DeviceMemoryArena::GetUsedBytes |
( |
| ) |
const |
|
inline |
Returns how many bytes have been allocated from the arena so far.
◆ operator=()
Deleted: DeviceMemoryArena owns a single device allocation, so copy-assignment would risk a double-free.
The documentation for this class was generated from the following file: