Repository navigation
hip dsv41: the indexer top-512 over fp32 score rows, under the kernel contract - #4914
Conversation
|
The clean trial merge of zig build test-kernel-contract -Dfixed-cpu -j2 --summary all
zig build test-hip-contract-select-host check-hip-kernel-contract-host -Dhip=true -Dfixed-cpu -j2 --summary allFor the NaN question, I compiled the production CUDA Igor Lessio - AIFLOW LABS |
|
Thanks, @Shoestring-dev. The selector follows its declared Metal rule, with stable ties, signed-zero handling, ascending indices and padding. The gfx1151 tests and resource results support landing this standalone kernel; the unrelated baseline limit findings remain visible. The NaN difference from CUDA is real: the 513-score example selects different indices. Before this feeds a CUDA-referenced serving path, the intended non-finite rule needs an explicit decision and comparison. This kernel-only result does not yet qualify that serving integration.
|
… contract A new HIP group, deepseek_v41/topk512.hip: tf_dsv41_topk512, the arithmetic of Metal's topk512.metal on a 1,024-thread block a row: an 11/11/10-bit radix select of order-preserving keys over 2,048 LDS bins, then a stable pass that writes the kept indices ascending (wave32 shuffles where Metal has simdgroup scans). NaN ranks as -inf, -0 as +0, ties go to the lower index, and row r keeps min(512, visible[r]) indices, then -1. Nothing launches it outside its tests yet. Kernel tests: each row against a stable sort at widths 1 to 131,072 over spread values, heavy ties, masked -inf rows and NaN, +-0 and +-inf, with visible counts whole, none, half and one, 512, 513, negative and past the width; a row's output the same alone as among other rows, and the scores left as they were. Contract: Metal's served shapes, rows and rule, each row against the CPU's stable sort; its four controls (NaN above +inf red at nonfinite, ties to the higher index and the last score dropped red at shapes, a write into its input red at repeat); gate-5 records from ROCm 10.1's hipcc.
347940f to
9007885
Compare
|
Thank you @Shoestring-dev. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
Part of #2065: the next single-box kernel PR on
deepseek_v41for HIP, after #3314 (EXL3 decode).What it adds. A new HIP group,
deepseek_v41/topk512.hip:tf_dsv41_topk512, the indexer's top-512 over fp32 score rows. It is the arithmetic of Metal'stopk512.metalon a 1,024-thread block a row: an 11/11/10-bit radix select of order-preserving keys over 2,048 LDS bins, then a stable pass that writes the kept indices ascending. Wave32 shuffles stand where Metal has simdgroup scans. The rule is Metal's: NaN ranks as -inf, -0 as +0, ties go to the lower index, and row r keeps min(512, visible[r]) indices, then -1. Nothing launches it outside its tests yet.One question on the rule. HIP follows Metal's stated rule. CUDA's decode top-k (
topk_cuda.cu) maps NaN to the image0x7FC00000, which ranks it above +inf. The two agree on every finite row, on ±0 and on ties. If HIP should follow CUDA's NaN instead, for the token-exact gate against CUDA's serial path, it is one line intf_topk512_keyplus the control.Kernel tests (
kernel_tests/dsv41.zig):Contract (
contract_dsv41_topk512.zig): Metal's served shapes, rows and rule, each row against the CPU's stable sort. Its four controls go red where they do on Metal: NaN above +inf atnonfinite; ties to the higher index and the last score dropped atshapes; a write into its input atrepeat. Gate-5 records come from ROCm 10.1's hipcc (HIP 7.16).Receipts (Radeon 8060S gfx1151, Linux, ROCm 10.1 hipcc; one commit on
683c66fe3, which merges clean on00e0e9878). The contract and limits ran at7d533820f;347940f9donly narrows the launcher's width check to an int, and the kernel and host tests were rerun there:zig build hip-kernel-test: pass (withhip-host-test)zig build hip-kernel-contract:SUMMARY gfx1151 210 kernels: 210 pass gates 1-4, 0 fail, 2 known findings; 74 controls: 74 red as planted, 0 missed; 1 limit problems(main alone: 209 kernels, 70 controls, the same 1 limit problem, below)nonfinitePASS (the stated rule holds),repeatPASS (five runs byte-identical, inputs and guards untouched),shapesPASS (43 shapes exact),sumsN/A (none declared); gate 5 live: 1,024 threads, 47 VGPRs, 8,584 LDS bytes, as recordedzig build hip-kernel-contract-limits: the new record passes on gfx1030, gfx1100, gfx1151 and gfx1201 (47 VGPRs, 56 SGPRs, 8,584 LDS bytes each)tools/pr_check.py --base main: 0 errors, lean 165 vs 165. The one warning is the changelog line, which is yours.On main with this hipcc. These findings come out the same on unmodified
683c66fe3, in files this PR doesn't touch:hip-kernel-contract-limitsreports 7 stale records:tf_moe_combine_gateon gfx1030/1100/1151, and four relu2 stream tiles on gfx1100.hip-kernel-contract's live limits failtf_moe_combine_gate("256 threads launched, the runtime allows 1024; 9 VGPRs, 0 + 0 LDS bytes (recorded 9, 0)"), the run's one limit problem with or without this PR.