Skip to main content
This page walks through writing, compiling, and running a vector-add kernel — the minimal end-to-end path in Enigma.

Step 1: define the kernel

Decorate a Python function with @enigma.kernel. The function body is traced, not executed: each expression becomes an IR node, not a Python value.
What this does:
  • A, B, C are typed buffer parameters (f32 = float in Metal)
  • thread_position_in_grid returns the global thread ID as an IRValue
  • Indexing A[tid] emits a load; assigning C[tid] = ... emits a store

Step 2: compile to a Metal library

enigma.compile runs the full pipeline:
  1. Traces the Python function to an IR
  2. Lowers the IR to the Enigma MLIR dialect
  3. Emits Metal Shading Language (MSL) source
  4. Invokes xcrun metal and xcrun metallib
  5. Returns a CompiledKernel with all artifacts

Inspect the output

Compile with verbose output

Step 3: dispatch

Key parameters

Step 4: validate

Common first-run mistakes

Next steps