Files
metal2vulkan/docs
Anees Iqbal c034220175 Private memory past the 16 KiB floor lives in the runtime's arena, one slot an invocation; a dispatch past its budget splits
A kernel whose private arrays (indexed at run time) passed the translator's 16 KiB floor was
refused as Unsupported{PrivateMemory}. The app's 780M library holds 7 such kernels (19,792 to
34,736 bytes a thread), and the Iris walk refused one at 28,704. Metal holds that memory itself.
The runtime now holds it in device memory it owns.

Translator, under the identity domains only (the default domains' binder supplies no such
memory, so they refuse as before):
- memory::plan::private_memory: a kernel with no call stack whose private bytes pass the floor
  places every alloca it indexes at run time in its private arena, and marks the arena
  ArenaLayout::device. The arena then leaves the private bytes. The kernel's own bytes decide;
  no device fact does.
- Such an arena has no Private variable. Its words are PhysicalStorageBuffer words (Aligned 4)
  at the invocation's slot. The slot is PushField::PrivateArenaAddress (a u64) plus
  i * slot_bytes, with i = ((wz*ny + wy)*nx + wx)*n + LocalInvocationIndex in 32 bits. It is
  computed once in the entry block (dispatch::KernelDecl::arena_slot, Invariant::ArenaSlot).
  RuntimeFact::PrivateArena { slot_bytes } states the slot: the arena's bytes rounded up to 16.
- A tile kernel's arena past the floor stays refused (PrivateMemory). A slot past u32 is
  LimitExceeded(PrivateArenaBytes).

Runtime (crate::arena):
- The arena is one Private pool block, never zeroed: Metal's private memory is undefined until
  the thread writes it. The device keeps a Weak to the last block. Each command buffer that
  dispatches into a block keeps it (keep_block), and a dispatch that needs no more than a block
  still kept takes it again.
- A dispatch's slots take at most 1/16 of the largest DEVICE_LOCAL heap, capped at the longest
  block, or one threadgroup's slots where those are more. A dispatch past that budget runs in
  pieces of whole threadgroups through the existing split loop, each piece's DispatchRegion
  carrying its first threadgroup. There is one split form; vkCmdDispatchBase is not used.
- A barrier (the encoder's owed barrier, so it merges with a hazard barrier) comes before each
  arena piece, except the first piece in a block the dispatch took new. Dispatches of kernels
  without an arena take no new barrier.
- An indirect dispatch of an arena kernel is Gap::IndirectPrivateArena: its counts are the
  GPU's, so the runtime can neither size the arena nor split it.
- Metrics::private_arena_dispatches, private_arena_pieces and private_arena_blocks count the
  path, and private_arena_allocations counts the block takes.
- The budget a device test splits with is Core::arena_budget's test override (cfg(test) with
  m2v_gpu or m2v_cpu_icd), never a DeviceOptions field.

Docs: docs/API.md (the field, the fact, the slot formula), the runtime README (Compute
encoders: the arena, its budget, its order, the indirect gap), docs/REFUSALS.md (regenerated),
api_signatures.tsv (blessed).
SEMANTICS_VERSION 2244 -> 2245, ARTIFACT_FORMAT_VERSION 581 -> 582, RUNTIME_VERSION 2549 -> 2550.

Tests:
- engine_private_memory's
  a_kernel_past_the_floor_keeps_its_private_memory_in_the_runtimes_memory_under_identity:
  7176, 9216 and 51,200 words on the 780M's, the Iris Xe's and an RTX 50's profiles. Each compiles,
  passes L3, pushes the address, states the fact, holds 0 private bytes and records no note.
  The default domains refuse as before.
- rt private_arena's
  every_device_holds_private_memory_past_the_floor_in_its_arena_split_or_whole: 28,704, 36,864
  and 204,800 bytes a thread, 8 groups of 64, under the device's budget (1 piece) and a test
  budget (4 and 8 pieces). Every answer matches a CPU reference. It counts 2 arena dispatches,
  their pieces, and exactly 2*pieces - (blocks taken) barriers beyond a plain command buffer's.
  Four plain dispatches take the barriers one does.

The kernel interface declares the arena's slot (Interface::private_arena, the slot bytes of
RuntimeFact::PrivateArena); the compute test's interface sets it to None.
2026-11-20 22:37:06 -08:00
..