Repository navigation
fix(b12x): move TC-GEMV split-K buffers out of global caches, unify 14 PCIe epochs, fix mHC PDL sync and MLA/DSA/MoE P0 bugs - #183
Merged
Conversation
…, fix mHC PDL sync and MLA/DSA/MoE P0 bugs Signed-off-by: Luke Alonso <lalonso@gmail.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
1. Why
This PR resolves a P0 wave of memory-safety, cross-stream aliasing, and GPU-scope synchronization bugs across
flashinfer/experimental/b12x/:bf16_gemv, blockscaled MXFP8, blockscaled NVFP4, andwo_projectionA16) stored L2 split-K completion flags (andbf16_gemvsplit-K partials) in process-global dicts (_TC_SPLITK_BUFFERS,_FLAGS_CACHE,_WOA_FLAGS_CACHE) keyed only by(device, shape, split_k). When concurrent streams run identical-shape split-K TC-GEMV projections (e.g., GLM-5.3 KDAg_b_proj/f_b_projBF16[2048, 128]withsplit_k in {2, 4}underConcurrentProjectionChain), both streams alias the same flags/scratch buffer, causing premature last-CTA arrival and NaN/corrupted outputs.graph_epoch_arrive,_a2a_graph_epoch_arrive,_advance_graph_epoch) across 14 kernels / 15 call sites still used unscopedatom.global.add.u32+ weakld/stinstead ofsync_threads_after_u32+graph_epoch_arrive_serialized.ClusterMhcAllReducePostYNorm.kernel(merged in perf(b12x/mhc): tune AllReduce cluster sizing and guard SM co-residency #158) calledcute.arch.griddepcontrol_launch_dependents()with no precedingcute.arch.sync_threads()and beforecluster_arrive()/cluster_wait(), letting dependent kernels launch before all threads/cluster peers finished writing outputs.reserve_smsCTA-vs-SM math, and INT64 expert-ID narrowing:attention/dense_mla/_math.py(write_partial_or_final) and_merge.py(output_offset) computed 4Dpartial_outputoffsets in 32-bitInt32, overflowing past 2 GiB on long-context split prefill (e.g., Kimi prefill4096) into an illegal memory access (IMA).attention/dsa_indexer/fused_indexer.pyelidedcute.arch.sync_threads()after split reduction whenpage_splits == 1(racing ons_scalereuse across pages inCONTIGUOUS_MLA) and readmerge_state[output_offset]with a plain L1-cached load afterthreadfence()(membar.gldoes not invalidate L1).moe/fused_moe/_impl.pysubtractedreserve_smsdirectly from CTA count instead of scaling remaining SMs byblocks_per_sm((num_sm - reserve_sms) * blocks_per_sm).topk_idstoint32before bounds-checking, allowing values outside INT32 range (e.g.,1 << 32) to wrap into valid expert IDs during CUDA-graph replay.2. What changed
flashinfer/experimental/b12x/_lib/utils/device.py: added stream-orderedzero_u32_async(cuMemsetD32Async).bf16_gemv/{_tensor_core.py,_preparation.py,api.py}: deleted_TC_SPLITK_BUFFERS/tc_splitk_buffers; moved non-DSMEM split-K partials + 256B-aligned flags into caller-ownedMemoryRequirements.scratch(bf16_gemv.tc_splitk, zeroPersistentMemory), added optionalworkspacetobf16_gemv.mm(with stream-localtorch.emptyfallback when omitted), and zeroed embedded flags per launch viazero_u32_async. Preserved DSMEM zero-scratch behavior and 16B-aligned dummy pointers (x.data_ptr()).blockscaled/{_mxfp8_tc_gemv.py,_nvfp4_tc_gemv.py,_preparation.py}: deleted_FLAGS_CACHEandcached_*_tc_gemv_flags; embedded 256B-aligned flags into*_tc_gemv_workspace_bytesand sliced/zeroed them per launch whensplit_k > 1 and not use_dsmem and flags is None(preservingcompile_mxfp8_tc_gemv_rope/projection_overlap.pycompatibility and DSMEM zero-workspace behavior).wo_projection/{_tc_gemv.py,_preparation.py}: deleted_WOA_FLAGS_CACHE/cached_wo_a16_tc_gemv_flagsandPersistentMemory("wo_projection.a16_woa_flags", ...); included aligned flags inwo_a16_tc_gemv_scratch_bytes, sliced flags intobinding.tmp_q, and zeroed per launch withzero_u32_asyncwhen non-DSMEMsplit_k > 1.graph_epoch_arrive,_a2a_graph_epoch_arrive, and_advance_graph_epoch; unified all 14 kernels / 15 call sites across_dcp_a2a_cute.py,_ring_gather_cute.py,_phased_gather_cute.py,_island_gather_cute.py,_recursive_gather_cute.py,_kimi_route_cute.py,_oneshot_cute.py, andinterleaved_topk/_cute.pyontosync_threads_after_u32+ non-divergentcute.arch.sync_threads()+graph_epoch_arrive_serialized; bumped every modifiedKernelCompileSpecversion.norm/mhc/_split_lagged.py: orderedcluster_arrive()/cluster_wait()(cluster_size > 1) andcute.arch.sync_threads()beforegriddepcontrol_launch_dependents(); bumpednorm.mhc.cluster_allreduce_post_y_normspec3 -> 4.reserve_sms, INT64 Expert-IDs:attention/dense_mla/{_math.py,_merge.py,_kernel.py}: switched 4Dpartial_outputstores andoutput_offsetto 64-bitInt64+get_ptr_as_int64; bumped forward & merge specs4 -> 5.attention/dsa_indexer/fused_indexer.py: made post-reducecute.arch.sync_threads()unconditional (page_splits == 1), replaced plain loadInt32(merge_state[output_offset])withld_global_acquire_i32(get_ptr_as_int64(merge_state, output_offset)), and bumped variant keysv13 -> v14.moe/fused_moe/_impl.py: added_apply_dynamic_reserve_smsscaling remaining SMs byblocks_per_sm(trackingblocks_per_sm = 2forw4a8_repacked and selected_tile_m <= 32).moe/_shared/kernels/w4a16/{route_pack.py,kernel/sum.py,kernel/sum_launch.py,kernel/execution.py}andmoe/calibration.py: validated full-width INT64 expert IDs before narrowing toint32across all route-pack, top-k sum (spec8 -> 9), direct TC-decode, and 6 calibration Triton kernels.3. Claimed benefit
reserve_smsCTA budgeting, and prevents INT64 expert-ID truncation wraparound under CUDA-graph replay.4. Supporting evidence and limitations
Validated at commit
9bf835a2d(rebased ontolil/main4e6f12cc7) on NVIDIA RTX PRO 6000 Blackwell (SM120, 1–8 GPUs), CUDA 13.5:tests/experimental/b12x/test_sm120_dsmem_splitk.py: 13 passedtests/experimental/b12x/test_sm120_decode_pdl.py: 13 passedtests/experimental/b12x/gemm/test_decode_gemm_moe_contracts.py+tests/experimental/b12x/gemm/test_tc_gemv_concurrent_streams.py: 63 passed (default) + 8 passed withB12X_TC_GEMV_DSMEM_SPLIT=0(100 CUDA-graph dual-stream replays per shape with0xFF-poisoned workspaces across BF16 KDA[16, 2048] x [128, 2048]^T, MXFP8, MXFP8-RoPEflags=None, NVFP4, and WO-A16)tests/experimental/b12x/moe/test_w4a16_int64_expert_ids_replay.py+test_calibration.py+test_moe_execution_model.py: 44 passedtests/experimental/b12x/attention/test_dense_mla.py: 17 passed (including 2.50 GiB BF16 & 5.00 GiB FP32 partials)tests/experimental/b12x/attention/test_fused_indexer.py: 108 passed, 1 pre-existing failure (test_dsa_indexer_config_and_merge_thresholdsin untouched_tuning.py)tests/experimental/b12x/norm/test_mhc_allreduce_post_y_norm.py(single-GPU) +test_w4a16_{route_pack,route_sum,reference}.py+test_interleaved_topk.py: 259 passed, 103 skippedtests/experimental/b12x/comm/test_kimi_topk16_gpu.py+tests/experimental/b12x/gemm/{test_mxfp8_wide_splitk,test_cute_mxfp8_splitk_pdl,test_mxfp8_linear,test_blockscaled}.py: 155 passedtest_pcie_twoshot_unit.py,test_pcie_dcp_a2a.py,test_mhc_allreduce_post_y_norm.py): 6 passedtests/experimental/b12x/lint/: 1 passedtest_mhc_allreduce_post_y_norm.py -k live_multi_gpu(B12X_RUN_PCIE_ONESHOT_TEST=1): 19 passedtest_interleaved_topk_gpu.py+test_paired_gather_gpu.py+test_pcie_dcp_a2a_gpu.py: 10 passed, 8 skippedtest_pcie_oneshot_fused_rmsnorm_gpu.py(B12X_RUN_PCIE_ONESHOT_RMS_TEST=1): 2 passedtest_pcie_oneshot_torture.py(B12X_RUN_PCIE_ONESHOT_TORTURE=1, 4 ranks): 59 passed, 24 skippedtest_interleaved_topk_gpu.py[8-4]+test_pcie_dcp_a2a_gpu.py(WORLD_SIZE=8): 3 passed, 2 skippedcompute-sanitizer(SM120):memcheckon >2 GiBtest_dense_mla.py: 2 passed, 0 errorssynccheck&memcheckontest_fused_indexer.py(page_splits == 1+ serial-merge replay): passed, 0 errors (both tools)memcheckontest_tc_gemv_concurrent_streams.py: 8 passed, 0 errorsmemcheckontest_w4a16_int64_expert_ids_replay.py+test_calibration.py: 20 passed, 0 errorsruff check,ruff format, whitespace/EOL/conflict checks) passed on commit.scripts/repro_glm_batched_speculation.pyand Kimi 6112-token serving repro inhyperflare-recipes) were not executed on this SM120 host.🔍 Related Issues
🚀 Pull Request Checklist
✅ Pre-commit Checks
ruff check,ruff format, whitespace/EOL checks).🧪 Tests
compute-sanitizer.🔬 Experimental Track
flashinfer/experimental/b12x/with tests undertests/experimental/b12x/.flashinfer/is untouched; nothing is registered inflashinfer/aot.py.tests/experimental/b12x/and were validated on SM120 hardware.Reviewer Notes
4e6f12cc7(perf(b12x/gemm): gate SM120 DSMEM split-K by CTA occupancy #169 DSMEM split-K) and8489b208a(perf(b12x): enable consumer PDL for SM120 decode kernels #165 consumer PDL); DSMEM split-K continues to skip L2 split-K scratch/flags, while non-DSMEM L2 split-K uses caller/owned workspace with per-launchcuMemsetD32Asyncflag zeroing and zero process-global flag/scratch dicts.