Skip to content

feat(hip): the MLX affine products: dot2 tiles, the gfx11 matrix-core GEMM tile, stream and K-parallel tiles - #621

Merged
ashhart merged 15 commits into
ashhart:mainfrom
BlivionIaG:hip-kernels-affine
Oct 16, 2026
Merged

ashhart merged 15 commits into
ashhart:mainfrom
BlivionIaG:hip-kernels-affine

Conversation

@BlivionIaG

Copy link
Copy Markdown
Contributor

What this changes

The MLX affine 2- to 8-bit products a model's projections run, the second kernels slice tracked in #491, chosen per product by the registry (#613) over a per-GPU tuning table:

  • decode: the row, column, stream (up to four products sharing x, and a stacked gate and up with its activation as the epilogue) and split tiles, and RDNA2's wide tile;
  • prompt: the dot2 GEMM tile, the K-parallel tiles of short prompts, and gfx11's matrix-core GEMM tile with the compiler's WMMA builtins, so no rocWMMA (Ubuntu's ROCm 7.1 package, which lacks its header, builds it);
  • routed plans over stacked experts, and the embedding gather;
  • tuning tables for gfx1030 (RDNA2) and gfx1100 (RDNA3, RDNA3.5, RDNA4 on their dot2 tiles), read at build time so every rank picks alike.

The tile sources hold device code only; each kernel the launches resolve is instantiated explicitly.

Stacks on #617 and #613 (their commits are included here until they land); review the last commit.

Receipt

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; a row's bytes at any row count are checked here.)
  • No precision traded for speed. Each tile is checked against float64 at the fp32 sum's bound.
  • 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.
…it and dense, with tensor-parallel cuts

core/quant reads a checkpoint's MLX affine projections (bits 2, 3, 4, 5, 6 and 8, any group) or dense ones,
detects the format from the tensors, cuts a projection by output rows, by a rank's whole input groups or into
its two K halves, splits an expert stack across ranks, and hands a backend the upload. Every cut keeps the
codes and group tables byte for byte: a test quantizes with affine4_host and checks each cut dequantizes to the
same bits as the rows and columns it covers, and it fails when a cut is off by one group.
…st, one family of bits at every row count

core/registry selects, for a format, op (product, group, routed plan, routed with activation) and path (decode
or prompt), the cheapest entry the GPU, the run's switches and the shape allow, by a per-GPU tuning table read
at build time (core/tuning), so every rank picks alike. Its family rule checks that one (op, path) keeps one
family of entries at every row count from 1 to 256 for each width and group: a row's bits never depend on how
many rows share its launch. The rule's test fails when a tuning table lets another family take some rows.
… GEMM tile, stream and K-parallel tiles

The MLX affine 2- to 8-bit products a model's projections run, chosen per product by the kernel registry over a
per-GPU tuning table (gfx1030's for RDNA2, gfx1100's for RDNA3 to RDNA4): the decode row, column, stream and
split tiles, the RDNA2 wide tile, the prefill dot2 GEMM and K-parallel tiles, the gfx11 matrix-core GEMM tile
(compiler WMMA builtins, no rocWMMA), routed plans and products sharing x, with the routed gate and up's
activation as an epilogue. The tile sources hold device code only; each kernel the Zig launches resolve is
instantiated explicitly. hip-kernel-test checks every entry on the served models' shapes and a ragged sweep of
every width and group against float64, the entries the registry picks between by rows for equal bytes, and a
row's bytes alone and in a round of 2 to 32 rows.
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 6254228, 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 57/57, hip-gpu-test 30/30, hip-affine-test 27/27, hip-host-test 48/48. Nothing skipped. hip-kernel-test took about 2 minutes here (6 s on feat(hip): the model-free kernels on #463's runtime: attention, DeltaNet, norms, RoPE, MoE routing and decode plans #617).
  • Linux zig build test: 32/32 steps, 331/331 tests.
  • Ubuntu's packaged HIP 7.1.52801 (no rocWMMA header) also builds and passes all four, 162/162, with -Dhip-device-lib=/usr/lib/llvm-21/lib/clang/21/amdgcn/bitcode, which bears out the description's claim on real RDNA3.5.

…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 #621 (the MLX affine products on HIP) together with #617 last night, at 625422815:

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. We read #621 again at 1152c67df for 1.0.8, since 1.0.7 went out this morning as a one-fix release.

Since #621 carries #617's commits, it waits on the one question on #617 about the SPDX lines in gdn_prefill.hip. Once that's answered, both go into 1.0.8.

…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.
@ThinkOffApp

Copy link
Copy Markdown
Contributor

From our point of view for gfx1151 everything seems fine. Between our receipt heads (b731206, 6254228) and today's (5d05894, df83c6f), the only changes are zig/tests/hip_kernels.md and the two SPDX lines (with their blank lines) removed from gdn_prefill.hip, so the kernel source we tested is unchanged.

@ashhart ashhart mentioned this pull request Oct 14, 2026
…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

@jkuepker the receipt still open on #621 is one you can run:

The receipt still open is one gfx1201 run of hip-affine-test. gfx1100, gfx1030, and gfx1151 are already in.

We have no gfx1201 card. Could you run zig build hip-affine-test -Dhip-arch=gfx1201 at #621's head da96b90 (with the -Dhip-device-lib you used for ROCm 7.2.1) and post the count here?

@jkuepker

Copy link
Copy Markdown
Contributor

gfx1201 receipt (Radeon AI PRO R9700, RDNA4), head da96b90, one card (HIP_VISIBLE_DEVICES=0), fresh Zig local cache for this head. This covers the gfx1201 hip-affine-test row still open.

  • Host Ubuntu 24.04.4, Linux 7.0.0-38; Ubuntu 24.04.4 container with ROCm 7.2.4 (HIP 7.2.53211, AMD clang 22.0.0git roc-7.2.4), Zig 0.17.0
  • Flags: -Dhip-arch=gfx1201 -Dhipcc=/opt/rocm/bin/hipcc -Dhip-device-lib=/opt/rocm/lib/llvm/lib/clang/22/lib/amdgcn/bitcode (ROCm 7.2.x keeps the device bitcode under lib/llvm/lib/clang/22, not the default lib/llvm/amdgcn/bitcode)
branch / SHA command result
hip-kernels-affine da96b90 zig build hip-affine-test -Dhip-arch=gfx1201 … 5/5 steps, 30/30 tests passed, 0 skipped
hip-kernels-affine da96b90 zig build hip-kernel-test -Dhip-arch=gfx1201 … 13/13 steps, 61/61 tests passed, 0 skipped (about 2 min)
hip-kernels-affine da96b90 zig build hip-gpu-test -Dhip-arch=gfx1201 … 5/5 steps, 36/36 tests passed, 0 skipped
hip-kernels-affine da96b90 zig build hip-host-test 8/8 steps, 51/51 tests passed (CPU)

rocminfo on the run: gfx1201, amdgcn-amd-amdhsa--gfx1201.

@BlivionIaG

Copy link
Copy Markdown
Contributor Author

gfx1201 receipt (Radeon AI PRO R9700, RDNA4), head da96b90, one card (HIP_VISIBLE_DEVICES=0), fresh Zig local cache for this head. This covers the gfx1201 hip-affine-test row still open.

  • Host Ubuntu 24.04.4, Linux 7.0.0-38; Ubuntu 24.04.4 container with ROCm 7.2.4 (HIP 7.2.53211, AMD clang 22.0.0git roc-7.2.4), Zig 0.17.0
  • Flags: -Dhip-arch=gfx1201 -Dhipcc=/opt/rocm/bin/hipcc -Dhip-device-lib=/opt/rocm/lib/llvm/lib/clang/22/lib/amdgcn/bitcode (ROCm 7.2.x keeps the device bitcode under lib/llvm/lib/clang/22, not the default lib/llvm/amdgcn/bitcode)
branch / SHA command result
hip-kernels-affine da96b90 zig build hip-affine-test -Dhip-arch=gfx1201 … 5/5 steps, 30/30 tests passed, 0 skipped
hip-kernels-affine da96b90 zig build hip-kernel-test -Dhip-arch=gfx1201 … 13/13 steps, 61/61 tests passed, 0 skipped (about 2 min)
hip-kernels-affine da96b90 zig build hip-gpu-test -Dhip-arch=gfx1201 … 5/5 steps, 36/36 tests passed, 0 skipped
hip-kernels-affine da96b90 zig build hip-host-test 8/8 steps, 51/51 tests passed (CPU)

rocminfo on the run: gfx1201, amdgcn-amd-amdhsa--gfx1201.

Thank you very much 🔥

@millaguie

Copy link
Copy Markdown
Contributor

gfx1150 receipt (Radeon 890M, RDNA 3.5 iGPU in a Ryzen AI 9 HX 370), head da96b90, the only GPU in the machine. This covers the gfx1150 hip-affine-test row still open.

  • Host Arch Linux, Linux 7.2.9, ROCm 7.2.4 (HIP 7.2.53211, AMD clang 22.0.0git), Zig 0.17.0
  • Flags: -Dhip-arch=gfx1150 -Dhipcc=/opt/rocm/bin/hipcc -Dhip-device-lib=/opt/rocm/amdgcn/bitcode (the Arch package keeps the bitcode under /opt/rocm/amdgcn/bitcode)
branch / SHA command result
hip-kernels-affine da96b90 zig build hip-affine-test -Dhip-arch=gfx1150 … 5/5 steps, 30/30 tests passed
hip-kernels-affine da96b90 zig build hip-gpu-test -Dhip-arch=gfx1150 … 5/5 steps, 36/36 tests passed
hip-kernels-affine da96b90 zig build hip-host-test 8/8 steps, 51/51 tests passed (CPU)

rocminfo on the run: gfx1150.

I could not finish hip-kernel-test on this machine. The 890M also drives the desktop, and while the test ran the kernel reported ring gfx_0.0.0 timeout for the compositor's queue. The first time the ring reset worked, the second time it failed and the driver did a full GPU reset (MODE2 reset), so I stopped the test. I think this is the shared iGPU and not the kernels, but I have no clean result for that row. If it helps, I can run it again from a text console without the desktop.

@ashhart
ashhart merged commit 4793b82 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
…A header needed

From ThinkOffApp's gfx1151 runs on this PR and #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 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
…alls

The loader step calls coreModule, which came into zig/build/hip.zig with the HIP affine products (#621), not yet on
this branch; the helper is that one, unchanged.

Co-authored-by: BlivionIaG <[email protected]>
ashhart added a commit that referenced this pull request Oct 16, 2026
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 added a commit that referenced this pull request Oct 16, 2026
The HIP affine line still said a hip-affine-test run on gfx1201 was owed. @jkuepker
ran it on 14 Oct on an RDNA4 Radeon AI PRO R9700 (#621): hip-affine-test 30 of 30,
hip-kernel-test 61 of 61, hip-gpu-test 36 of 36. The line now says so and thanks him.
@ashhart

ashhart commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Thank you, @BlivionIaG, for the affine products, and @ThinkOffApp for the gfx1151 runs.

It ships in TensorFold 1.0.12 under your name as 72d967ddb, right after #617. Your affine commit met #617's recurrence change in three places, and we resolved them as your own merge did, so the commit adds exactly your lines. Your head is merged after it, so this pull request shows as merged.

We have no AMD card, so this lands on your runs and @ThinkOffApp's plus our host checks: hip-kernel-test 57 of 57, hip-gpu-test 30 of 30 and hip-affine-test 27 of 27 on gfx1100 and gfx1030, and the same on gfx1151 with HIP 7.14 and with Ubuntu's packaged HIP 7.1. On our side the HIP host tests and zig build test pass on macOS and Linux, the GPU test roots compile against stub code objects, and the copy scan finds no shared window beyond runs of declarations.

Thank you, @jkuepker, for the gfx1201 run at this head on an R9700, the one chip whose dot2 tiles none of those cards take: hip-affine-test 30 of 30, hip-kernel-test 61 of 61 and hip-gpu-test 36 of 36.

Posted by Ash's AI Assistant Synthena

BlivionIaG added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…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.
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 added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…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.
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 added a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…alls

The loader step calls coreModule, which came into zig/build/hip.zig with the HIP affine products (ashhart#621), not yet on
this branch; the helper is that one, unchanged.

Co-authored-by: BlivionIaG <[email protected]>
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.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The HIP affine line still said a hip-affine-test run on gfx1201 was owed. @jkuepker
ran it on 14 Oct on an RDNA4 Radeon AI PRO R9700 (ashhart#621): hip-affine-test 30 of 30,
hip-kernel-test 61 of 61, hip-gpu-test 36 of 36. The line now says so and thanks him.
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.

5 participants