arXiv:2610.13679cs.PLOct 2026

Manuscript Offprint

arXiv:2610.13679

A Simplified Layout Algebra for GPU Kernels

Nan An, Xiaotian Zhou

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

The layout algebra behind NVIDIA’s CuTe library describes how tensor tiles map onto threads and memory. A layout is a shape with a stride for each entry, so a coordinate’s address is the sum of its indices times their strides. As formalized by Shah and by Cecka, its central operations (e.g., composition, complement, division, product) are guarded by at least six interacting admissibility conditions. We show that this complexity is an artifact of a representational choice, not of the domain.

We present a layout algebra in which every layout names the space its inputs and outputs live in: logical, physical, or thread-value indices. A layout into logical or thread-value space must be a bijection from its N coordinates onto [0,N)[0, N). A layout into physical space must be alias-free: distinct coordinates land on distinct addresses, except under broadcast, where many threads read one value on purpose and the layout must mark where. Nothing maps out of a physical index.

Composing ff with gg requires only that ff's range be exactly gg's flattened coordinate set. The index arithmetic can always be emitted naively: compute ff, split the result by division and remainder into gg's coordinates, and apply gg. Often the composite simplifies to a layout; we show that when it does, there is a coarsest such form, whose digits every other one refines, and we emit that.

A warp’s or thread’s slice is a restriction. A restricted layout is no longer composable, which forces the user to settle the whole view of a tile before taking slices.

We validate the algebra by reproducing within it CuTe's operations, such as composition, complement, and division. We implement it in OCaml and use the implementation to rederive CuTe's atoms and usage patterns. The decision procedure is proved correct in Rocq.

1 Introduction

For GPU kernels, it is important to have a scheme for describing how to move tiles of tensors between global memory, shared memory and registers. The de facto vocabulary for such schemes is the CuTe layout algebra underlying NVIDIA’s CUTLASS library [1, 2]. The most fundamental concept is the layout, which we shall reuse heavily.

Definition 1 (Layout). A shape is a positive integer nn, or a tuple (S1,…,Sk)(S_1, \ldots, S_k) of shapes; its size is sizen=nsizen = n and size (S1,…,Sk)=∏isizeSi(S_1, \ldots, S_k) = \prod_i \text{size} S_i. A coordinate of SS is an integer i∈[0,n)i \in [0, n), respectively a tuple (c1,…,ck)(c_1, \ldots, c_k) of coordinates of the SiS_i; write Coord(S)\text{Coord}(S) for the set of them. A layout S:DS:D is a shape SS together with a stride DD of the same structure: an integer where SS is a positive integer, and a tuple (D1,…,Dk)(D_1, \ldots, D_k) where SS is (S1,…,Sk)(S_1, \ldots, S_k). Its index function

Coord(S) → Z is defined by recursion on the shape,

(n:d)(i)=id,((S1,…,Sk):(D1,…,Dk))(c1,…,ck)=∑j=1k(Sj:Dj)(cj).(n:d)(i)=i d,\qquad\big((S_{1},\ldots,S_{k}):(D_{1},\ldots,D_{k})\big)(c_{1},\ldots,c_{k})=\sum_{j=1}^{k}(S_{j}:D_{j})(c_{j}).

Flattening is a bijection ⟨⋅⟩S:Coord(S)→[0,sizeS)\langle\cdot\rangle_S : \text{Coord}(S) \to [0, \text{size}S), taken row-major, so that the last component varies fastest, with inverse unflatten_S. For an integer shape both are the identity, and for S=(S1,…,Sk)S = (S_1, \ldots, S_k), writing wj=∏l>jsizeSlw_j = \prod_{l > j} \text{size} S_l,

⟨(c1,…,ck)⟩S=∑j=1kwj⟨cj⟩Sj,unflattenS(i)=(unflattenSj(⌊i/wj⌋ mod sizeSj))j=1k.\langle(c_{1},\ldots,c_{k})\rangle_{S}=\sum_{j=1}^{k}w_{j}\langle c_{j}\rangle_{S_{j}},\qquad\mathrm{unflatten}_{S}(i)=\left(\mathrm{unflatten}_{S_{j}}(\lfloor i/w_{j}\rfloor\bmod\mathrm{size}S_{j})\right)_{j=1}^{k}.

A coordinate may therefore be given as a single integer, and we say that integer is the coordinate. The cosize of the layout is the least NN with its image inside [0,N)[0, N), which is one plus the largest value it takes. The layout is dense when its image is an initial segment [0,N)[0, N) of the integers, and a dense bijection when it is moreover injective, in which case N=sizeSN = \text{size} S and every value below NN is taken exactly once. A mode is one entry of the shape together with the matching entry of the stride. Two layouts concatenate: for A=S:DA = S: D and B=S′:D′,B = S': D', the layout (A,B)(A, B) is (S,S′):(D,D′)(S, S'): (D, D'), and it sends (c,c′)(c, c') to A(c)+B(c′)A(c) + B(c').

Layouts are fundamentally the correct concept here, because physical memory is linearly addressed while the logical space is multidimensional and dense as we imagine it. They are a natural way to abstract and describe those mappings.

The algebra has four operations. Three of them, composition, complement and logical division, are formalized by Shah [3]; the fourth, logical product, we take from the CUTLASS implementation. We follow Shah's notation, which lists modes as CuTe does, indexed from 0 with the first varying fastest. Section 6 relates that order to the row-major one of Definition 1. The complement of a layout B=(N0,…,Nα):(d0,…,dα)B = (N_0, \ldots, N_\alpha):(d_0, \ldots, d_\alpha), sorted by stride, with respect to an integer MM, is

BM∗=(d0,d1N0d0,…,MNαdα):(1,N0d0,…,Nαdα),B_{M}^{*}=\left(d_{0},\frac{d_{1}}{N_{0}d_{0}},\ldots,\frac{M}{N_{\alpha}d_{\alpha}}\right):\left(1,N_{0}d_{0},\ldots,N_{\alpha}d_{\alpha}\right),

chosen so that the concatenation (B,BM∗)(B, B_M^*) has size MM and its layout function is a bijection of [0,M)[0, M) onto itself. Logical division is A/B=A∘(B,BsizeA∗)A / B = A \circ (B, B_{\text{size}A}^*), which reindexes AA so that one mode runs inside the tile BB selects and the other runs across copies of it. Logical product is A⊗B=(A,AM∗∘B)A \otimes B = (A, A_M^* \circ B), where M=sizeA⋅cosizeBM = \text{size} A \cdot \text{cosize} B, the smallest MM for which the composition is defined. Its first mode is one copy of AA, and its second walks BB through the addresses AA does not occupy, so the result is size BB copies of AA placed in the pattern BB names.

These operations are critical for constructing the layouts one usually wants, but they are partial: each is defined only under arithmetic side conditions on its operands. Layouts are in general non-injective and non-surjective onto [0,M)[0, M), and CuTe always wants to write the composite as a layout again. This causes at least six conditions. Two are in the complement, whose shape entries are quotients and so must divide: Ni−1di−1∣diN_{i-1}d_{i-1} \mid d_i for every ii, and Nαdα∣MN_\alpha d_\alpha \mid M. The other four belong to composition. Write the flattened shape of AA as M0⋯MαM_0 \cdots M_\alpha. It is left divisible by rr when r=M0⋯Mi−1⋅cr = M_0 \cdots M_{i-1} \cdot c for some ii, where cc is smaller than MiM_i and divides it, and weakly left divisible when the same holds except that cc need not divide MiM_i. For each mode (N):(r)(N):(r) of BB this is three checks, since the prefix must divide rr, the leftover cc must divide MiM_i, and what remains after rr must be weakly left divisible by NN. One more is required across modes, that the intervals on which they act be pairwise disjoint [3].

However, none of these conditions is part of the interface, and CuTe checks few of them: composition's divisibility is checked only at compile time, when both operands are static, and the complement checks only that each of its quotients is at least 1. Where a condition fails, the result can be wrong without a diagnostic. For example, B=(2,2):(1,3)B = (2, 2):(1, 3) has no complement for M=24M = 24: BB takes the values 0, 1, 3, 4, and no shifted copy of it covers 2 without overlapping BB. CuTe applies the formula anyway, truncating d1/N0d0=3/2d_1/N_0d_0 = 3/2 to 1, and returns a complement that together with BB covers only 16 of the 24 values; compiled against CUTLASS 4.8, this raises no error. Running the complement on every static rank-2 layout (N0,N1):(d0,d1)(N_0, N_1):(d_0, d_1) with N0,N1∈{2,3,4}N_0, N_1 \in \{2, 3, 4\}, d0∈{1,2}d_0 \in \{1, 2\} and d1≤16d_1 \leq 16, at M∈{12,24,48}M \in \{12, 24, 48\}, we found 40 such cases: a divisibility condition fails, and CuTe returns a complement that violates the postconditions of its own unit test, without an error.

We try to resolve those complexities by restricting what a layout can be.

Explicit index spaces. The input and the output of a layout each represent one of three things: a logical index into a tile, a thread-value index, or a physical offset in memory. Therefore a layout should declare which of the three its input and its output are, and we allow only the maps worth having between them. Logical and thread-value indices map into one another in either direction. Logical indices map into physical offsets. Nothing maps out of a physical offset. By design, a thread reaches memory by composing its map into logical space with the storage map.

Requirements that follow from the space. We allow those maps and not others because the three spaces do not carry the same obligations. Logical and thread-value indices have to account for their contents losslessly, so a map into either must be a dense bijection. Composition can only happen when one layout's image and the other's domain agree completely, which is natural because a physical offset is forbidden as a domain. A physical offset carries far fewer requirements, since gaps in memory are common and sharing one address between threads, to read the same element, is often what is wanted, so a map into physical need only be alias-free, meaning that distinct coordinates reach distinct addresses except where the layout marks a broadcast.

Composition and simplification. The composite of two layouts is not a layout in general. But we can decide if it can be written as a layout, and when it is a layout we emit one weighted sum of the coordinates. When it is not, we emit the composition literally, at the cost of a longer expression and more work at run time.