Skip to content

Swizzle modes: 32B, 64B, and unswizzled #14

Open

Description

@feitreim

Swizzle128B is the only Swizzle impl. ThunderKittens' st takes swizzle_bytes of 32, 64, or 128, plus an unswizzled mode.

The trait already exists with the right shape:

pub trait Swizzle {
    const ATOM_BYTES: usize;
    const DESCRIPTOR_MODE: u8;
}

so adding modes is adding impls — but the subtile scheme in shared.rs assumes the 128-byte atom in more places than the trait suggests, and the "width must be a whole number of subtiles" assertion is written against it.

What the other modes buy:

  • 64B — narrow operands. A [R, 32] bf16 tile is a whole subtile under 64B swizzle and an illegal width under 128B, so today it cannot be expressed at all.
  • 32B — narrower still, same argument.
  • Unswizzled — staging tiles that never feed an MMA (statistics, masks, scratch). Swizzling them costs address math for nothing.

Lower priority than it looks: everything the current kernels do is 128B, and the restriction is documented as deliberate rather than accidental. Worth doing when a kernel actually needs a narrow operand.

Depends on #8 (the descriptor mode has to be threaded through the layout type).

Activity

  1. added
    enhancement
    area:types
    on Jul 26, 2026
  2. feitreim commented on Jul 29, 2026

    @feitreim
    OwnerAuthor

    From the 2026-07-29 library audit — a concrete cost of the single-swizzle slice that this issue does not currently name, and which sharpens what "ATOM_BYTES is doing two jobs" means at a call site.

    SharedTile::k_walk carries const { assert!(C * E::BYTES == S::ATOM_BYTES) } (src/shared.rs:794-808): a linear K-major walk needs K to span exactly one swizzle atom, because the step is a byte offset along a row and a stacked subtile is not reachable that way. At bf16 under Swizzle128B that fixes K at 64.

    So a stage with BLOCK_K > 64 cannot produce a walk. examples/src/gemm.rs gets one by re-wrapping each subtile as a narrower tile type and walking that (gemm.rs:1199-1209):

    while atom < ATile::<BLOCK_K>::SUBTILES {
        mma_walk_cg2::<Bf16, ATOM_CHUNKS>(
            self.accumulator.raw(),
            Atom::<BLOCK_M>::from_raw(a.subtile(atom)).k_walk(),
            Atom::<HALF_N>::from_raw(b.subtile(atom)).k_walk(), ...

    with Atom<R> (gemm.rs:510) existing only to be one atom wide. gemm_ws.rs sidesteps it by fixing BLOCK_K = 64 (gemm_ws.rs:412) and calling k_walk() directly. The kernel's own host-side doc says the consequence outright (gemm.rs:5846-5852): "It cannot be swept as a walk width. SharedTile::k_walk carries const { assert!(C * E::BYTES == S::ATOM_BYTES) } … so 64 is what a walk is at bf16."

    Two things this is evidence for:

    1. The atom is a walk step as well as a swizzle period and a box width, so ATOM_BYTES is doing three jobs, not two. Whatever separates them for an unswizzled mode should separate this one too.
    2. A multi-atom k_walk is worth having regardless of the swizzle work. mma.rs already knows the arithmetic — k_major_offset(k, subtile_bytes) at src/mma.rs:103-105 steps across stacked subtiles correctly, and it is what mma_abt/mma_ab use. It is only the value-level OperandWalk, the one a runtime layout choice needs, that cannot cross a subtile. Giving OperandWalk a subtile stride would remove the re-wrap and make BLOCK_K sweepable, and it does not depend on a second Swizzle impl.

    Filing this here rather than as its own issue because item 1 is squarely this issue's; item 2 could be split out if the swizzle work is not imminent.

  3. feitreim commented on Jul 29, 2026

    @feitreim
    OwnerAuthor

    Upgrade note (20a5616): cuda-oxide now ships cuda_device::swizzle::Swizzle<B, M, S> plus bank/conflict arithmetic and transaction-width access planning.

    These are useful references but not a drop-in solution to this issue: upstream's XOR address transform is a software shared-memory mapping, while this issue also owns CUDA TMA descriptor swizzle modes and the separation of swizzle period, TMA box width and walk step. Before implementing new local modes, compare the formulas and reuse upstream conflict/access arithmetic where the semantics match rather than maintaining two derivations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:typesenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions