Inside FlashInfer's SM100 GEMM, Part 1: The Tile and the Instruction

What one tcgen05.mma computes in FlashInfer's block-scaled FP4 GEMM, how the tiles nest from that instruction up to the whole matrix, and where the scale factors go

October 13, 2026 · Markdown · Whole series as Markdown

Series: Part 1 · Part 2 · Part 3

If you open FlashInfer's NVFP4 GEMM for Blackwell, dense_blockscaled_gemm_sm100.py, you find about 2,000 lines of CuTe DSL. It's the kernel that flashinfer.mm_fp4(..., backend="cute-dsl") runs on B200 and B300 GPUs, which makes it one of the kernels that sit under the FP4 linear layers of a serving engine. And yet, the actual math in it fits on one line: multiply two matrices of 4-bit numbers, each with its own little scale factors, and add up the products. Everything else in those 2,000 lines is about getting the data to the tensor cores at the right moment, in the right layout, and choosing how to cut the problem into pieces.

Reading the kernel from top to bottom is hard, because the computation, the data movement and the synchronization are all interleaved, and almost every number in the code (128, 256, 4, 32, 512) comes from some hardware rule that the code doesn't explain. So, in this series, I want to take the kernel apart and look at each piece on its own, with one question in mind: what does this piece compute, and why is it shaped the way it is?

This first part is about the computation itself. We will start with what the kernel computes, including the block scale factors, then look at the one tensor core instruction that does all the work, and then see how the kernel nests its tiles around that instruction, from a single instruction up to the whole output matrix. Along the way, we will look at the two layouts the instruction insists on: the swizzled layout of the operands in shared memory and the layout of the scale factors in tensor memory. Part 2 is about the pipeline that keeps the tensor cores busy (warps, barriers, stages and the persistent loop), and part 3 is about tactics, which is to say how FlashInfer picks the tile shape, the cluster shape and a few other options for a given matrix shape.

Everything here refers to FlashInfer at commit c0e62fa7b and nvidia-cutlass-dsl 4.8.0, and I ran all the code and measurements on a B300 (compute capability 10.3, 148 SMs). I'll leave out everything about how FlashInfer compiles and caches the kernels, since none of it changes what the kernel computes. If some of the GPU terms below are new to you, my earlier articles on the TMA and on the SM100 memory hierarchy introduce shared memory, clusters, mbarriers and tensor memory from scratch. I'll briefly recap what we need as we go.

1. What the Kernel Computes

1.1 Three Block-Scaled Formats

Let's start with the numbers themselves. A 4-bit floating-point number, e2m1 (1 sign bit, 2 exponent bits, 1 mantissa bit), can only represent 16 values: 0, 0.5, 1, 1.5, 2, 3, 4 and 6, and their negatives. That is obviously not enough range for the weights or activations of a neural network, so these formats are always "block scaled": a short block of consecutive elements along the K dimension (the dimension we sum over in a matrix multiplication) shares one scale factor, and every element in the block is stored relative to it.

The kernel supports three such formats, which differ in the block size and in the type of the scale factor:

In the kernel, these are not three code paths. The kernel only looks at the element type, the scale-factor type and the block size (sf_vec_size), and CuTe DSL picks the matching tensor core instruction from those types. We'll see that choice in section 2. For most of this series, I'll use NVFP4 as the example, since it's what mm_fp4 uses by default, and since its global scale is a nice extra wrinkle.

So, what does the kernel compute? If we write qA for the 4-bit values of A, sA for its block scale factors, and similarly for B, then for row i of A and row j of B (the kernel wants both A and B with K as the contiguous dimension, so the product is A times B transposed):

C[i, j] = alpha x sum over blocks b of ( sA[i, b] x sB[j, b] x sum over k in b of qA[i, k] x qB[j, k] )

Here alpha is 1 / (gA x gB). NVFP4 multiplies each tensor by a global scale (gA for A, gB for B) before quantizing it, to stretch it into the range that an e4m3 scale times an e2m1 value can represent, and alpha undoes both stretches at the end. (I went through where alpha is applied, in fp32 in the epilogue right before the conversion to bf16, in the memory-hierarchy article. MXFP4 and MXFP8 have no global scale, so for them alpha is normally 1.)

Notice where the block scales sit in that formula: inside the sum over K. Since a scale factor only covers 16 elements along K, two blocks of the same row can have different scales, so we can't pull them out of the sum and apply them at the end. Either we dequantize everything first, which would mean multiplying 4-bit values in a wider format and losing the point of FP4, or the tensor core applies the scales itself, block by block, while it accumulates. Blackwell's tensor cores do the latter, and that is what "block-scaled MMA" means.

1.2 The Same Computation in PyTorch

To make this concrete, let's quantize two random matrices with FlashInfer, run the kernel, and then recompute the result in PyTorch from the raw bytes, without any help from FlashInfer. Here is the first half:

import torch
from flashinfer import SfLayout, mm_fp4, nvfp4_quantize

M, N, K = 256, 512, 1024
torch.manual_seed(0)
a = torch.randn(M, K, device="cuda", dtype=torch.bfloat16)
b = torch.randn(N, K, device="cuda", dtype=torch.bfloat16)
ga = 448 * 6 / a.float().abs().max()  # global scales, as in
gb = 448 * 6 / b.float().abs().max()  # FlashInfer's tests
a4, a_sf = nvfp4_quantize(a, ga, sfLayout=SfLayout.layout_128x4)
b4, b_sf = nvfp4_quantize(b, gb, sfLayout=SfLayout.layout_128x4)
alpha = (1 / (ga * gb)).reshape(1)
c = mm_fp4(a4, b4.T, a_sf, b_sf.T, alpha, torch.bfloat16,
           backend="cute-dsl")

a4 is a 256 x 512 tensor of uint8, two 4-bit values per byte, and a_sf holds one byte per block of 16 elements, so 256 x 64 bytes. The interesting part is the scale-factor layout, layout_128x4, which is not a plain row-major matrix. We'll see in section 5 exactly why it looks the way it does. For now, here is how to undo it, together with the decoding of the 4-bit values:

E2M1 = torch.tensor([0, 0.5, 1, 1.5, 2, 3, 4, 6,
                     -0.0, -0.5, -1, -1.5, -2, -3, -4, -6])


def unpack_e2m1(packed):  # (rows, K / 2) uint8 -> (rows, K)
    lo, hi = packed & 0xF, packed >> 4  # element 2i is the low nibble
    return E2M1[torch.stack((lo, hi), -1).long()].flatten(-2)


def unswizzle_sf(sf, rows, k, vec=16):  # 128x4 layout -> (rows, K / vec)
    kt = (k // vec + 3) // 4  # chunks along K, 4 scales each
    t = sf.reshape(-1, kt, 32, 4, 4)  # (row tile, k tile, r%32, r//32, kb)
    t = t.permute(0, 3, 2, 1, 4).reshape(-1, kt * 4)
    return t[:rows, : k // vec]


def dequant(packed, sf, rows, k):
    q = unpack_e2m1(packed.cpu().view(torch.uint8))
    s = unswizzle_sf(sf.cpu().view(torch.float8_e4m3fn), rows, k)
    return q * s.float().repeat_interleave(16, dim=1)


A = dequant(a4, a_sf, M, K)
B = dequant(b4, b_sf, N, K)
ref = alpha.cpu() * (A @ B.T)
err = (c.cpu().float() - ref).abs().max() / ref.abs().max()
print(f"largest error relative to max |C|: {err:.1e}")

This prints an error of 3.3e-3, which is about what we get from rounding the fp32 result to bf16 at the end (bf16 keeps 8 significant bits, so its relative rounding error is up to about 4e-3). So the kernel computes the formula above, and unswizzle_sf tells us something we'll need later: in the 128x4 layout, the scale factors are stored in chunks that cover 128 rows and 4 blocks of K, and inside a chunk, row r comes at position (r mod 32, r div 32). Keep that in mind until section 5.

2. The Instruction

2.1 One Thread, One Big Matrix Multiplication

All of the math in the kernel is done by one instruction, tcgen05.mma with the block_scale modifier. If you have written tensor core code for older GPUs, this instruction will look strange in two ways.

First, it is issued by a single thread. On Ampere, every thread of a warp held a few elements of the operands in its registers and the warp issued the mma together. On Hopper, a warpgroup of 128 threads issued wgmma together. On Blackwell, one thread issues the instruction, and the tensor cores then do the work asynchronously while that thread moves on.

Second, none of the operands are in registers. The instruction reads A and B from shared memory, through two 64-bit descriptors that say where each tile starts and how it's laid out. It reads the scale factors of A and B from tensor memory (TMEM), the dedicated 256 KB memory that every SM100 SM has for its tensor cores. And it accumulates the result D, in fp32, in TMEM as well.

So, one instruction computes D += (A x SFA) (B x SFB)^T for a whole tile at once. How big a tile? In CuTe DSL, the instruction shape is a property of the MMA "op" that the kernel builds, and the DSL checks it against the hardware rules when the op is created. For block-scaled MMAs, those rules (from BlockScaledMmaOp in cute/nvgpu/tcgen05/mma.py) are:

The K rule is easier to remember in bytes. FlashInfer computes it as mma_inst_bits_k // a_dtype.width with mma_inst_bits_k = 256, so one instruction always consumes 256 bits, 32 bytes, of every row of A and B. For FP4 that's 64 elements, for FP8 it's 32.

The kernel builds the op with a helper from CuTe DSL, which chooses between three instruction kinds based on the types: MmaMXF4NVF4Op for FP4 with blocks of 16 (NVFP4), MmaMXF4Op for FP4 with blocks of 32 (MXFP4), and MmaMXF8F6F4Op for FP8 (MXFP8). That's the choice I mentioned in section 1.1. Everything else in the kernel is the same for all three formats.

To get a feeling for the size, one 128 x 256 x 64 instruction does 128 x 256 x 64 = 2.1 million multiply-adds, or 4.2 million floating-point operations. In the NVFP4 case it also applies 128 x 4 scale factors of A and 256 x 4 of B, since K = 64 is four blocks of 16.

2.2 The CTA Pair

Now, the pair. Blackwell can run one MMA instruction across two SMs: two CTAs of the same cluster (a group of CTAs that the hardware schedules together on nearby SMs) form a pair, and one thread in the first CTA of the pair, the leader, issues an instruction with M = 256. Each CTA keeps 128 rows of A in its own shared memory and gets 128 rows of the result in its own TMEM. And B is split as well: each CTA holds half of the N columns of B, and the tensor cores of both SMs read B from both shared memories. Figure 1 shows who holds what for a 256 x 256 tile.

What each CTA of a pair holds for one 256 x 256 tile
Figure 1: One 256 x 256 tile computed by a CTA pair. Each CTA holds half of A and half of B, the leader issues the instruction, and each CTA's TMEM receives its own 128 rows of the result.

As shown in Figure 1, the pair computes a 256 x 256 tile while each CTA only stores half of A's rows and half of B's columns. We will see in section 6 why that matters so much: it halves the bytes each SM loads for B without halving the work.

In FlashInfer's kernel, the pair is switched on by the tile shape alone. use_2cta_instrs = mma_tiler_mn[0] == 256: an M tile of 256 means the pair instruction, an M tile of 128 means one CTA. Because the pair lives inside a cluster, a 256-row tile also requires a cluster with at least two CTAs along M.

2.3 Accumulate or Overwrite

One last detail about the instruction. TMEM isn't cleared between output tiles, so the first instruction of every tile has to overwrite D instead of adding to it. The instruction has a flag for that, which the kernel sets through the tiled MMA object, once per tile:

# excerpt from dense_blockscaled_gemm_sm100.py
tiled_mma.set(tcgen05.Field.ACCUMULATE, False)
# ...
for _k_block in range(k_block_cnt):
    # ...
    for kphase_idx in cutlass.range(num_kphases, unroll_full=True):
        # ...
        cute.gemm(
            tiled_mma,
            tCtAcc,
            tCrA[kphase_coord],
            tCrB[kphase_coord],
            tCtAcc,
        )

        # Enable accumulate on tCtAcc after first kphase
        tiled_mma.set(tcgen05.Field.ACCUMULATE, True)

cute.gemm with a tcgen05 tiled MMA becomes one instruction (UTCOMMA in the SASS, as we saw in the memory-hierarchy article), so the inner loop issues one instruction per "k-phase", and the outer loop walks over K. That brings us to the question of how the kernel organizes all those instructions.

3. Tiles All the Way Down

A GEMM kernel always cuts the problem into tiles, but in this kernel there are several levels of tiles, and they all have different names in the code (mma_inst_shape_mnk, mma_tiler, cta_tile_shape_mnk, cluster_shape_mn). Here they are from the smallest to the largest, for the configuration that FlashInfer picks for a large square problem: a 256 x 256 MMA tile computed by a CTA pair in a 2 x 1 cluster.

  1. The instruction: 256 x 256 x 64, as above. One leader thread issues it.
  2. The K tile, or stage: 4 instructions along K make one K tile of 256 elements. This is the unit that the kernel loads into shared memory at a time, and the code calls it the mma_tiler: (256, 256, 256). The 4 is mma_inst_tile_k, and the instructions inside one K tile are the "k-phases" of the loop above.
  3. The CTA tile: each CTA of the pair owns 128 rows of the output, so the CTA tile is 128 x 256 (cta_tile_shape_mnk). With one CTA per tile, the CTA tile and the MMA tile are the same.
  4. The cluster: the 2 x 1 cluster is exactly one pair, so it covers 256 x 256 outputs. Larger clusters cover several MMA tiles, which share their loads through multicast, as we'll see in part 2.
  5. The grid: the output matrix is covered by MMA tiles, 32 x 32 of them for an 8,192 x 8,192 output, and the persistent scheduler hands these tiles to the clusters one after another (also part 2).

Figure 2 shows the first four levels.

The levels of tiles in FlashInfer's SM100 GEMM
Figure 2: From the output matrix to one instruction. The output is cut into 256 x 256 MMA tiles; each is computed by a pair of CTAs that own 128 rows each; the K loop advances by K tiles of 256; and each K tile is four instructions of K = 64.

All of these shapes follow from the tactic, the tile and cluster shape the kernel is constructed with. Here is a short function that derives them the same way _setup_attributes does:

def tile_levels(tile_mn, cluster_mn, elem_bits=4, inst_per_k_tile=4):
    two_cta = tile_mn[0] == 256
    inst = (*tile_mn, 256 // elem_bits)  # one tcgen05.mma
    k_tile = (*tile_mn, inst[2] * inst_per_k_tile)  # one stage
    cta = (tile_mn[0] // (2 if two_cta else 1), tile_mn[1], k_tile[2])
    cluster = (cta[0] * cluster_mn[0], tile_mn[1] * cluster_mn[1])
    return dict(inst=inst, k_tile=k_tile, cta=cta, cluster_out=cluster)


for tile, cluster in [((256, 256), (2, 1)), ((128, 16), (1, 1)),
                      ((256, 128), (2, 2))]:
    print(tile, cluster, tile_levels(tile, cluster))

For the 256 x 256 tile, this gives an instruction of (256, 256, 64), a K tile of (256, 256, 256), a CTA tile of (128, 256, 256), and a cluster that covers 256 x 256 outputs. For a 128 x 16 tile, which FlashInfer uses for decoding with very few tokens (part 3), every level is (128, 16, ...) and the cluster is a single CTA. I checked all three against the values that the kernel itself computes while it compiles.

Why is the K tile 256 elements? For FP4, 256 elements are 128 bytes per row, and 128 bytes is the width of the swizzled shared-memory layout that the instruction reads, which is our next topic. (FlashInfer also has a "deep-K" variant with 8 instructions per stage, a K tile of 512 and 256-byte rows. It's one of the tactics in part 3.)

4. The Operand Layout in Shared Memory

4.1 Why the Layout Matters

The instruction reads A and B from shared memory without any help from the threads, so it can only read layouts it understands, and the descriptor describes which one it is. CuTe DSL picks the layout for us. When I printed the shared-memory layout of A for the 256 x 256 configuration, it came out as:

S<3,4,3> o 0 o ((128,64),1,4,5):((256,1),0,64,32768)

Let's read it from the right. The part after the : is a CuTe layout, shape on the left and strides on the right, in units of FP4 elements. (128, 64) with strides (256, 1) is one instruction's slice of A: 128 rows of 64 elements, where consecutive elements are next to each other and consecutive rows are 256 elements, 128 bytes, apart. Then 4 with stride 64 is the four k-phases of the K tile, each starting 64 elements (32 bytes) further along the same rows. And 5 with stride 32768 is five stages, each 32,768 elements or 16 KB. So, one stage of A is 128 rows of 128 bytes, and each instruction reads a 32-byte-wide column of it.

The part on the left, S<3,4,3>, is the swizzle, and it is the reason this layout exists.

4.2 The 128-Byte Swizzle

Shared memory is divided into 32 banks of 4 bytes, so a 128-byte row covers each bank exactly once. That is a problem for anyone who reads the same few bytes from many rows at once, which is exactly what a matrix multiplication does when it walks down a column: in an unswizzled layout, byte 0 of every row sits in bank 0, so reading the first 16 bytes of 8 rows means 8 accesses to the same 4 banks, one after another.

The fix is to permute the 16-byte pieces of each row. In the 128-byte swizzle (CuTe calls it K_SW128), a row of 128 bytes is 8 pieces of 16 bytes, and in row r, piece p is stored at position p XOR (r mod 8). The pattern repeats every 8 rows, so the unit of the layout, the swizzle atom, is 8 rows of 128 bytes, 1 KB. That's what S<3,4,3> encodes: take the 3 address bits starting at bit 4 (which 16-byte piece), and XOR them with the 3 bits starting at bit 7 (which 128-byte row within the atom). The swizzle works on byte addresses, which is why the very same S<3,4,3> shows up for FP4, FP8 and bf16, whose atoms are 8 x 256, 8 x 128 and 8 x 64 elements, always 8 x 128 bytes.

Here's the same thing in Python, together with a check of what it buys us:

def sw128(row, piece):  # byte offset of 16-byte piece `piece` of `row`
    return row * 128 + (piece ^ (row % 8)) * 16


def bank_group(offset):  # which 16-byte group of 4 banks
    return offset % 128 // 16


for piece in range(8):
    plain = {bank_group(r * 128 + piece * 16) for r in range(8)}
    swizzled = {bank_group(sw128(r, piece)) for r in range(8)}
    print(piece, len(plain), len(swizzled))

For every piece, the unswizzled layout puts all 8 rows into the same bank group (it prints 1), and the swizzled layout spreads them over all 8 groups (it prints 8). Figure 3 shows the same thing as a picture.

Plain and 128-byte swizzled layouts of an 8 x 128-byte block
Figure 3: Eight rows of 128 bytes, cut into 16-byte pieces. Without swizzling (left), piece 0 of every row lands in the same banks. With the 128-byte swizzle (right), piece p of row r goes to position p XOR r, so the eight copies of piece 0 cover all banks.

As we can see in Figure 3, the swizzle turns a column of the tile into a diagonal. The TMA writes tiles in this layout directly when it loads them from global memory (the TMA descriptor has a swizzle mode for exactly this purpose), and the tensor core reads them back in the same layout, so no thread ever has to know about it. That's also the reason for the 128-byte K tile from section 3: a K tile of 256 FP4 elements is exactly one swizzle-atom row wide, so one stage of A is a stack of 1 KB swizzle atoms, 16 of them for 128 rows.

5. The Scale Factors

5.1 Where the Instruction Wants Them

The scale factors are small (one byte per 16 elements, so 1/8 of the size of the FP4 data), but they have the most unusual path through the kernel. They come from global memory into shared memory with the TMA, like A and B, but the instruction doesn't read them from shared memory. It reads them from TMEM, so the kernel has to copy them from shared memory into TMEM first, with another tcgen05 instruction, tcgen05.cp, which is issued by the same thread that issues the MMAs.

How do they have to be arranged in TMEM? TMEM is a 2D memory of 128 lanes and 512 columns of 32-bit cells. For the NVFP4 instruction with K = 64, the PTX documentation (the figure for "scale_vec::4X/block16") specifies that the four scale factors of row m (one per block of 16) go into the four bytes of one cell, in lane m mod 32 and column m div 32. So 128 rows of SFA take up 32 lanes and 4 columns per instruction, and since a K tile has 4 instructions, 16 columns per K tile. That is exactly what the kernel computes for num_sfa_tmem_cols: (128 / 32) x 4 = 16.

5.2 Why the 128x4 Layout Looks the Way It Does

Now we can understand the strange global layout from section 1.2. In CuTe DSL, the layout of the scale factors in global memory is built from a fixed "basic chunk" (BlockScaledBasicChunk in cutlass/utils/blockscaled_layout.py):

shape  ((32, 4), (16, 4))
stride ((16, 4), ( 0, 1))

The first mode is the rows: 32 x 4 = 128 rows, where row r has offset (r mod 32) x 16 + (r div 32) x 4. The second mode is K: 16 elements share one scale factor (stride 0), and 4 blocks of 16 are consecutive bytes (stride 1). So one chunk covers 128 rows and 64 elements of K, and it is 512 bytes, with the scale factor of row r and block kb at byte

(r mod 32) x 16 + (r div 32) x 4 + kb.

Compare that with the TMEM rule: lane r mod 32, column r div 32, byte kb. If we view the 32 lanes of 4 columns as a 32 x 16-byte block, row r and block kb land at lane (r mod 32), byte (r div 32) x 4 + kb, which is the very same offset. In other words, a 512-byte chunk of the global layout is a byte-for-byte image of what the instruction wants to find in TMEM. Let's check that in Python:

def sf_byte(row, kb):  # offset inside one 512-byte chunk of the layout
    return (row % 32) * 16 + (row // 32) * 4 + kb


def tmem_cell(row, kb):  # (lane, column, byte), from the PTX docs
    return row % 32, row // 32, kb


same = all(sf_byte(r, kb) == lane * 16 + col * 4 + byte
           for r in range(128) for kb in range(4)
           for lane, col, byte in [tmem_cell(r, kb)])
print(same)

It prints True. Figure 4 shows the mapping for one example row.

How a 512-byte chunk of scale factors maps onto TMEM
Figure 4: One 512-byte chunk of scale factors covers 128 rows and 4 blocks of 16 along K. Viewed as 32 rows of 16 bytes, it is exactly the image of 32 TMEM lanes by 4 columns that one NVFP4 instruction reads. Row 37 is highlighted: lane 5, column 1.

So, the layout of the scale factors in global memory, which looked so odd in section 1.2, is chosen so that no part of the kernel ever has to rearrange them. The TMA copies chunks into shared memory as they are, and tcgen05.cp copies each chunk into TMEM as it is. The copy the kernel uses is Cp4x32x128bOp, which is PTX's tcgen05.cp with shape .32x128b (32 lanes of 128 bits, so 32 x 16 bytes, one chunk) and the multicast option .warpx4, which writes the same 32 lanes into all four lane quarters of TMEM. So the 32 lanes from section 5.1 exist four times, once in each quarter of TMEM.

5.3 SFB, and Why It Is Always 128 Wide

The scale factors of B follow the same rules, with B's rows (the N dimension of the output) in place of A's rows. But there is a complication: the scale-factor chunk always covers 128 rows, and the N tile can be smaller (64, 32 or even 8) or not a multiple of 128 (192). So the kernel always loads SFB in tiles of round_up(tile_n, 128) rows, through a second tiled MMA object, tiled_mma_sfb, that is never used for math but only for this partitioning. For N tiles smaller than 128, several output tiles share one SFB tile, and the MMA reads its part through a shifted TMEM address. We will come back to that in part 3, since that's what makes the narrow N tiles of 8, 16 and 32 possible.

In the CTA pair, both CTAs need the scale factors of all 256 columns of B, because each CTA computes all 256 columns for its own 128 rows. That's why the SFB copy is a multicast load to both CTAs, as Figure 1 showed, while A, B and SFA are each split between the two CTAs.

6. One K Tile, and How Big the Tile Should Be

6.1 Putting One K Tile Together

We now have all the pieces of one iteration of the main loop. The MMA warp waits until a stage of shared memory has been filled, copies that stage's scale factors into TMEM, and issues four instructions, one per k-phase, each pointing at its own 32-byte column of A and B and its own TMEM columns of scale factors:

# excerpt from dense_blockscaled_gemm_sm100.py
cute.copy(
    tiled_copy_s2t_sfa,
    tCsSFA_compact_s2t_staged,
    tCtSFA_compact_s2t,
)
cute.copy(
    tiled_copy_s2t_sfb,
    tCsSFB_compact_s2t_staged,
    tCtSFB_compact_s2t,
)

# tCtAcc += tCrA * tCrSFA * tCrB * tCrSFB
num_kphases = cute.size(tCrA, mode=[2])
for kphase_idx in cutlass.range(num_kphases, unroll_full=True):
    # ...
    # Set SFA/SFB tensor to tiled_mma
    sf_kphase_coord = (None, None, kphase_idx)
    tiled_mma.set(
        tcgen05.Field.SFA,
        tCtSFA[sf_kphase_coord].iterator,
    )
    tiled_mma.set(
        tcgen05.Field.SFB,
        tCtSFB_mma[sf_kphase_coord].iterator,
    )
    # ...

The two tiled_mma.set calls are how the TMEM addresses of the scale factors get into the instruction: each k-phase points at its own 4 columns of SFA and its own columns of SFB. For a 256 x 256 tile, a K tile is then 4 instructions of 256 x 256 x 64. For an 8,192 x 8,192 x 8,192 GEMM, that's 128 instructions per output tile and 1,024 tiles, so 131,072 instructions, issued by the 74 leader threads of the 74 CTA pairs that fit on the B300's 148 SMs. In my measurement this took about 158 to 164 microseconds, so each pair finished one 256 x 256 x 64 instruction about every 90 nanoseconds.

The waiting and the copying are what part 2 is about. But we can already answer one question with what we have: why does FlashInfer prefer the 256 x 256 tile for big problems?

6.2 FLOPs per Byte

Every stage, each CTA has to receive its A, B, SFA and SFB bytes from L2 or HBM before its tensor cores can do the stage's work. So the more FLOPs a tile gets out of every byte it loads, the less bandwidth it needs to keep its tensor cores busy. Here's that ratio for a few tiles, computed the same way the kernel sizes its shared-memory stages:

def stage(tile_mn, k=256, sf_vec=16):  # bytes and FLOPs per CTA per stage
    pair = 2 if tile_mn[0] == 256 else 1
    rows, cols = tile_mn[0] // pair, tile_mn[1]
    a, b = rows * k // 2, cols // pair * k // 2  # FP4: two per byte
    sfa = rows * k // sf_vec
    sfb = -(-cols // 128) * 128 * k // sf_vec  # SFB rounds N up to 128
    flops = 2 * rows * cols * k
    return a + b + sfa + sfb, flops


for tile in [(128, 64), (128, 128), (128, 256), (256, 128), (256, 256)]:
    nbytes, flops = stage(tile)
    print(tile, nbytes, round(flops / nbytes))

This prints 28,672 bytes and 146 FLOPs per byte for 128 x 64, 36,864 and 228 for 128 x 128, 55,296 and 303 for 128 x 256, 28,672 and 293 for 256 x 128, and 38,912 and 431 for 256 x 256. Those byte counts are exactly the stage sizes that the kernel computed for these tiles. Notice what the pair does: a 256 x 128 tile does the same work per CTA as a 128 x 128 tile, but each CTA loads only half of B, so its ratio goes from 228 to 293. And the 256 x 256 tile is the best of all, since each CTA computes a 128 x 256 piece of output while loading 128 rows of A and only 128 columns of B.

To see how much this matters, I ran the kernel with each of these tiles on an 8,192 x 8,192 x 8,192 problem, with a cold L2 cache and the same cluster for every tile (2 x 1 for 256-row tiles, a single CTA otherwise). Figure 5 shows the result.

Throughput of the kernel for each MMA tile shape
Figure 5: PFLOP/s of FlashInfer's NVFP4 GEMM on a B300 for an 8,192-cubed problem, one bar per MMA tile, with the FLOPs per loaded byte of each tile below it. All outputs were bit-identical to FlashInfer's CUTLASS backend.

As we can see in Figure 5, the throughput follows the FLOPs per byte almost perfectly, from 3.3 PFLOP/s for 128 x 64 to 6.7 PFLOP/s for 256 x 256. There is one exception, 128 x 256, which has a higher ratio than 256 x 128 but is a bit slower. Its stages are 55 KB, and only 3 of them fit in shared memory, while the 256 x 128 tile gets 7 stages. That's a nice preview of part 2: the FLOPs per byte tell us how much loading a tile needs, but the number of stages decides whether the loading can stay far enough ahead. (The same ranking holds for GLM-5.3's gate and up projection with 8,192 tokens, 8,192 x 24,576 x 6,144, which I also measured: 3.2 PFLOP/s for 128 x 64 and 6.5 PFLOP/s for 256 x 256.)

7. Summary

To summarize this first part, here is the computation of FlashInfer's SM100 block-scaled GEMM, from the bottom up:

  1. The math is C = alpha x sum over blocks of (sA sB x sum of qA qB). The block scales sit inside the sum over K, which is why the tensor cores apply them. NVFP4, MXFP4 and MXFP8 differ only in the types and the block size, and CuTe DSL picks the matching instruction kind.
  2. The instruction is tcgen05.mma with block scaling, issued by one thread. It reads A and B from shared memory, the scale factors from TMEM, and accumulates in TMEM. Its M is 128, or 256 for a CTA pair; its N is a multiple of 8 (16 for a pair) up to 256; and it consumes 32 bytes of K per row.
  3. The tiles nest as instruction, K tile (4 instructions, 128 bytes of FP4 per row), CTA tile (half the rows for a pair), cluster and grid.
  4. The operands sit in shared memory in the 128-byte swizzled layout, written that way by the TMA and read that way by the tensor cores, so that a column of the tile spreads over all banks.
  5. The scale factors come in 512-byte chunks that are byte-for-byte images of 32 TMEM lanes by 4 columns, so the TMA and tcgen05.cp can move them without any rearranging. SFB is always loaded 128 rows wide.
  6. The tile shape matters mostly through FLOPs per byte loaded, and the CTA pair is the trick that raises it, by splitting B between two SMs.

In part 2, we'll look at everything this part skipped: how the kernel waits for a stage to be filled, how many stages it keeps, how the accumulator in TMEM is handed to the epilogue while the next tile is already being computed, and how clusters and the persistent loop decide which SM works on which tile.

Sources