Skip to content

hip: a Q6_K kernel for gfx1011 / gfx1012 (1 to 8 columns, the same bits) - #173

Merged
VecSzn merged 2 commits into
simplexai-labs:mainfrom
Keoian:pr/q6k-rdna1
Nov 22, 2026
Merged

VecSzn merged 2 commits into
simplexai-labs:mainfrom
Keoian:pr/q6k-rdna1

Conversation

@Keoian

@Keoian Keoian commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

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.cu and 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_mmvq kernels are bound there by their instruction count, not by the weights' reads. q6k_rdna1_kernel computes the same bits with fewer instructions.

What changed

  • src/kernels/cuda/native_mmvq.cu (inside #if defined(__HIPCC__)): q6k_rdna1_kernel and 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-operand v_dot4_i32_i8, and a final sum done with DPP / permlanex16 moves.
  • It is taken only when the device's arch name is gfx1011 or gfx1012. STRATA_Q6K_RDNA1=0 keeps the generic kernels; =1 takes 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:

Matrix 1 column 2 4 8
output head, 248,320 x 2,048: before 3,448 4,537 6,686 12,329
after 2,707 3,040 3,794 5,837
attn_qkv, 8,192 x 2,048: before 100 147 219 410
after 91 101 128 186

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_parity on 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).
  • A standalone harness (not in this tree) on the real matrices at 1 to 8 columns, every output against native_mmvq, and 406 million outputs over repeated launches for determinism: 0 differ.
  • Greedy answers with 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

Keoian and others added 2 commits November 15, 2026 00:41
…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
@Keoian
Keoian marked this pull request as ready for review November 21, 2026 22:42
@VecSzn
VecSzn merged commit 8e3cb19 into simplexai-labs:main Nov 22, 2026
@VecSzn

VecSzn commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

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.

@Keoian

Keoian commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

First report from the Radeon Pro 5500M (gfx1012, 8 GB; i9-9980HK, 32 GB; Windows 11, ROCm 10.2.0a20260930 from the TheRock wheels), v0.2.19-poly.1 at d1f711e, compiled with the flags build_engine_poly_hip_win uses. Timings are not in yet; they follow.

1. The tag does not compile for HIP here. engine/src/poly/inkling2.cu is the only file that fails, 10 errors, all of this kind:

engine/src/poly/inkling2.cu:2383:30: error: no matching function for call to '__ldcg'
 2383 |             const float2 c = __ldcg(&cand[i]);
hip/amd_detail/amd_hip_fp16.h:606:26: note: candidate function not viable: no known conversion from 'const float2 *' to 'const __half *'

ROCm's headers give __ldcg / __ldcs for __half and __half2 only. The calls are __ldcg on float and float2 (lines 2383, 2418, 2426, 2429, 2444, 2527) and __ldcs on uint4 and uint32_t (2295, 2296, 2329, 2330). src/split/src/hip/fnx_hip.h has a template __ldcg (an agent-scope atomic load, 4 or 8 bytes), but inkling2.cu does not see it, and it would not take the 16-byte uint4.

To go on I put this above the namespace in inkling2.cu, locally:

#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; }
#endif

These are plain loads. I have not checked whether Inkling's __ldcg reads need the coherent load fnx_hip.h uses, and Inkling was not run here, so take it as what made the build pass, not as the fix. Everything below is that build.

2. On the card

Check Result
mmvq_multi_parity ok: 148,480 outputs, 0 differ bitwise, 0 non-finite; the control finds 63,901 differences. The same with STRATA_Q6K_RDNA1=0.
poly_hip_split_attend_test PASS, 79 checks
poly_hip_prefill_fp32_test PASS, 32 checks
Engine load Cyber-Tiel Coder 35B-A3B UD-Q3_K_XL, --max-context 262144 --kv q8_0 --threads 8 --vram-pool --vram-reserve-mib 256: loaded in 29.5 s, "ready for requests"

mmvq_multi_parity is registered under if(STRATA_ENABLE_CUDA) only (cmake/strata_gpu_engine.cmake), so I changed that line locally to build it for HIP.

3. Not done yet

  • No answer was generated: the run was stopped right after the load, because the laptop ran short of RAM with other programs open (the engine held 8,782 MiB for the experts outside VRAM, and the card had only 4,285 MiB free at the time, other programs holding the rest). So no tokens/s and no comparison of the answers with the kernel on and off yet.
  • I will run that with the machine idle and add the numbers here.

One more thing seen in passing: STRATA_CPU_NO_GATHER (#171) adds its flag to ggml-cpu, which the default build no longer has. The new quant layer's AVX2 file has no gather instructions in it as compiled here (llvm-objdump of dot_avx2.cpp.obj: 0 vpgather*), so nothing is lost; the option only matters with -DSTRATA_OWN_CPU_QUANT=OFF.

@Keoian

Keoian commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

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 gfx101X-dgpu wheels). v0.2.19-poly.1 at d1f711e, built as build_engine_poly_hip does it plus -DCMAKE_HIP_ARCHITECTURES=gfx1010 -DSTRATA_ISA_FLOOR=avx. This is the machine of #175 to #177. The Radeon Pro 5500M report above is a different PC.

Short version: the kernel of this PR is right and faster on gfx1010 with STRATA_Q6K_RDNA1=1. The release itself has three problems on this card that are not this PR's: it does not compile, it reads prompts about 30% slower than the build before, and on a layer split it writes token 0 when one token goes through at a time.

1. The tag does not compile for gfx1010

Besides the __ldcg / __ldcs errors in inkling2.cu reported above (the same 10 errors on ROCm 7.14 on Linux), two more files fail on gfx1010 only:

engine/src/kernels/cuda/rdna_gr.cu:92:12: error: '__builtin_amdgcn_sdot4' needs target feature dot1-insts
engine/src/kernels/cuda/rdna_mmvq.cu:67:12: error: '__builtin_amdgcn_sdot4' needs target feature dot1-insts

dot8i() and dot4_s8() take __builtin_amdgcn_sdot4 for every arch that is not gfx11 or gfx12, and Navi 10 has no dot instruction. Locally I gave gfx1010 strata::hip_compat::dp4a() in both (an #elif defined(__gfx1010__) branch and the intrinsics.hpp include). Those kernels are opt-in and gfx11 only at run time, so this only had to compile; I did not run them. Everything below is that build (three local changes, engine SHA-256 8372cce1…1fdaa7).

2. The Q6_K kernel on gfx1010 (STRATA_Q6K_RDNA1=1)

Off by default on gfx1010, as the PR says. With =1 it takes the SDWA dot.

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

@Keoian

Keoian commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

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, --max-context 262144 --kv q8_0 --threads 8 --vram-pool --vram-reserve-mib 256 --cache-bias 0.5, STRATA_HIP_SPLIT_ATTEND=2, STRATA_HIP_PREFILL_FP32=2, through each tree's own server, temperature 0, thinking off. A session is one server start: a warm-up, six coding prompts of 256 tokens (about 210 prompt tokens each), then an 18,712-token prompt (part of setup.py) and 192 tokens after it. Sessions in this order; each request waited for the card to cool to the session's starting temperature. The laptop was not on a cooling pad and the card reached 85 to 92 C in every session, so these are throttled numbers.

Session Writes, six chats (median) Reads ~210 tokens (median) Reads 18.7K Writes after 18.7K Experts in VRAM
release, kernel on 36.5 tokens/s 78 tokens/s 109 tokens/s 14.0 tokens/s 3,091
release, STRATA_Q6K_RDNA1=0 36.2 79 98 13.1 3,091
release, STRATA_Q6K_RDNA1=0 36.9 80 94 12.8 3,091
release, kernel on 35.2 80 95 14.5 3,091
my build before the release (main at 67dde64, 14 commits after v0.1.45-poly.9, plus pull requests 169 to 173: llama.cpp's MMQ prompt kernels, the same Q6_K kernel) 36.4 166 362 14.9 3,031

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; mmvq_multi_parity above is the evidence for that. All 35 answers were sensible code or a correct summary.

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 v_dot4 on this card), which would fit. I can build the tag with -DSTRATA_POLY_MMQ=ON -DSTRATA_GGML_DIR=<llama.cpp> and time it if that helps.

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.

@Keoian

Keoian commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

The same five sessions again, the laptop now on a cooling pad (same build, settings, prompts and order as the table above).

Session Writes, six chats (median; lowest to highest) Reads ~210 tokens (median) Reads 18.7K Writes after 18.7K
release, kernel on 44.5 tokens/s (37.5 to 47.1) 86 tokens/s 116 tokens/s 26.6 tokens/s
release, STRATA_Q6K_RDNA1=0 40.9 (37.5 to 44.2) 86 117 28.4
release, STRATA_Q6K_RDNA1=0 42.5 (39.9 to 47.1) 87 117 28.0
release, kernel on 44.6 (40.3 to 46.6) 86 117 29.3
my build before the release (main at 67dde64 plus pull requests 169 to 173) 42.4 (38.9 to 46.2) 179 370 26.4
  • The Q6_K kernel: 44.5 and 44.6 tokens/s on against 40.9 and 42.5 off in the short chats, so about 4 to 9% here, which is what the doc page had for window 8. After the long prompt on and off do not separate (26.6 / 29.3 against 28.4 / 28.0).
  • Prompt reading is unchanged by the cooling: 116 to 117 tokens/s in the release against 370 before it, and 86 against 179 on the short prompts. So it is not heat.
  • Not only the pad differs from the first table: more RAM was free this time (the least available during a session was 12.3 to 13.0 GB, against 6.5 to 6.9 GB), and that is the likelier reason the writing after the long prompt doubled (13 to 15 -> 26 to 29 tokens/s): the experts outside VRAM stayed in the file cache. The card still reached 89 to 90 C during the long read in every session and 81 to 90 C in the chats.
  • CPU while writing: 37 to 38% of the 16 logical CPUs in every session; 12 to 14% while reading.

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.

2 participants