0
Fork 0
mirror of https://github.com/zml/zml.git synced 2026-11-16 19:11:09 +00:00
zml/mlir/dialects/cute_ir
Benjamin Rabier 86ab457d0b
dsl/cute: add SM100 primitives and CTA-group support (#1007)
Add helpers for TMA gather/prefetch, weight-stationary MMA,
shared-memory descriptors, packed FP32 arithmetic, async cluster stores,
and register limits.

Make CTA groups and barrier scopes explicit across TMA, block-scaled
MMA, TMEM, and synchronization, including two-CTA operations and
multicast completion. Consolidate named CTA barriers and update the MoE
and paged-attention callers.

Cover instruction operands, descriptor encoding, and MLIR round-trips in
builder tests.
History 2026-11-03 10:26:31 +01:00
..
BUILD.bazel mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
capi.cc dsl/cute: add SM100 primitives and CTA-group support (#1007) 2026-11-03 10:26:31 +01:00
capi.h dsl/cute: add SM100 primitives and CTA-group support (#1007) 2026-11-03 10:26:31 +01:00
cute_ir.zig dsl/cute: add SM100 primitives and CTA-group support (#1007) 2026-11-03 10:26:31 +01:00
CuteAttrsAll.td mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
CuteAttrsCompiler.td mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
CuteEnums.td mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
CuteInference.cpp mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
CuteInference.h mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
CuteOps.cpp mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
CuteOps.td mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
CuteTypes.cpp mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
CuteTypesAll.td mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
CuteTypesCompiler.td mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
README.md mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
REGENERATING.md mlir/dialects: split into one package per dialect and unify them (#982) 2026-10-26 11:41:05 +01:00
test.zig mlir/dialects: build every remaining op and attribute through the dialect packages (#993) 2026-10-27 17:53:31 +01:00

CuTe dialects and Zig bindings

mlir/dialects/cute_ir is the CuTe dialect of nvidia-cutlass-dsl 4.8.0. The dialect, attributes, public types and cutegen layout algebra come verbatim from the CUTLASS release's cutlass_compiler/ tree (@cute_ir, pinned in third_party/cute_ir, one patch giving cutegen the ?{div=N} leaf); this tree carries what differs from it: CuteTypes.cpp with the compiler's remaining types, attributes and enums and ratio strides allowed, the compiler's attributes, types and enums beyond the release (CuteAttrsCompiler.td, CuteTypesCompiler.td, CuteEnums.td and the ../cute_nvgpu definitions), and every operation of the compiler's registry in CuteOps.td and the companion CuteNVGPUOps.td.

The companion dialects live in ../cute_nvgpu, ../nvvm, and ../cuda, with separate Bazel targets and Zig modules. NVIDIA's nvvm differs from upstream's. The CuTe builder registers these dialects together with upstream llvm.

Updating to a new DSL release means refreshing the compiler entry-point offsets and regenerating the .td files from the release's Python bindings and compiler. The C API (except the algebra attribute functions in capi.cc) and the Zig types, attributes, enums and operation builders are generated from those .td files and follow them.

Zig

Depend on //mlir/dialects/cute_ir and import mlir/dialects/cute_ir. cute.registerDialect(registry) registers cute.

Import each companion dialect explicitly and add its Bazel dependency: mlir/dialects/cute_nvgpu, mlir/dialects/nvvm, and mlir/dialects/cuda. CUDA and NVVM expose generated bindings in .ops and convenience builders at the module root. NVIDIA's NVVM handle is cute_nvvm; its dialect cannot share a registry with upstream NVVM.

const cute = @import("mlir/dialects/cute_ir");

const pointer = try cute.PtrType.get(ctx, .{
    .valueType = .float(ctx, .f32),
    .addressSpace = .smem,
    .alignment = 16,
});
const layout_attr = try cute.LayoutAttr.get(ctx, .{
    .shape = try .getStatic(ctx, 4),
    .stride = try .getStatic(ctx, 1),
});
const layout = try cute.LayoutType.get(ctx, .{ .attr = layout_attr.attribute() });
const memref = try cute.MemRefType.get(ctx, .{
    .ptr = pointer.type_(),
    .layout = layout.type_(),
});
const alloc = cute.memref_alloc_smem(ctx, memref.type_(), loc).appendTo(block);

The bindings follow mlir/dialects/README.md. Algebra types take an algebra attribute, cute.LayoutType.get(ctx, .{ .attr = layout_attr.attribute() }). Algebra attributes are built bottom up with named constructors: integer tuples, coordinates, shapes and strides from getStatic, getDynamic, getBasis (strides) or getUnderscore (coordinates) leaves and getTuple; layouts from a shape and a stride; tiles from getLayout, getUnderscore and getTuple; swizzles from their three parameters and composed layouts from an inner swizzle or layout, an offset and an outer layout. value() returns the canonical text. NVGPU atom types take their typed parameters, such as .valType and .copyBits. For reading existing IR use MLIR's generic Type.parse.

Operation builders take the operands, then the result types, then the attributes, then the location, and call mlir.Operation.make. Parameters follow ODS names, with a trailing underscore where needed. Result parameters append _type or _types; attributes take *const mlir.Attribute. Optional operands, attributes and result types go in a trailing opts struct whose fields default to null; pass .{} to omit them, and &.{} for empty variadic operands. Dots in mnemonics become underscores. Variable-length operand and result groups go through Operation.make's .variadic API, which writes the segment-size attributes. Builders verify the created operations; to defer verification, use mlir.Operation.make directly with .verify = false.

Builders of operations with regions (cuda.kernel) and of terminators (cuda.return) do not verify on creation, since their blocks are completed afterwards; the module is verified instead.

Each dialect exposes a :capi target and a package-local capi.h, independently of Zig: //mlir/dialects/cute_ir:capi, //mlir/dialects/cute_nvgpu:capi, //mlir/dialects/nvvm:capi, and //mlir/dialects/cuda:capi. C API declarations and definitions are grouped by registration, attributes, and types in capi.h and capi.cc. Constructors return a null handle for invalid parameters.

C++ implementations, headers, and TableGen sources live directly in each dialect package. Generated .inc files are emitted into the same package under Bazel's output tree. Virtual headers preserve upstream CuTe include paths required by the release sources.

bazel test //mlir/dialects/cute_ir:test //mlir/dialects/cute_nvgpu:test \
  //mlir/dialects/nvvm:test //mlir/dialects/cuda:test

These tests only check the bindings: every bound operation is registered, every type and attribute rebuilds from its getters, and a sample of the nvvm and cuda attributes and types print the compiler's own text byte for byte (#cuda<device_attributes{…}> and #cuda<func_attributes{…}> print with a space the compiler omits; it parses both). The dialect itself is tested where it is maintained. The dialects here do not implement the compiler's semantic verification or lowering.