[PR #741] [CLOSED] prefill: BF16 projections on FP16 tensor cores below sm_80 (+8-17% prefill on a 2080 Ti) #2798

Closed
opened 2026-11-04 02:03:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/741
Author: @konijiwa110
Created: 10/4/2026
Status: ❌ Closed

Base: main ← Head: prefill-bf16-as-f16-turing


📝 Commits (10+)

  • b0dda4b AMD: gfx1101 (RX 7800 XT, #254 by jhohertz) and gfx1200 (RX 9060 XT, #256 by Efeisot) as community-validated cards
  • cc97fcd setup: AMD layer splits with --gpus (every chosen card a supported AMD arch; the engine compiled for each)
  • e9e2ba3 pinned (#243 follow-up): the shared-memory-budget cap on the sliced pin is opt-in (STRATA_ARENA_PIN_GIB=auto) - by default the arena pins as in 0.1.30; on this 64 GB PC the cap pinned 26 instead of 30 GiB and cost ~20% prompt speed and 2-4% IQ3_S decode
  • cacffa9 CS-T speed: the file tier fetched in parallel, PCIe planning without file reads, a partial pin of the RAM tier, bit-exact AVX2 multi-token kernels for Q4_K / Q5_1 / Q8_0 experts, decode-only tier stats
  • a348c7a Merge branch 'f-131-srv' into r131-q4
  • b93a00c Merge branch 'f-q4-on242' into r131-q4
  • 8f5148c CS-T: the partial pin at most 24 GiB (STRATA_PARTIAL_PIN_GIB), the Q4_K/Q5_1/Q8_0 multi-token kernels from two tokens on
  • 5ffda19 CS-T: the GGUF-in-place prefetch asks Windows for all of a layer's missed slices at once (PrefetchVirtualMemory)
  • ed6c124 #253: the 8 GiB arena pin cap only under WDDM; STRATA_ARENA_PIN_GIB; the split's prompt chunk steps down
  • 450149d --split-skip-if-fits (opt-in): an auto split runs on the main card alone when it holds every profiled expert + KV

📊 Changes

4 files changed (+218 additions, -0 deletions)

View changed files

📝 CMakeLists.txt (+7 -0)
📝 include/strata/prefill/gemm.hpp (+2 -0)
📝 src/prefill/gemm.cu (+79 -0)
➕ tests/cuda/prefill_bf16_gemm_test.cpp (+130 -0)

📄 Description

What

Cards below sm_80 (RTX 20, GTX 16, V100) have FP16 tensor cores but none for BF16, so cuBLAS runs the prefill's BF16
GEMMs (Gemm::bf16: hyper-connection down/up, inject, SSM alpha/beta, indexer projections) on the CUDA cores. On an
RTX 2080 Ti at those shapes (T = 4096) that is 6-7 TFLOPS in BF16 against 34-48 TFLOPS in FP16.

There, Gemm::bf16 now converts W and X to FP16 in the existing dequantization scratch (W at its start, X in slices of
at least 256 rows) and calls cublasGemmEx in FP16 with the same FP32 accumulation:

  • a BF16 value converts exactly when its magnitude is in [2^-14, 65504]; smaller ones round to an FP16 subnormal
    (absolute error <= 2^-25), larger ones saturate to +-65504 and are counted (STRATA_PREFILL_BF16_F16_CHECK=1 prints
    the count; none in the prompts measured below)
  • a scratch too small for W + 256 rows keeps the BF16 GEMM
  • HIP builds are unchanged

STRATA_PREFILL_BF16_F16=0 keeps the BF16 GEMM; =1 takes the FP16 path on any card (used by the test).

New test prefill_bf16_gemm_test (CUDA, skips without a device): the call shapes above incl. a sliced X, beta = 1
accumulation into a strided ldy with an offset, and the scratch-too-small fallback, against an FP64 reference
(tolerance 1e-5), and cells outside the product left untouched.

Measured

Swift 1.5 IQ3_XXS on an RTX 2080 Ti 22 GB, same build A/B with STRATA_PREFILL_BF16_F16=0 / unset, prefill tok/s
after warm-up:

prompt BF16 FP16 path
4K 815 877 (+8%)
16K 933 1089 (+17%)
32K 976 1126 (+15%)
128K 848 973 (+15%)

The hc read phase (STRATA_PREFILL_TIMING) at 128K: 29.8 s -> 13.8 s. Decode unchanged. No saturation in any of
these prompts. Greedy output differs from the BF16 path after a few dozen characters, which is the same level as two
runs of the unchanged engine differ from each other (16-105 characters); answer quality looked the same.

prefill_bf16_gemm_test: all cases PASS, max error 4e-8 to 2.8e-7.

Only tested on sm_75 (2080 Ti); cards at sm_80+ never take the path unless the env forces it.

Developed with an AI coding assistant; all numbers measured on an RTX 2080 Ti 22 GB / i5-12490F / 64 GB.

🤖 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/741 **Author:** [@konijiwa110](https://github.com/konijiwa110) **Created:** 10/4/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `prefill-bf16-as-f16-turing` --- ### 📝 Commits (10+) - [`b0dda4b`](https://github.com/Niko1221/Strata/commit/b0dda4b14886293575e5fe5c92e5ba6636adc4a1) AMD: gfx1101 (RX 7800 XT, #254 by jhohertz) and gfx1200 (RX 9060 XT, #256 by Efeisot) as community-validated cards - [`cc97fcd`](https://github.com/Niko1221/Strata/commit/cc97fcde526e1b2d4cbee39ba21e54a0ef7505b1) setup: AMD layer splits with --gpus (every chosen card a supported AMD arch; the engine compiled for each) - [`e9e2ba3`](https://github.com/Niko1221/Strata/commit/e9e2ba31abdc211a618b5faf7226732d40bbcf2b) pinned (#243 follow-up): the shared-memory-budget cap on the sliced pin is opt-in (STRATA_ARENA_PIN_GIB=auto) - by default the arena pins as in 0.1.30; on this 64 GB PC the cap pinned 26 instead of 30 GiB and cost ~20% prompt speed and 2-4% IQ3_S decode - [`cacffa9`](https://github.com/Niko1221/Strata/commit/cacffa95aff016939edd7c15534c0067ec0ee93c) CS-T speed: the file tier fetched in parallel, PCIe planning without file reads, a partial pin of the RAM tier, bit-exact AVX2 multi-token kernels for Q4_K / Q5_1 / Q8_0 experts, decode-only tier stats - [`a348c7a`](https://github.com/Niko1221/Strata/commit/a348c7a4ed64f5f7f24ce3f1cba2d1439f673fed) Merge branch 'f-131-srv' into r131-q4 - [`b93a00c`](https://github.com/Niko1221/Strata/commit/b93a00c65a21fcc5b6431b8091e348d2976259f0) Merge branch 'f-q4-on242' into r131-q4 - [`8f5148c`](https://github.com/Niko1221/Strata/commit/8f5148c14d34c404e8a2d6a45188088714f3c9bb) CS-T: the partial pin at most 24 GiB (STRATA_PARTIAL_PIN_GIB), the Q4_K/Q5_1/Q8_0 multi-token kernels from two tokens on - [`5ffda19`](https://github.com/Niko1221/Strata/commit/5ffda19098202b82943fc80281ce0eb34d8e08a3) CS-T: the GGUF-in-place prefetch asks Windows for all of a layer's missed slices at once (PrefetchVirtualMemory) - [`ed6c124`](https://github.com/Niko1221/Strata/commit/ed6c1244dcd31789007540cb9d8498fbd4134b7f) #253: the 8 GiB arena pin cap only under WDDM; STRATA_ARENA_PIN_GIB; the split's prompt chunk steps down - [`450149d`](https://github.com/Niko1221/Strata/commit/450149d3f248438d8a2526c600b5a75c3dbea6c6) --split-skip-if-fits (opt-in): an auto split runs on the main card alone when it holds every profiled expert + KV ### 📊 Changes **4 files changed** (+218 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+7 -0) 📝 `include/strata/prefill/gemm.hpp` (+2 -0) 📝 `src/prefill/gemm.cu` (+79 -0) ➕ `tests/cuda/prefill_bf16_gemm_test.cpp` (+130 -0) </details> ### 📄 Description ## What Cards below sm_80 (RTX 20, GTX 16, V100) have FP16 tensor cores but none for BF16, so cuBLAS runs the prefill's BF16 GEMMs (`Gemm::bf16`: hyper-connection down/up, inject, SSM alpha/beta, indexer projections) on the CUDA cores. On an RTX 2080 Ti at those shapes (T = 4096) that is 6-7 TFLOPS in BF16 against 34-48 TFLOPS in FP16. There, `Gemm::bf16` now converts W and X to FP16 in the existing dequantization scratch (W at its start, X in slices of at least 256 rows) and calls `cublasGemmEx` in FP16 with the same FP32 accumulation: - a BF16 value converts exactly when its magnitude is in [2^-14, 65504]; smaller ones round to an FP16 subnormal (absolute error <= 2^-25), larger ones saturate to +-65504 and are counted (`STRATA_PREFILL_BF16_F16_CHECK=1` prints the count; none in the prompts measured below) - a scratch too small for W + 256 rows keeps the BF16 GEMM - HIP builds are unchanged `STRATA_PREFILL_BF16_F16=0` keeps the BF16 GEMM; `=1` takes the FP16 path on any card (used by the test). New test `prefill_bf16_gemm_test` (CUDA, skips without a device): the call shapes above incl. a sliced X, `beta = 1` accumulation into a strided `ldy` with an offset, and the scratch-too-small fallback, against an FP64 reference (tolerance 1e-5), and cells outside the product left untouched. ## Measured Swift 1.5 IQ3_XXS on an RTX 2080 Ti 22 GB, same build A/B with `STRATA_PREFILL_BF16_F16=0` / unset, prefill tok/s after warm-up: | prompt | BF16 | FP16 path | |---|---|---| | 4K | 815 | 877 (+8%) | | 16K | 933 | 1089 (+17%) | | 32K | 976 | 1126 (+15%) | | 128K | 848 | 973 (+15%) | The `hc read` phase (`STRATA_PREFILL_TIMING`) at 128K: 29.8 s -> 13.8 s. Decode unchanged. No saturation in any of these prompts. Greedy output differs from the BF16 path after a few dozen characters, which is the same level as two runs of the unchanged engine differ from each other (16-105 characters); answer quality looked the same. `prefill_bf16_gemm_test`: all cases PASS, max error 4e-8 to 2.8e-7. Only tested on sm_75 (2080 Ti); cards at sm_80+ never take the path unless the env forces it. Developed with an AI coding assistant; all numbers measured on an RTX 2080 Ti 22 GB / i5-12490F / 64 GB. 🤖 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-04 02:03:11 +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#2798
No description provided.