Skip to content

[Engine] rms_norm_many: keep input pointers out of local memory - #296

Open
okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/norm-many
Open

okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/norm-many

Conversation

@okada-shogo

@okada-shogo okada-shogo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem and result

rms_norm_many_kernel runs Inkling 2's three Q/K/V norms in every prompt layer. It read its input pointers as m.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 (9 STL.64 + 3 LDL.64 on sm_75), and the loads through those pointers become generic LD instead of global loads. The kernel ran 2.8× slower per row than rms_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 --serve engine for each run
with one warm-up request, 3 rounds in alternating order. Prompt tok/s, mean of 3 runs:

Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB IQ4_NL prompt 302 (tok/s) 222.2 224.2 +0.9%
RTX 2070 Super 8 GB IQ4_NL prompt 2K (tok/s) 493.0 494.5 +0.3%
RTX 2070 Super 8 GB IQ4_NL prompt 8K (tok/s) 606.3 610.3 +0.7%
RTX 2070 Super 8 GB IQ4_NL prompt 32K (tok/s) 645.4 650.6 +0.8%
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 302 (tok/s) 272.7 274.9 +0.8%
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 2K (tok/s) 588.1 594.0 +1.0%
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 8K (tok/s) 606.0 610.9 +0.8%
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 32K (tok/s) 616.6 621.6 +0.8%

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):

Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB IQ4_NL decode after 302 (tok/s) 42.5 42.5 +0.0%
RTX 2070 Super 8 GB IQ4_NL decode after 8K (tok/s) 34.7 34.8 +0.2%
RTX 2070 Super 8 GB UD-Q2_K_XL decode after 302 (tok/s) 45.8 46.3 +1.1%
RTX 2070 Super 8 GB UD-Q2_K_XL decode after 8K (tok/s) 42.1 40.7 -3.2%
Each run (tok/s)

Prompt, each run (tok/s):

Card Model Measure Build Run 1 Run 2 Run 3
RTX 2070 Super 8 GB IQ4_NL prompt 302 (tok/s) main 223.7 221.0 222.0
RTX 2070 Super 8 GB IQ4_NL prompt 302 (tok/s) this PR alone 223.5 225.3 223.9
RTX 2070 Super 8 GB IQ4_NL prompt 2K (tok/s) main 492.5 493.7 492.9
RTX 2070 Super 8 GB IQ4_NL prompt 2K (tok/s) this PR alone 494.3 493.9 495.2
RTX 2070 Super 8 GB IQ4_NL prompt 8K (tok/s) main 606.1 606.3 606.6
RTX 2070 Super 8 GB IQ4_NL prompt 8K (tok/s) this PR alone 610.4 610.3 610.3
RTX 2070 Super 8 GB IQ4_NL prompt 32K (tok/s) main 645.4 645.3 645.6
RTX 2070 Super 8 GB IQ4_NL prompt 32K (tok/s) this PR alone 650.9 650.0 651.0
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 302 (tok/s) main 271.5 273.3 273.2
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 302 (tok/s) this PR alone 274.8 275.4 274.6
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 2K (tok/s) main 589.3 587.9 587.1
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 2K (tok/s) this PR alone 594.6 594.7 592.7
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 8K (tok/s) main 607.0 606.0 605.1
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 8K (tok/s) this PR alone 610.6 610.6 611.4
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 32K (tok/s) main 616.7 616.2 616.8
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 32K (tok/s) this PR alone 622.6 621.1 621.0

Decode, each run (tok/s):

Card Model Measure Build Run 1 Run 2 Run 3
RTX 2070 Super 8 GB IQ4_NL decode after 302 (tok/s) main 42.5 42.4 42.5
RTX 2070 Super 8 GB IQ4_NL decode after 302 (tok/s) this PR alone 42.5 42.7 42.2
RTX 2070 Super 8 GB IQ4_NL decode after 8K (tok/s) main 34.6 34.7 34.8
RTX 2070 Super 8 GB IQ4_NL decode after 8K (tok/s) this PR alone 34.8 34.7 34.8
RTX 2070 Super 8 GB UD-Q2_K_XL decode after 302 (tok/s) main 48.3 47.9 41.3
RTX 2070 Super 8 GB UD-Q2_K_XL decode after 302 (tok/s) this PR alone 48.3 47.8 42.9
RTX 2070 Super 8 GB UD-Q2_K_XL decode after 8K (tok/s) main 42.6 42.4 41.3
RTX 2070 Super 8 GB UD-Q2_K_XL decode after 8K (tok/s) this PR alone 42.6 42.5 37.1

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):

Card Rows main this PR alone Change
RTX 2070 Super 8 GB 302 212.3 78.3 −63.1%
RTX 2070 Super 8 GB 1,024 707.6 251.8 −64.4%
RTX 2070 Super 8 GB 2,048 1413.4 493.3 −65.1%

Related discussion

none (one optimization per PR, as asked on #200)

Approach

rms_pick() returns p[0], p[1] or p[2] by comparing blockIdx.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 row
is 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_many of 5 and 300 rows = rms_norm of each input, bit for bit),
    RTX 2070 8 GB (sm_75): 431 checks, 0 failed; main: 425 checks, 0 failed.
  • Kernel bits, main's rms_norm_many_kernel against this PR's at 1, 302, 1,024 and 2,048 rows (3 × 2304): same
    bits at every size (standalone bench, RTX 2070 and RTX 2070 Super).
  • Engine identity, STRATA_FREEZE_EXPERTS=1 STRATA_GPU_EXPERTS=850, token ids + top-20 of 32 greedy tokens: IQ4_NL
    and 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 12
    cases (RTX 2070 8 GB).
  • HIP build (ROCm 7.2.4, gfx1201 + gfx1100): strata-poly and poly_inkling2_test compile.
  • End-to-end runs above (RTX 2070 Super, all 96 runs exited with code 0).

Failed:

  • none observed

Not run:

  • HIP run on an AMD card (compile only).
  • Cards other than sm_75.

Limits

🤖 Generated with Claude Code

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>
@okada-shogo okada-shogo changed the title [Engine] rms_norm_many: pick the input's pointers without local memory (same bits) [Engine] rms_norm_many: avoid local memory for the input pointers Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] rms_norm_many: avoid local memory for the input pointers [Engine] Inkling 2 prompt norms: keep rms_norm_many's input pointers out of local memory (kernel time -63-65%, prompt +0.3-1.0%, same bits) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 prompt norms: keep rms_norm_many's input pointers out of local memory (kernel time -63-65%, prompt +0.3-1.0%, same bits) [Engine] rms_norm_many: keep input pointers out of local memory Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant