Skip to main content
Metal defines four address spaces that correspond to different physical memory locations on the GPU. Enigma maps these to distinct kernel operations.

Address spaces

Device memory

All kernel buffer parameters (A: enigma.f32, etc.) are in device memory. Indexed access emits global loads and stores:
With vec_width=4, Enigma emits device float4* paths where alignment allows, improving memory bandwidth utilization.

Threadgroup (shared) memory

Threadgroup memory is a scratchpad shared by all threads in a threadgroup. It is fast, limited (typically 32 KB), and requires explicit synchronization. Allocate with enigma.threadgroup_alloc:
Key rules:
  • Always call enigma.barrier() between a write and a cross-thread read.
  • Allocation size is fixed at compile time.
  • The mem_flags argument controls which memory types the barrier synchronizes.

Barrier flags

Scalar parameters

enigma.Scalar(dtype) parameters are lowered as 1-element device buffers and auto-loaded at kernel entry. Use them for per-dispatch constants that vary across calls:

Higher-level memory primitives

The DSL provides register-and-pipeline building blocks for staged compute patterns: These are building blocks for advanced tiled GEMM and attention kernels. See Layout Algebra for the tiling workflow.

Device capabilities

Query hardware limits before using feature-gated operations:

Capability fields

Requiring capabilities

Gating kernel paths