Basic Data Types#
Scalar Types#
Numeric#
- class cutlass.Numeric(value: bool | int | float | Value)#
Base class for all numeric types in the DSL.
This class provides the foundation for both Integer and Float types, implementing basic arithmetic operations.
- Parameters:
value (Union[bool, int, float, Value]) – The value to store in the numeric type
- Variables:
value (Union[bool, int, float, Value]) – The stored numeric value
- __init__(
- value: bool | int | float | Value,
- bitcast(
- dtype: Type[Numeric],
Reinterpret the bits of this value as a different numeric type.
The source and target types must have the same bit width.
- Parameters:
dtype – Target DSL type (e.g.,
Float32when self isInt32).- Returns:
A new instance of
dtypewith the same bit pattern.
- to(dtype: Type) Any#
Convert this numeric value to another numeric type.
If the target type is the same as the current type, returns self. Otherwise, creates a new instance of the target type with the same value.
- Parameters:
dtype (Union[Type["Numeric"], Type[int], Type[float], Type[bool]]) – The target numeric type to convert to
- Returns:
A new instance of the target type, or self if types match
- Return type:
- Raises:
ValueError – If trying to convert an MLIR value to a static Python type
TypeError – If trying to convert to unsupported float types like Float8E4M3, Float8E4M3B11FNUZ, Float4E2M1FN, Float6E3M2FN, or Float6E2M3FN
Note
- Unsupported destination float types:
Float8E4M3
Float8E4M3B11FNUZ
Float4E2M1FN
Float6E3M2FN
Float6E2M3FN
Example:
# Convert between DSL numeric types. x = Int32(5) y = x.to(Float32) # Converts to Float32(5.0) # Convert to Python primitive types. # They are considered static values at JIT time. z = x.to(int) # Returns Python int 5. w = y.to(float) # Returns Python float 5.0. # This raises ValueError because MLIR values are not static. mlir_val = arith.constant(T.i32(), 42) num = Int32(mlir_val) num.to(int)
Integer#
- class cutlass.Integer( )#
A class representing integer values with specific width and signedness.
This class provides functionality to create and manipulate integer values with configurable width and signedness. It supports conversion from various input types including Python scalars, MLIR Values, and other numeric types.
- Parameters:
x (Union[bool, int, float, ir.Value, Integer, Float]) – The input value to convert to this integer type
- Returns:
A new Integer instance with the converted value
- Return type:
- Raises:
AssertionError – If the type’s numpy_dtype is None
NotImplementedError – If converting between different Integer types
ValueError – If the input type is not supported for conversion
OverflowError – If converting float infinity to integer
Type conversion behavior:
- Python scalars (bool, int, float):
Converted through numpy dtype casting
NaN and infinity values are rejected
Example: Int8(256) -> -256 (overflow behavior)
- MLIR Value with IntegerType:
Width differences handled by signless to signed/unsigned conversion
Example: i8 -> i8/ui8 depending on target type
- MLIR Value with FloatType:
Uses MLIR float-to-int conversion
NaN and infinity values is undefined behavior
Example: f32 -> i32/ui32 depending on target type
- Integer:
Uses MLIR float-to-int conversion or numpy dtype casting
Example: Int32(Int32(5)) => 5
- Float:
Uses MLIR float-to-int conversion
Example: Int32(Float(5.7)) -> 5
Example usage:
x = Int32(5) # From integer y = Int32(True) # From boolean z = Int32(3.7) # From float (truncates) w = Int32(x) # From same Integer type c5 = arith.constant(5, T.i32()) a = Int32(c5) # Treat c5 as int32 bitwise
Boolean#
- class cutlass.Boolean(a: bool | int | float | ir.Value | Numeric)#
Boolean type representation in the DSL.
This class represents boolean values in the DSL, with a width of 1 bit. It supports conversion from various types to boolean values.
- Parameters:
a (Union[bool, int, float, "Value", Numeric]) – Value to convert to Boolean
loc (Optional[Location], optional) – Source location information, defaults to None
ip (Optional[InsertionPoint], optional) – Insertion point for MLIR operations, defaults to None
- Raises:
DSLRuntimeError – If the input value cannot be converted to Boolean
Conversion rules:
Python bool/int/float: - Converted using Python’s bool() function - Example: Boolean(1) -> True, Boolean(0) -> False
Numeric: - Uses the Numeric.value to construct Boolean recursively
MLIR Value with IntegerType: - If width is 1: Direct assignment - Otherwise: Compares with 0 using arith.cmpi
MLIR Value with FloatType: - Compares with 0.0 using arith.cmpf - Uses unordered comparison to handle NaN values
- ir_value_int8() ir.Value#
Returns int8 ir value of Boolean. When we need to store Boolean tensor element, use ir_value_int8().
- Parameters:
loc (Optional[Location], optional) – Source location information, defaults to None
ip (Optional[InsertionPoint], optional) – Insertion point for MLIR operations, defaults to None
- Returns:
The int8 value of this Boolean
- Return type:
ir.Value
Signed Integer Types#
Unsigned Integer Types#
The public unsigned scalar classes currently start at cutlass.Uint8.
Packed 1-bit and 2-bit fields, such as predicate masks or sparse metadata, are
represented through wider storage types or API-specific packed operands rather
than separate cutlass.Uint1 or cutlass.Uint2 scalar classes.
Float#
- class cutlass.Float( )#
A class representing floating-point values.
- Parameters:
x (Union[bool, int, float, ir.Value, Integer, Float]) – The input value to convert to this float type.
Type conversion behavior:
Python scalars (bool, int, float): - Converted through numpy dtype casting - Example: Float32(1.7) -> 1.7
MLIR Value with FloatType: - If width differs: converts between float types - Example: f16 -> f32
MLIR Value with IntegerType: - Not supported, raises ValueError
Integer: - Converts using MLIR int-to-float operation - Example: Float32(Int32(5)) -> 5.0
Float: - Direct conversion between float types - Example: Float32(Float32(1.5)) -> 1.5
Note
The following narrow precision types are only supported in device code:
- 8-bit float types:
Float8E5M2
Float8E4M3
Float8E4M3FN
Float8E8M0FNU
Float8E4M3B11FNUZ
- 6-bit float types:
Float6E3M2FN
Float6E2M3FN
- 4-bit float types:
Float4E2M1FN
Narrow precision types and special floating-point formats support matrix on device:
- Raises:
AssertionError – If the type’s numpy_dtype is None
ValueError – If conversion from the input type is not supported
Standard Floating-Point Types#
Narrow Floating-Point Types#
- class cutlass.Float4E2M1FNx2( )#
Packed FP4 E2M1 — 2 elements per byte (matches
torch.float4_e2m1fn_x2).Shape and strides on any layout carrying this dtype are interpreted in fp4x2 tensor-element units. One tensor element is already one packed storage unit, so
create_tensor_map_tiled_from_viewuseswidth == 8directly when converting stride units for TMA.widthis the packed 8-bit tensor-element width andmlir_typeis the packed storage typei8. Internal helpers that still need scalar FP4 lane precision treat this packed dtype specially by class identity.Use this dtype when the input is already organized in packed fp4x2 storage units (for example a
torch.uint8buffer viewed astorch.float4_e2m1fn_x2) or when the kernel allocates layouts directly from packed extents.
Pointer#
- class cutlass.Pointer(
- base: ir.Value,
- *,
- dtype: Type[Numeric] | None = None,
- space: AddressSpace | int | None = None,
An
llvm.ptrvalue with element dtype metadata.Pointeris the canonical low-level DSL pointer type in thecutlassnamespace. It subclassesir.Valueso it can be passed directly to MLIR ops that require a pointer operand.- __init__(
- base: ir.Value,
- *,
- dtype: Type[Numeric] | None = None,
- space: AddressSpace | int | None = None,
Vector#
- class cutlass.Vector(v: ir.Value, *, dtype: Type[Numeric] | None = None)#
Wrap an MLIR
vector<NxTy>register value with DSL type information.Provides element extraction (
vec[i]/vec[a:b]), element-wise arithmetic (+,-,*,/), type conversion (to()), and bit-reinterpretation (bitcast()) on top of a raw MLIR vector.Vectors live entirely in registers — they carry no memory address and do not support in-place element assignment.
Registered as the MLIR value caster for
ir.VectorType, so any op that returns a vector automatically produces aVectorinstance.- Parameters:
v (ir.Value) – Underlying MLIR vector value.
dtype (type, optional) – DSL element type (e.g.
Float32,Int32). Inferred from the MLIR element type when omitted.
- bitcast(dtype: type) Vector#
Reinterpret the vector bits as a different element type.
The total bit width is preserved; the element count adjusts proportionally. For example,
vector<4xi32>bitcast toFloat16yieldsvector<8xf16>(4 × 32 = 8 × 16 bits).
- static from_elements(
- scalars: tuple,
- dtype: Type[Numeric],
Build a 1-D
Vectorfrom a tuple of scalar values.
- ir_value() ir.Value#
Return the underlying MLIR vector value.
- numel() int#
Total number of elements (product of all shape dimensions).
- reduce(
- op: Literal['add', 'mul', 'min', 'max'] = 'add',
- *,
- dim: int | list[int] | None = None,
- acc: Any = None,
Reduce the vector using the specified combining operation.
When
dimisNone(default), reduces all dimensions to a scalar viavector.reduction. Whendimis an int or list of ints, reduces only those dimensions viavector.multi_reduction, returning a lower-rankVector.- Parameters:
op – Reduction operation — one of
"add","mul","min","max". For"min"/"max"the combining kind adapts automatically to the element type (float vs signed vs unsigned integer).dim – Dimension(s) to reduce.
Nonereduces all dims to a scalar. An int or list of ints reduces only those dims.acc – Optional accumulator. For scalar reduction a scalar value; for multi-dim reduction a vector matching the result shape.
- Returns:
Scalar (when
dim is None) orVector(whendimis specified).
Examples
v = cute.full((4,), 3.0, dtype=cutlass.Float32).to_vector() v.reduce("add") # 12.0 (scalar) m = cute.full((4, 8), 1.0, dtype=cutlass.Float32).to_vector() m.reduce("add", dim=1) # vector<4xf32>, each element = 8.0 m.reduce("add", dim=0) # vector<8xf32>, each element = 4.0
Note
This method operates on a
Vectorvalue. If a higher-level API in a downstream library returns a different SSA wrapper with its ownreduce(...)method and a different signature, call that library’s.to_vector()(or equivalent) to get a plainVectorfirst so this 1-arg form applies.Note
Vector.reducebuilds an MLIRvector.reductionover the elements of one register vector. It is not the warp-collectivenvvm.redux_syncAPI. If a backend or target-specific lowering maps a reduction to PTXredux.sync, PTX legality still applies: integer/bitwiseredux.syncforms requiresm_80or higher, whileredux.sync.f32min/max support was added in PTX ISA 8.6 and is limited tosm_100aplus thesm_100ffamily support added in PTX ISA 8.8. For examples that must remain portable to genericsm_120targets, prefer an explicit scalar fold or shuffle tree forFloat32min/max instead of relying on a lowering that may chooseredux.sync.f32.
- property shape: tuple[int, ...]#
The logical shape of the vector array (1D, 2D, or 3D).
- to(dtype: type) Vector#
Convert the vector elements to a different numeric type.
- Parameters:
dtype (Type[Numeric]) – Target DSL element type (e.g.
Float16,Int32).- Returns:
A new
Vectorwith the same shape and elements cast todtype.- Return type:
- Raises:
TypeError – If
dtypeis not a subclass ofNumeric.
Example:
vec_f32 = cute.full((4,), 1.5, dtype=cutlass.Float32).to_vector() vec_i32 = vec_f32.to(cutlass.Int32) # fp → int truncation vec_f16 = vec_f32.to(cutlass.Float16) # fp32 → fp16 narrowing