Skip to main content

Tensor Core Programming

Tensor Cores are specialized hardware units in modern NVIDIA GPUs that dramatically accelerate matrix multiply-accumulate (MMA) operations. This page explains how CUTLASS leverages Tensor Cores for peak performance.

What are Tensor Cores?

Tensor Cores are dedicated matrix processing units that can perform multiple multiply-accumulate operations in a single instruction. They are the key to achieving peak throughput for deep learning and HPC workloads.
Key Characteristics:
  • Perform matrix operations on small tiles (e.g., 16×8×16)
  • Operate at warp granularity (32 threads collaborate)
  • Deliver 8-16× higher throughput than CUDA cores for matrix math
  • Support various data types: FP64, FP32, TF32, FP16, BF16, FP8, INT8, INT4

Architecture Evolution

Volta (SM70) - First Generation

  • Shape: 16×16×4 (M×N×K)
  • Data Types: FP16 input, FP16/FP32 accumulation
  • Instructions: wmma API

Turing (SM75) - Second Generation

  • Shapes: 16×8×8, 8×8×4
  • Data Types: FP16, INT8, INT4, INT1
  • Instructions: Enhanced wmma and mma.sync

Ampere (SM80) - Third Generation

  • New Shapes: 16×8×8, 16×8×16
  • New Types: BF16, TF32 (19-bit format)
  • Instructions: mma.sync.aligned
  • Features: Async copy, structured sparsity (2:4)

Hopper (SM90) - Fourth Generation

  • New Shapes: 64×64×16, 64×128×16, 64×192×16
  • New Types: FP8 (E4M3, E5M2)
  • Instructions: wgmma (warpgroup MMA)
  • Features: TMA (Tensor Memory Accelerator), Thread Block Clusters
  • Throughput: Up to 2000 TFLOPS (FP8)

Blackwell (SM100) - Fifth Generation

  • Enhanced Shapes: Larger warpgroup operations
  • New Types: FP4, MXFP formats
  • Features: Enhanced TMA, distributed shared memory
  • Throughput: Up to 4000 TFLOPS (FP4)

MMA Instruction Format

Tensor Core operations are exposed through MMA (Matrix Multiply-Accumulate) instructions. Here’s an example from Ampere (SM80):
Reference: include/cutlass/arch/mma_sm80.h:76
The instruction name encodes:
  • m16n8k8: Matrix dimensions (16×8 output, K=8)
  • row.col: A is row-major, B is column-major
  • f32.bf16.bf16.f32: Output type, A type, B type, accumulator type

Fragment Layout

Tensor Core operands are distributed across threads in a warp. Understanding fragment layouts is crucial:

Thread-to-Fragment Mapping (16×8×8 example)

CUTLASS handles fragment distribution automatically when you use the provided templates. You rarely need to compute layouts manually!

Warpgroup MMA (Hopper SM90+)

Hopper introduced warpgroup-scoped MMA instructions that enable larger, more efficient operations:

Key Differences

Using Tensor Cores in CUTLASS

CUTLASS provides high-level abstractions for Tensor Core programming:

Method 2: CuTe MMA Atoms

CuTe provides composable MMA atoms for fine-grained control:

Data Type Support

Different Tensor Core generations support different types:

FP16 (Half Precision)

BF16 (Brain Float16)

TF32 (TensorFloat32)

FP8 (8-bit Float)

Block-Scaled Types (SM100+)

Higher Throughput (Lower Precision):
  • FP4: 4× FP16 throughput
  • FP8: 2× FP16 throughput
  • INT8: 2× FP16 throughput
Higher Precision (Lower Throughput):
  • FP64: 1/16× FP16 throughput
  • FP32: 1/2× FP16 throughput (via TF32)
  • FP16/BF16: Baseline throughput
Choose based on your accuracy requirements!

Structured Sparsity (SM80+)

Ampere introduced 2:4 structured sparsity support:
Matrix A is compressed, and a metadata tensor indicates which elements are non-zero.

Performance Optimization

1. Tile Size Selection

Choose tile sizes that are multiples of Tensor Core operation sizes:

2. Maximizing Occupancy

3. Double Buffering

4. Async Copy (SM80+)

Performance Checklist:
  • ✓ Tile sizes are multiples of Tensor Core shapes
  • ✓ High occupancy (8+ warps per SM)
  • ✓ Multi-stage pipeline (2-4 stages)
  • ✓ Vectorized memory accesses (128-bit when possible)
  • ✓ Async copy for SM80+ targets
  • ✓ TMA for SM90+ targets

Common Pitfalls

1. Misaligned Data

2. Wrong Layout

3. Incorrect Fragment Distribution

Debugging Tensor Core Kernels

Real-World Example

Complete Tensor Core GEMM snippet:

Next Steps

Memory Layouts

Optimize data layouts for Tensor Cores

CuTe Library

Use CuTe abstractions for MMA operations

Examples

Explore Tensor Core code examples

GEMM Operations

Build complete GEMM kernels