Repository navigation
Flash Next MTP wide norm: more blocks a row, byte-identical (CUDA sm_120/121, HIP gfx1201) - #1702
Merged
Merged
Conversation
laudney
marked this pull request as ready for review
October 30, 2026 23:05
tf_rms_rows_sums runs Flash Next's 10,240-wide MTP norm on one block a row, so decode rows leave most SMs idle. tf_rms_rows_sums_tiles splits each row into 1, 10 or 40 output tiles of 256 threads; every block repeats the row's sums in the native kernel's exact order, so its normed values and group sums keep the current bytes. A table by the current device's SM and row count picks the tiles on sm_120 and sm_121, every other call keeps the one-block row, and the kernel registers with the contract as tf_rms_rows_sums' replacement.
tf_fn_rms_wide norms Flash Next's 10,240-wide bf16 MTP row in one 256-thread block, and its runtime kind branch serialises each thread's forty loads. On gfx1201 the launcher now runs its two fn_block_sum stages as two launches: tf_fn_rms_wide_waves stores each wave's sum from the same thread chains and xor tree, and tf_fn_rms_wide_apply adds a row's wave sums in order and stores y over 160 groups a row, so the bytes stay the current kernel's. It serves rows up to 16 with alternates on and registers with the contract as tf_fn_rms_wide's replacement.
ashhart
force-pushed
the
pr-rms-wide-tiles
branch
from
October 31, 2026 11:06
ab22816 to
532de59
Compare
Owner
|
Thank you @laudney. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in 1.2.1, credited to you in the changelog and the release notes. |
Owner
|
Thanks @laudney! The faster Flash Next MTP head norm on CUDA and HIP is in 1.2.1: https://github.com/ashhart/TensorFold/releases/tag/v1.2.1 |
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.
Fixes #1689.
Flash Next's MTP head norms each row of its four 2,560-value streams as one 10,240-value row, one block a row. At decode row counts most of the GPU idles. This PR adds faster kernels for that shape that store the current kernels' bytes by construction: the same per-thread sums, reduction trees, division, square root, multiply order and rounding. Every other shape, SM and architecture keeps the current launch.
CUDA:
tf_rms_rows_sums_tiles(rms_tiles.cuh)(tiles, rows), 256 threads,tilesin {1, 10, 40}. Each block repeats its row's inverse norm exactly astf_rms_rows_sumsforms it: threadcof the 1,024-thread kernel's ten-value__fmaf_rnchain, four chains a thread; chaint + 256 jis lanet & 31of native warp(t >> 5) + 8 j, so it runs the same warp XOR tree, then the same 32-warp tree and__fdiv_rn/__fsqrt_rnsteps. The block stores its tile'syand that tile's FP32 sums of 32 stored BF16 values in ascending order.Normsreads the current context's device capability once (Driver.currentCapability).rmsSumstakes the tiled launch for width 10,240, group 32 and rows 1–16 on sm_120 (40 tiles at one row, else 10) and sm_121 (10 tiles up to four rows, else 1).HIP (gfx1201):
tf_fn_rms_wide_waves+tf_fn_rms_wide_apply(streams.hpp)fn_block_sumis two stages, each wave's XOR tree and then the eight wave sums in order; the launch boundary follows it.tf_fn_rms_wide_wavesruns one 32-thread group per (wave, row) withtf_fn_rms_wide's thread chains and tree and stores the wave sum.tf_fn_rms_wide_applyadds a row's eight wave sums in order in every thread, forms the samersqrtf(total / width + eps)and stores(x * rinv) * scale, one value a thread.bf16_to_float/float_to_bf16, whatload/storedo at kind 2; the runtime kind branch kept the forty loads a thread from issuing together.rmsWidetakes the split on gfx1201 builds with alternates on (Choices.fuse), bf16, width 10,240, the head's scratch (8 floats a row) and rows 1–16.Gates
replaces), so gate 3 requires the current kernel's bytes. CUDA registers two views of the launch (BF16y; FP32 group sums, whose stress rows sum exactly in fp32 while bf16 and fp16 sums miss).SUMMARY 472 kernels: 472 pass gates 1-4, 0 fail, 6 known findings; 321 controls: 321 red as planted, 0 missed; 181 limit problems— both views16 shapes bit-equal to the kernel it replaces, group sumsexact sums at k 10240, where fp16 sums would miss by infx and bf16 by 8388608x; the new launch's live limits match its record (48 registers, 20612 shared bytes); the limit problems are inherited and none is a new launch.16 shapes bit-equal to the kernel it replaces; group sumsexact sums at k 10240, where fp16 sums would miss by infx and bf16 by 8388608x).SUMMARY gfx1201 50 kernels: 50 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 120 limit problems— the limit problems are inherited live-register differences of other kernels under ROCm 7.16; none is a new launch..fuse = falseat rows 1–17, on random, zero, mixed-magnitude, fp32-overflowing, NaN and ±Inf rows (CUDA with rows 64 elements apart and NaN between them). GB10 and RTX PRO 6000tf-cuda-test norm-rowsPASS; R9700hip-kernel-test107/107.zig build test1388/1396 (8 skipped),test-cuda-host3736/3744 (8 skipped),test -Dhip=true429/434 (5 skipped); lean checker at the 425 baseline.Timings
Width 10,240, captured graphs of 1,000 operations, alternating order, eleven samples, median; buffers repeat in cache, so these are kernel timings, not model throughput.
The CUDA rows were measured on a prototype with this kernel's arithmetic and launch geometry; the HIP rows on this PR's kernels. The norm runs once per MTP step, so whole-model decode gains are small.
Not run