Repository navigation
hip: a Q6_K kernel for gfx1011 / gfx1012 (1 to 8 columns, the same bits) - #173
Conversation
…etup opt-in Navi 12 and Navi 14 (gfx1011, gfx1012) have v_dot4_i32_i8 (LLVM's dot1-insts); Navi 10 (gfx1010) does not. The engine gave gfx1012 the SDWA sequence written for gfx1010. On a Radeon Pro 5500M the builtin matched the byte-wise form on 1,048,576 random operand triples and ran 3.47 times as fast in a loop of dot products. - intrinsics.hpp: dp4a takes __builtin_amdgcn_sdot4 on gfx1011 / gfx1012 where the compiler has it. -DSTRATA_GFX1012_SDWA_DOT=ON keeps the SDWA sequence; gfx1010 is unchanged. - CMakeLists.txt: the same for llama.cpp's ggml_cuda_dp4a (the prompt path's MMQ kernels), patched in the downloaded checkout at configure time, only when the HIP architectures include gfx1011 or gfx1012. - hip_split_attend.cuh: STRATA_HIP_SPLIT_ATTEND=2's int8 scores use the SDWA sequence only on gfx1010. - setup.py: STRATA_EXPERIMENTAL_GFX1012=1 makes setup know the card under Windows (PCI 0x7340, or its name), compile strata-poly for gfx1012 and write 64K, --kv q8_0 and one thread a physical core. Unset: unchanged. - docs/RADEON_PRO_5500M.md: the install and the measurements. Engine alone (Tiel Coder UD-IQ3_XXS, 32K, window 8): 27.0 -> 32.7 tokens/s. Checked on the card: poly_hip_split_attend_test (79) and poly_hip_prefill_fp32_test (32); tools/test_setup_amd.py with and without the opt-in (64). Built for HIP (gfx1012, Windows) only. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N976Pzh5TRuGLTNLV61TXc
Tiel Coder's attention, GDN and shared-expert matrices and its output head are Q6_K, and with MTP drafts they are multiplied by two to eight columns at once. On RDNA1 the generic kernels were bound there by their instruction count: four 64-bit address calculations a column, the activations reloaded for every row, and a final sum whose lane exchanges waited on ds_bpermute. q6k_rdna1_kernel keeps every thread's blocks, every expression and every order of addition, so the outputs are the same bits, and gets there with buffer loads, one activation load a block for 2 to 8 rows, the three-operand v_dot4_i32_i8 and a DPP / permlanex16 final sum. Radeon Pro 5500M, Tiel Coder's real matrices: the output head (248,320 x 2,048) at 4 columns 6.69 -> 3.79 ms, at 8 columns 12.3 -> 5.8; attn_qkv at 4 columns 219 -> 128 us. Decode at window 8: +4 to 10%. It runs only on gfx1011 / gfx1012 (by the device's arch name), and only in HIP builds. STRATA_Q6K_RDNA1=0 keeps the generic kernels; =1 takes it on any gfx10 card (unmeasured there). Checked: mmvq_multi_parity on the card (148,480 outputs, 0 differ, the control still finds differences); a standalone harness on the real matrices at 1 to 8 columns, every output. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01N976Pzh5TRuGLTNLV61TXc
|
I've merged it and it's on v0.2.19-poly.1, I can only build it because I don't have an rdna1 card to test it on. If you can try this release on your card, a short report would help me a lot. |
|
First report from the Radeon Pro 5500M (gfx1012, 8 GB; i9-9980HK, 32 GB; Windows 11, ROCm 10.2.0a20260930 from the TheRock wheels), 1. The tag does not compile for HIP here. ROCm's headers give To go on I put this above the namespace in #if defined(__HIPCC__)
template <typename T> __device__ inline T __ldcg(const T* p) { return *p; }
template <typename T> __device__ inline T __ldcs(const T* p) { return *p; }
#endifThese are plain loads. I have not checked whether Inkling's 2. On the card
3. Not done yet
One more thing seen in passing: |
|
Report from the other RDNA1 card: 2x RX 5700 XT 8 GB (gfx1010, Navi 10), the layers split over both, i7-3770 (AVX, no AVX2), 32 GB, Ubuntu 26.04.1, Linux 7.0.0-43, ROCm 7.14.0a20260612 (TheRock Short version: the kernel of this PR is right and faster on gfx1010 with 1. The tag does not compile for gfx1010Besides the
2. The Q6_K kernel on gfx1010 (
|
| Check | Result |
|---|---|
A standalone harness (not in the tree): native_mmvq on random Q6_K matrices, 7 shapes from 512 x 2,048 to 248,320 x 2,048, 1 to 8 columns, every output written to a file, =0 against =1, on each card |
9,473,292 outputs a run; the four files are byte-identical (and identical to a run with the variable unset); 0 non-finite; a repeated launch gave the same bits in every case |
mmvq_multi_parity with =1 and with =0 (enabled for HIP locally, as above) |
ok both: 148,480 outputs, 0 differ bitwise; the control finds 63,830 |
Greedy answer, Cyber-Tiel Coder UD-IQ3_XXS (its attention, GDN, shared-expert matrices and head are Q6_K), strata-poly --tokens, 31-token prompt, window 8, 64K, both cards |
the same 171 tokens with =0 and =1, in 3 runs of each and in one of each with STRATA_FREEZE_EXPERTS=1 |
One launch, µs, card 0 (card 1 is within 2%), mean of 50, random weights:
| Matrix | Columns | generic | q6k_rdna1 |
|
|---|---|---|---|---|
| head, 248,320 x 2,048 | 1 | 1,377 | 1,216 | 1.13x |
| 2 | 1,764 | 1,287 | 1.37x | |
| 4 | 3,428 | 1,839 | 1.86x | |
| 8 | 5,769 | 3,277 | 1.76x | |
| 8,192 x 2,048 | 1 | 46.7 | 45.1 | 1.04x |
| 2 | 54.9 | 45.4 | 1.21x | |
| 4 | 114.0 | 60.1 | 1.90x | |
| 8 | 195.3 | 107.8 | 1.81x | |
| 2,048 x 2,048 | 1 | 13.8 | 11.2 | 1.23x |
| 4 | 31.0 | 17.7 | 1.75x | |
| 8 | 50.0 | 29.8 | 1.68x |
In the engine, Cyber-Tiel Coder UD-IQ3_XXS, 64K, --kv q8_0 --vram-pool --vram-reserve-mib 256, every expert in VRAM, =0 then =1, alternating:
=0 |
=1 |
|
|---|---|---|
--tokens, 171 greedy tokens, window 8 (3 pairs) |
92.1 / 103.2 / 103.4 tokens/s | 115.0 / 115.5 / 115.2 |
| Through the server, three coding chats (2 starts of each arm) | 108.7, 92.8, 92.3 and 108.7, 92.7, 93.1 | 119.3, 101.9, 102.2 and 119.1, 101.8, 102.1 |
About 10 to 12% in the answers. The whole machine's CPU was 20 to 23% during the chats in both arms, 31 GiB of RAM available. So on gfx1010 the SDWA variant is worth having on; I have not measured it at window 1 (see 4) or with other models' Q6_K shapes.
3. The release reads prompts slower than the build before on this card
Same day, the same client (terminal/tools/strata_bench.py --url ... --long of the tag, 3 runs a test), Cyber-Tiel Coder UD-Q4_K_XL, 262K, --kv q8_0 --threads 6 --cache-bias 0.5 --vram-pool --vram-reserve-mib 256, STRATA_HIP_SPLIT_ATTEND=2, STRATA_HIP_PREFILL_FP32=2, a fresh server each. "Before" is main at 67dde64 with #175 and #176, which has served here for a week.
| Median (range) | before | v0.2.19-poly.1 |
|---|---|---|
| Chat writes, tokens/s (9) | 76.8 (67.3 to 102.1) | 75.1 (71.3 to 101.3) |
| Chat first token, s | 1.02 | 1.56 |
| ~4K prompt reads, tokens/s | 451 (445 to 464) | 321 (320 to 322) |
| ~16K prompt reads | 451 (433 to 458) | 324 (320 to 325) |
| ~32K prompt reads | 410 (407 to 414) | 299 (296 to 302) |
| Agent session writes (15 turns) | 121.7 (61.4 to 134.4) | 134.7 (71.4 to 139.5) |
| Agent turn first token, s | 5.09 | 6.72 |
Writing is the same or better; reading is 27 to 29% slower. A second build of the tag with -DSTRATA_POLY_MMQ=ON -DSTRATA_GGML_DIR=<llama.cpp at 3cf03257> gets it back: a fresh 33,832-token prompt read at 368 tokens/s before, 240 with the tag, 363 with the tag and STRATA_POLY_MMQ (one run of each). So it is the new prompt products (mmq_own.cu's dequantize-and-BLAS path, which the cmake comment says is the HIP path), not anything else in the release. The override is "kept for two releases": on gfx1010 it should stay, or the new path needs work there. I can test a change.
Seen once and not chased: the first three chats after a fresh start were slower with the tag (47, 61, 73 tokens/s against 87, 84, 79 before), one start of each. The nine chats of the suite above do not show it.
Also fine in the release here: --vram-pool on the split (5,562 and 5,222 MiB claimed, 5,746 experts in VRAM, loaded in 4.7 s), #175's wait (no fault in any run), 262K of context, and no request failed in the suite.
4. On a layer split, one token at a time writes token 0
strata-poly --tokens <31 ids> --max-new 48 --max-context 65536 --threads 6, greedy, the tag's build:
| Cards | Options | Tokens written |
|---|---|---|
both, --layer-split auto |
--window 1 |
2,0,0,0,0,0,0,… |
| both | --window 8 --no-draft |
2,0,0,0,0,2,2,2,2,380,380,380,… |
| both | --window 2 or --window 8 |
a normal answer |
| both | --window 1 --top-probs 3 |
a normal answer (2,380,92007,8771,…) |
| one card | --window 1 |
a normal answer |
The same with Cyber-Tiel UD-Q4_K_XL and UD-IQ3_XXS, with STRATA_Q6K_RDNA1 0 or 1, with and without STRATA_POLY_MMQ, and the build before the release answers normally at --window 1 on the split. --top-probs is what main.cpp uses to turn card_picks off (reads_logits), so my reading, from the code and not confirmed, is that step_picks() / eval_picks() on a split returns the pick of the wrong card's engine or an empty one. A server request with the default window and the draft on is not affected, which is why the suite above passed. I did not test a greedy server request with "window": 1 or a split on NVIDIA cards.
Not tested
Windows on this card, one card beyond the probe above, Inkling 2 (the __ldcg shim only had to compile), the gfx11 kernels of rdna_gr.cu / rdna_mmvq.cu, PR 180's --kv q4_0 / --kv-resident, pictures, more than one request at once, a soak. CUDA and SYCL were not built.
I can send the three compile fixes as a pull request, and open issues for 3 and 4 if you prefer them tracked apart from this thread.
🤖 Generated with Claude Code
|
The numbers, same machine and build as above (the tag plus the two local changes). One finding is bigger than the kernel: this release reads prompts at about a quarter to a half of the speed of the build I had before it. Cyber-Tiel Coder 35B-A3B UD-Q3_K_XL,
The Q6_K kernel: it runs and nothing breaks. Writing a short chat is the same with it on and off within what one session differs from the next here (35.2 to 36.9). After the long prompt it wrote 14.0 and 14.5 tokens/s on against 13.1 and 12.8 off, two sessions each, so take that as a hint and not as a measurement. The answers: with the server at temperature 0 two sessions of the same build already part after 26 to 536 characters (the guessed-token window follows the machine's timing, as the doc page says), so the texts cannot show whether the kernel changes anything; Prompt reading: 362 -> 94 to 109 tokens/s on the 18.7K prompt and 166 -> 79 on the short ones. CPU use while reading was 13 to 15% of the 16 logical CPUs in the release and 21% before. I have not looked for the cause; the release notes say a card without int8 or fp16 tiles (HIP) now reads prompts through a dequantized matrix and the BLAS library where the older build used llama.cpp's MMQ kernels (with RAM and CPU: while writing, 44 to 47% CPU in every session. The least RAM available during a session was 6.7 to 6.9 GB with the release and 6.5 GB with the older build (32 GB machine, a browser open). A correction to my first comment: the 4,285 MiB "free" at the load is what is left for the experts after the 262K context's caches, and the older build shows the same line. Other programs were not holding VRAM; that was my misreading. I will repeat this on a cooling pad. |
|
The same five sessions again, the laptop now on a cooling pad (same build, settings, prompts and order as the table above).
|
Title
hip: a Q6_K kernel for gfx1011 / gfx1012 (1 to 8 columns, the same bits)
Issue: none filed. Stacked on #172: the first commit here is that PR; only the last commit (
native_mmvq.cuand the doc section) is new. Draft until #172 is decided; I will rebase it then.Summary
Tiel Coder's attention, GDN and shared-expert matrices and its output head are Q6_K, and with MTP drafts they are multiplied by two to eight columns at once. On an RDNA1 card the generic
native_mmvqkernels are bound there by their instruction count, not by the weights' reads.q6k_rdna1_kernelcomputes the same bits with fewer instructions.What changed
src/kernels/cuda/native_mmvq.cu(inside#if defined(__HIPCC__)):q6k_rdna1_kerneland its dispatch. It keeps every thread's blocks, every expression and every order of addition, and uses buffer loads (a lane's 32-bit offset plus a scalar one), one activation load a block for 2 to 8 rows, the three-operandv_dot4_i32_i8, and a final sum done with DPP /permlanex16moves.STRATA_Q6K_RDNA1=0keeps the generic kernels;=1takes it on any gfx10 card (unmeasured there; gfx1010 has no dot instruction and gets the SDWA sequence).docs/RADEON_PRO_5500M.md: its section and numbers.What it leaves alone: every other format and every other card; CUDA and SYCL builds (the code is compiled only under HIP); the outputs.
Extra Notes
Measured on a Radeon Pro 5500M 8 GB (gfx1012, Windows 11, ROCm 10.2.0a20260930), Tiel Coder 35B-A3B UD-IQ3_XXS's real matrices, µs a launch:
In the engine (
strata-poly --tokens, 256 greedy tokens, 64K, window 8, three alternating pairs): 39.2 / 36.1 / 35.1 -> 43.2 / 38.7 / 38.1 tokens/s. At window 1 nothing measurable.Checked:
mmvq_multi_parityon the card, built from this branch: 148,480 outputs, 0 differ bitwise, and its control still finds differences. Upstream registers that test only for CUDA builds, so I enabled it for HIP locally to run it; that CMake line is not in this PR (say if you want it).native_mmvq, and 406 million outputs over repeated launches for determinism: 0 differ.STRATA_FREEZE_EXPERTS=1: the same tokens as the build before at window 1. At window 8 some runs take another token at a near tie (token 44 or 51 of 256); the build before does the same when only the window changes, so I read it as the draft grouping following timing, not the kernel. That is my reading, not a proof.Not tested: gfx1011, gfx1010 with
=1, an RX 5500 XT desktop card, Linux, other models' Q6_K shapes. CUDA and SYCL were not built (no such card here); the new code is behind__HIPCC__.🤖 Generated with Claude Code
https://claude.ai/code/session_01N976Pzh5TRuGLTNLV61TXc