NVIDIA CUTLASS

repository·main·Indexed 27 days ago

https://github.com/nvidia/cutlass

A collection of CUDA C++ and Python-based abstractions for implementing high-performance matrix-matrix multiplication (GEMM) and related linear algebra computations, designed for modularity and scalability across NVIDIA GPU architectures. Version 4.2.0.0 includes the CUTLASS Operator API for kernel discovery and execution, a TVM FFI DSL Bridge for binding generation, and utilities like block_copy for TMA and S2T operations.

Tokens
157.2K
Snippets
264
Records
558
Agent score
94%

What's inside nvidia-cutlass

  1. Overview of CUTLASS Operator API features

    main

    The CUTLASS Operator API provides a high-level Python interface for managing and integrating CUTLASS kernels.

    Key Capabilities:

    • Kernel Discovery: Use get_operators(args) to find kernels matching specific dtypes, layouts, and hardware constraints.
    • Consistent Interface: Pass PyTorch or DLPack tensors directly into argument objects and call .run(args) without writing kernel-specific glue code.
    • Custom Epilogue Fusions: Pass a plain Python function to fuse activations or elementwise operations into supported kernels via the CuTe DSL's Epilogue Fusion Configuration (EFC) framework.
    • Bring-Your-Own-Kernel: Register custom CuTe DSL kernels to use them through the same interface as officially maintained kernels.
    • Automatic Updates: Upgrading nvidia-cutlass-operators automatically provides access to new kernels, fixes, and optimizations in the registry.
  2. Overview of CUTLASS DSLs

    main

    CUTLASS 4.x provides Python-based Domain-Specific Languages (DSLs) to interface with the CUTLASS C++ template library. This allows for faster prototyping and easier iteration of high-performance linear algebra kernels on NVIDIA GPUs by using Python syntax instead of complex C++ metaprogramming.

    The first DSL released is CuTe DSL, a low-level programming model consistent with CuTe C++ abstractions. It enables control over hardware threads, data hierarchy, and core concepts like layouts and tensors.

  3. Overview of Blackwell SM100 tcgen05.mma Instructions

    main
    Blackwell SM100 architecture introduces tcgen05.mma instructions, which provide 2x to 4x higher throughput compared to Hopper's WGMMA instructions. These instructions support legacy types (tfloat32_t, half_t, bfloat16_t, int8_t, uint8_t) as well as new 4, 6, and 8-bit floating point datatypes, including support for block scaling.
  4. Overview of CuTe DSL

    main

    CuTe is a core library introduced in CUTLASS 3.0 for describing and manipulating tensors of threads and data. It uses C++ CUDA template abstractions to define hierarchically multidimensional layouts.

    Key abstractions include:

    • Layout: Compactly packages type, shape, memory space, and layout of data, performing complex indexing automatically.
    • Tensor: Composes Layout objects with data arrays to represent tensors.

    CuTe allows for functional composition of layouts, supporting operations like tiling and partitioning, which simplifies the design of dense linear algebra operations.

  5. Overview of CUTLASS

    main

    CUTLASS is a collection of CUDA C++ template abstractions designed for implementing high-performance matrix-matrix multiplication (GEMM) and related computations. It provides modular software components for hierarchical decomposition and data movement, allowing developers to specialize primitives via custom tiling sizes, data types, and algorithmic policies.

    Key features include:

    • Support for mixed-precision computations (FP64, FP32, TF32, FP16, BF16, 8b floating point, block scaled data types like NVFP4/MXFP4, and integer/binary types).
    • Support across NVIDIA architectures: Volta, Turing, Ampere, Ada, Hopper, and Blackwell.
    • CUTLASS DSLs: Python-native interfaces for writing high-performance CUDA kernels using CuTe concepts, offering faster compile times and easier integration with DL frameworks.
  6. Overview of tcgen05 MMA Programming

    main

    Blackwell (SM100) architecture introduces the tcgen05 family of PTX instructions, which are 5th-generation Tensor Core matrix multiply-accumulate (MMA) operations. These instructions compute D = A * B + C and offer 2x–4x the throughput of Hopper's WGMMA instructions depending on the data type.

    Key architectural features include:

    • Tensor Memory (TMEM): A dedicated on-chip memory for the accumulator (and optionally operand A). tcgen05 MMA reads/writes the accumulator directly in TMEM, reducing register file pressure.
    • Single-thread launch: A single thread issues the MMA instruction.
    • CTA-pair cooperation: Two adjacent CTAs can jointly execute a single MMA to double the tile size without additional synchronization logic.
  7. Understand CUTLASS Code Organization

    main

    The CUTLASS repository is organized into several key components:

    • CUTLASS Template Library: Header-only CUDA C++ templates for linear algebra subroutines and solvers.
    • CuTe Template Library: Core layout types and associated algebra (header-only).
    • CUTLASS Instance Library: Procedurally generated instantiations of templates covering various configurations (data types, tile sizes, etc.).
    • CUTLASS Profiler: A command-line application used to evaluate the functionality and performance of the Instance Library.
    • CUTLASS Utilities: A companion library supporting tests, examples, and client applications.
    • Examples: SDK examples demonstrating how to apply CUTLASS templates to basic computations.
  8. Understand CuTe Tensor fundamentals

    main
    A Tensor in CuTe is a multidimensional array container defined by two template parameters: Engine (the data provider/iterator) and Layout (the organization of elements). It abstracts how elements are stored, allowing algorithms to work generically across different memory spaces (global, shared, or register memory) by inspecting traits like rank, shape, and layout.
  9. Interpret Layouts as Vectors or Matrices

    main

    In CuTe, specific ranks define logical structures:

    • Vector: Any Layout with rank == 1. This includes hierarchical shapes that can be flattened into a single mode (e.g., ((4,2)):((2,1)) is a vector of size 8).
    • Matrix: Any Layout with rank == 2.
      • Column-major: The first mode has a stride of 1.
      • Row-major: The second mode has a stride of 1.

    Matrices can also have multi-mode dimensions (e.g., a column might be composed of multiple sub-modes), but they can still be indexed using 2-D coordinates.

  10. Use the cute.arch module for CUDA built-in functions and memory management

    main

    The cute.arch module provides lightweight wrappers for NVVM Operation builders, allowing you to implement CUDA built-in device functions within the CuTe DSL. These wrappers integrate with CuTe DSL types and support source location tracking via the @dsl_user_op decorator.

    Key capabilities include:

    • Core CUDA built-ins: Access functions like thread_idx, warp_idx, block_dim, grid_dim, and cluster_dim.
    • Memory Barrier Management: Manage barriers using functions such as mbarrier_init, mbarrier_arrive, and mbarrier_wait.
    • Memory Allocation: Use SmemAllocator for low-level shared memory (SMEM) management and TmemAllocator for low-level tensor memory (TMEM) management.
  11. Understand CuTe MMA Atoms architecture

    main

    CuTe supports GPU Matrix Multiply-Accumulate (MMA) hardware instructions by abstracting architecture-specific PTX instructions into a hierarchical structure. This allows generic CUDA C++ code to use MMAs via high-level abstractions.

    The hierarchy consists of:

    1. Operation struct: Wraps a specific PTX instruction. It defines the physical interface (arguments and types) required by the hardware.
    2. MMA_Traits struct: A template specialization for an Operation that defines meta-information like logical compute types, logical shapes, and the Layout of threads and values.
    3. Atom: The combination of an Operation and its corresponding MMA_Traits. Atoms provide methods to construct cute::Tensor fragments and perform operations on existing tensors.
    4. TiledMMA: A utility that combines multiple Atoms to build complex partitioning patterns, creating layouts and interleavings of Atoms.
  12. Compose a Layout and Tensor

    main

    A Layout is composed of a Shape and a Stride (both of which are IntTuple concepts). It maps coordinates within the Shape to an index via the Stride.

    A Tensor is created by composing a Layout with data (such as a pointer or an array). The Layout generates the index used to subscript the data to retrieve elements.