Skip to content

asahi: sink matching shared stores with identical access qualifiers - #1538

Merged
DjDeveloperr merged 2 commits into
aurora-wipfrom
perf/closeout-761-shared-store-reviewed
Dec 2, 2026
Merged

DjDeveloperr merged 2 commits into
aurora-wipfrom
perf/closeout-761-shared-store-reviewed

Conversation

@RyanTheTide

Copy link
Copy Markdown

Supersedes #1537 and carries the shared-store part of #761 onto current aurora-wip. Dj's original authorship and sign-off are carried in the extraction commit. The follow-up requires identical access qualifiers throughout the diamond, so sinking cannot drop a coherent access requirement from either arm. Both original qualifiers are preserved in the retained store.

The existing host fixture covers matching and commuted addresses, different addresses, volatile stores, and the new coherent versus ordinary mismatch. The remaining optimizer changes are tracked in #1535 and #1536.

Tested

Exact head 2290bdbf011619df325d839686f2b58ff95027a9 versus trunk 93ce24cda24ba73ef0a80a5c15787fa9edbbd141. The Asahi compiler suite passed 1,955 with one skip, including both focused shared-store checks. Both AArch64 ICD builds and all 44 repository-policy self-tests passed.

J615 (M3 Air, G15G C0) stayed on saved 7.3.0-aurora-edge. Confirmed the exact per-process VK_DRIVER_FILES and ran four alternating ABBA/BAAB pairs (32 fresh processes) with MESA_SHADER_CACHE_DISABLE=1 AGX_MESA_DEBUG=shaders. Each process dispatched 16,384 workgroups of 64 lanes, checked 1,048,576 reference outputs and the same number of sentinel words, and retained 20 GPU timestamp samples after four warmups. The candidate emits one shared store instead of two. The boot stayed unchanged and the kernel journal was empty.

Median paired GPU time changed −0.01%, with blocks from −1.89% to +2.89%. Pooled medians were 141,500 ns and 143,020.5 ns (+1.07%). Both directions occurred in the paired comparison.

Vulkan fixture and timing
#version 450
layout(local_size_x = 64) in;
layout(set = 0, binding = 0, std430) readonly buffer Left { uint a[]; };
layout(set = 0, binding = 1, std430) readonly buffer Right { uint b[]; };
layout(set = 0, binding = 2, std430) writeonly buffer Output { uint c[]; };
shared uint tile[64];

void main()
{
    uint lane = gl_LocalInvocationIndex;
    uint index = gl_GlobalInvocationID.x;

    if ((lane & 1u) != 0)
        tile[lane] = a[index];
    else
        tile[lane] = b[index];

    barrier();
    c[index] = tile[lane ^ 1u];
}
block	base_ns	head_ns	pct
1	142979.0	142750.0	-0.16
2	143021.0	143208.5	+0.13
3	143417.0	140708.0	-1.89
4	142041.5	143437.5	+0.98
5	144250.5	142854.0	-0.97
6	142603.5	141146.0	-1.02
7	139145.5	140895.5	+1.26
8	141124.5	145208.0	+2.89

Risk

Moves two matching terminal shared stores into a single store after control-flow reconvergence. The pass admits equal address expressions, equal memory qualifiers and matching store properties, and refuses atomic and volatile stores.

DjDeveloperr and others added 2 commits December 3, 2026 02:57
Carry the shared-store portion of 8e2d121 onto current trunk. Match terminal stores in if/else diamonds and retain one store after the merge.

Signed-off-by: DjDeveloperr <hey@djdev.me>
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Require equal qualifiers on both stores. Intersecting the flags could remove coherent access on one arm. Cover that mismatch in the existing rejection test.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2290bdbf0116 (asahi: sink matching shared stores with identical access qualifiers):

  • Both items from #1537 are cleanly addressed: 6dc29e25d358 preserves Dj's authorship and Signed-off-by: trailer above Ryan's, and 2290bdbf0116 requires nir_intrinsic_access(ts) == nir_intrinsic_access(es) (still rejecting ACCESS_VOLATILE | ACCESS_ATOMIC) and preserves access on the sunk nir_store_shared without dropping requirement qualifiers like ACCESS_COHERENT.
  • RefusesToSinkMismatchedSharedStores covers mismatched offsets, volatile stores, and ACCESS_COHERENT vs ordinary mismatches, alongside SinkCommonStoreShared covering commuted address expressions and NIR validation.
  • Exact-head verification (1,955 Asahi compiler tests with 0 failures, AArch64 ICD builds, 44 policy self-tests, and J615 M3 Air paired ABBA/BAAB correctness + shader dump confirming 2 -> 1 shared store) and ## Risk are clean.

LGTM.

@satchlj

satchlj commented Dec 2, 2026

Copy link
Copy Markdown
Member

Exact-head M5 Max (J775c, G17C B1, kernel 7.3.0-1-54.20261202-ARCH) verification at 2290bdbf011619df325d839686f2b58ff95027a9 (vs parent 93ce24cda24b):

  • Native AArch64 assert-enabled Meson build (-Dbuildtype=release -Db_ndebug=false -Dbuild-tests=true -Dgallium-drivers=asahi -Dvulkan-drivers=asahi):
    • Full Meson suite: 349/349 OK, 0 Fail.
    • Targeted *FlattenLoads* (agx_tests): 14/14 PASSED, including FlattenLoadsKeeps.SinkCommonStoreShared and FlattenLoadsKeeps.RefusesToSinkMismatchedSharedStores (covering ACCESS_COHERENT vs 0).
  • Live G17C B1 Borealis Vulkan checks (release build -Db_ndebug=true, isolated VK_DRIVER_FILES, MESA_SHADER_CACHE_DISABLE=true, 0 GPU faults / 0 kernel warnings):
    • dEQP-VK.api.smoke.*: 8/8 PASS (0 fail).
    • gpubench-rt-vk (depth 2): rt.scene raster 2,279.6 fps (crc32=cca69c73), medium (trace=query) 136.7 fps / 336.5 Mray/s (crc32=e91ea686).
    • Same-boot interleaved ABBA llama-bench (llama-2-7b.Q4_0, -fa 1, -r 5, MESA_SHADER_CACHE_DISABLE=true, PR 2290bdbf0116 vs base 93ce24cda24b — parity across all rows, 0 regressions):
      • Default (NV_coopmat2): pp128 base 791.14 / 792.11 vs PR 791.55 / 792.51 (+0.05%); pp512 base 876.50 / 874.20 vs PR 877.88 / 874.86 (+0.12%); tg32 base 121.97 / 122.45 vs PR 122.49 / 122.62 (+0.28%).
      • GGML_VK_DISABLE_COOPMAT=1: pp128 base 373.84 / 373.91 vs PR 373.93 / 373.92 (+0.01%); pp512 base 775.93 / 776.53 vs PR 775.77 / 777.08 (+0.03%); tg32 base 122.56 / 122.32 vs PR 122.38 / 122.67 (+0.07%).

@DjDeveloperr
DjDeveloperr merged commit da7d055 into aurora-wip Dec 2, 2026
@DjDeveloperr
DjDeveloperr deleted the perf/closeout-761-shared-store-reviewed branch December 2, 2026 16:17

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 2290bdb

Checked: an exact-head x86-64 assert-enabled build (-Db_ndebug=false -Dbuild-tests=true, drm-shim, asahi Gallium + Vulkan) with meson test --suite asahi --suite poly gave 393 OK, 0 fail, 1 skip. That includes agx_tests with SinkCommonStoreShared and RefusesToSinkMismatchedSharedStores. Mesa has no Actions CI, so this local run is the CI record. Code points I worked through:

  • Both stores are each arm's last instruction, and the new store goes at nir_after_phis of the merge block, so nothing runs between the old and new store positions. Moving the store past reconvergence changes nothing.
  • same_pure_expr admits only load_const/ALU trees whose leaves dominate the if. Matching includes swizzles, fp_math_ctrl and nsw/nuw, and commuted integer ops. clone_pure_expr hoists the then-arm tree before the if, and nir_instr_clone_deep leaves out-of-arm sources unmapped, so they stay as they are. Pure ALU speculation is safe.
  • Access must be equal and must not include VOLATILE/ATOMIC. base, write_mask, alignment and value/address sizes must match, so the coherent mismatch case refuses.
  • Lanes in different arms writing the same address with no barrier race in both the old and new code, so no observable order changes.

Follow-ups: none blocking.

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.

3 participants