Repository navigation
rdna2spirv: typed stores through the V# FORMAT encode flat and store once; compute modules compile 10x faster on NVIDIA - #4777
Conversation
…flat and stored once
Kam471
left a comment
There was a problem hiding this comment.
Ran at 434b98e55 on Windows 11, RTX 5070 Ti:
tests/semantic/test_typed_store_flat.py-> 8 tests, OK.tests/test_translate.pywithLLVM_MC-> 596 passed.- GPU typed-store fixtures:
--filter cs_fmt-> 6/6 passed (cs_fmt_101010264/64,cs_fmt_d16_xyz80/80 and 128/128,cs_fmt_int_narrow136/136,cs_fmt_sint3264/64,cs_fmt_xy_xyz128/128, all exact);--filter cs_store-> 1/1, words exact. git diff --checkclean.
The typed store now selects one flat encoder per run-time V# FORMAT instead of emitting every format's branch, and the tests/interpreter cover the flat path; the GPU fixtures keep the measured words. I could not measure the claimed compile-time improvement here, but the behaviour is exact across the format fixtures. No blocking issue.
|
Tested What I ran:
Code review:
|
whattheflop
left a comment
There was a problem hiding this comment.
Independent Windows CPU verification, AI-assisted, with uv CPython 3.12.13. Exact head 434b98e5 and its parent 98fa503f both matched an independently computed memory expectation for 25/25 hand-built cases (800 lane invocations and 25,700 final dwords per revision). All five modules per revision passed spirv-val --target-env vulkan1.2.
This adds indexed and scratch swizzle with runtime V# descriptors, signed and unsigned D16 channel remapping, exact-fit and straddling 8-, 12-, and 16-byte stores, and unsupported FORMAT no-ops where the buffer bounds would otherwise permit a write. In a shared-dword byte case, two active lanes wrote bytes 0 and 2. Bytes 1 and 3 stayed unchanged, and the interpreter observed one atomic AND/OR pair per lane. Fixed-format MTBUF controls also matched. CPU interpretation only.
|
Tested 434b98e on RTX 5090, 621.24, Windows 11: pass. Programs rebuilt from this tree, One note from the runner side, not your PR: the first attempt died with |
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Verified at head 434b98e on Windows 11 (Python 3.14):
- \python -m unittest discover -s tests/semantic -p test_typed_store_flat.py\ -- 8/8 OK.
- \python -m unittest discover -s tests/semantic -p test_buffer_store_rdna2.py\ -- 5/5 OK.
- \python -m unittest discover -s tests/semantic -p test_buffer_format_narrow_int.py\ -- 3/3 OK.
- \python -m unittest discover -s tests/semantic -p test_tbuffer_store.py\ -- 4/4 OK.
- \python -m unittest tests/test_docs_design_rows.py\ -- 4/4 OK.
- \python -I tests/test_docs_links.py\ -- 6/6 OK. \git diff --check\ clean.
- Code read: \Gen.store_format_body\ cleanly encodes elements flat and stores once (\store_format_subdword\ correctly restricted to subdword 1/2-byte formats, non-decoding formats store nothing). Massive compile-time improvement confirmed without semantic divergence.
No game files. AI-assisted review (Gemini).
|
Verified merged with current main, CPU-only: the flat typed-store encoding is word-for-word equivalent under the interpreter — the new test_typed_store_flat.py runs 8/8 (whole dwords, packed, sub-dword neighbour-keeping, d16 sources, shape/arity checks), and the store family (test_buffer_store_rdna2, test_tbuffer_store, test_buffer_format_narrow_int, test_image_load_typed, test_translate 596 passed) is green. The design.md row is updated and no behaviour change should show on the pending linux-gpu-tools run. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
|
Tested 434b98e on Intel UHD 630 (Coffee Lake GT2), Mesa 25.2.8 ANV, Ubuntu 24.04: tests/semantic test_typed_store_flat passes (8 tests), the nine existing buffer and tbuffer store modules pass, and tests/test_translate.py gives 629 passed with tests/test_u16_high_half.py 33 passed under pytest. On the GPU with LEONIDA_VK_DEVICE=Intel, cs_store passes 1/1 and the cs_fmt filter gives 5/6: cs_fmt_1010102, cs_fmt_d16_xyz, cs_fmt_sint32 and cs_fmt_xy_xyz pass, while cs_fmt_int_narrow fails (word 34: expected 0xffffffff, got 0x00000000), the same failure as the recorded main 3faac55 run on this GPU. A nonexistent device name fails with "no Vulkan physical device matches", so the filter applied. AI-assisted. |
|
Tested
|
|
Status: this is CONFLICTING and not a textual rebase. Since this PR was written, main (b26688f, "emit the typed-store encode once per module") moved the V#-FORMAT store encode into a module-level |
Compile time of dynamic-format typed stores (found while looking at the shaders that sat for minutes in the driver during the pipelines stage).
What was slow.
buffer_store_format_*(and_d16_*) through the V# FORMAT encoded the element in a branch for each of the 41 formats inGen.FORMATSand stored in each branch, a dozen of them with atomics: about 2,000 SPIR-V instructions per store. The NVIDIA driver inlines every function, so outlining it is not enough. On an RTX 4080 SUPER withvk_pipeline_checkat7b7d73f89, a compute module with 22 such stores (1.03 MB) takes 30 s alone. Restricting the stores to 3 formats makes it 1.4 s; restricting only the loads leaves it at 31 s. The corpus has 4,740 such stores in 1,063 compute shaders and 668 in 657 pixel shaders.Fix. With a run-time FORMAT,
Gen.store_format_bodyencodes the element in every format as straight-line arithmetic and selects the words of the matching format. One sequence then stores them: a dword store for each of the 4 words if the format's size (the existing%fmt_size_tab) covers it, and a single and/or pair for a 1- or 2-byte element. That lives in one function per (component count, d16, linear/swizzled) form,Gen.format_store_call.tbuffer_store_format_*is unchanged (one format, no branch).tests/semantic/spirv_mini_interp.pynow returns from a void function.Measured (RTX 4080 SUPER, 3 compiles at a time,
vk_pipeline_checkon the SPIR-V of the same 12 compute and 6 pixel shaders, 18 to 40 typed stores in each compute one, translated at7b7d73f89and with this change):The 22-store module alone: 1.03 MB to 0.24 MB, 29.7 s to 5.0 s (NVIDIA binary 1.49 MB to 0.40 MB), 25.6 s to 12.9 s on the Intel UHD 770; Intel's pipeline creation fails with
VK_ERROR_INITIALIZATION_FAILEDon it before and after.Tests. Windows 3.13.1 and Linux 3.12.16:
tests/semantic/test_typed_store_flat.py(new, 7 tests, synthetic V#s): one function per form and one atomic pair per function, a further store costs under 60 lines (it was about 2,000), the words left by whole-dword, packed, 1- and 2-byte, d16 and unknown formats (neighbouring dwords untouched).test_buffer_store_format,_store_rdna2,test_tbuffer_store,test_buffer_swizzle,_oob_select,_format_narrow_int,_f16_narrowing_hw) pass.7b7d73f89's translator against this one: all 41 formats x 4 component counts x d16/no x DST_SEL XYZW / XY01 / YX01 / ZYXW x 2 random value sets (1,300 distinct stores, five dwords compared each): 0 differences.tools/rdna2spirv.pyfromupstream/main, the two shape tests fail (no function, 15,648 more lines for 8 stores) and the value tests pass, as they should.tests/semanticon Linux 3.12.16: 6,252 tests, the same 3 failures + 3 errors as untouchedupstream/main(6,245 tests; the 7 more are the new file). That run predates the last commit's one-line change (below); the store, tbuffer and bounds files above and the new file were run again after it.tests/test_translate.py+tests/test_u16_high_half.pywithspirv-as/spirv-val/llvm-mc(Windows binaries, from Linux 3.12.16): 629 passed, as on untouchedupstream/main. A first run found that two forms with the same parameter list declared the sameOpTypeFunctiontwice (cs_fmt_sint32.asmfailedspirv-val); the type is now declared once per parameter count andtest_forms_with_one_signature_share_its_typecovers it.scripts/run_gpu_tests.pyon Windows 3.13.1:cs_fmt_1010102,cs_fmt_d16_xyz(x2),cs_fmt_int_narrow,cs_fmt_sint32,cs_fmt_xy_xyzandcs_storepass exactly on the RTX 4080 SUPER and the Intel UHD 770.Not the SHADER-774 loads or the per-write chains (#4440, #4473, #4518); independent of them. AI-assisted.