Skip to main content
This page documents the decorators that mark a Python function for GPU compilation, and the built-in queries that return thread and grid indices. For the conceptual overview, see Kernels and JIT.

@enigma.kernel

Marks a function as a GPU compute kernel. The body is traced once at compile time, producing an IR graph that is lowered to Metal Shading Language.

Parameter types

Each parameter must have a type annotation: Parameters map to MSL [[buffer(N)]] bindings in declaration order, starting at index 0. See Data Types for the full type table.

Returns

A KernelDef object. Do not call directly — pass to enigma.compile().

@enigma.jit

Marks a host-side function that runs at compile time. Use for layout algebra, tile partitioning, and multi-kernel orchestration.
Pass Tensor arguments to enigma.compile():
See Kernels and JIT for the full pattern.

Thread & grid queries

These return an IRValue of dtype "uint" representing a thread or group index. They are valid only inside @enigma.kernel bodies.

Shorthand (x dimension)

Per-dimension queries

Each query takes an optional dim argument: "x" (default), "y", or "z".

Flat queries (no dim parameter)

Example: 2D grid


Function constants

Metal specialization constants bound at pipeline creation time. Use these for values that should be compile-time-constant in the pipeline but selectable per dispatch (e.g. tile sizes, fusion flags).

enigma.function_constant(dtype, index) -> IRValue


arch namespace

Hardware-feature gating helpers. Use these to write kernels that adapt to the active GPU family. These are host-side helpers (not callable inside @enigma.kernel). For the runtime-side equivalent, see MetalRuntime.device_capabilities() in Runtime.