Repository navigation
[Engine] rms_norm_many: keep input pointers out of local memory - #296
Open
okada-shogo wants to merge 1 commit into
Open
okada-shogo wants to merge 1 commit into
okada-shogo wants to merge 1 commit into
Conversation
rms_norm_many_kernel took its input's pointers as m.x[blockIdx.y]: an index into the kernel's parameters by a register, which nvcc compiles as a copy of the whole struct to local memory in every block (nine STL.64 and three LDL.64 on sm_75), and the pointers read back from there made every load a generic one (LD) instead of a read-only global load. The three-input norms of Inkling 2's prompt layers took about 2.8 times as long a row as rms_norm_kernel in an nsys trace on an RTX 2070 Super. The pointers are now picked by comparisons (rms_pick()). The rest of the kernel is unchanged: each row's sum is the same threads' values in the same order, so the same bits. A new case in poly_inkling2_test checks rms_norm_many() of 5 and 300 rows against rms_norm() of each input, bit for bit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Problem and result
rms_norm_many_kernelruns Inkling 2's three Q/K/V norms in every prompt layer. It read its input pointers asm.x[blockIdx.y]. Indexing the kernel's parameters with a register value makes nvcc copy the whole parameter struct to local memory in every block (9STL.64+ 3LDL.64on sm_75), and the loads through those pointers become genericLDinstead of global loads. The kernel ran 2.8× slower per row thanrms_norm_kernel, which has the same body.This PR picks the pointer with comparisons instead; nothing else changes. The kernel takes 63-65% less time, prompts get 0.3-1.0% faster on an RTX 2070 Super, and the output is the same bits.
End to end, RTX 2070 Super 8 GB (Ryzen 5 3600XT), main's default flags on both sides, a fresh
--serveengine for each runwith one warm-up request, 3 rounds in alternating order. Prompt tok/s, mean of 3 runs:
Decode tok/s, the same runs, mean of 3 runs. This change is not in the decode path. The UD-Q2_K_XL decode rows move because of a slow round 3 that hit every build (see each run):
Each run (tok/s)
Prompt, each run (tok/s):
Decode, each run (tok/s):
Experts in VRAM at load were the same for main and this PR in every run: 917 for IQ4_NL and 1967 for UD-Q2_K_XL (decode after 302 and 8K, prompt 2K and 32K).
Kernel time, RTX 2070 Super, n = 2304, 3 inputs (µs, lower is better; median of the bench's repeats, mean of 3 runs):
Related discussion
none (one optimization per PR, as asked on #200)
Approach
rms_pick()returnsp[0],p[1]orp[2]by comparingblockIdx.y(the launcher allows 1 to 3 inputs). The pointers then stay in the constant bank, nothing goes to local memory, and the loads are global loads again. Each rowis still summed by the same threads in the same order, so the result is bit-identical. The change is only in
kernels.cu; CUDA and HIP compile the same code.rms_norm_many()is only called by Inkling 2.Validation
All on branch 5956327 = main 36e654b + this PR.
Passed:
poly_inkling2_test(new case:rms_norm_manyof 5 and 300 rows =rms_normof each input, bit for bit),RTX 2070 8 GB (sm_75): 431 checks, 0 failed; main: 425 checks, 0 failed.
rms_norm_many_kernelagainst this PR's at 1, 302, 1,024 and 2,048 rows (3 × 2304): samebits at every size (standalone bench, RTX 2070 and RTX 2070 Super).
STRATA_FREEZE_EXPERTS=1 STRATA_GPU_EXPERTS=850, token ids + top-20 of 32 greedy tokens: IQ4_NLand UD-Q2_K_XL, 302 and 2,048 tokens, each with main's defaults,
--no-graphs, and the int8/w4a8 prompt flags(
--prompt-int8 STRATA_PREFILL_NVFP4=w4a8 STRATA_INK_FAST_CTRL=1 STRATA_INK_PRESTAGE=1): same as main in all 12cases (RTX 2070 8 GB).
strata-polyandpoly_inkling2_testcompile.Failed:
Not run:
Limits
ink_cat_norm_kernelandink_norm_many_q8_kernel(separate PR: [Engine] Inkling 2: keep norm parameters out of local memory #297),ink_mix_many_kernel(decode, 12 jobs) and the conv state kernel; those two are not changed.🤖 Generated with Claude Code