Skip to content

feat: AllocateAligned — per-allocation GPU-aligned sub-allocation - #1

Merged
kolkov merged 2 commits into
mainfrom
feat/aligned-allocation
Jul 27, 2026
Merged

feat: AllocateAligned — per-allocation GPU-aligned sub-allocation#1
kolkov merged 2 commits into
mainfrom
feat/aligned-allocation

Conversation

@kolkov

@kolkov kolkov commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • AllocateAligned(size, alignment uint32) for GPU-aligned sub-allocation
  • TLSF-style over-allocate: O(1), zero heap allocs, zero overhead when alignment <= 1
  • Supports all GPU alignment requirements: Vulkan (256), DX12 (4-65536), Metal (64-256)
  • SyncAllocator.AllocateAligned thread-safe wrapper

Details

Per-allocation alignment is a prerequisite for GPU integration (ADR-050 Phase 3). Every real GPU allocator (gpu-allocator, gpu-alloc, TLSF) uses per-allocation alignment. Upstream C++ OffsetAllocator and Rust offset-allocator don't have it — we're the first port to add it.

Implementation over-allocates by up to alignment - 1 bytes, then adjusts the returned offset. Free() works unchanged (uses Metadata node index, not Offset). Waste is <6% for the dominant 256-byte alignment case.

Test plan

  • 12 new tests: various alignments (4, 32, 64, 256, 512, 65536), multiple aligned allocations with overlap check, fast paths (alignment 0/1), alignment > size, non-power-of-2 panic, exhaustion, coalescing, sync, concurrent
  • 2 new benchmarks: AllocateAligned256 (~50ns/op), AllocateAligned1 (fast path)
  • FuzzAllocAligned: 2.5M+ executions, 0 failures, 97 interesting inputs
  • All 35 tests pass, 0 lint issues, 0 heap allocations
  • Cross-platform build: Windows, Linux, macOS

…R-001)

TLSF-style over-allocate approach: O(1), zero heap allocs, zero overhead
when alignment <= 1. Supports Vulkan (256), DX12 (4-65536), Metal (64-256).

- AllocateAligned(size, alignment) on Allocator and SyncAllocator
- 12 new tests (various alignments, coalescing, exhaustion, concurrency)
- 2 new benchmarks (~50ns/op, 0 allocs/op — same as Allocate)
- FuzzAllocAligned: 2.5M+ executions, 0 failures
- CHANGELOG, ROADMAP, README, AGENTS.md updated
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@kolkov
kolkov merged commit 021a224 into main Jul 27, 2026
10 checks passed
@kolkov
kolkov deleted the feat/aligned-allocation branch July 27, 2026 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant