Repository navigation
perf(b12x/gemm): stream BF16 GEMV weights with .cs and add tk=128 TMA prefill tiles - #187
Open
original-el8 wants to merge 1 commit into
Open
original-el8 wants to merge 1 commit into
original-el8 wants to merge 1 commit into
Conversation
… prefill tiles - Use ld_global_cs_v4_u32 for SmallNGemvKernel weight loads and default block_threads=256 on <=64-SM GPUs for wide-N (out_features >= 16384, max_rows <= 8) SIMT decode. - Parameterize Bf16PrefillKernel with (tile_m, tile_n, tile_k, m_warps, n_warps, evict_b, k_chunk_flush), switch grid order to (grid_m, n_tiles, split_k), apply L2 evict-first cache policy on TMA B loads, and add _warp_gemm_direct with periodic k_chunk_flush=16 for tk=128 tiles. - Expose _PREFILL_TK128_TILES alongside torch in gemm.bf16_gemv for large-N prefill projections (max_rows >= 24, out_features >= 8192, in_features >= 1024), validate prefill_tile across all backends, and bump config_schema_version (24 -> 25) and candidate_contract_version (18 -> 19). - Update test_bf16_gemv_search_levels.py for TC_MAX_ROWS/split_k contracts and add coverage for SM121 256-thread defaults and prefill_tile tuning. Validated on CPU with CUDA_VISIBLE_DEVICES="" (113 passed, 349 CUDA-skipped across tests/experimental/b12x/gemm/test_bf16*.py). Signed-off-by: Jason Cook <jasonc@maxlyn.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📌 Description
Optimize BF16->BF16/FP32 projections on SM121 (and large-N prefill projections) with cache-streaming SIMT weight loads,
block_threads=256wide-N decode defaults, andtk=1282-stage TMA prefill tiles:flashinfer/experimental/b12x/gemm/bf16_gemv/_kernel.py: switchSmallNGemvKernelglobal weight loads told_global_cs_v4_u32(preserving.nccaching on activations) and bumpgemm.bf16_projection.selectedcompile spec version (4 -> 5).flashinfer/experimental/b12x/gemm/bf16_gemv/_prefill.py: parameterizeBf16PrefillKernel(tile_m,tile_n,tile_k,num_stages,m_warps,n_warps,evict_b,k_chunk_flush), switch launch grid order to(grid_m, n_tiles, split_k)(mnorder) to avoid L2 thrashing atM >= 128, attachcreate_l2_evict_first_policy()ontma_atom_Bwhenevict_bis active, add_warp_gemm_directwith periodick_chunk_flush=16accumulation fortk=128tiles, and bumpgemm.bf16_prefillcompile spec version (3 -> 4).flashinfer/experimental/b12x/gemm/bf16_gemv/_preparation.py&_tuning.py: addprefill_tiletoGemvConfig(config schema24 -> 25, candidate contract18 -> 19), defaultblock_threads=256on<=64-SM GPUs for wide-N (out_features >= 16384,max_rows <= 8) SIMT decode, expose_PREFILL_TK128_TILESalongsidetorchformax_rows >= 24, out_features >= 8192, in_features >= 1024, in_features % 128 == 0, and validateprefill_tileacross all backends.tests/experimental/b12x/gemm/test_bf16_gemv_search_levels.py: updateTC_MAX_ROWSand_tc_split_k_candidatesexpectations to match_tensor_core.py, and add unit tests for SM121block_threads=256decode defaults, large-Nprefill_tilecandidate exposure, andvalidate_configprefill_tileguards.Benchmark Results (NVIDIA GB10, SM121, 48 SMs, 273 GB/s LPDDR5x)
Conditions: captured CUDA graph replay for
K=5120 -> N=32320BF16->FP32 (330.96 MBweight, theoretical 273 GB/s floor1212.8 usatM=1to1343.1 usatM=256):Mbackend,us,% 273)config,us,GB/s,% 273)simt(r8,t128)1342.2 (90.4%)simt(r8,t256,cs)1284.4 (257.8, 94.4%)torch)1.19e-6simt(r8,t128)1322.3 (91.8%)simt(r8,t256,cs)1290.2 (256.8, 94.1%)1.91e-6simt(r8,t128)1362.1 (89.2%)simt(r8,t256,cs)1292.0 (256.8, 94.1%)1.91e-6simt(r8,t128)1355.7 (89.7%)simt(r8,t256,cs)1295.5 (256.3, 93.9%)8.11e-6torch1409.6 (86.6%)torch1409.6 (86.6%)torchretained5.05e-5(torch)torch1510.3 (81.1%)TMA(16x64x128,st2,w1x2,ev1,kf10)1437.1 (85.2%)1.24e-5torch1518.0 (80.9%)TMA(64x64x128,st2,w4x2,ev1,kf0)1428.3 (234.8, 86.0%)4.72e-5torch1547.3 (80.5%)TMA(64x64x128,st2,w4x2,ev1,kf0)1451.2 (234.2, 85.8%)4.72e-5torch1624.4 (78.7%)TMA(64x64x128,st2,w4x2,ev1,kf0)1502.6 (232.1, 85.0%)4.86e-5torch1895.9 (70.8%)TMA(128x64x128,st2,w4x2,ev1,kf20)1635.0 (224.3, 82.2%)2.53e-5Conclusion: streaming weights via
ld.global.cs.v4.u32with 256-thread CTAs reaches 93.9%–94.4% of GB10 peak bandwidth atM=1..8, whiletk=1282-stage TMA tiles withmngrid order and L2evict_firston weights reduceM=256latency by 261 us vstorch(and 644 us vs the 64x64x64prefillbaseline at 2279.4 us).Combined-Stack End-to-End TP4 Serving Verification (
flare run)flare runverification below integrates the combined SM121/RoCE kernel, recipe, and scheduler optimization set (isolated single-component GPU microbenchmarks are reported directly above).GB10,SM121, 48 SMs, 121 GiB unified LPDDR5x, dual-rail ConnectX-7 200 GbE RoCEv2),deepseek-ai/DeepSeek-V4.1-Flash-1017TP4 exported package (draft_tokens = 7,speculative_token_capacity = 256,graph_budget = 80,prefill_chunk = 8192,row_shard_prefill = True,row_shard_attention = True,adaptive_verification_alpha = 0.75), served viaflare run(27,051,776logical KV tokens/rank, up from26,272,640baseline).17 * 23 = 391): pass4/4distinct images,4vision graph launches):4/4pass8K, 16K, 32K, 64K, 128K,0reused tokens):5/5pass (128Kin11.71 s)4 x 32Klong-context stress:4/4pass in12.19 s,0failed requests,0preemptionsllm-decode-benchv0.8.0 (exactnative token counting,30 s/cell sustained decode,0errors,0CJK):prompt_tokens / client TTFT):8K8,639 tok/s(0.95 s),32K10,994 tok/s(2.98 s, vs10,810 tok/sbaseline),128K11,349 tok/s(11.55 s, vs11,181 tok/sbaseline); cold64Kpass-2 prefill reached11,390.9 tok/swall (11,462.6 tok/sGPU).C = 1, 2, 4, 8):8K:67.7 / 106.5 / 159.1 / 224.6 tok/s(vs65.4 / 107.1 / 152.5 / 218.6 tok/smatchingdraft_tokens = 7,alpha = 0.75baseline)32K:71.2 / 107.6 / 163.1 / 227.6 tok/s(vs70.2 / 105.0 / 154.9 / 222.4 tok/sbaseline)128K:69.1 / 99.2 / 154.0 / 219.9 tok/s(12-cell geomean126.61 tok/svs124.96 tok/sbaseline;B16xW1pure 1-token/lane GPU step75.70 ms -> 70.54 ms,-6.8%)8K C=16 / C=32underalpha = 0.75(272.5 / 411.0 tok/s): atalpha = 0.75withmax_verification_token_budget = 256, unclamped calibration offers~2.8–2.9drafts/lane on low-acceptance prose (49.4%–51.8%accept rate vs59.7%–62.2%baseline), increasing packed verification rows;C=32fixed-prompt sweep (P=256) reached419.93 tok/s.5/5runs,0CJK):109.0 tok/smedian,110.7 tok/smean,118.0 tok/speak (vs116.5 tok/sbaseline).46,766completion tokens:27,108reasoning +19,658HTML/JS code,temperature = 1.0, adaptivedraft_tokens = 7):118.23 tok/s(179.53 tok/s1s peak,162.56 tok/s5s peak; vs114.68 tok/sfixed-W=8baseline and87.74 tok/sflat-ceiling adaptiveW=6baseline)105.49 tok/s(4.19mean tokens/step,5.40offered drafts/round)19,655tokens up to47Kcontext):141.85 tok/s(6.11mean tokens/step,6.59offered drafts/round,77.6%accept rate, per-depth survival[0.955, 0.904, 0.854, 0.791, 0.715, 0.614, 0.279]).🔍 Related Issues
🚀 Pull Request Checklist
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
Tests have been added or updated as needed.
All tests are passing (
unittest, etc.).This PR requires full-scope CI, not targeted tests (expensive; justify below).
Suggested CI test targets:
tests/experimental/b12x/gemm/test_bf16_gemv.py tests/experimental/b12x/gemm/test_bf16_gemv_search_levels.py tests/experimental/b12x/gemm/test_bf16_gemv_vocab_summary.py tests/experimental/b12x/gemm/test_bf16_vocab_projection.py tests/experimental/b12x/gemm/test_bf16_vocab_search_levels.py🔬 Experimental Track
flashinfer/experimental/and/or an@flashinfer_experimental_api.flashinfer/experimental/b12x/gemm/bf16_gemv/).tests/experimental/and were validated on CPU and GB10 hardware.flashinfer/aot.py, and no experimental backend is reachable frombackend="auto"withoutFLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1.Reviewer Notes
CUDA_VISIBLE_DEVICES=""(113 passed, 349 skippedacross alltests/experimental/b12x/gemm/test_bf16*.py; CUDA runtime cases skipped on CPU build host).