Back to Blog
Sep 20, 2024
•By Swasthik Shetty•commit: e7192ab

Why 64-Byte Alignment Matters: Designing the Storage Core

Decoupling tensor storage from metadata and enforcing 64-byte cache line alignment.

Diagnostic Challenge

Standard Rust Vec<T> alignment is only 4 bytes for f32, causing AVX-512 unaligned load penalties on CPU.

Architectural Discovery

Using std::alloc::alloc with Layout::from_size_align(size, 64) guarantees single-cycle vector register loading.

Why 64-Byte Alignment Matters: Designing the Storage Core

2024-09-20 • By Swasthik Shetty •commit: e7192ab
What Broke

Standard Rust Vec<T> alignment is only 4 bytes for f32, causing AVX-512 unaligned load penalties on CPU.

What Was Learned

Using std::alloc::alloc with Layout::from_size_align(size, 64) guarantees single-cycle vector register loading.

When building a machine learning framework in Rust, the most common trap is wrapping a Vec<f32> in a struct. While simple, Vec<T> does not guarantee 64-byte alignment, meaning every SIMD instruction has to use unaligned load instructions (vmovups instead of vmovaps).

In Dark Forest, Storage<T, D> manages raw memory directly:

  • Guarantees 64-byte memory boundary alignment.
  • Enables direct conversion to CUDA pinned host memory.