Skip to content

dense_gemv_bf16_batchm on HIP: stage the activation k-tile in LDS (Flash-Next C4/C8 +12%, byte-identical) - #298

Merged
AzeezIsh merged 1 commit into
mainfrom
perf/hip-gemv-a-lds
Oct 31, 2026
Merged

AzeezIsh merged 1 commit into
mainfrom
perf/hip-gemv-a-lds

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Cause: the batched BF16 decode GEMV read its M activation rows straight from global memory, K × 2 bytes apart. When that stride is a multiple of 4 KiB, every iteration's M lines land in one cache set.

Framework f147 (engine-built code object, M = 8, N = 2560):

  • K 4096 / 6144 / 8192: 55 GB/s
  • K 6400 / 6656: ~170 GB/s
  • at K 6144: M 1 166, M 2 139, M 4 66, M 8 56 GB/s

Flash-Next's GDN out_proj is K = 6144, and it was 11% of the C8 decode window (f141).

Fix: the HIP path stages each k-tile of every row in LDS once per block, shared by the block's 4 outputs. Each thread still walks kv = lane, lane + 64, … in the same accumulation order. M == 1 keeps the direct loads (the barriers cost it ~12%). The gb10 path is untouched (#if defined(__HIP_PLATFORM_AMD__)).

Kernel (f148, orig vs staged, 200 cold launches, C byte-compared on random A/B, every shape IDENTICAL):

shape (M 8) before after
N 16384 K 2560 (GDN qkvz) 0.524 ms 0.362 ms (×1.45)
N 2560 K 6144 (GDN out_proj) 0.565 ms 0.225 ms (×2.5)
N 16384 K 6144 3.56 ms 1.06 ms (×3.4)

End to end (framework f149, main-292 170c3ed vs a621fe5, Flash-Next NVFP4 via serve-amd MAX_BATCH 8, lane on, AR, Gufo protocol ×2):

  • C1: 12.8 / 12.8 → 12.8 / 12.8
  • C4: 30.5 / 30.4 → 34.0 / 34.0 (+12%)
  • C8: 34.2 / 34.1 → 38.1 / 38.2 (+12%)
  • solo replies identical across builds 8/8; solo-vs-C8 identity 5/8 on both; 0 faults.

The same staging in the FP8 w8a16_gemv_batch8_dyn_vl2_n2 tier measured only +5..17% at M 8 and −6% at M 5 (f150, also byte-identical). FP8 rows are half as wide, so the aliasing bites less. Left out of this PR.

🤖 Generated with Claude Code

…row cache-set aliasing; 1.45-3.4x, byte-identical)

With the M activation rows read straight from global memory, rows K * 2
bytes apart, every iteration's M lines land in one cache set whenever
that stride is a multiple of 4 KiB. Framework f147 (M = 8, N = 2560):
- K 4096 / 6144 / 8192: 55 GB/s
- K 6400 / 6656: ~170 GB/s
- at K 6144: M 1 166, M 2 139, M 4 66, M 8 56 GB/s

The HIP path now stages each k-tile of every row in LDS once per block,
shared by the block's 4 outputs. Each thread still walks
kv = lane, lane + 64, ... in the same accumulation order. M == 1 keeps
the direct loads (the barriers cost it ~12%). The gb10 path is untouched.

f148, engine-built code objects, 200 cold launches, C byte-compared on
random A/B, every shape IDENTICAL:
- N 16384 K 2560 M 8 (Flash-Next GDN qkvz): 0.524 -> 0.362 ms (x1.45)
- N 2560 K 6144 M 8 (GDN out_proj): 0.565 -> 0.225 ms (x2.5)
- N 2560 K 2560 M 8: x1.45
- N 16384 K 6144 M 8: x3.4

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AzeezIsh

Copy link
Copy Markdown
Contributor Author

27B no-regression (strix s173, main-292 vs a621fe5, AR ×2): C1 9.55 → 9.6; C4 26.0 → 25.7; C8 32.55 → 32.85 (within round noise); solo text identical 8/8; identity 5/8 both; 0 faults. CI + DevLab 41233022277 green. Merging.

@AzeezIsh
AzeezIsh merged commit 385d465 into main Oct 31, 2026
24 of 25 checks passed
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