arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2610.13679cs.PL
收藏

面向GPU内核的简化布局代数

A Simplified Layout Algebra for GPU Kernels

Nan An, Xiaotian Zhou

AI总结:

本文提出一种简化的布局代数,解决CuTe库布局代数的复杂约束,用OCaml实现并在Rocq中验证,可复现CuTe核心操作,用于GPU内核张量映射优化。

摘要:

NVIDIA的CuTe库背后的布局代数描述了张量块如何映射到线程和内存。布局是一种带有每个元素步长的形状,因此坐标的地址是其索引乘以对应步长的总和。正如Shah和Cecka所形式化的,其核心操作(如组合、补集、除法、乘积)受至少六个相互作用的可容许性条件约束。我们表明,这种复杂性是一种表示选择的产物,而非领域本身的特性。我们提出一种布局代数,其中每个布局都指明其输入和输出所在的空间:逻辑空间、物理空间或线程值索引空间。映射到逻辑空间或线程值空间的布局必须是从其N个坐标到[0,N)的双射。映射到物理空间的布局必须是无别名的:不同的坐标对应不同的地址,除非在广播场景下,此时多个线程故意读取同一个值,布局必须标记该情况,且没有任何内容会映射出物理索引空间。将f与g组合仅要求f的范围恰好是g的扁平化坐标集。索引算术总能直接生成:计算f,通过除法和取余将结果拆分为g的坐标,再应用g。通常组合结果会简化为一个布局;我们证明当简化发生时,存在最粗的此类形式,其每个数位都被更细的形式细化,我们会生成该形式。 warp或线程的切片是一种“限制”。受限布局不再可组合,这要求用户在取切片前确定张量块的完整视图。我们通过在该代数中复现CuTe的操作(如组合、补集和除法)来验证其正确性。我们用OCaml实现该代数,并利用该实现重新推导CuTe的原子操作和使用模式。该决策过程在Rocq中被证明是正确的。

英文摘要:

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)$. 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 $f$ with $g$ requires only that $f$'s range be exactly $g$'s flattened coordinate set. The index arithmetic can always be emitted naively: compute $f$, split the result by division and remainder into $g$'s coordinates, and apply $g$. 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 \emph{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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑