Skip to content

[Engine] Inkling 2: larger tiles for prompt F32 products (controllers, routers) - #224

Draft
okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/gemm-f32
Draft

okada-shogo wants to merge 1 commit into
simplexai-labs:mainfrom
okada-shogo:port/gemm-f32

Conversation

@okada-shogo

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

Copy link
Copy Markdown

Speed-neutral end to end. The two F32 products themselves get 12% (one slow run; 25% without it) to 47% faster on an RTX 2070 Super, but prompt
tok/s moves only +0.2% to +0.9% there, and −0.5% to +0.1% on an RTX 3060. Same bits as main.

Problem and result

For prompts with Inkling 2 Mini (CUDA and HIP). It adds a faster kernel for the two F32 matrix products of a
prompt batch. Same bits. The two products get faster, but end-to-end prompt speed does not move (see the top line).

What it changes, in plain words: in a prompt batch, Inkling 2 Mini sends two F32 products through gemm_f32():
the loop controllers' down products (4,608 inputs -> 64 outputs) and the routers (2,304 -> 128). This PR adds
gemm_f32_tiles(), which takes one group of 33 to 256 outputs in a new kernel, gemm_ahead_kernel. The kernel uses
bigger tiles, reads values into registers two steps ahead, and stores to shared memory without bank conflicts. Other
shapes go to gemm_f32() as before.

Prompt speed, this PR alone against main, in tokens per second (tok/s), higher is better, mean of 3 runs (--serve, one GEN 1 request, fp16 KV; same experts in VRAM both ways: RTX 2070 Super
IQ4_NL 929, UD-Q2_K_XL 1,988 of 3,072):

Card Model Measure main (tok/s) this PR alone (tok/s) Change
RTX 2070 Super 8 GB IQ4_NL prompt of 2K tokens 417.9 418.6 +0.2%
RTX 2070 Super 8 GB IQ4_NL prompt of 8K tokens 494.1 497.2 +0.6%
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) prompt of 2K tokens 514.9 519.0 +0.8%
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) prompt of 8K tokens 504.4 508.7 +0.9%
RTX 3060 12 GB IQ4_NL prompt of 2K tokens 743.9 739.9 −0.5%
RTX 3060 12 GB IQ4_NL prompt of 8K tokens 983.9 981.2 −0.3%
RTX 3060 12 GB UD-Q2_K_XL (loop) prompt of 2K tokens 864.8 863.8 −0.1%
RTX 3060 12 GB UD-Q2_K_XL (loop) prompt of 8K tokens 888.0 888.6 +0.1%
Each run (tok/s)

Prompt tok/s, higher is better, each run:

Card Model Measure Build Run 1 (tok/s) Run 2 (tok/s) Run 3 (tok/s)
RTX 2070 Super 8 GB IQ4_NL prompt of 2K tokens main 417.6 419.1 416.9
RTX 2070 Super 8 GB IQ4_NL prompt of 2K tokens this PR alone 418.1 416.5 421.3
RTX 2070 Super 8 GB IQ4_NL prompt of 8K tokens main 492.8 494.2 495.4
RTX 2070 Super 8 GB IQ4_NL prompt of 8K tokens this PR alone 496.1 497.5 498.1
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) prompt of 2K tokens main 513.6 515.3 515.8
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) prompt of 2K tokens this PR alone 519.2 519.4 518.4
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) prompt of 8K tokens main 504.7 504.4 504.2
RTX 2070 Super 8 GB UD-Q2_K_XL (loop) prompt of 8K tokens this PR alone 509.0 508.4 508.8
RTX 3060 12 GB IQ4_NL prompt of 2K tokens main 742.3 745.9 743.6
RTX 3060 12 GB IQ4_NL prompt of 2K tokens this PR alone 749.1 723.5 747.1
RTX 3060 12 GB IQ4_NL prompt of 8K tokens main 980.8 983.6 987.2
RTX 3060 12 GB IQ4_NL prompt of 8K tokens this PR alone 987.5 979.9 976.2
RTX 3060 12 GB UD-Q2_K_XL (loop) prompt of 2K tokens main 866.4 862.5 865.6
RTX 3060 12 GB UD-Q2_K_XL (loop) prompt of 2K tokens this PR alone 864.7 861.9 864.7
RTX 3060 12 GB UD-Q2_K_XL (loop) prompt of 8K tokens main 888.6 886.7 888.8
RTX 3060 12 GB UD-Q2_K_XL (loop) prompt of 8K tokens this PR alone 886.3 890.6 888.9

strata-poly --serve --prompt-cache 0 --conversation-cache-mib 0 --max-context 32768 --kv fp16; main d1f711e and
this branch alternated, order swapped each round. RTX 2070 Super: local card, sm_75 build. RTX 3060: rented box,
both builds for 86;89 on that box.

Kernel time in µs: poly_gemm_small_test --bench

Kernel time, in microseconds (µs), lower is better. What it times: one prompt-batch F32 product of Inkling 2 Mini's shapes (routers 2304 inputs -> 128 outputs, loop controllers 4608 -> 64) for a batch of 333, 1024 or 4096 prompt rows. Mean of 3 runs; a negative Change is faster.

Card Shape main, gemm_f32 (µs) this PR alone, gemm_f32_tiles (µs) Change
RTX 2070 Super 8 GB 2304 -> 128, 333 rows 167.4 147.3 −12.0%
RTX 2070 Super 8 GB 4608 -> 64, 333 rows 305.3 194.0 −36.5%
RTX 2070 Super 8 GB 2304 -> 128, 1024 rows 250.3 214.5 −14.3%
RTX 2070 Super 8 GB 4608 -> 64, 1024 rows 415.5 276.2 −33.5%
RTX 2070 Super 8 GB 2304 -> 128, 4096 rows 862.8 614.6 −28.8%
RTX 2070 Super 8 GB 4608 -> 64, 4096 rows 1406.6 748.6 −46.8%
RTX 3060 12 GB 2304 -> 128, 333 rows 127.5 89.0 −30.2%
RTX 3060 12 GB 4608 -> 64, 333 rows 174.0 129.7 −25.5%
RTX 3060 12 GB 2304 -> 128, 1024 rows 201.1 245.6 +22.1% (slower)
RTX 3060 12 GB 4608 -> 64, 1024 rows 322.1 296.2 −8.0%
RTX 3060 12 GB 2304 -> 128, 4096 rows 733.9 712.0 −3.0%
RTX 3060 12 GB 4608 -> 64, 4096 rows 1042.7 707.5 −32.1%

RTX 2070 Super, 2304 -> 128, 333 rows, this PR alone: run 2 (191.1 µs) was an outlier against 125.2 and 125.5.
Without it the mean is 125.35 µs, −25.1% against main; the smallest other gain on that card is then −14.3%.

Kernel time in µs, lower is better, each run:

Card Shape Build Run 1 (µs) Run 2 (µs) Run 3 (µs)
RTX 2070 Super 8 GB 2304 -> 128, 333 rows main, gemm_f32 167.3 167.4 167.4
RTX 2070 Super 8 GB 2304 -> 128, 333 rows this PR alone, gemm_f32_tiles 125.2 191.1 125.5
RTX 2070 Super 8 GB 4608 -> 64, 333 rows main, gemm_f32 366.0 249.4 300.6
RTX 2070 Super 8 GB 4608 -> 64, 333 rows this PR alone, gemm_f32_tiles 194.0 194.0 194.1
RTX 2070 Super 8 GB 2304 -> 128, 1024 rows main, gemm_f32 249.8 250.6 250.6
RTX 2070 Super 8 GB 2304 -> 128, 1024 rows this PR alone, gemm_f32_tiles 214.8 214.6 214.2
RTX 2070 Super 8 GB 4608 -> 64, 1024 rows main, gemm_f32 416.9 414.8 414.9
RTX 2070 Super 8 GB 4608 -> 64, 1024 rows this PR alone, gemm_f32_tiles 275.6 276.4 276.7
RTX 2070 Super 8 GB 2304 -> 128, 4096 rows main, gemm_f32 845.2 898.2 844.9
RTX 2070 Super 8 GB 2304 -> 128, 4096 rows this PR alone, gemm_f32_tiles 611.9 618.0 613.9
RTX 2070 Super 8 GB 4608 -> 64, 4096 rows main, gemm_f32 1425.6 1368.8 1425.4
RTX 2070 Super 8 GB 4608 -> 64, 4096 rows this PR alone, gemm_f32_tiles 749.2 748.7 747.9
RTX 3060 12 GB 2304 -> 128, 333 rows main, gemm_f32 127.5 127.7 127.4
RTX 3060 12 GB 2304 -> 128, 333 rows this PR alone, gemm_f32_tiles 88.9 89.3 88.9
RTX 3060 12 GB 4608 -> 64, 333 rows main, gemm_f32 174.0 174.0 174.0
RTX 3060 12 GB 4608 -> 64, 333 rows this PR alone, gemm_f32_tiles 129.7 129.8 129.5
RTX 3060 12 GB 2304 -> 128, 1024 rows main, gemm_f32 201.0 201.2 201.2
RTX 3060 12 GB 2304 -> 128, 1024 rows this PR alone, gemm_f32_tiles 245.8 245.5 245.5
RTX 3060 12 GB 4608 -> 64, 1024 rows main, gemm_f32 322.2 322.0 322.0
RTX 3060 12 GB 4608 -> 64, 1024 rows this PR alone, gemm_f32_tiles 296.3 296.2 296.0
RTX 3060 12 GB 2304 -> 128, 4096 rows main, gemm_f32 738.6 726.4 736.6
RTX 3060 12 GB 2304 -> 128, 4096 rows this PR alone, gemm_f32_tiles 710.0 715.7 710.2
RTX 3060 12 GB 4608 -> 64, 4096 rows main, gemm_f32 1037.1 1037.4 1053.6
RTX 3060 12 GB 4608 -> 64, 4096 rows this PR alone, gemm_f32_tiles 708.1 709.3 705.2

Both functions print the same hash of the product in every case. These two products are a small part of a prompt
batch, which is why the end-to-end change is small.

Related discussion

Split out of #200, as the maintainer asked there:
#200 (comment)

Independent of the other split PRs (based on main, not stacked).

Approach

  • Same bits: each output is still one fmaf after the other in input order, like gemm_small_kernel and
    gemm_tile_kernel.
  • Tile choice: it picks the largest of four tiles that still gives half the SMs a block. That rule picked the fastest
    of 19 tiles (64 outputs) and of 27 tiles (128 outputs) measured on the 2070 Super in our earlier engine.
  • Inkling 2 only (Engine::f32_tiles_, set in Inkling2::load_geometry()). Other families do not change. CUDA and HIP;
    Metal keeps its own gemm_f32.
  • poly_gemm_small_test checks both functions against the host, bit for bit, and --bench times Inkling 2's shapes.

Validation

Tested tree: 17a95fe9b (the engine diff to the PR head 2cc8c18 is empty); main d1f711e.

Passed:

  • CUDA 12.9 build, sm_75: strata-poly and poly_gemm_small_test build at this commit.
  • poly_gemm_small_test (both functions vs the host fma chain, bit for bit) and --bench, 3 runs each: all passed,
    0 FAIL lines, on the RTX 2070 Super (sm_75) and an RTX 3060 12 GB (sm_86). gemm_f32 and gemm_f32_tiles print
    the same product hash in all 6 shapes.
  • Identity (prompts of 302, 2,048 and 8,192 tokens + 4 greedy tokens, --top-probs 20, fp16 KV, --expert-swaps 0,
    IQ4_NL and UD-Q2_K_XL, main twice and this PR twice): token ids and top-20 lines the same as main at 2,048 and
    8,192 tokens on both cards, and UD-Q2_K_XL 302 on the RTX 3060. At 302 tokens (IQ4_NL on both cards, UD-Q2_K_XL on
    the 2070 Super) the top-20 lines differ, but main vs main differs there as well, so those cases are not conclusive.
  • Speed above.

Failed: none observed.

Not run:

  • HIP build and run; cards other than the RTX 2070 Super and the RTX 3060.

Limits

  • Speed-neutral end to end on the two cards measured.
  • The tile rule is tuned on one card (40 SMs). On the RTX 3060 (28 SMs) one shape (2304 -> 128 at 1,024 rows) is 22%
    slower. Not measured on larger cards or AMD.
  • Inkling 2 only, although the bits would be the same for any model.

Credits: ported from our Inkling engine in #200.

🤖 Generated with Claude Code

…tiles, loaded two steps ahead

Inkling 2 Mini's prompt batches send its controllers' down products (4,608 inputs to 64 outputs) and its routers
(2,304 to 128) through gemm_f32(). gemm_f32_tiles() takes one group of 33 to 256 outputs in gemm_ahead_kernel: a
template on the block's and a thread's tokens and outputs that reads a step's inputs and weights into registers two
steps before it works on them and stores them so that a warp's writes fill the 32 banks, in the largest of four tiles
that still gives half the SMs a block. Other shapes go to gemm_f32().

Each output is still one fmaf after the other in the inputs' order, so the bits are gemm_f32()'s: poly_gemm_small_test
checks both against the host on Inkling 2 Mini's shapes too, and its --bench times both and prints a hash of each
product. Only Inkling 2 takes it (Engine::f32_tiles_); the other families' products are unchanged. CUDA and HIP;
Metal keeps its own gemm_f32.

Ported from our Inkling engine (simplexai-labs#200, a34789a), adapted to main's gemm_f32().

Co-Authored-By: Claude Opus 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