Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
Loading...
Searching...
No Matches
Deep::DeviceMemoryArena Class Reference

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>

Public Member Functions

 DeviceMemoryArena (IComputeBackend *backend, size_t total_floats)
 Allocates a single 64-byte-aligned device buffer large enough to hold total_floats floats, rounded up to the nearest 64-byte boundary.
 ~DeviceMemoryArena ()
 Frees the underlying device buffer via the same backend it was allocated from.
 DeviceMemoryArena (const DeviceMemoryArena &)=delete
 Deleted: DeviceMemoryArena owns a single device allocation, so copying would risk a double-free.
DeviceMemoryArena & operator= (const DeviceMemoryArena &)=delete
 Deleted: DeviceMemoryArena owns a single device allocation, so copy-assignment would risk a double-free.
float * AllocateFloats (size_t num_floats)
 Allocates a 64-byte aligned chunk of floats from the arena.
size_t GetUsedBytes () const
 Returns how many bytes have been allocated from the arena so far.
size_t GetCapacityBytes () const
 Returns the arena's total capacity.

Detailed Description

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).

Constructor & Destructor Documentation

◆ 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
backendThe 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_floatsTotal number of floats this arena can hand out across all future AllocateFloats() calls combined.
Exceptions
std::bad_allocif 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.

Member Function Documentation

◆ AllocateFloats()

float * Deep::DeviceMemoryArena::AllocateFloats ( size_t num_floats)
inline

Allocates a 64-byte aligned chunk of floats from the arena.

Parameters
num_floatsNumber 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_errorif 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=()

DeviceMemoryArena & Deep::DeviceMemoryArena::operator= ( const DeviceMemoryArena & )
delete

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: