Barriers
enigma.barrier(mem_flags="mem_threadgroup") -> None
Threadgroup barrier — every thread in the threadgroup must reach this point
before any can continue.
Accepted
mem_flags values:
enigma.simd_barrier(mem_flags="mem_threadgroup") -> None
SIMD-group barrier. Synchronizes only the 32 threads of one SIMD group.
Cheaper than a full threadgroup barrier when ordering is only needed within
a warp.
Same mem_flags values as enigma.barrier().
Threadgroup shared memory
enigma.threadgroup_alloc(dtype, size) -> TracingTensor
Allocates threadgroup T[size] storage local to the threadgroup.
Returns: A
TracingTensor supporting:
- Indexed access —
shared[i]for load,shared[i] = vfor store - Atomic methods —
shared.atomic_fetch_add(i, v),shared.atomic_load(i), etc. (see Atomic Operations)
Example: reverse via shared memory
Buffer indexing
Inside a kernel body, kernel-parameter buffers and threadgroup allocations both support index access:index may be:
- An
IRValue(from a grid query, arithmetic op, etc.) - A Python
int— auto-wrapped as auintconstant
Masked load / store
Predicated memory access for boundary handling without a fullenigma.if_.
enigma.load_if(buf, index, mask, default=0) -> IRValue
Loads buf[index] when mask is true, otherwise returns default. Always
emits an unconditional load followed by a select — safe for unrolled inner
loops where branching would inhibit vectorization.
enigma.store_if(buf, index, value, mask) -> None
Stores value to buf[index] only when mask is true. Lowered as
scf.if { store }.
Async copy (experimental)
Non-blocking device ↔ threadgroup data movement via AIR intrinsics. Requires M3 or newer.
See Async Copy for parameter details and
caveats.
See also
- Atomic Operations — full atomic API including CAS
- SIMD Group Operations — communication without barriers
- Registers, Copy & Pipeline —
register_tensor,copy,pipeline
