Deepity
Ultra-fast, SIMD-accelerated Predictive Coding
Loading...
Searching...
No Matches
MemoryArena.h File Reference

A 64-byte-aligned bump-pointer allocator over a single heap-allocated block, used to pack every layer's beliefs/errors/ weights/scratch buffers into one contiguous region for cache locality (see the "Contiguous Arena Allocator" design note in the project README). Host-side counterpart to DeviceMemoryArena.h's CUDA version. More...

#include <cstddef>
#include <cstdlib>
#include <new>
#include <stdexcept>
#include <sys/mman.h>

Go to the source code of this file.

Classes

class  Deep::MemoryArena
 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...

Namespaces

namespace  Deep
 This file exists to provide both Tensor.h and IComputeBackend.h with device types without introducing circular dependencies.
namespace  Deep::detail

Functions

void * Deep::detail::AlignedAllocPortable (size_t alignment, size_t size)
 Allocates a block of memory aligned to alignment bytes, using whichever aligned-allocation API is actually reliable on the current platform (see the comment above for why this can't just be std::aligned_alloc everywhere).
void Deep::detail::AlignedFreePortable (void *ptr)
 Frees a block previously returned by AlignedAllocPortable().
void * Deep::detail::HugePageAllocPortable (size_t size, bool &succeeded)
 Attempts to allocate size bytes backed by huge pages. This is genuinely opt-in and best-effort: on Linux, requests Transparent Huge Pages via madvise(MADV_HUGEPAGE) on a normal anonymous mmap – this is a HINT to the kernel, not a guarantee, and requires zero system-level configuration (unlike explicit hugetlbfs, which needs pages pre-reserved via /proc/sys/vm/nr_hugepages). On Windows, requests MEM_LARGE_PAGES via VirtualAlloc, which requires the process to hold SeLockMemoryPrivilege – NOT granted by default, so this will typically fail unless explicitly configured by an administrator.
void Deep::detail::HugePageFreePortable (void *ptr, size_t size)
 Frees a block previously returned by HugePageAllocPortable() with succeeded=true.

Detailed Description

A 64-byte-aligned bump-pointer allocator over a single heap-allocated block, used to pack every layer's beliefs/errors/ weights/scratch buffers into one contiguous region for cache locality (see the "Contiguous Arena Allocator" design note in the project README). Host-side counterpart to DeviceMemoryArena.h's CUDA version.

Note
Individual chunks handed out by AllocateFloats() cannot be freed independently – the entire arena is released at once in the destructor, matching the bump-pointer/no-reclaim design used throughout this codebase's memory arenas.
Version
1.0
Date
2026-06-30
Author
Jack Rose