Skip to main content
The Gemm class provides a high-level interface for constructing, compiling, and running General Matrix Multiply operations in CUTLASS.

Class Reference

cutlass.op.Gemm

Constructs a GEMM operation that computes: D = alpha * (A @ B) + beta * C The data types and layouts of operands are bound to the Gemm object throughout its lifetime and cannot be changed after construction.
tensor, optional
Input tensor A with shape (M, K). Can be torch.Tensor, numpy.ndarray, or cupy.ndarray. If provided, the element type and layout are inferred from this tensor.
tensor, optional
Input tensor B with shape (K, N). Can be torch.Tensor, numpy.ndarray, or cupy.ndarray. If provided, the element type and layout are inferred from this tensor.
tensor, optional
Input tensor C with shape (M, N). Can be torch.Tensor, numpy.ndarray, or cupy.ndarray. If provided, the element type and layout are inferred from this tensor.
tensor, optional
Output tensor D with shape (M, N). Can be torch.Tensor, numpy.ndarray, or cupy.ndarray. If provided, the element type and layout are inferred from this tensor.
scalar, optional
default:"1.0"
Scalar multiplier for the A @ B product.
scalar, optional
default:"0.0"
Scalar multiplier for the C tensor. When beta=0, C is not read.
cutlass.DataType, optional
Data type for operand A. Overrides generic element parameter.
cutlass.DataType, optional
Data type for operand B. Overrides generic element parameter.
cutlass.DataType, optional
Data type for operand C. Overrides generic element parameter.
cutlass.DataType, optional
Data type for operand D. Overrides generic element parameter.
cutlass.DataType, optional
Data type used for accumulation. If not specified, defaults to the element type.
cutlass.DataType, optional
Generic data type for all operands (A, B, C, D) and accumulator. Can be overridden per operand.
cutlass.LayoutType, optional
Memory layout for operand A. Overrides generic layout parameter.
cutlass.LayoutType, optional
Memory layout for operand B. Overrides generic layout parameter.
cutlass.LayoutType, optional
Memory layout for operand C and D. Overrides generic layout parameter.
cutlass.LayoutType, optional
Generic layout for all operands. Can be overridden per operand.
int, optional
Compute capability of the target device (e.g., 90 for H100). Defaults to auto-detection.
int, optional
Compute capability of the kernel to generate. Useful for using older kernel implementations on newer hardware.

Methods

run()

Executes the GEMM operation.
tensor, optional
Input tensor A. If not provided, uses the tensor from initialization.
tensor, optional
Input tensor B. If not provided, uses the tensor from initialization.
tensor, optional
Input tensor C. If not provided, uses the tensor from initialization.
tensor, optional
Output tensor D. If not provided, uses the tensor from initialization.
scalar, optional
Scalar alpha. If not provided, uses the value from initialization.
scalar, optional
Scalar beta. If not provided, uses the value from initialization.
bool
default:"True"
If True, waits for the kernel to complete. If False, returns immediately.
bool
default:"False"
If True, prints the generated CUDA C++ code.
Returns: GemmArguments object that can be used to synchronize or retrieve results.

compile()

Explicitly compiles the GEMM kernel. This is optional as run() will compile if needed.
cutlass.TileDescription, optional
Custom tile description for advanced kernel configuration.
int, optional
Memory alignment requirement in elements. Defaults to automatic selection.

plan()

Generates an execution plan without compiling. Returns the selected operation configuration. Returns: Operation descriptor with selected kernel parameters.

Properties

activation

Sets the activation function to fuse into the epilogue. Available activations:
  • cutlass.epilogue.identity (default)
  • cutlass.epilogue.relu
  • cutlass.epilogue.gelu
  • cutlass.epilogue.sigmoid
  • cutlass.epilogue.tanh
  • cutlass.epilogue.silu
  • cutlass.epilogue.hardswish
  • cutlass.epilogue.leaky_relu

swizzle

Sets the threadblock swizzling function for improved performance.

Examples

Basic GEMM

GEMM with Data Type Configuration

GEMM with Activation Fusion

Mixed Precision GEMM

Column-Major GEMM (Fortran Layout)

Asynchronous Execution

Performance Tips

Alignment: Ensure tensor dimensions are multiples of 8 or 16 for optimal performance with FP16/BF16 data types.
Persistent Tensors: Reuse tensor allocations across multiple run() calls to minimize memory allocation overhead.
Auto-tuning: The default parameters prioritize correctness over performance. For production workloads, consider profiling and tuning tile sizes, kernel schedules, and other parameters.

Type Aliases

For convenience, you can use native tensor types instead of CUTLASS types:

Source Code

Implementation: cutlass/python/cutlass_cppgen/op/gemm.py

See Also