Repository navigation
rdna2spirv: intra-block %vgpr/%sgpr value forwarding - #4518
SweatierKey wants to merge 2 commits into
Conversation
Kam471
left a comment
There was a problem hiding this comment.
Ran this at c31262e3 on Windows 11: tests/semantic/test_reg_load_forwarding.py -> 6 tests, OK; compileall and git diff --check clean.
The translator forwards %vgpr/%sgpr values within a block (updating the tests that depended on the old repeated loads), and the new forwarding cases plus the affected suites pass. No blocking issue.
|
Replying to @SweatierKey. Register forwarding preserved the full GPU readback in two cases on Linux, RTX 5090 (driver 595.99.02, subgroup 32), at
For each fixture the eight expected words matched, and the entire output buffer was byte-identical with forwarding on and off. AI-assisted. |
|
I ran In the head disassembly, both lane shuffles immediately following The fixture and official runner were byte-identical across revisions. Both runs used the same |
|
Tested
This PR and #4473 don't merge cleanly with each other (conflict in Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
whattheflop
left a comment
There was a problem hiding this comment.
AI-assisted independent Windows CPU check at c31262e3, base 03b09a08, with a disposable integration of #4473 aa813789 and #4510 7ea906d5. uv CPython 3.12.13, synthetic shaders only.
- Five defined probes were bit-exact across main, the PR and the combined tree. The diamond/backedge case matched all 32 lanes, and a masked-lane case exercised all four dynamic VGPR writers while preserving lane 7. All 15 modules passed
spirv-val --target-env vulkan1.2. - The same float chain assembled to 12,836 bytes on main, 9,660 on this PR and 7,420 combined. The combined tree removed 38 cross-instruction bitcast round trips attributable to forwarding. Disabling forwarding in the combined tree removed that opportunity and raised size to 10,692 bytes with identical outputs.
- #4510 applied cleanly. #4473 required reconciling ten hunks in
tools/rdna2spirv.py: constructor signature and fields,emit,x_split,translatesetup and five reset sites. Keeping both caches' initialization and resets passed the six forwarding, six EXEC-cache and two bitcast tests. - The combined
v_mad_i16and D16 SINT-store probes both exercised signed inputs totou()and neither reached a signed inversion throughtof().
There was a problem hiding this comment.
I tested c31262e3 against its parent 03b09a08 on Linux with Mesa 26.1.6 RADV (GFX1201 via Mesa's DRM shim). These measurements cover cold pipeline creation and use synthetic RDNA2 only. I used the same native vk_pipeline_check executable for every run, a fresh process per sample, one worker, and MESA_SHADER_CACHE_DISABLE=true.
| Synthetic compute workload | Translator | SPIR-V bytes | Pipeline creation, median (range) |
|---|---|---|---|
1,024 chained v_fma_f32 |
Main | 305,040 | 31 ms (30–40 ms) |
1,024 chained v_fma_f32 |
#4518 | 177,992 | 24 ms (19–42 ms) |
128 dynamic buffer_load_format_x loads |
Main | 521,036 | 7.05 s (6.98–7.77 s) |
128 dynamic buffer_load_format_x loads |
#4518 | 514,344 | 7.45 s (7.06–7.98 s) |
128 dynamic buffer_load_format_x loads |
Single-component decoder prototype | 491,336 | 0.41 s (0.40–0.46 s) |
128 dynamic buffer_load_format_x loads |
#4518 plus prototype | 484,644 | 0.44 s (0.39–0.45 s) |
Five samples per FMA variant and three per typed-load variant. Each module passed spirv-val and created its pipeline successfully. Register forwarding reduced the FMA binary by 41.7%. The small, overlapping timing ranges make the FMA result inconclusive for compile time. On this typed-load fixture, the decoder change accounts for the large speedup. It applies cleanly on top of #4518 and keeps the compile time in the same range.
On #4518 alone the six forwarding tests and 156 buffer semantic tests pass with SPIRV-Tools required. With the decoder patch applied, the six forwarding tests and 157 buffer tests pass. The decoder differential also matches all 5,120 reference words bit-for-bit on that combined tree.
AI-assisted. No game files or physical GPU required for this check.
Larger synthetic cases
- 512 dynamic single-result typed loads. Main and #4518 both hit a 100-second timeout. The decoder prototype compiled in 3.40 s and the combined tree compiled in 4.27 s. One run per build with an 8 GiB address-space limit, otherwise the same compiler and cache settings. All four modules passed
spirv-val. - 2,048 integer multiply/add pairs under a partial EXEC mask. The observable value depends on a push-constant multiplier and the lane ID. #4518 reduces the binary from 744,744 to 384,296 bytes. Cold RADV pipeline creation went from a median 119 ms (119–138 ms) to 98 ms (93–101 ms), three samples per build. For synthetic chains of 128, 512 and 2,048 pairs, all 64 output words per dispatch matched a CPU reference on llvmpipe with both builds, including the 35 inactive lanes that retained their original values.
|
Tested What is fine:
What breaks: the 28 pytest-marked files as CI's
All 17 new failures are in one file, so the forwarding now leaves an Also fine on their own: RTX 5080 not run (186 MiB free, another job holds it). Machine: Linux Mint 22 (Ubuntu 24.04 base), |
|
Tested
AI-assisted (Devin). |
|
Apple M2 no-regression check at head c31262e (macOS 26.4, MoltenVK 1.4.2 direct, subgroup 4..32, llvm-mc 23.1.6, clean full build exit 0).
AI-assisted. |
|
Thanks @chpeu for catching the
|
|
Independent check of the current head
AI-assisted. |
Claim: #4421 (comment).
What changes
%vgpr/%sgprvalue forwarding (Gen._reg_val, default-on intranslate()):load_reg(kind, r)returns the cached SSA value for(kind, r)when already loaded or stored earlier in the current basic block (eliminating both theOpAccessChainandOpLoad).store_reg,dst, andv_writelane_b32continue emittingOpStoreto%vgpr/%sgpr(so cross-block readers and dynamics_movrels/v_movrelsreads always see exact memory) and update_reg_val[(kind, r)]to the stored SSA value;dstandv_writelane_b32also reuse_reg_valforold.v_swaprel_b32,v_movreld_b32,v_movrelsd_b32,v_movrelsd_2_b32) invalidate all"vgpr"entries in_reg_val._reg_valclears on everyOpLabel,x_split, and block boundary intranslate().Gen()unit-test callers default tocache_regs=False, keeping inline loads insideg.body.tests/test_translate.py,tests/test_image_load_typed.py,tests/test_rcp_iflag_mods.py,tests/semantic/test_buffer_oob_select.py,tests/semantic/test_buffer_swizzle.py) to also recognize forwarded VGPR/SGPR values (OpStore %vgpr[r] <val>and constant-foldedOpBitFieldUExtract), and addstests/semantic/test_reg_load_forwarding.py.SHADER-789), rdna2spirv: cache per-block %active loads and fast-path no-EXEC dst() writes #4473 (SHADER-796), spirv_opt: sound dominator-tree SPIR-V optimizer (#884) #2298 (--opt), rdna2spirv: f32 constants are module-scope OpConstants, not a bitcast at each use (-2.4% SPIR-V) #4391 (Gen.fconst), andtof/touround-trip folding (and synergizes withtof/touby exposing cross-instruction bitcast chains).Measured impact (
spirv-as+spirv-val --target-env vulkan1.2)03b09a08)s_cbranch_execzblocks).spv/ ~7,800 reg loads.spv/ 925 uint loads.spvbytes,spirv-val34→24 msv_fma_f32).spv/ ~4,000 reg loads.spv/ 48 uint loads.spvbytes,spirv-val14→8 ms.asmfixtures (runtime/test/shaders/*.asm)Verification (Linux CPU, Python 3.13.5, LLVM 18.1.8, SPIRV-Tools, no game files)
tests/semantic/test_reg_load_forwarding.py: 6/6 OK (32-lane divergentrun_wavewiths_and_saveexec_b32/v_writelane_b32/self-aliasing, divergent loops,v_movreld_b32+v_swaprel_b32invalidation,v_movrels_b32/s_movrels_b32coexistence,--wave64-emulatevalidation, directGen()default).tests/test_translate.py: 343/343 passed (1 skipped, 0 failed) + 234/234 GPU.asmfixtures validated withspirv-val --target-env vulkan1.2(1 pre-existing LLVM 18 operand error onps_sdwa_f16_const, identical to03b09a08).tests/semanticsuite (7,456 tests): zero new failures vs03b09a08;tests/test_semantic_translator_use.py: 3/3 OK; all 74 non-pytest translator/SPIR-Vtests/test_*.py: 74/74 passed.git diff --checkclean.AI-assisted.