[PR #2019] [CLOSED] prefill: q's split, norm and rope as one kernel (opt-in STRATA_QPREP=1, the same bits) #3811

Closed
opened 2026-11-07 15:30:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2019
Author: @libratechw
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: pr/prefill-fusions


📝 Commits (1)

  • d61666e prefill: q's split, norm and rope as one kernel (opt-in STRATA_QPREP=1, the same bits)

📊 Changes

5 files changed (+144 additions, -3 deletions)

View changed files

📝 CMakeLists.txt (+4 -0)
📝 include/strata/prefill/kernels.hpp (+4 -0)
📝 src/prefill/kernels.cu (+62 -0)
📝 src/prefill/prefill.cpp (+9 -3)
➕ tests/hip/prefill_q_prep.cpp (+65 -0)

📄 Description

Title

Issue: none

Summary

On the full-attention layers' prompt path, split_q, rms_rows over the 24 q heads and rope run as one kernel
(q_prep), one block per (token, head) row, with the same bits as the three kernels. The gain is small (+0.6% on a 32K
prompt), so it is opt-in. Say if you would rather not carry it. (This PR first also carried the gated attention epilogue;
that is now its own PR, #2588.)

What changed

  • src/prefill/kernels.cu, include/strata/prefill/kernels.hpp: q_prep. It keeps rms_rows_kernel's and rope_kernel's
    loop shapes and expressions (a register version with a constant 256 differed in ~5% of the rows by one ulp; the cause was
    not isolated).
  • src/prefill/prefill.cpp: STRATA_QPREP=1 calls it in place of the three kernels; without it they run as before.
  • tests/hip/prefill_q_prep.cpp, CMakeLists.txt: hip_prefill_q_prep compares q_prep with the three kernels bitwise
    for 1, 5, 64, 1,000 and 4,089 tokens from positions 0 / 4,089 / 100,000, with the default RoPE scaling: 0 values differ
    on gfx1151.

Ryzen AI Max+ 395 (gfx1151, ROCm 7.14.1, Linux), on 296b59d2, the branch's binary without and with STRATA_QPREP=1,
UD-Q4_K_XL, --serve --prefill 16384 --spec 4, the section-5 switches of docs/STRIX_HALO.md with
STRATA_PF_SWITCH_MIN_T=2048 and STRATA_PF_FUSED_KQ=1, a 32K chat request, fresh servers alternating, 7 pairs (of 8, one dropped for page migration or reclaim during a prompt): 1,249 -> 1,257 tok/s
(median), the median of the pair ratios +0.6%, 6 of 7 pairs faster.
The records and scripts are in libratechw/Strata@686de2e9, 2019q/.

A wider check outside ctest (a local copy of the test, in the records): 72 combinations of none / linear / YaRN scaling,
the angle table on / off, MRoPE on / off, 1 / 65 / 513 tokens and start positions 0 / 8,190 (across the table's end at
8,192) give the same bits.

Builds and tests on this branch:

  • HIP gfx1151: ctest, 113 tests: 105 pass (hip_prefill_q_prep among them), 5 skip, and the same three fail as on 296b59d2
    (ple_parity, expert_parity, pool_test).
  • HIP: strata_kernels, strata_prefill and strata_mmq compile for gfx1012, gfx1030, gfx1100, gfx1103, gfx1150, gfx1151,
    gfx1200 and gfx1201.
  • CUDA 13.0, RTX 3060 (Windows): builds; ctest, 117 tests: 114 pass, 2 skip, and ple_parity fails as on 296b59d2.
  • SYCL: not affected (the SYCL port has its own kernels and prefill.cpp).

Not run: STRATA_QPREP=1 on CUDA (the bitwise test is HIP's), other GPUs, UD-IQ4_XS.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/2019 **Author:** [@libratechw](https://github.com/libratechw) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/prefill-fusions` --- ### 📝 Commits (1) - [`d61666e`](https://github.com/Niko1221/Strata/commit/d61666ed30ee0249e0228421ea406579b2aa2e64) prefill: q's split, norm and rope as one kernel (opt-in STRATA_QPREP=1, the same bits) ### 📊 Changes **5 files changed** (+144 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+4 -0) 📝 `include/strata/prefill/kernels.hpp` (+4 -0) 📝 `src/prefill/kernels.cu` (+62 -0) 📝 `src/prefill/prefill.cpp` (+9 -3) ➕ `tests/hip/prefill_q_prep.cpp` (+65 -0) </details> ### 📄 Description ## Title Issue: none ## Summary On the full-attention layers' prompt path, `split_q`, `rms_rows` over the 24 q heads and `rope` run as one kernel (`q_prep`), one block per (token, head) row, with the same bits as the three kernels. The gain is small (+0.6% on a 32K prompt), so it is opt-in. Say if you would rather not carry it. (This PR first also carried the gated attention epilogue; that is now its own PR, #2588.) ## What changed - `src/prefill/kernels.cu`, `include/strata/prefill/kernels.hpp`: `q_prep`. It keeps `rms_rows_kernel`'s and `rope_kernel`'s loop shapes and expressions (a register version with a constant 256 differed in ~5% of the rows by one ulp; the cause was not isolated). - `src/prefill/prefill.cpp`: `STRATA_QPREP=1` calls it in place of the three kernels; without it they run as before. - `tests/hip/prefill_q_prep.cpp`, `CMakeLists.txt`: `hip_prefill_q_prep` compares `q_prep` with the three kernels bitwise for 1, 5, 64, 1,000 and 4,089 tokens from positions 0 / 4,089 / 100,000, with the default RoPE scaling: 0 values differ on gfx1151. Ryzen AI Max+ 395 (gfx1151, ROCm 7.14.1, Linux), on 296b59d2, the branch's binary without and with `STRATA_QPREP=1`, UD-Q4_K_XL, `--serve --prefill 16384 --spec 4`, the section-5 switches of `docs/STRIX_HALO.md` with `STRATA_PF_SWITCH_MIN_T=2048` and `STRATA_PF_FUSED_KQ=1`, a 32K chat request, fresh servers alternating, 7 pairs (of 8, one dropped for page migration or reclaim during a prompt): 1,249 -> 1,257 tok/s (median), the median of the pair ratios +0.6%, 6 of 7 pairs faster. The records and scripts are in [libratechw/Strata@686de2e9, `2019q/`](https://github.com/libratechw/Strata/tree/686de2e9eedd6e34c18e7d5fab7a2fd2fe3e4241/2019q). A wider check outside ctest (a local copy of the test, in the records): 72 combinations of none / linear / YaRN scaling, the angle table on / off, MRoPE on / off, 1 / 65 / 513 tokens and start positions 0 / 8,190 (across the table's end at 8,192) give the same bits. Builds and tests on this branch: - HIP gfx1151: ctest, 113 tests: 105 pass (`hip_prefill_q_prep` among them), 5 skip, and the same three fail as on 296b59d2 (`ple_parity`, `expert_parity`, `pool_test`). - HIP: `strata_kernels`, `strata_prefill` and `strata_mmq` compile for gfx1012, gfx1030, gfx1100, gfx1103, gfx1150, gfx1151, gfx1200 and gfx1201. - CUDA 13.0, RTX 3060 (Windows): builds; ctest, 117 tests: 114 pass, 2 skip, and `ple_parity` fails as on 296b59d2. - SYCL: not affected (the SYCL port has its own `kernels` and `prefill.cpp`). Not run: `STRATA_QPREP=1` on CUDA (the bitwise test is HIP's), other GPUs, UD-IQ4_XS. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:30:55 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3811
No description provided.