Inside FlashInfer's SM100 GEMM, Part 3: Choosing a Tactic
How mm_fp4 turns a matrix shape into a tile, a cluster and a few switches, why swapping A and B wins for small batches, how the narrow N tiles reach their scale factors, and how to time tactics without fooling yourself
Series: Part 1 · Part 2 · Part 3
In the first two parts of this series, we took FlashInfer's SM100 block-scaled GEMM apart: in part 1 the instruction, the tiles and the scale factors, and in part 2 the warps, barriers, stages, accumulators and the persistent loop that keep the tensor cores busy. Along the way, we kept running into choices: 128 or 256 rows per tile, 64 or 256 columns, a cluster of 2 or of 8, the early or the late accumulator release. Most of those choices aren't fixed in the kernel. They are parameters of its constructor, and somebody has to pick them for every matrix shape the kernel is called with.
FlashInfer calls one such set of choices a tactic. In this last part, we'll look at what a tactic contains, how much it matters which one you pick (quite a lot, as we'll see), and how mm_fp4(..., backend="cute-dsl") picks one, both with its autotuner and without it. The most interesting choices are for small batches, where the kernel swaps its two operands and uses very narrow tiles, so those get the most space. At the end, we'll look at how the autotuner times the tactics, since a wrong timing method picks the wrong tactic even when the candidate list is right.
As before, the code is FlashInfer at c0e62fa7b with CuTe DSL 4.8.0, and the measurements are from a B300. All shapes are from GLM-5.3's dense layers, unsharded: the fused gate and up projection (N = 24,576, K = 6,144), the down projection (N = 6,144, K = 12,288) and the attention output projection (N = 6,144, K = 16,384), each with M from 1 to 8,192 tokens. I timed every kernel with CUPTI, from the start of the kernel to its end, with the L2 cache flushed before every launch (section 7 explains why), and every output was bit-identical to FlashInfer's CUTLASS backend.
1. What a Tactic Is
1.1 Six Fields
In the mm_fp4 runner for the CuTe DSL backend (CuteDSLFp4GemmRunner in gemm_base.py), a tactic is a tuple of six fields:
# (mma_tiler_mn, cluster_shape_mn, swap_ab, use_prefetch, kernel_type, extra)
((256, 256), (2, 1), False, False, "sm100", None) # large M
((128, 16), (1, 1), True, False, "sm100", None) # a few tokens
((128, 8), (1, 1), True, False, "sm100sk", 2) # split-K, two slices
The first two are the MMA tile and the cluster shape from parts 1 and 2. swap_ab exchanges the roles of A and B, which is the subject of section 4. use_prefetch makes the TMA warp issue L2 prefetches for the next few K tiles ahead of its loads. kernel_type is "sm100" for the kernel we have been reading, or "sm100sk" for a separate split-K kernel that FlashInfer also offers for small batches. The last field depends on the kernel type: for the split-K kernel, it's the number of K slices, and for the persistent kernel it's either None or 8, which selects the "deep-K" variant with 8 instructions per K tile instead of 4. One more knob, the L2 eviction policy of the TMA loads, isn't part of the tuple, because the runner derives it from the tactic and the shape (section 6).
Everything else we saw in parts 1 and 2 (the number of stages, the number of accumulators, the epilogue subtile, the multicast masks) follows from these fields when the kernel is constructed.
1.2 Where the Candidates Come From
The runner builds the list of candidates from two fixed lists in kernels/utils.py, 11 MMA tiles and 9 cluster shapes:
# excerpt from kernels/utils.py
_SM100_MMA_TILER_MN_CANDIDATES = [
(128, 8),
(128, 16),
(128, 32),
(128, 64),
(256, 64),
(128, 128),
(256, 128),
(128, 192),
(256, 192),
(128, 256),
(256, 256),
]
# ...
_CLUSTER_SHAPE_MN_CANDIDATES = [
(1, 1),
(1, 2),
(1, 4),
(2, 1),
(2, 2),
(2, 4),
(4, 1),
(4, 2),
(4, 4),
]
It takes every combination with both values of swap_ab and keeps the ones that the kernel's can_implement accepts. That check encodes the rules from parts 1 and 2: a 256-row tile needs at least two CTAs along M in the cluster, cluster dimensions are powers of two and at most 4, and the narrow tiles (N of 8, 16 or 32) have extra rules that we'll see in section 5. use_prefetch is only offered when it can plausibly help: when the grid fills between half and all of the SMs, or when K is at least 8,192. For M up to 32, the runner keeps only swapped tactics with a narrow tile. It then appends the deep-K variants of the narrow tiles and the split-K tactics.
That still leaves a lot: between 120 and 258 valid persistent-kernel tactics for our 30 shapes, before the split-K and deep-K ones. Profiling all of them would take a while for every new shape, so the runner ranks them with a heuristic score and the autotuner only profiles the best 32 (_MM_FP4_CUTE_DSL_MAX_TUNING_CONFIGS). The same score picks the tactic when no autotuning has happened, which we'll come back to in section 8.
2. How Much the Choice Matters
Before looking at how the choice is made, I wanted to know how much is at stake. So for each of our 30 shapes (3 layers times 10 token counts), I timed every tactic that the autotuner would profile, 918 kernels in total. Here's the spread between the best and the worst of them:
- Across all shapes, the slowest profiled tactic took 1.6 times as long as the fastest, as a geometric mean, and 4.4 times as long in the worst case (GLM-5.3's gate and up projection with 32 tokens: 19.7 against 87.2 microseconds).
- The untuned choice, which
mm_fp4makes when no autotuning has happened, was 5% slower than the best tactic on average and 13% slower at most.
So, the list of candidates already contains mostly reasonable tactics (it's ranked, after all), but picking the wrong one among them can still cost several times the runtime, and even the heuristic pick is 5% slower than the best on average. Let's look at what drives the differences, starting with the effect that the heuristic models most directly.
3. Tile and Wave Quantization
3.1 Two Kinds of Waste
There are two ways a tile shape can waste work, and the heuristic score (_score_block_scaled_tactic in kernels/utils.py) measures both.
The first is tile quantization. If the matrix dimension isn't a multiple of the tile, the last row or column of tiles is only partly filled, but the tensor cores compute it in full. With M = 300 and 128-row tiles, there are 3 tiles along M covering 384 rows, so 22% of the work is thrown away. The score calls the useful fraction m_eff (and n_eff for N).
The second is wave quantization, which we met at the end of part 2. The persistent kernel runs one CTA per SM, and the tiles are dealt out in rounds. If the number of CTA tiles isn't a multiple of the number of SMs, the last round leaves some SMs idle. The score counts the rounds (num_waves) and divides by them.
Put together, the core of the score is the useful work per round, normalized by the width of the tile: m_eff * n_eff * sqrt(tile_n / 256) / (num_waves * tile_n), where the square root is a rough model of how wider tiles get more throughput per CTA. On top of that come a few corrections: a penalty for tiles wider than 128 when K is short (since the pipeline can't hide their latency), a 5% bonus for the CTA pair, small penalties for large clusters, and a 5% penalty for any tactic whose orientation disagrees with a simple rule, swap when M is at most 32 and don't swap otherwise (section 4).
3.2 A Worked Example
Let's take one shape where this matters: GLM-5.3's down projection with 4,096 tokens, so M = 4,096, N = 6,144 and K = 12,288. Here is the wave arithmetic for the two tiles that came out on top:
import math
def waves(m, n, tile, sms=148):
ctas_m = math.ceil(m / tile[0]) * (2 if tile[0] == 256 else 1)
ctas_n = math.ceil(n / tile[1])
ctas = ctas_m * ctas_n
return ctas, ctas / sms, math.ceil(ctas / sms)
for tile in [(256, 256), (256, 192)]:
ctas, exact, rounds = waves(4096, 6144, tile)
print(tile, ctas, f"{exact:.2f} waves -> {rounds} rounds,",
f"{exact / rounds:.0%} of the SMs busy on average")
The 256 x 256 tile gives 768 CTAs, which is 5.19 waves of 148, so 6 rounds in which the SMs are busy 86% of the time. The 256 x 192 tile gives 1,024 CTAs, 6.92 waves, so 7 rounds that are 99% full. The narrower tile does a little less work per CTA, but it wastes almost nothing at the end.
Which one is faster? In my measurement, 256 x 192 took 91.6 microseconds and 256 x 256 took 99.6, so the better-filled waves save 8% of the time. The heuristic score, though, prefers 256 x 256 here, by about 1%: its square-root throughput model credits the wider tile with 15% more throughput per CTA, which almost exactly cancels the extra round it needs. So the untuned path picks the slower tile, and this is a nice illustration of why FlashInfer profiles the top candidates instead of trusting the score. The score is a good way to rank a list, but it's a model, and at the margin the model is wrong.
4. Swapping A and B
4.1 The Problem with Small M
Now let's look at decoding, where M, the number of tokens, is tiny: 1 to 32 tokens per step is typical for a serving engine at low concurrency. Here we run into the instruction's shape rules from part 1. The M dimension of tcgen05.mma is 128 or 256, never smaller. So with M = 1, the kernel computes a 128-row tile in which one row is real and 127 are padding. That is tile quantization at its most extreme, with an m_eff of 1/128.
In terms of time, it isn't quite as bad as it sounds, since a decoding GEMM is limited by reading the weight matrix from HBM and not by the tensor cores. But the padding still costs: without swapping, N is the weight dimension, which is far above the 32 that the narrow tiles allow (section 5), so the smallest usable N tile is 64. The weight matrix B is then cut into 64-row slabs, and every slab is multiplied by a 128-row tile of A that is almost all zeros.
The fix is a transposition identity. The kernel computes C = A B^T. If we transpose both sides, C^T = B A^T, which is the same kind of product with the roles of A and B exchanged. So we can give the kernel the weights as its A operand and the activations as its B operand, and it computes C^T. Now the large dimension, the 24,576 output features of the gate and up projection, is on the M side, where the instruction wants 128 rows, and the tokens are on the N side, where the instruction accepts as few as 8 columns. Figure 1 shows the two orientations.
4.2 Swapping in Practice
In code, the identity is one line of PyTorch:
import torch
a = torch.randn(4, 64) # 4 tokens, K = 64
b = torch.randn(256, 64) # 256 output features
c = a @ b.T # what we want: (4, 256)
c_t = b @ a.T # what the swapped kernel computes: (256, 4)
print(torch.allclose(c, c_t.T, atol=1e-5))
# the swapped result, written column-major, is c in row-major order
col_major = torch.empty_strided((256, 4), (1, 256))
col_major.copy_(c_t)
print(torch.equal(col_major.as_strided((4, 256), (256, 1)), c_t.T))
The second check shows the other half of the trick. The kernel writes its (N, M)-shaped output in column-major order, which in memory is exactly the (M, N) row-major matrix the caller wants. So the runner doesn't need any transpose after the kernel. It passes the weights as A and the activations as B, swaps the two scale-factor tensors, and gives the kernel a column-major view of the output buffer:
# excerpt from gemm_base.py
if swap_ab:
kernel_m, kernel_n = n, m
# ...
kernel_a, kernel_b = b.T, a
kernel_a_sf, kernel_b_sf = b_descale.T, a_descale
(Full disclosure: I wrote the changes that let mm_fp4 swap for M that isn't a multiple of 8 and added the narrow tiles of the next section, so I'm not a neutral reporter here. All the numbers below are from this article's measurements.)
How much does it buy? For M from 1 to 32, I timed the best non-swapped tactic (over five tiles of 64 to 256 columns and six cluster shapes) against the best swapped one. Figure 2 shows the result.
As we can see in Figure 2, the swapped tactic wins every time, by a factor of 1.07 to 1.21. The gain is largest for one token and shrinks as M approaches 32, where the unswapped 64-column tiles waste less and the swapped tiles have to grow to 32 columns. Notice also how flat the swapped times are: the down projection takes 12.3 microseconds for one token and 13.3 for 32, since in both cases the kernel mostly reads the same 42 MB of weights and scale factors. For the gate and up projection, that's 85 MB in 19.2 microseconds, or 4.4 TB/s, a bit more than half of the B300's 7.7 TB/s peak memory bandwidth.
5. The Narrow Tiles
5.1 Scale Factors for Eight Tokens
With the tokens on the N side, the N tile can be as small as the instruction allows: 8 columns for one CTA. That's what the tiles (128, 8), (128, 16) and (128, 32) are for. But they run into a problem we saw at the end of part 1: the scale factors of B (now the activations) always come in chunks of 128 rows, because that's the unit that tcgen05.cp copies into TMEM. A 16-wide tile only needs 16 of those 128 rows.
The kernel's solution is to load the whole 128-row SFB chunk anyway and let several narrow tiles share it. In the mainloop, tile number i along N computes its offset into the chunk and points the MMA at the right part:
# excerpt from dense_blockscaled_gemm_sm100.py
tok_off = (
mma_tile_coord_mnl[1] % self.sfb_sub_tiles_per_tile
) * self.cta_tile_shape_mnk[1]
offset = cutlass.Int32(tok_off // 32)
shifted_ptr = cute.recast_ptr(
acc_tmem_ptr
+ self.num_accumulator_tmem_cols
+ self.num_sfa_tmem_cols
+ offset,
dtype=self.sf_dtype,
)
tCtSFB_mma = cute.make_tensor(shifted_ptr, tCtSFB_layout)
sSFB_shifted = cute.make_tensor(
sSFB.iterator + cutlass.Int32(tok_off % 32) * 16,
sSFB.layout,
)
Remember from part 1 that row r of the chunk lives in TMEM lane r mod 32, column r div 32, and in shared memory at byte (r mod 32) x 16 + (r div 32) x 4. So a tile that starts at token tok_off has two things to adjust: its first row should land in TMEM lane 0, which the kernel arranges by starting the shared-memory source of the copy tok_off mod 32 lines (16 bytes each) later; and its TMEM column moves by tok_off div 32, which shifts the MMA's SFB address. Since the shifted copy still reads a full 512-byte chunk, it can run up to 31 lines past the end of the real one, which is why narrow tiles reserve one extra chunk of shared memory for SFB (the 512 bytes we saw in part 2's stage count).
5.2 Why Only 32 Tokens
That column shift turned out to be the catch. According to the kernel's comments, tcgen05.mma faults with a misaligned address when the SFB column shift is odd, so a tile that starts at token 32 (shift 1) or 96 (shift 3) crashes. (The 64-wide tile also shifts SFB, by two columns, which is fine.) So the kernel only allows narrow tiles while every tile starts in the first 32 tokens of the chunk, which means that the kernel's N, the number of tokens in the swapped orientation, has to be at most 32:
# excerpt from dense_blockscaled_gemm_sm100.py
NARROW_TILE_MAX_N = 32
# ...
return tile_n >= 64 or kernel_n <= cls.NARROW_TILE_MAX_N
Here is the arithmetic for all narrow tiles, which also shows why 32 is the limit:
def sfb_shift(tile_n, tile_index):
tok_off = tile_index % (128 // tile_n) * tile_n
return tok_off // 32, tok_off % 32 * 16 # (TMEM column, smem bytes)
for tile_n in (8, 16, 32):
tiles = [sfb_shift(tile_n, i) for i in range(128 // tile_n)]
fits = [s for i, s in enumerate(tiles) if (i + 1) * tile_n <= 32]
print(tile_n, "tokens <= 32:", fits, "first odd shift at tile",
next(i for i, (c, _) in enumerate(tiles) if c % 2))
For 8-wide tiles, the four tiles that cover tokens 0 to 31 all have column shift 0 and start 0, 128, 256 and 384 bytes into the chunk, and the first odd shift comes with tile 4, at token 32. For 16-wide tiles it's tiles 0 and 1, then tile 2 at token 32, and for 32-wide tiles only tile 0, with tile 1 again at token 32. So "at most 32 tokens" is exactly "never an odd column shift". Figure 3 shows the shared chunk.
can_implement also rejects narrow tiles in clusters with more than one CTA along N, so the SFB chunk of a narrow tile is never multicast. And it explains the stale-tactic check in the runner's forward: the autotuner's cache is bucketed by M, so a tactic tuned for 16 tokens could be replayed for 40, which would fault. The runner checks narrow_tile_ok before every launch and falls back to the untuned choice if it fails.
One more thing I noticed while measuring: for M up to 32, the runner lists (256, 8) among the narrow tiles it allows, and can_implement accepts it, but the CTA-pair instruction requires N to be a multiple of 16 (part 1), so CuTe DSL rejects that tile when the kernel is built. None of the runner's ranked tactics for our shapes used it, but it's a candidate that can never run.
5.3 Which Narrow Tile?
With three narrow tiles to choose from, which one should a given M use? A tile covers tile_n tokens, so with 16 tokens and 8-wide tiles, the kernel needs two tiles along N, and each of them reads the entire weight matrix. Whether that matters depends on the layer. For the gate and up projection, with 24,576 weight rows, there are already 192 weight tiles of 128 rows, more than the 148 SMs, and splitting the tokens over two tiles doubles the work for no gain: with 16 tokens, the 8-wide tile took 32.6 microseconds against 19.7 for the 16-wide one, about the cost of reading the weights twice.
The down projection has only 6,144 weight rows, so 48 weight tiles, and most SMs are idle. Here, splitting the tokens over two tiles gives the idle SMs something to do: with 16 tokens, the 8-wide and 16-wide tiles took 12.3 and 12.5 microseconds, and with 32 tokens, two 16-wide tiles beat one 32-wide tile, 12.7 against 13.2. My guess is that the second read of the weights is mostly served by L2, since the CTAs that read the same weight tile run at the same time, but I haven't measured the L2 hit rates. Either way, the rule of thumb is to use the smallest narrow tile that covers all tokens when the weight tiles already fill the GPU, and that splitting the tokens is cheap when they don't. The autotuner finds both cases on its own.
6. More Switches: Split-K, Deep-K, Prefetch and L2 Hints
The remaining options all target the same situation: a small grid that leaves SMs idle, or a weight matrix that has to stream through once. I'll go through them briefly, with what I measured for each.
Split-K. When the output has very few tiles (say, 20 tiles of 128 weight rows for N = 2,560), most of the 148 SMs have nothing to do. A split-K kernel cuts K into 2 or 4 slices, computes them on different CTAs of a cluster, and adds the partial results at the end. FlashInfer's _select_sm100_mm_fp4_splitk_tactic documents when it measured this to help on B200 and GB300: mostly for 20 or fewer weight tiles. GLM-5.3's dense layers have at least 48 weight tiles, and in my sweep, split-K was never the fastest tactic for them. For the attention output projection with one token, the untuned choice picks two slices (because K = 16,384 is long), at 15.4 microseconds against 14.9 for the best persistent tactic.
Deep-K. The variant with 8 instructions per K tile makes every TMA row fetch 256 bytes instead of 128, which according to FlashInfer's comments helps HBM efficiency for narrow tiles once there are enough weight tiles to fill the GPU. For our three shapes, I measured it against the normal 4 instructions per K tile with the same tile and cluster: it ranged from 1% faster to 7% slower, so mostly a wash or a small loss here.
Prefetch. With use_prefetch, the TMA warp issues L2 prefetches (the cute.prefetch from the TMA article) for the K tiles it will load next, so that the actual loads find their data in L2. Comparing each prefetch tactic in the sweep with the same tile and cluster without prefetch, it ranged from a big win to a big loss. For the attention output projection with 256 tokens and a 128 x 128 tile in a 2 x 2 cluster, prefetch took the kernel from 22.5 to 18.2 microseconds. For the down projection with 4,096 tokens and a 128 x 192 tile, it made it slower, from 116.2 to 147.9. So it is a switch for the autotuner, not one to turn on by default.
L2 eviction hints. The runner gives the TMA loads an L2 eviction policy based on the shape (mm_fp4_l2_policy in gemm_mm_fp4_cute_dsl.py). When there are at most two tiles of tokens, the weights are read at most twice, so they are loaded with evict_first, which, as the function's docstring explains, keeps them from pushing the small, much-reused activation tile out of L2. When there are more token tiles and no swap, both operands are re-read many times, and both get evict_last. Here is what that was worth in my measurements: with 16 tokens, evict_first on the weights took the swapped 128 x 16 kernel from 22.8 to 20.2 microseconds for the gate and up projection, and from 13.8 to 12.5 for the down projection; with 256 tokens and a 128 x 128 tile, from 32.0 to 26.7 and from 20.3 to 17.3. With 8,192 tokens, the docstring reports 0.1 to 10% from evict_last on B200 and GB300, but on the B300 with our shapes I saw no difference beyond the noise. So on this machine, the hints matter for the case of streaming the weights once past a small, hot activation tile.
7. Timing Tactics Without Fooling Yourself
7.1 Cold L2
All of this depends on timing each candidate correctly, and that turns out to be harder than it looks. The obvious way, launching a kernel many times in a row and dividing the total time, measures the kernel with a warm L2 cache: the second launch finds the operands of the first one in L2. On the B300, the L2 holds 126.5 MiB, and the weights of the gate and up projection (85 MB with their scale factors) fit entirely. So a warm measurement of a decoding step measures how fast the kernel reads from L2, while in a real model, the next layer's weights are almost never in L2 when its GEMM starts.
Here's what that does to the choice. For the gate and up projection with 16 tokens, Figure 4 shows every tactic that the autotuner profiles, with its warm time against its cold time.
As we can see in Figure 4, the tactic that is fastest with a warm L2 is split-K with two slices, at 14.2 microseconds, but with a cold L2 it takes 26.9, while the best cold tactic takes 19.5. My guess is that split-K helps when the operands come from L2, since then more CTAs can pull from it at once, but when they come from HBM, the bandwidth is the limit, and splitting K only adds the traffic of the partial results. Across all 30 shapes, picking by warm time cost 6% on average against the best cold tactic, and up to 38%. The big losses, 34 to 38%, were all the gate and up projection with at most 16 tokens, where the warm measurement always preferred split-K; for the other shapes, the warm pick was off by 3 to 10% or not at all.
That's why the mm_fp4 tuning config sets use_cold_l2_cache=True. Before every sample, the autotuner zeroes a buffer of twice the L2 size, which evicts everything, and then times one launch.
7.2 CUDA Graphs and Timers
The other half of the config is use_cuda_graph=True: the autotuner captures the launch in a CUDA graph and replays the graph, so that the host-side launch overhead (Python, argument packing, the driver) doesn't end up in the measurement. That overhead is not small next to these kernels. For the down projection with 16 tokens, whose kernel takes 9.4 microseconds with a warm L2, I measured about 7 microseconds of host time per call of the runner's forward alone, and about 55 microseconds per call of the public mm_fp4 function, so back-to-back eager calls would mostly measure the host.
Even with a graph, though, the timer matters. The autotuner's default timer is a pair of CUDA events around the graph replay. On the B300, CUDA events themselves resolve 32 nanoseconds, but the span between the two events includes the graph launch, and I measured it to add about 4.5 microseconds to every sample of these kernels, for example 24.2 microseconds by events for a kernel that CUPTI times at 19.6. Since the offset is roughly the same for every tactic, it doesn't change the ranking much: picking by event time cost only 1% on average against picking by CUPTI time, and 8% at most. But it compresses the differences, which matters when two tactics are close. FlashInfer's autotuner can also use CUPTI (its measurement policy has a "cupti" timer), and that's what I used for every number in this series.
8. Without the Autotuner
Autotuning takes time, so mm_fp4 also has an untuned path, which is what runs when a shape was never tuned. It uses the same score as the ranking, but precomputes it once per (N, K) for a fixed set of M buckets, the powers of two from 1 to 32,768, and then looks up the bucket of each call, which takes about 0.2 microseconds on the host. For small M, it first asks the split-K selector from section 6, and falls back to the score otherwise.
How good is it? From the sweep, the untuned choice was within 5% of the best tactic on average and 13% in the worst case, the attention output projection with 128 tokens, where the best tactic used a 1 x 4 cluster with prefetch and the untuned one a single CTA without. For decoding shapes, it always swaps and picks a narrow tile, and most of its losses elsewhere come from the cluster shape and prefetch, which the score can't see well, and from wave effects like the one in section 3.2. So the heuristic is a reasonable default, and the autotuner adds a few percent on top, mostly at medium and large M.
9. Summary of the Series
To summarize this part:
- A tactic is (tile, cluster, swap_ab, prefetch, kernel type, extra). The runner enumerates 11 tiles, 9 clusters, both orientations and both prefetch settings, filters them with
can_implement, ranks them with a heuristic score, and profiles the best 32. - The choice matters: the slowest profiled tactic was 1.6 times slower than the fastest on average and up to 4.4 times. The untuned choice was 5% slower on average.
- Tile and wave quantization drive most of the score. At the margin the score is wrong, as for the down projection with 4,096 tokens, where better-filled waves beat a wider tile by 8%.
- Swapping A and B puts the weights on the instruction's 128-row M side and the tokens on the N side, where tiles of 8, 16 and 32 are possible. It was 1.07 to 1.21 times faster for 1 to 32 tokens.
- Narrow tiles share a 128-row chunk of scale factors and reach their part through a shifted TMEM column and shared-memory offset; an odd column shift faults, which is why they are limited to 32 tokens. When the weight tiles fill the GPU, the best narrow tile is the smallest one that covers all tokens; when they don't, splitting the tokens over two tiles is cheap.
- The extra switches (split-K, deep-K, prefetch, L2 hints) help in specific places; the L2 hint was worth up to 17% for small and medium batches.
- Timing must use a cold L2 and a CUDA graph. With a warm L2, the weights of a decoding GEMM sit in L2, and the warm winner was up to 38% slower with a cold one.
And to summarize the whole series: FlashInfer's SM100 block-scaled GEMM is built around one instruction, tcgen05.mma with block scaling, which a single thread issues for a whole 128- or 256-row tile, reading its operands from shared memory and its scale factors from TMEM (part 1). Everything else in the kernel exists to keep that instruction busy: a TMA warp, an MMA warp and four epilogue warps connected by rings of mbarriers, two accumulators in TMEM that even overlap for the widest tiles, and a persistent loop that deals out tiles to clusters (part 2). And since no single configuration is right for every shape, the kernel is a family of configurations, and the last piece of the puzzle is picking one well, which means modeling quantization, swapping the operands for small batches, and timing the candidates the way they will actually run.
Sources
- FlashInfer's SM100 block-scaled GEMM (dense_blockscaled_gemm_sm100.py)
- FlashInfer's mm_fp4 runner and tuning configs (gemm_base.py)
- FlashInfer's tactic candidates and heuristic score (kernels/utils.py)
- FlashInfer's compile helper and L2 policy (gemm_mm_fp4_cute_dsl.py)
- FlashInfer's autotuner (autotuner.py)
- PTX ISA: tcgen05.mma block scaling
- GLM-5.3 model card and config