Splits the monolithic mlir/dialects library into one Bazel package per dialect, then makes every package follow the same layout, C API and Zig API. Each package owns its Zig bindings, its C API when upstream doesn't provide one, and its tests. Dialect registration moves out of the core mlir package, so a target only pulls in the dialects it actually uses. The conventions are documented in `mlir/dialects/README.md`, with a porting checklist and conformance checks. Along the way: - cute_ir is flattened, and its Cuda, CuteNVGPU and NVVM sub-dialects become their own packages - fly's ROCDL extension moves to fly_rocdl - new packages for ROCDL and UB - kernels/ is renamed to dsl/, since it holds the DSLs - every package registers through its own registerDialect, and each DSL through registerDialects, instead of dialect name strings - the C and C++ follow the LLVM and MLIR C API conventions, formatted with a new mlir/.clang-format - BUILD files share one template - accessors are named as nouns like in the rest of ZML - each package tests itself in its own test.zig, including that every bound operation is registered and that every wrapper method compiles Fixes: - memref atomic_rmw emitted the wrong kind, because the AtomicRMWKind values didn't match the pinned LLVM - the pinned Triton and Mosaic no longer have tt.cat and tpu.repeat, so the DSL's cat and repeat now lower the way tl.cat and pltpu.repeat do - the ROCDL bindings are completed: buffer address spaces, vector types, waves_per_eu range Breaking changes: - register dialects through their package instead of DialectHandle.fromString, and mlir.registerFuncExtensions becomes func.registerExtensions - accessors drop the get prefix, so getValue() becomes value() - ttir.cat and mosaic_tpu.repeat are removed, and stablehlo pad and mosaic_tpu sort take their options before the location - zml.kernel.fly.rocdl becomes fly_rocdl - Mesh.sdyMeshAttr takes a context and returns an attribute instead of text - func.func no longer prints public, its default visibility --------- Co-authored-by: Steeve Morin <steeve@zml.ai> |
History
|
|
|---|---|---|
| .. | ||
| annotations.zig | ||
| attributes.zig | ||
| BUILD.bazel | ||
| capi.cc | ||
| capi.h | ||
| enums.zig | ||
| ops.zig | ||
| README.md | ||
| REGENERATING.md | ||
| rocdl.zig | ||
| target.zig | ||
| test.zig | ||
| types.zig | ||
ROCDL
Depend on //mlir/dialects/rocdl and import mlir/dialects/rocdl for LLVM's
AMDGPU intrinsic dialect. The package links LLVM's ROCDLDialect and
CAPIROCDL. fly_rocdl is a separate dialect and package.
The pinned LLVM revision supplies 374 operations, 15 attributes, and 12 enums.
opsprovides every operation builder. Names replace dots with underscores, such asops.raw_buffer_loadandops.mfma_f32_16x16x4f32. Arguments are operands, explicit result types, required attributes, anoptsstruct when there are optional attributes, and the location, preceded by the MLIR context. Attribute names match ODS. Optional and default-valued attributes are fields ofoptswithnulldefaults; pass.{}to omit them and let MLIR supply its defaults. Builders verify the resulting operation.- Enum types and attribute wrappers are available at the module root and in
enums/attributes. Attribute constructors returnerror.InvalidMlirfor invalid enum values or flag bits. Bit enums supportcombineandcontains. TargetAttrconstructs and reads#rocdl.target, including optimization level, triple, chip, features, ABI, flags, and link files. Defaults match LLVM. Invalid fields and attributes from another context are rejected.annotationssupplies function, module, and memory annotations. Apply function annotations tollvm.func, andxnack/srameccto LLVM-compatible modules. A missing module option preserves the target default;falseexplicitly disables the option.typessupplies every builtin vector type ROCDL's TableGen records use, named or inline, and LLVM pointers in ROCDL address spaces. ROCDL defines no independent MLIR types.registerDialectregisters ROCDL; loading it also loads its LLVM dependency. The existingcvtPkF32Fp8convenience builder remains available.
const rocdl = @import("mlir/dialects/rocdl");
const policy = try rocdl.Gfx942CachePolicyAttr.get(ctx, .{ .value = .combine(&.{ .sc0, .nt }) });
const load = rocdl.ops.raw_buffer_load(
ctx, resource, offset, scalar_offset,
mlir.Type.float(ctx, .f32), .{ .aux = policy.attribute() }, location,
);
The :capi target exposes attribute constructors, predicates, and getters
through capi.h; dialect registration comes from upstream
mlir-c/Dialect/ROCDL.h. Declarations and implementations are grouped by
introspection (a test helper), attributes, and target configuration. Getters require a handle
accepted by the matching predicate. Contexts own all returned attributes and
strings. There are no additional C operation wrappers: Zig builders use MLIR's
standard operation API.
Tests compare the generated operation list with the loaded dialect's registered operation count, check every operation name, round-trip every named enum value, reject invalid enum/target inputs, and verify and reparse representative barrier, scheduling, buffer, and matrix operations in an LLVM function. The tests require no AMD GPU or ROCm runtime.