Skip to main content
This guide demonstrates how to implement a dense General Matrix Multiply (GEMM) kernel using CUTLASS CuTe DSL. The example shows a complete implementation for both Ampere and Blackwell architectures.

Overview

The GEMM kernel computes C = A * B where:
  • Matrix A is MxKxL (L is batch dimension)
  • Matrix B is NxKxL
  • Matrix C is MxNxL
Key features:
  • Utilizes GPU tensor cores for MMA operations
  • Multi-stage pipelining to overlap compute and memory access
  • Shared memory buffering for efficient data transfer
  • Support for various data types (fp16, bf16, fp8, int8, tf32)

Ampere Architecture Example

Blackwell Architecture Example

For Blackwell GPUs, the implementation uses more advanced features:

Key Blackwell Features

Tensor Memory Access (TMA) TMA provides efficient memory operations:
Cluster Computing Blackwell supports CTA clusters for better parallelism:

Running the Example

Performance Profiling

Use NVIDIA Nsight Compute to profile your kernel:

Key Concepts

The tile shape determines how the problem is divided:
  • M dimension: Affects register usage and occupancy
  • N dimension: Should align with MMA instruction shape
  • K dimension: Larger values improve arithmetic intensity
Common configurations:
  • Ampere: 128x128x32, 128x256x32, 256x128x32
  • Blackwell: 128x128x64, 256x128x128
Understanding the memory hierarchy is crucial:
  1. Global Memory (GMEM): Input matrices A, B, output C
  2. Shared Memory (SMEM): Tile-level cache, swizzled to avoid bank conflicts
  3. Registers (RMEM): Thread-level storage for MMA operands
  4. Tensor Memory (TMEM): Blackwell-specific accumulator storage
Multi-stage pipelining overlaps memory and compute:
  • Stage 1: Load next tile from GMEM to SMEM
  • Stage 2: Compute current tile MMA
  • Stage 3: Write previous results to GMEM
More stages provide better overlap but increase SMEM usage.

Source Code

Ampere GEMM

Complete source: examples/python/CuTeDSL/ampere/tensorop_gemm.py

Blackwell GEMM

Complete source: examples/python/CuTeDSL/blackwell/dense_gemm.py