Files
metal2vulkan/docs
Anees Iqbal 3625b90721 SEMANTICS 2121 / RUNTIME 2331: A kernel's unit-axes variant, taken once made, never waited for
A kernel's unit-axes variant: the translator and the binding plan

In a threadgroup of one thread along an axis (Metal's threads_per_threadgroup 1
there), every thread's thread_position_in_threadgroup on that axis is 0 and its
thread_position_in_grid is its threadgroup's position, partial threadgroups
included. A kernel whose emulated simdgroups are walked predicated only because
such a position steers a synchronization (a simdgroup sum in a loop whose trip
count reads gid.y, the shape of a depthwise convolution dispatched in 8x1x16
threadgroups) pays the predicated walk's live flags and votes for nothing.

- lower::simd::uniform tracks per-lane masks for vectors of up to 8 lanes, and
  takes the lanes of thread_position_in_threadgroup and thread_position_in_grid
  on the unit axes LoweringInputs::unit_axes names as uniform.
- A kernel walked predicated (divergent::barriers, workgroup::check) states
  RuntimeFact::UnitAxes { axes: 0, relief }: bit m-1 for each mask m of axes
  under which fewer of its synchronizing blocks stay divergent (one analysis
  for all three axes, then the six others only where that one relieves).
- VariantKey::unit_axes compiles the variant; its module states
  UnitAxes { axes, relief: 0 }.
- BindingPlan::unit_axes_variant offers the variant to a dispatch whose
  threadgroups have one thread along relieving axes, where the plan's own
  variant runs it; the variant's plan sends any other dispatch back
  (dispatch_variant, NeedsVariant).

SEMANTICS_VERSION 2121: a predicated kernel's artifact states a new fact.
No new Degradation kind.

Test: engine_simd_unit_axes (lavapipe's profile, CPU interpreter, 8/16/32
lanes): predicated without the variant, unpredicated with it, Metal's words
in both; the variant traps at two threads along y (Vulkan's barrier rule), unit
x relieves nothing, and a kernel steered by x is offered no variant for unit y.

The runtime takes a kernel's unit-axes variant once it is made, never waiting

A direct dispatch whose plan offers the unit-axes variant
(BindingPlan::unit_axes_variant) takes it only where its translation is
done and each of its regions' VkPipelines is made (pipeline/unit_axes.rs).
Otherwise it settles on its plain variant, which gives the same answers,
and the variant is begun: its translation as a piece on the pipeline pool,
kept by the state (piece_holds.rs), at the first such dispatch; its objects
and pipeline notices on the program's thread at the next (no piece announces
a notice), with its regions' makings handed to the pool as any dispatch's
are. Nothing waits for the translation or a making. A dispatch planned
meanwhile is kept neither in the state's latest plans nor in its encoder's
memo, so a later one asks again. A refused translation or a failed making is
remembered, the plain variant then running those dispatches; the state tracks
at most VARIANTS such variants at once, and they live among its VARIANTS
others.

The dispatch that begins it is recorded for a later process's warm pass,
which compiles the variant and makes its regions beside the plain variant's.

The one-row and emulated-simdgroups variants are still compiled on the
encoding thread when a dispatch first asks (ComputePipelineState::settle ->
variant -> Variant::compile); this path does not follow them.

WorkCounts: unit_axes_variants_begun, unit_axes_dispatches,
unit_axes_meanwhile. No new Degradation kind. docs/API.md section 3 and the
bind module's docs state the rule and the variant; api_signatures.tsv
blessed.

Test: tests::unit_axes (m2v_gpu / m2v_cpu_icd): a 16-thread threadgroup
kernel whose simdgroup sum sits in a loop steered by gid.y; 4x2x2 never begins
the variant; 8x1x2 begins it once, runs on the plain variant meanwhile, then
settles on it, Metal's words every time.

A unit-axes variant's objects are made under its state's lock of begun variants

Two dispatches of one state could both find a translated variant gone from
the begun set while the first made its objects, and the second begin its
translation again. The first now makes them under the lock, as variant()
compiles under the lock of the state's variants.

Public: RuntimeFact::UnitAxes { axes, relief }, VariantKey.unit_axes,
LoweringInputs.unit_axes, BindingPlan::unit_axes_variant; WorkCounts
unit_axes_variants_begun, unit_axes_dispatches, unit_axes_meanwhile. No new
Degradation kind.

Verified: job 31119 at 58f7ef3c21: workspace clippy under --cfg m2v_gpu,
metal2vulkan with no feature and each feature alone, rustdoc -D warnings.
Job 31118: metal2vulkan + runtime suites 5187/5188; the one failure is the
golden hash table (24 cells of rfs_async_copy_{1,2,4}, the expected
SEMANTICS change), re-blessed on development. Job 31098 at c7f44ff865: the
engine test tests::engine_simd_unit_axes and the runtime test
tests::unit_axes on lavapipe. Iris compile-only replay of a guest's records
(31117): one depthwise state takes the variant (driver estimate 2.47M ->
0.57M cycles, spills 179:340 -> 0); the GPU-time A/B is pending.
2026-11-14 20:23:55 -08:00
..