CompiledKernel.
Signature
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
fn | @enigma.kernel or @enigma.jit | required | The kernel or JIT function to compile |
*jit_args | Tensor, … | — | For @enigma.jit: positional arguments passed to the JIT function at compile time |
vec_width | int | 0 | Vectorization lane width. 0 = scalar. 4 = float4 paths |
dump_ir | bool | False | Print the traced IR to stdout |
dump_mlir | bool | False | Print the Enigma dialect MLIR to stdout |
keep_metal_source | bool | False | Write .metal source file to work_dir |
work_dir | str | None | None | Directory for build artifacts. Defaults to a temp directory |
emit_only | bool | None | None | Skip Metal compilation. None = auto (True on non-macOS). True = emit MSL only (no .metallib) |
Returns: CompiledKernel
Attributes
| Attribute | Type | Description |
|---|---|---|
kernel_name | str | Metal function name, e.g. enigma_kernel_vector_add |
metallib_path | str | Absolute path to the compiled .metallib file |
metallib_bytes | bytes | Raw bytes of the .metallib |
metal_source | str | Generated Metal Shading Language source |
mlir_source | str | None | Enigma dialect MLIR (when dump_mlir=True) |
grid | tuple[int, int, int] | None | For @jit kernels: launch grid computed at compile time |
block | tuple[int, int, int] | None | For @jit kernels: threadgroup size computed at compile time |
Methods
export_metal(path: str) -> str
Write the generated Metal source to a file. Returns the resolved path.
Usage
Compiling a @enigma.kernel
With debug output
Vectorized compilation
Compiling a @enigma.jit function
Pass the Tensor arguments that the JIT function receives at compile time:
Errors
| Error | Cause |
|---|---|
xcrun exit code error | Metal compiler toolchain not found. Run xcrun -sdk macosx metal -v to diagnose. |
EnigmaError: tiler exceeds tensor | A layout division produced a tiler larger than the tensor in some mode. |
TypeError in tracer | Invalid operand types — check that you are not mixing Python values with IRValue in kernel bodies. |
