libr4d: step past the full-card launch cliff in qkv_norm_rope and the row norms

On gfx1201 a launch whose wavefronts fall in the last 32 before a multiple of 2048 (every wave slot
of the R9700's 64 CUs x 2 SIMDs x 16) runs about five times slower than the same work one workgroup
wider, whatever the kernel does. A launch-count sweep on one card (2026-10-17): 256-thread
workgroups take 27.6 us at 253 to 256 of them and 5.2 us at 252 or 257, for a norm, an LDS-only
kernel and a plain copy alike; 128- and 512-thread workgroups hit it at the same wavefront counts.
An empty kernel does not, and moving the data does not move it.

The 31B lands on it: qkv_norm_rope at a tp-4 verify is 16 rows x 16 heads of 8 wavefronts, exactly
a full card (21 us a call against ~6 expected; kbench's one-card 4-row point, 256 workgroups, 17.4
us against 5.3 at 8 rows), and a drafter's 256-row head norm through rmsnorm likewise (21.9 us).

r4d_cliff_rows(rows, per_row, waves) is the row count to launch: `rows` when clear of the window,
else the first count past it. qkv_norm_rope, rmsnorm and rmsnorm_p launch that many and return at
once in a row at or past the real count, so every result is the same bytes. r4d_selftest's
qkv_norm_rope case gains 8 rows of the head-256 class (32 heads a row: 256 workgroups, padded).

The window's two numbers are the R9700's, named as such in r4d_common.h, and apply on every target
libr4d builds for (RDNA4 only). They are not derived from the device: no other card has been
measured, and HIP's multiProcessorCount counts WGPs, not CUs, on RDNA. On an RDNA4 part with fewer
CUs a launch padded here costs one idle row and gives the same bytes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
AshlynandClaude Opus 5.5 authored and StillDeadcode committed 2026-10-21 09:24:52 +02:00
1 parent 13a917910f
commit dffec0b770
4 files changed
+52 -11

No files matched your search

+3 -1
View File
@@ -10884,7 +10884,9 @@ static void qkv_norm_rope_numeric(const Plugin& pl) {
for (const Cls& cl : { Cls{ 256, 16, 8, 256, "rotary", 10000.0, false, true },
Cls{ 512, 16, 2, 128, "head", 1000000.0, true, true },
Cls{ 128, 16, 8, 128, "rotary", 10000.0, false, false } }) {
for (const int64_t M : { (int64_t)1, (int64_t)4, (int64_t)40 }) {
/* 8 rows of the head-256 class are 8 x 32 workgroups of 8 wavefronts, a full card: the
* launch adds an idle row past the cliff (r4d_cliff_rows), which must not change a byte. */
for (const int64_t M : { (int64_t)1, (int64_t)4, (int64_t)8, (int64_t)40 }) {
const int64_t QD = cl.nq * cl.hd, KD = cl.nkv * cl.hd;
std::vector<uint16_t> hq((size_t)M * QD), hk((size_t)M * KD), hv((size_t)M * KD);
std::vector<uint16_t> hqw((size_t)cl.hd), hkw((size_t)cl.hd);