尧图精选

CUTLASS 2.x Tile Iterator 概念详解:从 Tensor 分块、概念族到 GEMM 实战

🕒 发布时间:2026/9/16 19:51:58 📁 来源:尧图网络
CUTLASS 2.x Tile Iterator 概念详解从 Tensor 分块、概念族到 GEMM 实战【免费下载链接】cutlassCUDA Templates and Python DSLs for High-Performance Linear Algebra项目地址: https://gitcode.com/GitHub_Trending/cu/cutlass导读Tile Iterator分块迭代器是 CUTLASS 2.x 在固定尺寸矩阵/张量分块tile上实现通用算法如 GEMM、卷积的核心抽象它将对巨大张量的分块抽象成一组带类型约束的迭代器概念让同一套 GEMM 模板可以无缝适配全局内存、共享内存等不同数据布局。本文以 media/docs/cpp/tile_iterator_concept.md 为主体结合仓库中PredicatedTileIterator、RegularTileIterator、MmaPipelined等真实实现与模板消费点完整梳理 CUTLASS 2.x Tile Iterator 的概念族、常用组合、掩码机制与 GEMM 流水线中的实际用法读完即可在自定义 kernel 中正确选用和实现自己的 Tile Iterator。需要说明的是CUTLASS 3.0 已弃用这套迭代器并全面转向 CuTe 的cute::Tensor单一词汇类型本文讨论的内容仅适用于 CUTLASS 2.x API。下图展示了 CUTLASS GEMM 中 tile 迭代器沿逻辑坐标空间按固定步长遍历矩阵分块的示意蓝色区域为被迭代的分块在张量中的位置右侧网格中重复出现的同一 tile 标识如 T9表示迭代器在不同迭代步所指向的 tile。背景与定位为什么需要 Tile IteratorCUTLASS 2.x 的算法如gemm::threadblock::MmaPipelined、各种卷积与 epilogue并不是直接操作整块巨大张量而是基于尺寸恒定的 tile进行泛型编程。这些 tile 可以被视为尺寸无穷大张量的分区partition而Tile Iterator 就是访问这些分区序列的工具它负责回答下一个 tile 在内存中的哪里、如何把 tile 的数据搬进/搬出寄存器片段Fragment这类问题。文档 tile_iterator_concept.md 特别强调了一个设计动机不同的数据结构对随机访问的支持能力不同。例如链表式矩阵只能顺序遍历而连续内存中的矩阵可以廉价地随机访问某个 tile。因此以 tile 序列为单位实现的算法只应要求 Tile Iterator 提供最小必要算子集——顺序算法只需要前向遍历流水线算法可能还需要指针偏移与随机访问。这正是下述概念族存在的意义用接口组合而非继承体系来刻画迭代器能力。需要澄清的是这里的 Concept 并非 C20 引入的concept关键字而是一组施加在类型上的成员与类型定义要求requirement set。一个 Tile Iterator 往往同时实现多个概念其公开成员就是各个概念成员的并集。这套定义的灵感来自 Boost 的 New style iterator concepts。虽然全部概念组合的数量非常大但 CUTLASS 中绝大多数 Tile Iterator 模板都能由少数几种常见组合描述见后文常用组合一节。基础概念族以下每个概念都给出了成员签名但注意这些是需求规格而非真实类定义——仓库中并不存在名为TileIteratorConcept的类真实的迭代器如PredicatedTileIterator通过满足这些签名来兑现概念。1. 基础概念Base Tile Iterator Concept所有 Tile Iterator 都必须描述两种类型组成 tile 的Element类型以及描述 tile 范围的Shape类型。/// Base concept for all tile iterators struct TileIteratorConcept { using Element; /// Element type composing tile (concept: numeric type or Array) using Shape; /// Shape type describing extent of tile. The shape concept depends /// on iterator implementation. };Element可以是标量数值类型也可以是cutlass::Array这样的向量类型Shape描述 tile 的尺寸行列等其具体形状概念由迭代器实现决定例如 2D tile 的Shape是TileCoord。2. 连续内存Contiguous Memory Tile Iterator Concept针对存储在连续内存块中、可任意排布的 tile。其要点是可以向内部持有的指针加上以Element为单位的线性偏移来移动迭代器。因此该概念要求一个Index类型与一个add_pointer_offset()方法/// Tile iterator over partitions of a tensor in contiguous memory which may be referenced via a /// TensorRef object. struct ContiguousMemoryTileIterator : public TileIteratorConcept { using Index; /// index type used to add pointer offsets /// Adds a linear offset in units of Element to internal pointer(s) into tensor CUTLASS_DEVICE void add_pointer_offset(Index pointer_offset); };3. 可读Readable Tile Iterator Concept可读迭代器定义一个Fragment类型用来存放每个线程各自负责的那部分数据load()方法把 tile 从内存读入Fragment/// Tile iterator capable of loading tiles from memory into fragments struct ReadableTileIteratorConcept { using Fragment; /// fragment object derived from cutlass::ArrayElement, N CUTLASS_DEVICE void load(Fragment frag); /// loads a fragment from memory };4. 可读 连续内存Readable Contiguous Tile Iterator Concept在从连续内存读取时支持一个可选指针偏移加载前叠加到内部指针上便于加载与偏移折叠成一次操作/// Union of the following tile iterator concepts: /// /// - ReadableTileIteratorConcept /// - ContiguousMemoryTileIterator /// struct ReadableContiguousTileIteratorConcept : public ReadableTileIteratorConcept, public ContiguousMemoryTileIterator { /// Loads a fragment from memory with additional logical offset CUTLASS_DEVICE void load_with_pointer_offset( Fragment frag, /// fragment to load from the tensor Index pointer_offset); /// loads a tile with a linear offset };5. 可写Writeable Tile Iterator Concept与可读概念对称Fragment持有每个线程要写出的数据store()把 tile 写入内存/// Tile iterator capable of storing tiles from memory struct WriteableTileIteratorConcept { using Fragment; /// fragment object derived from cutlass::ArrayElement, N /// Stores a fragment to memory CUTLASS_DEVICE void store(Fragment const frag); /// stores a fragment to memory };6. 可写 连续内存Writeable Contiguous Tile Iterator Concept写路径同样支持折叠偏移的store_with_pointer_offset()/// Union of the following tile iterator concepts: /// /// - WriteableTileIteratorConcept /// - ContiguousMemoryTileIterator /// struct WriteableContiguousTileIteratorConcept : public WriteableTileIteratorConcept, public ContiguousMemoryTileIterator { /// Loads a fragment from memory with additional logical offset CUTLASS_DEVICE void store_with_pointer_offset( Fragment const frag, /// fragment to store to the tensor Index pointer_offset); /// stores a tile with a linear offset };7. 前向遍历Forward Tile Iterator Concept提供沿预定序列向前推进一个 tile的能力。序列通常与迭代器被定义的上下文相关例如沿 GEMM 的 K 维推进。相等/不等运算符用于判断两个迭代器是否指向同一个 tile/// Tile iterator that may be incremented along a traversal sequence. struct ForwardTileIteratorConcept { CUTLASS_DEVICE bool operator(TileIterator const it); /// true if iterators point to same tile, false if otherwise CUTLASS_DEVICE bool operator!(TileIterator const it); /// false if iterators point to same tile, true if otherwise CUTLASS_DEVICE ForwardTileIteratorConcept operator(); /// pre-increment - advance to next tile in sequence CUTLASS_DEVICE ForwardTileIteratorConcept operator(int); /// post-increment - advance to next tile in sequence };8. 双向遍历Bidirectional Tile Iterator Concept在ForwardTileIteratorConcept基础上增加--递减支持前后两个方向/// Tile iterator which may be traverse in both directions along a defined sequence. struct BidirectionalTileIteratorConcept : public ForwardTileIteratorConcept { CUTLASS_DEVICE BidirectionalTileIteratorConcept operator--(); /// pre-decrement - traverse to previous tile in sequence CUTLASS_DEVICE BidirectionalTileIteratorConcept operator--(int); /// post-decrement - traverse to previous tile in sequence };9. 随机访问Random Access Tile Iterator Concept随机访问发生在底层张量的逻辑坐标系中因此要求底层张量具有明确的Layout、描述逻辑位置的TensorCoord以及TensorRef引用类型。偏移以整 tile为单位沿每个维度推进/// Tile iterator offering random access to tiles in contiguous memory. struct RandomAccessTileIteratorConcept : public BidirectionalTileIteratorConcept, public ContiguousMemoryTileIterator { using Layout; /// Layout object mapping using TensorRef; /// Tensor Reference object using TensorCoord; /// Logical coordinate in referenced tensor /// advances in units of whole tiles along the logical coordinate space of the tensor CUTLASS_DEVICE RandomAccessTileIteratorConcept add_tile_offset(TensorCoord const tile_offset); /// advances in units of whole tiles along the logical coordinate space of the tensor CUTLASS_DEVICE RandomAccessTileIteratorConcept operator(TensorCoord const tile_offset); /// advances in units of whole tiles along the logical coordinate space of the tensor CUTLASS_DEVICE RandomAccessTileIteratorConcept operator-(TensorCoord const tile_offset); };10. 可读随机访问Readable Random Access Tile Iterator Concept在加载 Fragment 时额外接受一个逻辑坐标系下的 tile 偏移/// Loads a fragment with a logical coordinate offset in units of whole tiles. struct ReadableRandomAccessTileIteratorConcept : public RandomAccessTileIteratorConcept, public ReadableTileIteratorConcept { /// Loads a fragment from memory with logical offset in units of whole tiles. CUTLASS_DEVICE void load( Fragment frag, /// fragment to load from the tensor TensorCoord const tile_offset); /// loads a tile with a logical offset in units of whole tiles };11. 可读随机访问 连续内存Readable Random Access Contiguous Tile Iterator Conceptload()同时接受逻辑 tile 偏移与线性指针偏移是逻辑 物理双偏移的完整形态/// Loads a fragment with a logical coordinate offset in units of whole tiles. struct ReadableRandomAccessContiguousTileIteratorConcept : public ReadableRandomAccessTileIteratorConcept, ReadableContiguousTileIteratorConcept { /// Loads a fragment from memory with logical offset in units of whole tiles. CUTLASS_DEVICE void load( Fragment frag, /// fragment to load from the tensor TensorCoord const tile_offset, /// loads a tile with a logical offset in units of whole tiles Index pointer_offset); /// loads a tile with a logical offset AND a pointer offset };12. 可写随机访问Writeable Random Access Tile Iterator Concept写路径的对称形式store()接受逻辑 tile 偏移/// Stores a fragment with a logical coordinate offset in units of whole tiles. struct WriteableRandomAccessTileIteratorConcept : public RandomAccessTileIteratorConcept, public WriteableContiguousTileIteratorConcept { /// Stores a fragment from memory with logical offset in units of whole tiles. CUTLASS_DEVICE void store( Fragment const frag, /// fragment to store to the location pointed to by the tensor TensorCoord const tile_offset); /// stores a tile with a given offset from the current iterator };13. 可写随机访问 连续内存Writeable Random Access Contiguous Tile Iterator Concept/// Stores a fragment with a logical coordinate offset in units of whole tiles. struct WriteableRandomAccessContiguousTileIteratorConcept : public WriteableRandomAccessTileIteratorConcept, public WriteableContiguousTileIteratorConcept { /// Stores a fragment from memory with logical offset in units of whole tiles. CUTLASS_DEVICE void store( Fragment const frag, /// fragment to store to the location pointed to by the tensor TensorCoord const tile_offset, /// stores a tile with a logical offset in units of whole tiles Index pointer_offset); /// stores a tile witha logical offset AND a pointer offset };14. 掩码Masked Tile Iterator Concept矩阵/张量的尺寸未必是整 tile 的整数倍此时需要用掩码Mask守卫内存访问避免越界。掩码的具体语义与接口由每个迭代器自行定义但概念规定了几个通用便捷方法用于高效地清空/使能全部守卫的访问/// Supports iterating over tiles that are not whole in memory. Iterator maintains a mask object /// which guards against out-of-bounds access. /// /// Note, this concept definition does not formally define operations on the mask or methods it /// supports. These remain implementation-dependent details of iterators implementing this concept. struct MaskedTileIteratorConcept { using Mask; /// mask object used to guard against acceses. CUTLASS_DEVICE void clear_mask(); /// efficiently disables all accesses guarded by mask CUTLASS_DEVICE void enable_mask(); /// efficiently enables all accesses guarded by mask CUTLASS_DEVICE void get_mask(Mask mask); /// gets the mask CUTLASS_DEVICE void set_mask(Mask const mask); /// sets the mask };常用组合Frequently Used Tile Iterator Concepts单独的概念是积木实际迭代器由若干概念组合而成。文档将两个最常见的组合完整展开为类型声明方便读者对照。它们在 CUTLASS 中被大量复用比如PredicatedTileIterator的注释明确标注其满足ForwardTileIteratorConcept | ReadableContiguousTileIteratorConcept | WriteableContiguousTileIteratorConcept | MaskedTileIteratorConcept见 include/cutlass/transform/threadblock/predicated_tile_iterator.h。组合 AWriteable, Readable, Forward, Contiguous Memory能够加载/存储 tile 并沿遍历序列向前推进的迭代器是流水线式全局内存加载的基础形态。它等于以下三个概念的并集ForwardTileIteratorConceptReadableContiguousTileIteratorConceptWriteableContiguousTileIteratorConcept/// This tile iterator embodies several of the above: /// /// - ForwardTileIteratorConcept /// - ReadableContiguousTileIteratorConcept /// - WriteableContiguousTileIteratorConcept /// /// It is restated explicitly for convenience of the reader. /// struct WriteableReadableForwardContiguousTileIteratorConcept { // // Data types // using Element; /// Element type composing tile. using Shape; /// Shape type describing extent of tile. The shape concept depends /// on iterator implementation using Index; /// index type used as base for TensorCoord using Fragment; /// fragment object derived from cutlass::ArrayElement, N // // Methods // /// Adds a linear offset in units of Element to internal pointer(s) into tensor CUTLASS_DEVICE void add_pointer_offset(Index offset); /// true if iterators point to same tile, false if otherwise CUTLASS_DEVICE bool operator(WriteableReadableForwardContiguousTileIteratorConcept const it); /// false if iterators point to same tile, true if otherwise CUTLASS_DEVICE bool operator!(WriteableReadableForwardContiguousTileIteratorConcept const it); /// pre-increment - traverse to next tile in sequence CUTLASS_DEVICE WriteableReadableForwardContiguousTileIteratorConcept operator(); /// post-increment - traverse to next tile in sequence CUTLASS_DEVICE WriteableReadableForwardContiguousTileIteratorConcept operator(int); /// Loads a fragment from memory CUTLASS_DEVICE void load(Fragment frag); /// fragment to be loaded from memory /// Loads a fragment from memory with additional logical offset CUTLASS_DEVICE void load_with_pointer_offset( Fragment frag, /// fragment to be loaded from memory Index pointer_offset); /// linear offset (in units of Element) when loading /// Stores a fragment to memory CUTLASS_DEVICE void store(Fragment const frag); /// fragment to store to memory /// Stores a fragment from memory with additional logical offset CUTLASS_DEVICE void store_with_pointer_offset( Fragment const frag, /// fragment to store to memory Index pointer_offset); /// linear offset (in units of Element) when storing };组合 BWriteable, Readable, Random Access, Contiguous Memory适合加载 GEMM 矩阵操作数的随机访问迭代器等价于以下两个概念的并集ReadableRandomAccessContiguousTileIteratorConceptWriteableRandomAccessContiguousTileIteratorConcept/// This tile iterator embodies several of the above: /// /// - ReadableRandomAccessContiguousTileIteratorConcept /// - WriteableRandomAccessContiguousTileIteratorConcept /// /// It is restated explicitly for convenience of the reader. /// struct WriteableReadableRandomAccessContiguousTileIteratorConcept { // // Data types // using Element; /// Element type composing tile. using Shape; /// Shape type describing extent of tile. The shape concept depends /// on iterator implementation using Layout; /// Layout object mapping using TensorRef; /// Tensor Reference object using TensorCoord; /// Logical coordinate in referenced tensor using Index; /// index type used as base for TensorCoord using Fragment; /// fragment object derived from cutlass::ArrayElement, N // // Methods // /// Adds a linear offset in units of Element to internal pointer(s) into tensor CUTLASS_DEVICE void add_pointer_offset(Index pointer_offset); /// true if iterators point to same tile, false if otherwise CUTLASS_DEVICE bool operator(WriteableReadableRandomAccessContiguousTileIteratorConcept const it); /// false if iterators point to same tile, true if otherwise CUTLASS_DEVICE bool operator!(WriteableReadableRandomAccessContiguousTileIteratorConcept const it); /// pre-increment - traverse to next tile in sequence CUTLASS_DEVICE WriteableReadableRandomAccessContiguousTileIteratorConcept operator(); /// post-increment - traverse to next tile in sequence CUTLASS_DEVICE WriteableReadableRandomAccessContiguousTileIteratorConcept operator(int); /// pre-decrement - traverse to previous tile in sequence CUTLASS_DEVICE WriteableReadableRandomAccessContiguousTileIteratorConcept operator--(); /// post-decrement - traverse to previous tile in sequence CUTLASS_DEVICE WriteableReadableRandomAccessContiguousTileIteratorConcept operator--(int); /// advances in units of whole tiles along the logical coordinate space of the tensor CUTLASS_DEVICE WriteableReadableRandomAccessContiguousTileIteratorConcept operator(TensorCoord const tile_offset); /// advances in units of whole tiles along the logical coordinate space of the tensor CUTLASS_DEVICE WriteableReadableRandomAccessContiguousTileIteratorConcept operator-(TensorCoord const tile_offset); /// Loads a fragment from memory CUTLASS_DEVICE void load(Fragment frag); /// fragment to be loaded from memory /// Loads a fragment from memory with additional logical offset CUTLASS_DEVICE void load_with_pointer_offset( Fragment frag, /// fragment to be loaded from memory Index pointer_offset); /// linear offset (in units of Element) when loading /// Loads a fragment from memory with logical offset in units of whole tiles. CUTLASS_DEVICE void load( Fragment frag, /// fragment to be loaded from memory TensorCoord const tile_offset); /// loads a tile with a logical offset in units of whole tiles /// Loads a fragment from memory with logical offset in units of whole tiles. CUTLASS_DEVICE void load( Fragment frag, /// fragment to be loaded from memory TensorCoord const tile_offset, /// loads a tile with a logical offset in units of whole tiles Index pointer_offset); /// loads a tile with a logical offset AND a pointer offset /// Stores a fragment to memory CUTLASS_DEVICE void store(Fragment const frag); /// fragment to store to memory /// Loads a fragment from memory with additional logical offset CUTLASS_DEVICE void store_with_pointer_offset( Fragment const frag, /// fragment to store to memory Index pointer_offset); /// linear offset (in units of Element) when loading /// Stores a fragment from memory with logical offset in units of whole tiles. CUTLASS_DEVICE void store( Fragment const frag, /// fragment to store to memory TensorCoord const tile_offset); /// stores with logical offset in units of whole tiles /// Stores a fragment from memory with logical offset in units of whole tiles. CUTLASS_DEVICE void store( Fragment const frag, /// fragment to store to memory TensorCoord const tile_offset, /// stores with logical offset in units of whole tiles Index pointer_offset); };源码实现这些概念在仓库里长什么样概念是规格实现才是血肉。下面以 CUTLASS 2.x 中最具代表性的几个迭代器类为例看它们如何兑现上述概念。全部位于 include/cutlass/transform/threadblock/。PredicatedTileIterator掩码 连续内存 前向的典型代表PredicatedTileIteratorinclude/cutlass/transform/threadblock/predicated_tile_iterator.h专门负责从pitch-linear 的 rank2 张量加载/存储 tile其头注释明确给出概念归属Satisfies: ForwardTileIteratorConcept | ReadableContiguousTileIteratorConcept | WriteableContiguousTileIteratorConcept | MaskedTileIteratorConcept也就是说它是组合 A 掩码的实现。其模板签名如下源码 L133-L143template typename Shape, typename Element, typename Layout, int AdvanceRank, typename ThreadMap, int AccessSize ThreadMap::kElementsPerAccess, bool Gather false, typename PermuteLayout layout::NoPermute class PredicatedTileIterator;关键设计要点来自源码头注释与实现预计算 Params 对象Params源码 L198-L219由宿主端基于 layout 构造把大量常量计算提前完成从而把迭代器保存在寄存器中的运行时状态降到最低迭代过程中用整数加法推进指针。残差 tile 稳态 tile 两段式遍历迭代序列被设计为先访问一个可能部分满的残差 tileresidual tile再进入稳态steady state。operator()源码 L280-L301第一次调用时更新谓词并把内部指针回退到第一个稳态 tile后续调用只需更新指针非常轻量。沿哪个维度推进由AdvanceRank决定kAdvanceRank1时add_tile_offset({0,1})否则add_tile_offset({1,0})。掩码接口clear_mask()、enable_mask()、set_mask()、get_mask()全部委托给内部地址迭代器源码 L303-L317对应MaskedTileIteratorConcept。只要在解引用前调用clear_mask()越界访问就是安全的表现为 NO-OP。加载与偏移折叠load_with_pointer_offset()把指针偏移换算成字节偏移后由load_with_byte_offset()实现源码 L319-L348内部按ThreadMap::Iterations与kAccessesPerVector展开循环并通过address_iterator_.valid()得到谓词后调用cutlass::arch::global_load执行带掩码的全局加载。源码头注释还给出了一个高效流水线使用范式源码 L88-L130先加载残差 tile、iter进入稳态然后在#pragma unroll循环中反复fragment *iter; iter;在最后一轮迭代前调用iter.clear_mask()让后续 load 变为 NO-OP从而把整数运算压到最低。RegularTileIterator无掩码的规则迭代器与PredicatedTileIterator相对RegularTileIteratorinclude/cutlass/transform/threadblock/regular_tile_iterator.h用于尺寸恰好对齐、无需谓词守卫的场景头注释定位为存储 pitch-linear rank2 张量的 tile的模板。其签名同样携带Shape / Element / Layout / AdvanceRank / ThreadMap / Alignment模板参数其中Alignment默认由sizeof_bitsElement::value * ThreadMap::kElementsPerAccess / 8推导保证访问按向量宽度对齐。同一目录下还有面向 TensorOp、sm70、2D thread tile 等专门化的变体regular_tile_iterator_tensor_op.h适配 Tensor Core 操作数布局regular_tile_iterator_tensor_op_sm70.hregular_tile_iterator_pitch_linear.h 与 regular_tile_iterator_pitch_linear_2dthreadtile.h更多特化形态同一概念族在仓库中还有大量针对具体数据通路/算子的特化例如ell_predicated_tile_iterator.h面向 ELL 稀疏格式的掩码迭代器predicated_tile_iterator_2dthreadtile.h 与 predicated_tile_iterator_triangular_matrix.h2D 线程块 tile、三角矩阵特化epilogue 侧则在 include/cutlass/epilogue/threadblock/ 下提供了PredicatedTileIterator的卷积predicated_tile_iterator_conv.h、直接卷积predicated_tile_iterator_direct_conv.h、dgradpredicated_tile_iterator_strided_dgrad.h、仿射predicated_tile_iterator_affine.h、BLAS3predicated_tile_iterator_blas3.h等变体其头注释分别标注ReadableTileIterator | PredicatedTileIterator | ForwardTileIterator等满足关系。这些实现分布印证了文档的判断概念组合种类虽多但实际迭代器都收敛在少数几种常见组合上。GEMM 流水线中的消费方式Tile Iterator 的最终价值体现在被高层算法模板当作模板参数使用。以gemm::threadblock::MmaPipelinedinclude/cutlass/gemm/threadblock/mma_pipelined.h为例其模板参数包含IteratorA、SmemIteratorA、IteratorB、SmemIteratorB等源码 L62-L88IteratorA/IteratorB遍历全局内存中 A/B 操作数 tile 的迭代器通常即上述PredicatedTileIterator或RegularTileIterator系列SmemIteratorA/SmemIteratorB遍历共享内存 tile 的迭代器。在类内部源码 L99-L119可以清楚看到消费方式using IteratorA IteratorA_; /// Iterates over tiles of A operand in global memory using IteratorB IteratorB_; /// Iterates over tiles of B operand in global memory using SmemIteratorA SmemIteratorA_; using SmemIteratorB SmemIteratorB_; using FragmentA typename IteratorA::Fragment; using FragmentB typename IteratorB::Fragment;FragmentA/FragmentB直接取自已满足ReadableTileIteratorConcept的迭代器——这就是概念中using Fragment在真实模板中的用法算法只依赖迭代器暴露的Fragment与load/store方法而不关心具体迭代器实现。交换不同布局的迭代器pitch-linear、TensorOp 专用布局等同一套MmaPipelined模板即可生成不同数据通路上的 kernel。K 维主循环中全局内存迭代器加载到 Fragment → 存入共享内存 → 共享内存迭代器喂给 MMA的流水线正是文档所说沿 K 维推进的前向序列语义的实际体现。与 CUTLASS 3.0 的关系为何被弃用文档开头的 Note 是理解整个概念体系历史地位的关键CUTLASS 3.0 deprecates all tile access iterators in favour of CuTes single vocabulary typecute::Tensor, which is parameterized oncute::Layout.cute::Tensors can therefore be manipulated with the same layout algebra as all CuTe layouts. This removes the need for bespoke types that encapsulate iterator properties.翻译过来即是CUTLASS 3.0 弃用了全部 tile access iterator转而使用 CuTe 的单一词汇类型cute::Tensor以cute::Layout为参数。由于cute::Tensor可以直接套用 CuTe 整套布局代数layout algebra进行操作就不再需要封装迭代器属性的专用类型了。因此本文描述的概念族仅适用于 legacy CUTLASS 2.x API。仓库中对应 CuTe 的文档位于 media/docs/cpp/cute/如 00_quickstart.md、03_tensor.md、04_algorithms.md同一概念的 CuTe 侧表述可以参考cutlass_compiler下的 cute_concepts 相关教程。迁移到 3.x 时原来迭代器 Fragment load/store的写法被cute::Tensor CuTe 算法如cute::copy、cute::gemm取代。小结CUTLASS 2.x Tile Iterator 概念体系可以用一句话概括用一组最小化的类型约束Element/Shape/Index/TensorCoord/Fragment与方法约束add_pointer_offset/load/store//--//-/掩码管理描述能干什么用组合而非继承表达复合能力让算法模板只依赖接口而保持实现可替换。理解这套概念是读懂 CUTLASS 2.x 的MmaPipelined、epilogue 迭代器以及各类卷积/GEMM kernel 的关键前置知识而PredicatedTileIterator的残差-稳态两段式遍历与掩码折叠技巧即使在今天编写自定义 CUDA kernel 时依然有直接借鉴价值。版权说明本文涉及的概念定义与源码片段均来自 CUTLASS 仓库版权归 NVIDIA CORPORATION AFFILIATES 所有许可证为 BSD-3-Clause见 LICENSE.txt。【免费下载链接】cutlassCUDA Templates and Python DSLs for High-Performance Linear Algebra项目地址: https://gitcode.com/GitHub_Trending/cu/cutlass创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
上一篇/下一篇内容由系统自动关联 返回资讯列表 →