Repository navigation
ggml-hrx: derive decode-split FA tile visibility from shared memory (engine#314) - #95
bong-water-water-bong wants to merge 1 commit into
Conversation
…engine#314) The decode-split flash-attention kernel fails to emit for D=256 with 24 q / 4 kv heads: the AMDGPU scheduler cannot order a low.cond_br whose condition comes from a subgroup collective, reporting unresolved state dependency from node 'low.cond_br' to node 'amdgpu.s_cmp_lg_u64.src1_inline' ... 2 unscheduled node(s) kernel.subgroup.vote.all/any are that collective. Each lane's key visibility is already stored in the shared %visibility_view, so the tile predicates are derived by reading the tile's 16 entries directly. No collective, same semantics: the vote's all_visible reduces to 'all 16 lanes of this tile see a visible key', since the other 48 lanes in the subgroup are outside the tile by construction. Verified: compiles and runs for key_value_token_count=1024, query_head_count=24, key_value_head_count=4, qk/value_head_size=256; bit-identical output (out0, sum) to the voting kernel on a masked-KV check where only the masked rows V changes. NOT verified against the authoritative masked-KV tool, and the original emission failure does not currently reproduce on demand.
|
Status (goal continuation, 2026-10-06): the base was Disposition: kept as a draft candidate, NOT part of the release pin. The engine-pinned tree |
|
Not the variant that landed — It is worth keeping as a reference, though: it removes the same collectives while retaining the direct V path for key tiles that need no masking, so if decode throughput ever matters here, this is the variant to benchmark against the landed always-stage form. Neither was benchmarked when the decision was made (no machine headroom at the time). |
…e-split FA (engine#314) cf4dfd8 (the commit the engine currently pins) and f9ff066 (PR #95) are siblings on f2099e9: the first removes the two subgroup collectives by forcing the staging path on every key tile, the second keeps the conditional staging and derives the visibility predicates from shared memory instead. This merge keeps the second, so the emission fix (#314) remains and the unconditional staging cost it introduced goes away. Resolved on the single conflicting file; the kernel content is byte-identical to f9ff066's. Engine#315 context: the unconditional staging plus looser arena reuse is the configuration under which the pressure-dependent all-NaN logits concentrate.
…4/315) Moves third_party/llama.cpp cf4dfd801e -> 26330cc20, a merge that keeps the engine#314 emission fix and drops the cost it introduced. Context: cf4dfd801e removed the two unordered subgroup collectives in the decode-split FA kernel by forcing the staging path on every key tile (the engine#314 always-stage fallback). Its own commit message noted it "pays the staging loop and two subgroup barriers on every key tile instead of only the tiles that need masking". The merged commit takes f9ff06675 (open as 1bit-MONSTER/llama.cpp#95) instead, which keeps the conditional staging and derives the visibility predicates from shared memory, so no collective remains: real subgroup.vote in the kernel: 0 merged kernel file is byte-identical to f9ff06675 Measured on Strix Halo with the pressure harness (3 neighbour servers so each arm runs at gtt_start ~102 GiB, 66 requests per arm, control and guard-off arms paired inside one box state): on cf4dfd801e the guard-off arm faulted with all-NaN logits (count=154880 of 154880, contiguous=yes, the whole output vector unwritten) 1 time in 7 arms; on the pre-#314 revision f2099e9b the same harness produced 0 NaN in 11 arms, including 5 of 5 clean in the guard-off cell. That is consistent with the unconditional staging being implicated, and is NOT significant (about 59% by chance at the ~10% base rate), so this change is justified by removing a known unconditional cost while keeping the correctness fix, not by a measured cure. The engine#315 residual fault is therefore not claimed fixed. Its acceptance criterion remains 12 consecutive arms with 0 NaN and 66/66 requests at gtt_start >= 95 GiB, judged on the guard's count/contiguous=yes case rather than on frequency. Also note the automatic route has been dead: bump-hrx has failed on 12 consecutive scheduled runs (last success 2026-09-24), so this is a hand pin move, which .gitmodules documents as the practice ("hrx-system is rebased by hand") and which every recent pin move has used. hrx-system is unchanged at 98d05d94a9f9.
…4/315) (#347) Moves third_party/llama.cpp cf4dfd801e -> 26330cc20, a merge that keeps the engine#314 emission fix and drops the cost it introduced. Context: cf4dfd801e removed the two unordered subgroup collectives in the decode-split FA kernel by forcing the staging path on every key tile (the engine#314 always-stage fallback). Its own commit message noted it "pays the staging loop and two subgroup barriers on every key tile instead of only the tiles that need masking". The merged commit takes f9ff06675 (open as 1bit-MONSTER/llama.cpp#95) instead, which keeps the conditional staging and derives the visibility predicates from shared memory, so no collective remains: real subgroup.vote in the kernel: 0 merged kernel file is byte-identical to f9ff06675 Measured on Strix Halo with the pressure harness (3 neighbour servers so each arm runs at gtt_start ~102 GiB, 66 requests per arm, control and guard-off arms paired inside one box state): on cf4dfd801e the guard-off arm faulted with all-NaN logits (count=154880 of 154880, contiguous=yes, the whole output vector unwritten) 1 time in 7 arms; on the pre-#314 revision f2099e9b the same harness produced 0 NaN in 11 arms, including 5 of 5 clean in the guard-off cell. That is consistent with the unconditional staging being implicated, and is NOT significant (about 59% by chance at the ~10% base rate), so this change is justified by removing a known unconditional cost while keeping the correctness fix, not by a measured cure. The engine#315 residual fault is therefore not claimed fixed. Its acceptance criterion remains 12 consecutive arms with 0 NaN and 66/66 requests at gtt_start >= 95 GiB, judged on the guard's count/contiguous=yes case rather than on frequency. Also note the automatic route has been dead: bump-hrx has failed on 12 consecutive scheduled runs (last success 2026-09-24), so this is a hand pin move, which .gitmodules documents as the practice ("hrx-system is rebased by hand") and which every recent pin move has used. hrx-system is unchanged at 98d05d94a9f9. Co-authored-by: bcloud <bcloud@localhost>
…n kernel (engine #449) (#107) * qwen: publish the next-RMSNorm q8 alternate from the fused routed-down kernel (engine #449) The q8 producer the ruling asked for is in the corpus, unregistered: qwen3_moe:qwen3_moe_routed_down_weighted_reduce_next_rmsnorm_q8_1_x4. Its launch signature (route weights, routed-down f16 alternate, hidden state accumulated in place, next norm weight, quantized next-projection input) is the same five bindings as the f32 variant, so selecting it replaces the f32 normalized row rather than adding one. Selection is consumer-driven: publish_q8 is set only when the normalized value feeds a projection that reads Q8_1 x4 (new common/dispatch-q8-publication.h), so a BF16 consumer, a transposed operand or an unqualified output size keeps the f32 path and no quantize work happens. Layout aliases that cover the whole row are followed. Test: the guard's residual source is now a transient (ggml_dup), which is what a real layer feeds the fused kernel; an external residual keeps its storage (#95), which is why the fused arm was unreachable in this case. Expected producer names are the two corpus kernels, and the arity is five for both because the q8 form has no separate f32 buffer. The pre-re-head _publish_q8 kernel took a sixth buffer and the pre-re-head test asserted six. Host suite (CPU, ryzen): 45 passed, 13 failed, 7 known-fail, 1 unexpected-pass, 66 total. The unexpected pass is this guard; its marker is retired in the same PR once the device gate passes, as instructed. Co-Authored-By: Claude Opus 5.5 <[email protected]> * tests: retire the #449 marker for qwen weighted-reduce q8 (device gate passed) Device gate on HRX0 (IREE_HAL_AMDGPU_LIBHSA_PATH=therock100 libhsa, which is what attaches HRX0 on this box): test-backend-ops -b HRX0 1141/1141 passed; Qwen3-Coder-30B-A3B tg128 91.32 -> 91.86 t/s, pp512 2041 -> 2036 t/s; Qwen3-8B tg128 42.65 -> 42.70 t/s, pp512 2267 -> 2342 t/s; needle 7341 @4732 3/3. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: bong-water-water-bong <[email protected]>
… require (engine#2138) (#365) At the engine#2357 pin (e1be68d) AMD's hrx-loom-jit-test fails `compile` and `binary-fusions` with CONFIG/INVALID "unresolved config ... remains for final compilation". All three kernels involved take compile parameters that this line added and AMD's corpus (9bf5871) does not have; our dispatch emits each of them, and the AMD test predates them: - ggml.flash_attention.value_stride (prefill, #95): kv_heads * head_size, as test-hrx-loom-jit.cpp already passes; - llm.ssm_conv.generic.n_t / n_s (generic SSM_CONV): the token and sequence counts, as dispatch-ssm-conv.cpp sets; - ggml.copy_transpose_f16.row_count / column_count / output_pitch (6c4a83f): the values dispatch-flash-attention.cpp emits for the case's 8192 x 1024 V (spread pitch 8192 + 32). No kernel or dispatch change. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…sidual - it builds the graph-internal one and runs on the host tier (engine#3380) (#506) engine#3380: qwen.matmul.attention_output_q4k_q8_1_x4_next_q8 was selected in no configuration, and its two rows were known-fail device cases that no host run ever reached. match_qwen_attention_output_next_q8() requires the residual input to be ValueKind::Transient (dispatch_registration/qwen/dispatch-qwen-matmul.cpp:318): the fused kernel accumulates the projection into the residual buffer (qwen3_moe.dense_quantized.output_accumulation=1, same file:437), so writing a caller-owned value would corrupt it (#95). The row built the residual with ggml_new_tensor_2d - a graph input, ValueKind::External (graph/graph.cpp:31-49) - so the matcher declined at that clause every time and the projection fell to common.mul_mat_postops.f32_f32_wmma / common.mul_mat.f32_f32_decode. The shipped Qwen3-MoE graph does not look like that: inpSA is the layer input, produced inside the same graph (src/models/qwen3moe.cpp:83, 127, 155, 161). In the shipped build a second thing hides the route: the add-on's hip.gemv_wide is a Fused MUL_MAT matcher at 329 and claims a one-token Q4_K projection whose q8_1 input exists before this route at 300 is tried. It binds the same q8_1 alternate the FA route publishes (its matcher asks for an existing q8_1 input), so that copy is read, not wasted. - tests/hrx-ops-test.cpp: the row's residual comes from a producer, as in the shipped graph, and the graph-internal kind is asserted. The plan is 4 dispatches (FA, residual, the fused route, the next projection) and 2 completion counters, with the fused kernel present in both graph shapes. - tests/hrx-ops-test.cpp: both rows are host_case rows now (the case builds a graph and reads the plan back; it never opens a device), and the known_fail label is gone. On an add-on tree the add-on matcher wins, so the row says what it does not assert and returns, the engine#3085 pattern, instead of failing on a name no add-on build produces. - dispatch-qwen-matmul.cpp: the registration comment records the transient-residual requirement and the 329 add-on matcher above it; tests/test-hrx-ops.cpp's fallback comment records why its external residual cannot select the route. Evidence (host tier on ryzen, no device; the plans are for gfx1151 and execute nothing): Control at e0e7c8d with only the two rows registered host-tier so the case can run at all: $ GGML_HRX_LOG_DISPATCH=1 build/bin/hrx-ops-test --hrx-test-filter '^qwen_decode_attention_output_next_q8\.' \ --hrx-test-jobs 1 --hrx-test-output all [FAIL] qwen_decode_attention_output_next_q8.no_selectors ggml_hrx dispatch: common.flash_attention_decode_split_next_q8 (single) ggml_hrx dispatch: common.mul_mat_postops.f32_f32_wmma (fused) ggml_hrx dispatch: qwen.decode_rmsnorm_f32_quantize_q8_1_x4 (fused) ggml_hrx dispatch: common.mul_mat.f32_f32_decode (fused) tests/hrx-ops-test.cpp:5557: requirement failed: plan.dispatches.size() == 3 (the selectors row fails the same way; its projection is taken by common.mul_mat.f32_f32_decode + common.gather_add_f32) With this change: [PASS] qwen_decode_attention_output_next_q8.no_selectors ggml_hrx dispatch: common.flash_attention_decode_split_next_q8 (single) ggml_hrx dispatch: qwen.matmul.attention_output_q4k_q8_1_x4_next_q8 (fused) ggml_hrx dispatch: common.binary_f32 (single) ggml_hrx dispatch: common.mul_mat.f32_f32_decode (fused) [PASS] qwen_decode_attention_output_next_q8.selectors (same four, plus common.get_rows.f32 before the add) HRX test summary: 2 passed, 0 failed, 0 known-fail, 0 unexpected-pass, 2 total Add-on build (-DGGML_HRX=ON -DLLAMA_BUILD_TESTS=ON -DGGML_HRX_KERNEL_CORPUS_SOURCE_FORMAT=text -DGGML_HRX_HIP_TARGETS=gfx1151 -DGGML_HRX_HIP_ADDON_DIR=<gpu-kernels b80d7496>/addons/hip-hrx): hip.gemv_wide (fused) takes the projection in both shapes, each row labels the non-assertion and exits 0: HRX test summary: 2 passed, 0 failed, 0 known-fail, 0 unexpected-pass, 2 total Full host tier: hrx-ops-test 12 passed, 0 failed, 0 known-fail, 0 unexpected-pass (12 total, rc 0); test-hrx-ops 2 passed, 0 failed, 0 known-fail (rc 0). check_stale_expectations.py --check: 490 expectation literal(s), every one selectable; --self-test ok. Not verified here: no device run, no decode tok/s. Plan-level selection is shown on the host tier; whether the fused route beats hip.gemv_wide plus separate add/rmsnorm/mul dispatches on gfx1151 is unmeasured, and moving this registration above 329 would need that measurement. Assisted-by: DeepSeek Harness (deepseek-flash) Co-authored-by: bong-water-water-bong <[email protected]>
engine#314 candidate 1 of 2 — needs the authoritative masked-KV check before merge
Do not merge on this branch alone. Rationale and limits are in the commit message; summarised:
D=256, 24 q / 4 kvheads: the AMDGPU scheduler cannot order alow.cond_brwhose condition comes from a subgroup collective (kernel.subgroup.vote.all/any), reporting an unresolved dependency onamdgpu.s_cmp_lg_u64.%visibility_view(the tile's 16 entries) — the same predicate, since the vote'sall_visiblereduces to "all 16 lanes of this tile see a visible key": the other 48 lanes are outside the tile by construction.out0=0.0100021362,sum=61.453125) to the voting kernel on an equivalent masked-KV check where only the masked rows' V changes.ggml-hrx-attn-masked-kv-check— the authoritative instrument, which I don't have — and I cannot demonstrate that it fixes the emission failure, because that failure no longer reproduces for me, not even in a freshly configured tree.There is a simpler alternative:
1bit/fa-always-stage(+6/-2), opened as a second draft PR. It removes the same collectives by taking the staging path unconditionally. This branch keeps the direct V path for tiles that need no masking and stages only where it must; the other pays the staging loop and two subgroup barriers on every key tile. Pick one, not both. Neither is benchmarked — no machine headroom — so the performance difference between them is reasoning, not measurement.Tracked as
1bit-MONSTER/engine#314.