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.
xcrun is present but the metal tool is missing, try:
Tracer TypeError
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:
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:| Symptom | Likely cause | Fix |
|---|---|---|
| Last N elements are zero | grid too small | Set grid=(n, 1, 1) to cover all elements |
| Values are 2× or 4× wrong offset | Wrong stride in index math | Check row/column ordering in kernel index |
| Values look like memory garbage | output_size too small | Use elements * sizeof(dtype) in bytes |
| Values are consistently off by a constant | Buffer bound wrong | Verify input array ordering and dtype |
output_size gotcha
output_size is in bytes, not elements:
Runtime dispatch exception
Whenrt.execute() raises, the error message includes the kernel name, grid, threads, and the Metal return code. Check:
- Kernel name matches what you compiled
- Grid × threadgroup size covers your data range
- Input dtypes match kernel parameter types
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:Vectorized kernel produces wrong results
When usingvec_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:
