Skip to content

feat(hip): the model-free kernels on #463's runtime: attention, DeltaNet, norms, RoPE, MoE routing and decode plans - #617

Merged
ashhart merged 6 commits into
ashhart:mainfrom
BlivionIaG:hip-kernels-ops
Oct 16, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
BlivionIaG:hip-kernels-ops

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

The model-free kernels a model engine composes, on #463's runtime: the first kernels slice tracked in #491, everything but the MLX affine products (the next slice).

  • 21 HIP sources (3,385 lines) built by hipcc for -Dhip-arch with the caps table's instruction switches, embedded as one code object a source group and launched from Zig with Add model-free Zig HIP runtime and GPU qualification #463's Module and launch: elementwise ops and casts, norms and the merged decode tails, RoPE, attention (the flat decode walk; the planned walk over a page table, reading a KV head once for the query heads that share it; the 64-row prompt tile flat and paged), the DeltaNet recurrence in fp32 at every length, the linear attention's conv and gates, the MoE router, pick and route, argmax and top-k, and a lane round's plan kernels.
  • launches.zig resolves every kernel at load; Launcher.Choices picks between two kernels that give the same bits (merged decode launches, the 64-row prompt tile).
  • The sources hold device code only: plain kernels are extern "C" (tf_*), and each template kernel the launches resolve is instantiated explicitly; no host launchers or C API.
  • ops/ checks shapes for each launch; arena.zig hands out a forward's scratch front to back, and a counting stream measures what a forward takes without launching.
  • -Dhip-device-lib names ROCm's device bitcode for layouts other than TheRock's (Arch keeps it in <rocm>/amdgcn/bitcode); zig/tests/hip_kernels.md has the notes.

Stacks on #611 (its three commits are included here until they land); review the last commit.

Receipt

  • Environment: base main at c37d0a4 (+ build(hip): -Dhip-arch accepts gfx1030 (RDNA2) and gfx1100 (RDNA3) #607, feat(hip): a caps table from RDNA2 to RDNA4, keyed by exact gfx name #609, feat(hip): what a model engine needs from the runtime: graphs, device copies, mapped memory, device queries #611), head d91b074. Zig 0.17.0, HIP 7.14.60850 (TheRock), Linux 7.1.7.
  • Exactness, hip-kernel-test (43 tests), on both GPUs below:
    • the planned decode walk over a permuted page table writes the flat walk's bits for 8, 6, 4 and 1 query heads a KV head, within 1e-5 of float64;
    • the 64-row prompt tile over pages writes the flat tile's bits, within the cache type's rounding of float64;
    • the merged conv split, MoE pick and gated norm write the replaced chains' bytes; the merged router and tails sit no further from float64 than twice the launches they replace;
    • casts, sums, column copies, cache writes, argmax, top-k and the MoE route give torch's bits; silu products, gates, the MoE activation and RoPE sit within one rounding of float64; the DeltaNet within 5e-3 of a float64 recurrence at 64 to 4170 tokens, and a 200-row prompt cut at 1, 63, 64, 65 or 136 rows gives one call's rows and state, bit for bit.
    • Fails before the fix: dropping a tile's last key in the planned walk, or a subtraction in the sum kernel, fails the attention and the casts-and-sums tests; the cut test fails with the former chunked DeltaNet kernel (42/43).
    • Device code unchanged by removing the host launchers (at b731206): each of the 89 kernels a target resolved disassembled to the same instructions before and after, on gfx1100 and gfx1030.
  • Decode and prompt speed: not applicable here (no model path); the grouped decode walk's effect on served decode was measured on HIP: native Zig engine for Qwen3.5 MLX affine on RDNA2 / RDNA3 #490.
  • Tests run, fresh Zig cache:
    • Radeon PRO W7800 (gfx1100): hip-kernel-test 43/43, hip-gpu-test 30/30, hip-affine-test 27/27.
    • Radeon PRO V620 (gfx1030, fp16 activations): hip-kernel-test 43/43, hip-gpu-test 30/30, hip-affine-test 27/27.
    • macOS: zig build test -Dcpu=apple_m1 1013/1015 tests (2 skipped), test-golden 0 unexpected differences (the launches and ops compile in the host tests); Linux: CI zig passes. CI fmt passes. lean_check.py: 544 problems, the same as main.
  • Not run, and why: RDNA3.5 and RDNA4 hardware (none here); Metal and CUDA (sources untouched).

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (No engine path in this change.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (No engine path; the kernels a round uses keep a row's bits at any row count, which these tests check where they apply.)
  • No precision traded for speed. Each kernel's sums are checked against float64 or against the form it replaces.
  • Prompt processing is no slower than the last release. (No prompt path in this change.)
  • The description says which platforms I ran and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

…, DeltaNet, norms, RoPE, MoE routing and decode plans

The kernels a model engine composes, built by hipcc for -Dhip-arch with the caps table's instruction switches and
embedded as one code object a source group, launched from Zig: elementwise ops and casts, norms and the merged
decode tails, RoPE, the attention walks (flat, planned over a page table with the query heads of a KV head read
together, the 64-row prompt tile flat and paged), the DeltaNet recurrence token-serial and chunked, the
linear attention's conv and gates, the MoE router, pick and route, argmax and top-k, and a lane round's plan
kernels. A typed Ops layer checks shapes; an arena hands out a forward's scratch, and a counting stream measures
it without launching. hip-kernel-test checks each against a host or float64 reference, and the merged and paged
forms against the forms they replace, bit for bit where they promise it; -Dhip-device-lib names ROCm's bitcode.
The sources hold device code only: plain kernels by C name, templates instantiated for the types the launches use.
BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 10, 2026
… and model checks

The HIP branch's engine (ashhart#490) on ashhart#463's runtime and the kernel launches of ashhart#617 and ashhart#621: the lane rounds with
MTP drafts, the paged attention cache and the radix prompt cache (ashhart#625), chunked prompts (ashhart#623), CUDA-graph
rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The
native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (ashhart#624);
`tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels.

The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other
than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its
only reader is the plan.
@ThinkOffApp

Copy link
Copy Markdown
Contributor

gfx1151 receipt (Strix Halo: Ryzen AI Max+ 395, Radeon 8060S, RDNA3.5), head b731206, fresh Zig cache per step. This covers the RDNA3.5 row your receipt lists as not run.

  • Ubuntu 26.04.1, Linux 7.0.0, Zig 0.17.0, HIP 7.14.60850 (TheRock), -Dhip-arch=gfx1151
  • hip-kernel-test 42/42, hip-gpu-test 30/30, hip-affine-test 27/27, hip-host-test 40/40. Nothing skipped.
  • Linux zig build test: 32/32 steps, 307/307 tests.
  • Ubuntu's packaged HIP 7.1.52801 also builds and passes all four (139/139) with -Dhip-device-lib=/usr/lib/llvm-21/lib/clang/21/amdgcn/bitcode. Without it, the default <rocm>/lib/llvm/amdgcn/bitcode doesn't exist on Ubuntu and clang stops at "cannot find ROCm device library"; that layout could join the Arch note in zig/tests/hip_kernels.md.

…A header needed

From ThinkOffApp's gfx1151 runs on this PR and ashhart#621: Ubuntu's HIP 7.1 keeps its device bitcode in LLVM's clang
resource directory, and the kernels build there with -Dhip-device-lib set to it, without rocWMMA's header.
@ashhart

ashhart commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Thank you, @BlivionIaG. We read #617 (the model-free kernels on #463's runtime) together with #621 last night, at b731206a8:

It missed 1.0.6, which froze with the release gate already running, and it's first in line for 1.0.7. We'll read this morning's docs commit (9b6b26072) with that landing.

@ashhart

ashhart commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Thanks, @BlivionIaG. 1.0.7 went out this morning as a one-fix release for Living Weights, so #617 and #621 moved to 1.0.8 and we read them again at today's heads, 9b6b26072 included.

One question before it lands. zig/kernels/hip/recurrence/gdn_prefill.hip opens with vLLM's two SPDX lines, Apache-2.0 and "Copyright contributors to the vLLM project". It's the only file in the tree with them. We found no lines in common with vLLM's or your fork's GDN kernels, and its state layout is different, so it looks like code you wrote for TensorFold that kept the header from the fork's hand port. Is that right?

  • If so, could you drop those two lines? The file's next line already credits FLA's chunk_gated_delta_rule for the algorithm, and we'll add the matching line to THIRD_PARTY_NOTICES.md, as we did for our CUDA DeltaNet kernel.
  • If part of it was translated from vLLM's or FLA's Triton kernels, tell us which part. The tree only takes code written for it, so we'd work out with you how to redo that part.

Once that's settled, #617 and #621 go into 1.0.8 together, with #630's events beside them.

…e fork's hand ports

The kernel was written for TensorFold after FLA's chunk_gated_delta_rule; no
code came from vLLM or FLA, and the header only came along from the
opengfx1030/vllm-rdna ports.
@BlivionIaG

BlivionIaG commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@ashhart yes, it was written for TensorFold. It follows FLA's chunked gated delta rule, the stages I'd hand-ported in my fork (opengfx1030/vllm-rdna), and the header came from those files. No code was translated: the WY step is a forward substitution, not FLA's blockwise inverse; prep and kt are layout kernels with no FLA counterpart; h and o have their own tiling. No six-line window is shared with my fork's GDN kernels, exact or blanked.

Header dropped in 5d058942, merged into #621 (df83c6f6).

@ashhart ashhart mentioned this pull request Oct 14, 2026
@ashhart

ashhart commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Hello @BlivionIaG,

Thank you for the model-free HIP kernels, and for the gfx1100 and gfx1030 runs.

Two sums still disagree.

gated_delta.hip walks the sequence in fp32. gdn_prefill.hip multiplies fp16 operands and decays with __expf (gdn_prefill.hip:216, gdn_prefill.hip:229). gatedDelta sends 64 rows, or any prefill, to the chunked kernel when the head size is 128 (recurrence.zig:55). A prompt cut on either side of 64 rows is a different sum. Please keep one fp32 recurrence at every length.

The flat attention tile calls expf (attention_fa.hip:421). The paged tile calls __expf (prefill.hip:171, prefill.hip:175). Please call expf in both.

A push with those two, and a hip-kernel-test rerun on gfx1100 or gfx1030, is the update we need.

Thank you again.

…refill kernel goes

gatedDelta sent 64 rows or any prefill to gdn_prefill.hip (fp16 products, __expf), so a prompt cut on either side
of 64 rows was a different sum. Every length now runs the fp32 recurrence. The new test cuts a 200-row prompt at
1, 63, 64, 65 and 136 rows and checks the rows and state equal one call's bits; it fails with the chunked kernel.
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Hello @BlivionIaG,

Thank you for the model-free HIP kernels, and for the gfx1100 and gfx1030 runs.

Two sums still disagree.

gated_delta.hip walks the sequence in fp32. gdn_prefill.hip multiplies fp16 operands and decays with __expf (gdn_prefill.hip:216, gdn_prefill.hip:229). gatedDelta sends 64 rows, or any prefill, to the chunked kernel when the head size is 128 (recurrence.zig:55). A prompt cut on either side of 64 rows is a different sum. Please keep one fp32 recurrence at every length.

The flat attention tile calls expf (attention_fa.hip:421). The paged tile calls __expf (prefill.hip:171, prefill.hip:175). Please call expf in both.

A push with those two, and a hip-kernel-test rerun on gfx1100 or gfx1030, is the update we need.

Thank you again.

Sounds good to me, launched a rerun I expect some slight hit in prefill.

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

gated_delta.hip walks the sequence in fp32. gdn_prefill.hip multiplies fp16 operands and decays with __expf (gdn_prefill.hip:216, gdn_prefill.hip:229). gatedDelta sends 64 rows, or any prefill, to the chunked kernel when the head size is 128 (recurrence.zig:55). A prompt cut on either side of 64 rows is a different sum. Please keep one fp32 recurrence at every length.

d91b074: every length runs the fp32 recurrence (gated_delta.hip); gdn_prefill.hip and its dispatch are gone. A new test cuts a 200-row prompt at 1, 63, 64, 65 and 136 rows and checks that the rows and the state equal one call's bits; on the previous head it fails (42/43).

The flat attention tile calls expf (attention_fa.hip:421). The paged tile calls __expf (prefill.hip:171, prefill.hip:175). Please call expf in both.

5537d6a: the paged prefill tile calls expf (prefill.hip:171, prefill.hip:175).

A push with those two, and a hip-kernel-test rerun on gfx1100 or gfx1030, is the update we need.

Pushed. hip-kernel-test: 43/43 on gfx1100 and on gfx1030.

@ashhart

ashhart commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Hello @BlivionIaG,

Thank you for turning both changes around so quickly. One fp32 recurrence at every length, with gdn_prefill.hip gone, and a test that cuts a 200-row prompt at 1, 63, 64, 65 and 136 rows and checks the rows and state against one call's bits, is exactly the gate we wanted. The paged tile calling expf matches the flat one.

This is ready. It lands first in the HIP series, on your gfx1100 and gfx1030 receipts plus our host checks. We make three small fixes when it lands: the unused line at zig/src/hip/launches.zig:43, and wraps at zig/build/hip.zig:79 and zig/src/hip/kernel_tests/gdn.zig:110 and :114. #631, #697 and #655 follow it.

Thank you again.

@ashhart
ashhart merged commit d841aee into ashhart:main Oct 16, 2026
4 checks passed
ashhart pushed a commit that referenced this pull request Oct 16, 2026
… and model checks

The HIP branch's engine (#490) on #463's runtime and the kernel launches of #617 and #621: the lane rounds with
MTP drafts, the paged attention cache and the radix prompt cache (#625), chunked prompts (#623), CUDA-graph
rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The
native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (#624);
`tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels.

The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other
than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its
only reader is the plan.
ashhart pushed a commit that referenced this pull request Oct 16, 2026
… and model checks

The HIP branch's engine (#490) on #463's runtime and the kernel launches of #617 and #621: the lane rounds with
MTP drafts, the paged attention cache and the radix prompt cache (#625), chunked prompts (#623), CUDA-graph
rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The
native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (#624);
`tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels.

The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other
than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its
only reader is the plan.
ashhart added a commit that referenced this pull request Oct 16, 2026
The contributor's affine commit landed above, its lines unchanged on top of #617 (its other two commits are #612 and #613, in main since 1.0.6); this keeps the PR's head in the history with no change to the tree.
ashhart added a commit that referenced this pull request Oct 16, 2026
The contributor's two commits landed above, the kernels' lines on the post-#617 source groups, followed by our wraps; this keeps the PR's head in the history with no change to the tree.
ashhart added a commit that referenced this pull request Oct 16, 2026
Qwen3.5, Qwen3.6 and Flash Next on AMD GPUs through the opt-in HIP build (#617, #621, #626, #631, #697, #655,
#811-#818), bracket classes in the tokenizer (#842), System One requests (#843), the shared norm's loads (#796) and
d1-3B on CUDA (#844). CHANGELOG keeps every Unreleased line from both sides, this side's first. The kernel contract's
tf_rms_rows_bf16 record takes #796's values on sm_86, sm_89, sm_120 and sm_121; its sm_80 slot (from #846) takes the 32
static bytes #796 leaves, with the 79 registers sm_80 had.
@ashhart

ashhart commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Thank you, @BlivionIaG, for the model-free HIP kernels and the quick turn on the fp32 recurrence and the paged tile's expf.

Your six commits ship in TensorFold 1.0.12 under your name: 6a84628e1, 9fa17f787, bb39eadf0, 553ad7f42, 5d679ac70 and 53dbc1d61. Our 3bbce71a1 follows with the three small fixes we named: zig/src/hip/launches.zig no longer re-exports gdn_chunk, and three new lines wrap at 120 columns. Your head is merged after them, so this pull request shows as merged.

We have no AMD card, so this lands on your gfx1100 and gfx1030 runs plus our host checks. The HIP host tests and zig build test pass on macOS and Linux, and the three GPU test roots compile against stub code objects for macOS, aarch64 Linux and x86_64 Linux, with a planted type error failing each. The copy scan finds no shared window with the kernels we keep, and the CUDA and Metal servers built with the series are byte for byte the ones built without it.

@jkuepker ran these kernels on gfx1201 (an R9700) at #621's head, which carries them: hip-kernel-test 61 of 61 and hip-gpu-test 36 of 36. Still open: a gfx1151 run of this version, since @ThinkOffApp's was of an earlier one.

Posted by Ash's AI Assistant Synthena

BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… and model checks

The HIP branch's engine (ashhart#490) on ashhart#463's runtime and the kernel launches of ashhart#617 and ashhart#621: the lane rounds with
MTP drafts, the paged attention cache and the radix prompt cache (ashhart#625), chunked prompts (ashhart#623), CUDA-graph
rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The
native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (ashhart#624);
`tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels.

The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other
than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its
only reader is the plan.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The contributor's six commits landed above with the same code, followed by our fix-ups; this keeps the PR's head in the history with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The contributor's affine commit landed above, its lines unchanged on top of ashhart#617 (its other two commits are ashhart#612 and ashhart#613, in main since 1.0.6); this keeps the PR's head in the history with no change to the tree.
BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… and model checks

The HIP branch's engine (ashhart#490) on ashhart#463's runtime and the kernel launches of ashhart#617 and ashhart#621: the lane rounds with
MTP drafts, the paged attention cache and the radix prompt cache (ashhart#625), chunked prompts (ashhart#623), CUDA-graph
rounds, the memory plan, and tensor parallelism over RCCL (comm/: the library, the rank link, the group). The
native server takes it with `zig build native-hip -Dhip-arch=...` and the serve flags it lists (ashhart#624);
`tf-qwen35-test` runs the model checks on a GPU. `zig build test` compiles both against stub kernels.

The engine reads the policy (`--policy`, TF_POLICY) once and hands the kernels `Launcher.Choices`; a GPU other
than the one the kernels were built for is refused with both names. round_shape.zig stays in the family: its
only reader is the plan.
BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The contributor's two commits landed above, the kernels' lines on the post-ashhart#617 source groups, followed by our wraps; this keeps the PR's head in the history with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…rt#844 onto the candidate

Qwen3.5, Qwen3.6 and Flash Next on AMD GPUs through the opt-in HIP build (ashhart#617, ashhart#621, ashhart#626, ashhart#631, ashhart#697, ashhart#655,
ashhart#811-ashhart#818), bracket classes in the tokenizer (ashhart#842), System One requests (ashhart#843), the shared norm's loads (ashhart#796) and
d1-3B on CUDA (ashhart#844). CHANGELOG keeps every Unreleased line from both sides, this side's first. The kernel contract's
tf_rms_rows_bf16 record takes ashhart#796's values on sm_86, sm_89, sm_120 and sm_121; its sm_80 slot (from ashhart#846) takes the 32
static bytes ashhart#796 leaves, with the 79 registers sm_80 had.
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.

3 participants