Skip to content

inkling2 on AMD: flash prefill attention on wave32 WMMA - #413

Closed
AzeezIsh wants to merge 1 commit into
mainfrom
perf/inkling2-hip-prefill-attn
Closed

AzeezIsh wants to merge 1 commit into
mainfrom
perf/inkling2-hip-prefill-attn

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

inkling2 on AMD: flash prefill attention on wave32 WMMA

Ports the Ciru B2-style flash prefill body (Apache-2.0, attributed) to
gfx1151 wave32 WMMA for the inkling-2-mini strix-hip target: K/V staged in
LDS, Q in registers, register online softmax over the (row=2e+lane_hi,
col=lane_lo) fragment layout, fp16 P staged per warp for the PV MMA.
Semantics kept bit-for-bit with inkling2_prefill_attn: bf16-rounded
rel-bias in inkling2_rel_bias_table's accumulation order, per-token sinks,
1024-token SWA on the sliding layers vs full attention on the 4 full
layers, 4096-token prefill chunks reading the paged KV of earlier chunks.
rows >= 64 takes this kernel on cfg!(atlas_scale); the PTX body and all
non-AMD routing are untouched.

Fixes folded in from the first gate:

  • the score A-fragment is loaded by memcpy of the raw 32 bf16 bytes; the
    original (__bf16)((unsigned short*)&lo)[i] was a numeric ushort->bf16
    conversion (0x3F40 -> 16256.0) that made every score ~1e4 garbage.
  • P staging publishes through a fenced wave sync (the ink_wave_sync
    pattern): hipcc's __syncwarp is a bare wave barrier with no LDS
    ordering.

Standalone hipcc check vs a CPU reference on gfx1151: q_len 1..4096,
windows 0/16/64/1024/full, chunked prefill q_offset 500..3000 over paged
KV -> max|d| <= 0.004.

Framework gate (vs PR-1 parent binary, official checkpoint + Spark
overlay): prefill_h2h 7,773 tok 5.71s -> 5.10s (1,362 -> 1,525 tok/s),
30,993 tok 27.94s -> 22.41s (1,109 -> 1,383 tok/s); task_probe math 30/30
and tools 10/10 on all four arms; pd_check 96/96 aligned x6, mean|dlp|
0.0046-0.0188 (inside the f373 noise); NLL code 0.63684 (ref 0.63689),
text 0.89670 (ref 0.89618) - inside tolerance given the flash
accumulation order and fp16 P; greedy C1 spark 8/8 identical, strict 6/8
(concurrent-batch scheduling jitter class, same as the PR-1 gate);
0 ERROR/panic on every arm.

gb10 byte-identity: nvcc -ptx (sm_121a) of kernels/gb10/inkling-2-mini/
nvfp4/inkling2_flash_prefill.cu at this commit vs main 7a717b6 produces
identical PTX - the AMD body is fully inside #if SCALE /
HIP_PLATFORM_AMD and the PTX body under #else is untouched.

Stacked on the batched-NVFP4 PR (base = its branch). DevLab strix-hip build 45343130375: success.

Generated with Devin

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Queued in train #421 (integ/train-inkling-20261125), merged --no-ff in stack order. GB10 gate is running on sparky (job 187); results will be posted on #421.

🤖 Generated with Claude Code

@AzeezIsh
AzeezIsh force-pushed the perf/inkling2-hip-batched-nvfp4 branch from 258d9a5 to fbb7f4f Compare November 25, 2026 10:56
@AzeezIsh
AzeezIsh force-pushed the perf/inkling2-hip-prefill-attn branch from b98d65c to 75e3941 Compare November 25, 2026 10:56
AzeezIsh added a commit that referenced this pull request Nov 25, 2026
…logue bound

#412 and #413 were re-pushed with one change: w4a16_wmma's prologue loads
a K group's first weight tile only when the slice has one (a short last
slice read one tile past the pretiled buffer; HSA memory fault on a 16-row
Spark prefill chunk, DevLab 45568957561 / 45587106711). The earlier heads
are already merged above; this brings in the fixed ones.

# Conflicts:
#	kernels/strix-hip/inkling-2-mini/nvfp4/inkling2_w4a16_wmma.cu
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

The re-pushed head (with the guarded w4a16_wmma prologue) is in train #421 at 26c2a7ac7. DevLab Strix serves Spark again: C1 42.7 tok/s, C8 84.3. The old head faulted on the first 16-token Spark prefill chunk (bisect on #421).

🤖 Generated with Claude Code

@AzeezIsh
AzeezIsh changed the base branch from perf/inkling2-hip-batched-nvfp4 to main November 25, 2026 12:57
Prefill: 1,362 -> 1,525 tok/s @7.7K and 1,109 -> 1,383 @31k on framework
(hipcc 7.13); runner (hipcc 7.16) 1,192/954 -> 1,327/1,174 (+11%/+23%)
after staging V as fp16 in LDS, which drops 7.16 VGPR spill slots
128 -> 16 (fused softmax row staging; no tm/pv temporaries).

pd_check 96/96 aligned x6 prompts, mean|dlp| 0.0046-0.0188 (f373 noise);
NLL code 0.63684 (-0.00005), text 0.89670 (+0.00052, accepted:
flash accumulation order + fp16 P on AMD; pd within noise).
task_probe math 30/30 + tools 10/10 spark and strict; agentic 10/10.
gb10 inkling-2-mini PTX byte-identical to main.

ST-995 (bfcl-subset n=995): 77.99/78.19 vs main's 79.10/79.63.
Per-sample rescore vs #412-only responses: 57 verdict flips,
34 lost / 23 gained (-1.11 net); two-sided sign test p ~= 0.19,
indistinguishable from accumulation-order noise at temp 0.
Deterministic across reruns (bit-identical rerun).
@AzeezIsh
AzeezIsh force-pushed the perf/inkling2-hip-prefill-attn branch from 75e3941 to de09da3 Compare November 25, 2026 16:02
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Its content at 75e3941 merged to main in train #421 (791b347). On the DevLab runners' hipcc 7.16 that kernel spills registers: 256 VGPRs and 117 spill slots, against 234 and 0 on hipcc 7.13. That makes runner prefill 8–12% slower than before. The fix (fused softmax staging and fp16 V staged in the kernel) follows in a new PR on current main.

@AzeezIsh AzeezIsh closed this Nov 25, 2026
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

Superseded: this branch's content at 75e3941 merged via merge train #421. Follow-up fix for the hipcc 7.16 register-spill regression in the flash kernel (runner prefill regression) is on perf/inkling2-hip-flash-spills (5783098) — new PR to be opened separately.

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.

1 participant