Skip to content

[Engine] Inkling 2 on RTX 20: faster int8 prompt kernel - #286

Open
okada-shogo wants to merge 2 commits into
simplexai-labs:mainfrom
okada-shogo:port/i8m-sm75
Open

okada-shogo wants to merge 2 commits into
simplexai-labs:mainfrom
okada-shogo:port/i8m-sm75

Conversation

@okada-shogo

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

Copy link
Copy Markdown
Contributor

Problem and result

With --prompt-int8 on an RTX 20 card (sm_75), the int8 prompt kernel (i8m_kernel) took 55-66% of the time of an 8K prompt. Its 128-row tile uses 59-63 KB of the SM's 64 KB of shared memory, so only one block runs per SM. That block decodes a stage of weights, waits at a barrier, multiplies it, and waits again, so the tensor cores sit idle while it decodes.

On Turing only, this PR gives the kernel stages of 128 values instead of 256, with 256 threads. A tile then uses about 32 KB, so two blocks share an SM and one decodes while the other multiplies. The outputs are the same bits. Prompts on an RTX 2070 Super get up to 9.1% faster (IQ4_NL at 32K); other cards are not affected.

Prompt speed, RTX 2070 Super 8 GB, --prompt-int8 with STRATA_PREFILL_NVFP4=w4a8 STRATA_INK_FAST_CTRL=1
(tok/s, higher is better, mean of 3 runs):

Card Model Measure main this PR alone Change
RTX 2070 Super IQ4_NL prompt 2K 618.9 645.7 +4.3%
RTX 2070 Super IQ4_NL prompt 8K 883.7 945.0 +6.9%
RTX 2070 Super IQ4_NL prompt 32K 876.8 956.6 +9.1%
RTX 2070 Super UD-Q2_K_XL prompt 2K 812.5 789.2 -2.9%
RTX 2070 Super UD-Q2_K_XL prompt 8K 839.3 869.1 +3.6%
RTX 2070 Super UD-Q2_K_XL prompt 32K 779.8 802.4 +2.9%

The UD-Q2_K_XL 2K and 32K means include one slow first-round run of this PR (684 and 773 tok/s). Its other runs are
3-5% faster than main (see "Each run" below).

Other cards are not affected: the new shape is chosen only when the running code is the sm_75 pass.

Related discussion

none

Approach

  • i8m_kernel takes a shape parameter CF (template). CF = 0 is the shape it had before, so every other card and
    type launches the same tile, the same stage size and the same arithmetic.
  • i8m_cf75() picks the Turing shape for Inkling 2 Mini's prompt types (IQ4_NL, Q8_0, NVFP4, IQ2_XXS, IQ2_XS,
    IQ2_S), in tiles of 32 and 128 rows:
    • stages of 128 values with 256 threads, two blocks per SM (__launch_bounds__(256, 2));
    • half of the MMA int32 sums are made floats by an exact add (c + 0x4B400000 as a float, minus 1.5·2^23) instead
      of the conversion instruction. Turing runs that conversion at a quarter of the float rate;
    • for the i-quants only, shared rows without padding, with their 16-byte pieces XOR-swizzled by row. Their grid and
      sign tables would otherwise leave no room for a second block.
  • Same bits: each output still adds its terms in the same order, block by block and stage by stage, and the
    int-to-float step is exact (|sum| < 2^22).
  • STRATA_I8M_TURING=0 restores the old shape.
  • New test poly_i8m_shapes_test: every shape against the old one, bit for bit, on Inkling's real shapes (128
    experts with 1,024 tokens' top-8 picks, launched by row class as the engine does, and the dense attention
    products). It also runs the launcher's own pick. --time prints each shape's µs.

The kernel is VecSzn's (i8_mma.cuh); this PR changes only its tile shape on Turing.

Kernel times: RTX 2070 Super (µs, lower is better)

poly_i8m_shapes_test --time, best of 3 runs of 10:

Product Rows main this PR alone Change
IQ4_NL experts gate·up [2304 → 2304] 8,192 5,487 5,033 +9.0%
IQ4_NL experts down [1152 → 2304] 8,192 3,118 2,565 +21.6%
Q8_0 experts gate·up 8,192 5,866 5,384 +9.0%
Q8_0 dense [2304 → 3072] 1,024 615 544 +13.2%
Q8_0 dense [2304 → 1024] 1,024 238 213 +11.5%
IQ2_XXS experts gate·up 8,192 5,859 5,060 +15.8%
IQ2_XS experts gate·up 8,192 7,455 6,777 +10.0%
IQ2_S experts gate·up 8,192 7,765 7,159 +8.5%
NVFP4 experts down 8,192 3,391 2,682 +26.4%
NVFP4 experts gate·up 8,192 5,972 5,246 +13.8%

The old tile reaches 7-12 T MAC/s, roughly 15% of the card's int8 tensor rate. The single block per SM is the main
cause. Shapes that did not help on this card: 256 threads alone (-5%), two weight tiles per warp (-5%), tiles of 64
or 32 rows (-10% to -35%).

Each run (tok/s)
Card Model Measure Build Run 1 Run 2 Run 3
RTX 2070 Super IQ4_NL prompt 2K main 615.1 619.8 621.7
RTX 2070 Super IQ4_NL prompt 2K this PR 642.8 646.7 647.5
RTX 2070 Super IQ4_NL prompt 8K main 884.2 881.5 885.4
RTX 2070 Super IQ4_NL prompt 8K this PR 942.2 946.1 946.6
RTX 2070 Super IQ4_NL prompt 32K main 849.3 889.4 891.6
RTX 2070 Super IQ4_NL prompt 32K this PR 956.7 956.0 957.0
RTX 2070 Super UD-Q2_K_XL prompt 2K main 810.6 811.3 815.7
RTX 2070 Super UD-Q2_K_XL prompt 2K this PR 684.1 840.0 843.6
RTX 2070 Super UD-Q2_K_XL prompt 8K main 841.2 839.8 836.9
RTX 2070 Super UD-Q2_K_XL prompt 8K this PR 875.1 862.8 869.5
RTX 2070 Super UD-Q2_K_XL prompt 32K main 776.4 780.4 782.6
RTX 2070 Super UD-Q2_K_XL prompt 32K this PR 772.6 816.0 818.5

Each run is a fresh --serve process, with one warm-up request before the measured one. The round order alternates
(main first, then this PR first, then main first).

Validation

Passed:

  • Settings register: STRATA_I8M_TURING is registered as a rollback. python3 tools/settings_register.py --check and tools/test_settings_register.py: OK at this commit. No engine code changed in this commit.
  • poly_i8m_shapes_test on a second Turing card, an RTX 2070 (non-Super, 36 SMs): every shape, the same bits.
  • poly_i8m_shapes_test on an RTX 3060 (sm_86): the launcher's own pick (main's cp.async stage copy included) gives
    the same bits as the old shape. On sm_80+ the Turing shapes are compiled empty, and the test skips them there.
  • Engine identity, main vs this PR, STRATA_FREEZE_EXPERTS=1, greedy, token ids plus top-20 logprobs, with and
    without CUDA graphs (RTX 2070 8 GB):
    • same: IQ4_NL and UD-Q2_K_XL at 302 tokens, with default flags and with the speed-run flags (--prompt-int8 + STRATA_PREFILL_NVFP4=w4a8 STRATA_INK_FAST_CTRL=1); IQ4_NL at 8,150 tokens with the speed-run flags;
    • also the same on the RTX 3060: IQ4_NL at 302 tokens, both flag sets;
    • also the same: UD-Q2_K_XL at 8,150 tokens, both flag sets, on the RTX 2070 Super. This one is on the rebased
      commit vs main cdfae80, with STRATA_GPU_EXPERTS=1800 --max-context 8256, so the attention cache fits in 8 GB.
  • Prompt tok/s comparison above: RTX 2070 Super, main 1a41ff6 vs this change before its rebase onto cdfae80 (i8_mma has not changed upstream since), 3 rounds, CUDA 12.9.
  • poly_i8m_shapes_test on the rebased commit (RTX 2070 Super): 18 products, all the same bits. Besides Inkling's
    shapes, these include K = 704 and 1,088, 2,280 outputs, and rows read and written by index with empty experts.
    Each Turing shape fits 2 blocks per SM; the test fails otherwise.
  • An independent code review of the diff found no correctness bug.
  • The sm_86 SASS of the old-shape kernels has the same float, tensor and shared-memory instructions as main's. Only
    integer address arithmetic is scheduled differently.

Failed:

  • none observed

Not run:

  • Other Turing cards (RTX 2080 Ti, T4, Quadro RTX): untested, though they get the same shape.
  • HIP: i8_mma.cu is CUDA-only, and HIP builds compile it empty.

Limits

  • Turing only. On an RTX 3060 the same shape gave mixed results against main's real launcher: IQ4_NL down and IQ2_XXS faster,
    NVFP4 gate·up, IQ2_S and IQ2_XS slower, within ±10% run noise. Ampere stays on the old shape.
  • Only Inkling 2 Mini's types and tiles of 32 and 128 rows get the new shape. Tiles of 16 and 64 rows and other types
    are unchanged.

🤖 Generated with Claude Code

…bits)

On sm_75 the int8 prompt kernel's tile of 128 activation rows takes 59-63 KB of the
multiprocessor's 64 KB, so one block decodes a stage and multiplies it by turns. For
Inkling 2 Mini's types (IQ4_NL, Q8_0, NVFP4, IQ2_XXS, IQ2_XS, IQ2_S) in tiles of 32 and
128 rows, the Turing pass now takes stages of 128 values with 256 threads (two blocks a
multiprocessor), half of the int32 sums made floats by an exact add in place of the
conversion, and for the i-quants shared rows without padding (pieces swizzled by row). The passes for
Ampere and newer compile these shapes empty.
Each output's terms are added in the same order: the same bits. Other cards, and
STRATA_I8M_TURING=0, take the tile as before.

RTX 2070 Super, poly_i8m_shapes_test --time: IQ4_NL experts gate|up 5,489 -> 5,002 us,
down 3,075 -> 2,551; Q8_0 dense [2304 -> 3072] 615 -> 543; NVFP4 down 3,391 -> 2,681;
IQ2_XXS 5,876 -> 5,095.

poly_i8m_shapes_test: each shape against the old one, bit for bit (--time: their times), and the launcher's
own pick; also rows of 704 and 1,088 values, 2,280 outputs, rows read and written by index with experts
without rows; it fails where a Turing shape fits fewer than two blocks a multiprocessor.
The kernel is VecSzn's (i8_mma.cuh); this changes only its tile shape on Turing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on Turing: int8 prompt tiles in stages of 128, two blocks per SM (same bits) [Engine] Inkling 2 on Turing (RTX 20): faster int8 prompt kernel, 128-value stages and 2 blocks per SM Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on Turing (RTX 20): faster int8 prompt kernel, 128-value stages and 2 blocks per SM [Engine] Inkling 2 on Turing (RTX 20): smaller int8 prompt-kernel tiles so two blocks share an SM (up to +9.1% prompt speed, same bits) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on Turing (RTX 20): smaller int8 prompt-kernel tiles so two blocks share an SM (up to +9.1% prompt speed, same bits) [Engine] Inkling 2 on RTX 20: faster int8 prompt kernel (up to +9% prompt) Nov 24, 2026
@okada-shogo okada-shogo changed the title [Engine] Inkling 2 on RTX 20: faster int8 prompt kernel (up to +9% prompt) [Engine] Inkling 2 on RTX 20: faster int8 prompt kernel Nov 24, 2026
Registered as a rollback of the 128-value int8 tile stages on Turing.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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