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

A 64-byte-aligned bump-pointer allocator over a single contiguous block of host memory. Every chunk handed out via AllocateFloats() is itself 64-byte aligned, satisfying this codebase's strict alignment requirement for AVX2/AVX-512 loads. More...

#include <MemoryArena.h>

Public Member Functions

 MemoryArena (size_t total_floats, bool use_huge_pages=false)
 Allocates a single 64-byte-aligned buffer large enough to hold total_floats floats, rounded up to the nearest 64-byte boundary.
 ~MemoryArena ()
 Frees the underlying allocation, via whichever deallocator matches the allocator actually used (see used_huge_pages).
 MemoryArena (const MemoryArena &)=delete
 Deleted: MemoryArena owns a single aligned allocation, so copying would risk a double-free.
MemoryArena & operator= (const MemoryArena &)=delete
 Deleted: MemoryArena owns a single aligned 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.
bool UsedHugePages () const
 Returns whether this arena's memory is actually huge-page-backed. Since huge pages are requested on a best-effort basis, this can be false even if use_huge_pages was passed to the constructor, if the request wasn't honored (system lacks configuration/privilege, or the allocation call failed) and the arena silently fell back to the standard aligned allocator instead.

Detailed Description

A 64-byte-aligned bump-pointer allocator over a single contiguous block of host memory. Every chunk handed out via AllocateFloats() is itself 64-byte aligned, satisfying this codebase's strict alignment requirement for AVX2/AVX-512 loads.

Constructor & Destructor Documentation

◆ MemoryArena() [1/2]

Deep::MemoryArena::MemoryArena ( size_t total_floats,
bool use_huge_pages = false )
inlineexplicit

Allocates a single 64-byte-aligned buffer large enough to hold total_floats floats, rounded up to the nearest 64-byte boundary.

Parameters
total_floatsTotal number of floats this arena can hand out across all future AllocateFloats() calls combined.
use_huge_pagesOpt-in, best-effort request for huge-page-backed memory (see HugePageAllocPortable() for the platform-specific caveats). Defaults to false, preserving existing behavior exactly for anyone not explicitly opting in. Falls back safely to the standard aligned allocator if the request isn't honored – this never causes a hard failure on its own.
Exceptions
std::bad_allocif the underlying allocation fails (including the fallback path, if huge pages were requested but unavailable).

◆ ~MemoryArena()

Deep::MemoryArena::~MemoryArena ( )
inline

Frees the underlying allocation, via whichever deallocator matches the allocator actually used (see used_huge_pages).

◆ MemoryArena() [2/2]

Deep::MemoryArena::MemoryArena ( const MemoryArena & )
delete

Deleted: MemoryArena owns a single aligned allocation, so copying would risk a double-free.

Member Function Documentation

◆ AllocateFloats()

float * Deep::MemoryArena::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, so the returned chunk may have more usable capacity than requested.
Returns
Pointer to the start of the allocated chunk, valid for the lifetime of this MemoryArena. 64-byte aligned.
Exceptions
std::runtime_errorif the requested allocation would exceed the arena's total capacity.
Warning
Individual chunks are never freed independently; the entire arena is released at once in the destructor.

◆ GetCapacityBytes()

size_t Deep::MemoryArena::GetCapacityBytes ( ) const
inline

Returns the arena's total capacity.

Returns
The capacity, in bytes, rounded up to a multiple of 64.

◆ GetUsedBytes()

size_t Deep::MemoryArena::GetUsedBytes ( ) const
inline

Returns how many bytes have been allocated from the arena so far.

Returns
The current offset, in bytes.

◆ operator=()

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

Deleted: MemoryArena owns a single aligned allocation, so copy-assignment would risk a double-free.

◆ UsedHugePages()

bool Deep::MemoryArena::UsedHugePages ( ) const
inline

Returns whether this arena's memory is actually huge-page-backed. Since huge pages are requested on a best-effort basis, this can be false even if use_huge_pages was passed to the constructor, if the request wasn't honored (system lacks configuration/privilege, or the allocation call failed) and the arena silently fell back to the standard aligned allocator instead.


The documentation for this class was generated from the following file: