CuTe: CUDA Template Library
CuTe (CUDA Templates) is the foundational abstraction layer introduced in CUTLASS 3.0. It provides powerful tools for describing and manipulating tensors of threads and data with compile-time layouts.What is CuTe?
CuTe is a collection of C++ CUDA template abstractions for defining and operating on hierarchically multidimensional layouts of threads and data. It provides:- Layouts: Compile-time mappings from logical coordinates to linear indices
- Tensors: Data structures combining engines (storage) with layouts
- Algorithms: Operations on tensors (copy, GEMM, partition, etc.)
CuTe represents a paradigm shift in GPU programming - instead of manually computing indices and strides, you describe the logical structure of your data and let CuTe handle the mechanical bookkeeping.
Core Abstractions
Shapes and Strides
CuTe uses tuple-based shapes and strides to describe multidimensional data:include/cute/layout.hpp:47
Layouts
ALayout combines shape and stride to map logical coordinates to linear memory offsets:
include/cute/layout.hpp:98
Example: Row-Major vs Column-Major
Hierarchical Layouts
CuTe supports nested, hierarchical layouts for representing complex data structures:Tensors
Tensors combine an engine (storage) with a layout (indexing):include/cute/tensor_impl.hpp:135
Tensor Engines
Engines define how tensors store data:ArrayEngine (Owning)
Allocates and owns data storage:include/cute/tensor_impl.hpp:70
ViewEngine (Non-Owning)
References existing data without ownership:include/cute/tensor_impl.hpp:106
Tensor Operations
Creating Tensors
Indexing Tensors
Partitioning Tensors
Partitioning divides tensors across threads or threadblocks:Tiling Tensors
Tiling restructures tensors into hierarchical tile views:Understanding Partition vs Tile
Understanding Partition vs Tile
- Partition: Distributes tensor elements across threads/threadblocks
- Tile: Restructures a tensor into a hierarchical layout
- Both: Can be combined to partition tiled tensors
Copy Operations
CuTe provides high-level copy abstractions:Async Copy (SM80+)
TMA (Tensor Memory Accelerator) SM90+
Layout Algebra
CuTe layouts support algebraic composition:Composition
Product
Complement
Layout algebra enables powerful compile-time transformations that would be error-prone to write manually.
Integration with CUTLASS
CuTe is deeply integrated into CUTLASS 3.x:Why CuTe?
Traditional GPU programming:Benefits of CuTe:
- Type-safe indexing with compile-time checking
- Composable abstractions (partition, tile, slice)
- Zero-overhead when fully static
- Dramatically reduced boilerplate code
- Easier to reason about correctness
CuTe DSL (Python)
CUTLASS 4.0 introduced CuTe DSL, a Python interface to CuTe concepts:Real-World Example
Here’s how CuTe simplifies GEMM implementation:Next Steps
Tensor Cores
Learn how CuTe interfaces with Tensor Cores
Memory Layouts
Deep dive into layout strategies
GEMM Operations
See CuTe in action for GEMM
Examples
Explore CuTe code examples