Skip to main content
CUTLASS Python packages provide seamless integration with PyTorch, enabling you to use CUTLASS kernels directly with PyTorch tensors and build custom CUDA extensions.

Overview

Direct Integration

Use CUTLASS kernels with PyTorch tensors without conversion

CUDA Extensions

Export kernels as PyTorch CUDA extensions for deployment

Custom Autograd

Implement custom backward passes for training

Stream Integration

Work with PyTorch CUDA streams

Using PyTorch Tensors

With cutlass_cppgen

The CUTLASS Python interface accepts PyTorch tensors directly:

With CuTe DSL

Convert PyTorch tensors using DLPack:

Data Type Conversion

cutlass.torch.dtype

Convert between CUTLASS and PyTorch types:

CUDA Stream Integration

Getting Current Stream

Using Multiple Streams

Building PyTorch CUDA Extensions

Method 1: JIT Compilation

Build and load extensions at runtime:

Method 2: Setuptools Extension

Build extensions with setup.py:
1

Create Extension Directory

2

Write Kernel Code

cutlass_kernel.py:
3

Create Python Wrapper

extension.cpp:
4

Create setup.py

setup.py:
5

Build and Install

6

Use Extension

Custom Autograd Functions

Implement custom forward and backward passes:

Custom nn.Module

Wrap CUTLASS operations in PyTorch modules:

Grouped GEMM Example

Export grouped GEMM as PyTorch extension:

Performance Optimization

Tensor Layout

Ensure optimal memory layout:

Warm-up Compilation

Compile kernels before timing:

Memory Pinning

Use pinned memory for faster CPU-GPU transfers:

Troubleshooting

Ensure PyTorch and CUTLASS types match:
Make tensors contiguous:
Synchronize streams when needed:
Monitor and free memory:

Example: Complete Training Loop

Next Steps

CuTe DSL

Learn to write custom kernels

Examples

Explore more integration examples

API Reference

Browse the complete API

Quickstart

Get started quickly