Skip to main content

Compilation failures

xcrun: error: unable to find utility "metal"

The Metal compiler is not in your PATH. This almost always means Xcode Command Line Tools are not installed or need to be re-selected.
If xcrun is present but the metal tool is missing, try:

Tracer TypeError

You are mixing a Python value with an IRValue in a way the tracer cannot handle. Make sure all kernel-body computation goes through IRValue objects. Integer and float literals are fine — Python variables holding IRValue nodes are fine — but numpy arrays, Python lists, or conditionals on IRValue objects are not. Wrong:
Correct:

EnigmaError: tiler exceeds tensor in mode N

A layout division produced a tiler dimension larger than the tensor dimension. Print the shape and stride of the tensor and tiler at each step:

Dispatch failures

Wrong output shape or garbage values

The most common causes:

output_size gotcha

output_size is in bytes, not elements:

Runtime dispatch exception

When rt.execute() raises, the error message includes the kernel name, grid, threads, and the Metal return code. Check:
  1. Kernel name matches what you compiled
  2. Grid × threadgroup size covers your data range
  3. Input dtypes match kernel parameter types
Try dispatching with a minimal input (e.g. n=32) to isolate the failure.

Correctness issues

Values differ between GPU and CPU

GPU floating-point order of operations differs from CPU. Use loose tolerances:
For reductions especially, large input arrays accumulate floating-point error. Compare relative error rather than absolute.

Vectorized kernel produces wrong results

When using vec_width=4, the grid must be divided by the vector width:

2D kernel has transposed output

Enigma uses the Metal convention: x is the fast (column) dimension and y is the slow (row) dimension. Ensure grid and kernel indexing agree: