Skip to content

[Engine] Inkling 2: keep norm parameters out of local memory - #297

Open
okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/ink-param-pick
Open

okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/ink-param-pick

Conversation

@okada-shogo

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

Copy link
Copy Markdown
Contributor

Problem and result

This PR makes two Inkling 2 norm kernels pick their input pointer by comparisons instead of indexing the kernel's
parameter struct. The kernels get 27-38% faster; end-to-end prompt speed gains up to 0.5%. Same bits.

The kernels are ink_cat_norm_kernel (the loop controllers' norms in a prompt, 3 pairs a launch) and
ink_norm_many_q8_kernel (a token's 3 norms of a full layer's inputs). Both read their pointers as p[blockIdx.y].
When a kernel indexes its parameters with a register value, nvcc copies the struct to local memory in every block
(9 and 12 STL.64 stores on sm_75), and the loads through those pointers become generic LDs.

End-to-end, RTX 2070 Super 8 GB (Ryzen 5 3600XT), main's default flags on both sides, one --serve engine per 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 222.2 -0.0%
RTX 2070 Super 8 GB IQ4_NL prompt 2K (tok/s) 493.0 493.8 +0.1%
RTX 2070 Super 8 GB IQ4_NL prompt 8K (tok/s) 606.3 608.6 +0.4%
RTX 2070 Super 8 GB IQ4_NL prompt 32K (tok/s) 645.4 648.3 +0.4%
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 302 (tok/s) 272.7 274.0 +0.5%
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 2K (tok/s) 588.1 590.6 +0.4%
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 8K (tok/s) 606.0 609.1 +0.5%
RTX 2070 Super 8 GB UD-Q2_K_XL prompt 32K (tok/s) 616.6 619.8 +0.5%

Decode tok/s, the same runs, mean of 3 runs. The UD-Q2_K_XL decode rows are moved by a slow round 3 that hit every
build (see each run below); the decode kernel itself gains ~2 µs a layer.

Card Model Measure main this PR alone Change
RTX 2070 Super 8 GB IQ4_NL decode after 302 (tok/s) 42.5 42.4 -0.1%
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 47.9 +4.6%
RTX 2070 Super 8 GB UD-Q2_K_XL decode after 8K (tok/s) 42.1 42.3 +0.5%

Kernel time, RTX 2070 Super, n_embd 2304 (µs, lower is better; median of 7 × 50 launches, mean of 3 runs):

Card Kernel Rows main this PR alone Change
RTX 2070 Super 8 GB ink_cat_norm_set (3 pairs) 302 172.0 111.1 −35.4%
RTX 2070 Super 8 GB ink_cat_norm_set (3 pairs) 1,024 586.8 366.4 −37.6%
RTX 2070 Super 8 GB ink_norm_many_q8 (3 inputs, decode) 1 7.09 5.15 −27.4%
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 217.9 225.9 222.7
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 493.8 494.2 493.3
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 608.5 608.4 608.8
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 647.8 648.5 648.6
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 272.9 275.3 273.8
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 591.3 590.4 590.2
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 608.4 609.3 609.7
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 619.6 620.9 618.9

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.0 42.6 42.7
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.8 34.7
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.0 47.9 47.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.5 42.6 41.8

Experts in VRAM at load: 917 in every IQ4_NL run and 1,967 in every UD-Q2_K_XL run, on both main and this PR.

Related discussion

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

Approach

ink_pick() returns p[0], p[1] or p[2] by comparing blockIdx.y (both launchers allow 1 to 3 entries).
Nothing else changes: the same threads add the same values in the same order. Only inkling2.cu changes. The same
pattern is in rms_norm_many_kernel (kernels.cu), fixed in a separate PR (#296, port/norm-many); the two are
independent.

Validation

All on branch 325c4dd = main 36e654b + this PR (the binaries measured were built from d549fa8b3, which
differs only in a comment).

Passed:

  • Kernel bits: ink_cat_norm_set (3 pairs, 302 and 1,024 rows) and ink_norm_many_q8 (3 inputs, 1 row), main's
    inkling2.cu against this PR's: byte-identical outputs, 2 runs each (RTX 2070 8 GB).
  • poly_inkling2_test: 425 checks, 0 failed (RTX 2070 8 GB).
  • 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:
    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.
  • The 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

  • ink_mix_many_kernel (decode, 12 jobs per launch) and the conv state kernel have the same pattern; they are not
    changed here.

🤖 Generated with Claude Code

ink_cat_norm_kernel (the loop controllers' norms in a prompt, three
pairs a launch) and ink_norm_many_q8_kernel (a token's three norms of
a full layer's inputs) took their pointers as p[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 and
twelve STL.64 on sm_75), and the loads through the pointers read back
from there became generic loads (60 LD in ink_cat_norm_kernel) instead
of global ones.

ink_pick() picks the pointer by comparisons.  Nothing else changes: the
same threads add the same values in the same order, so the same bits.
(rms_norm_many_kernel in kernels.cu has the same pattern; a separate
change.)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@okada-shogo okada-shogo changed the title [Engine] Inkling 2: norm kernels without their parameters in local memory (same bits) [Engine] Inkling 2: avoid local memory for norm kernel parameters Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2: avoid local memory for norm kernel parameters [Engine] Inkling 2: keep norm kernel parameters out of local memory (norm kernels 27-38% faster, same bits) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2: keep norm kernel parameters out of local memory (norm kernels 27-38% faster, same bits) [Engine] Inkling 2: keep norm kernel parameters out of local memory Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2: keep norm kernel parameters out of local memory [Engine] Inkling 2: keep norm parameters 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