tilelang.contrib.cutedsl.atomic¶
Atomic operations for CuTeDSL backend.
This module provides implementations of atomic operations using NVVM and LLVM dialects.
Functions¶
|
Perform atomic addition on a pointer. |
|
Perform atomic addition and return the previous value. |
|
Vectorized atomic add for 2 consecutive elements. |
|
Vectorized atomic add for 2 consecutive elements, returning the previous values. |
|
Vectorized atomic add for 4 consecutive elements. |
|
Vectorized atomic add for 4 consecutive elements, returning the previous values. |
|
Perform atomic maximum operation. |
|
Perform atomic maximum and return the previous value. |
|
Perform atomic minimum operation. |
|
Perform atomic minimum and return the previous value. |
|
Perform atomic load with specified memory ordering. |
|
Perform atomic store with specified memory ordering. |
Module Contents¶
- tilelang.contrib.cutedsl.atomic.AtomicAdd(ptr, value, *, loc=None, ip=None)¶
Perform atomic addition on a pointer.
Supports float16, float32, int32, and int64 types. Returns the old value before addition (atomicrmw semantics).
- Parameters:
ptr (cutlass.cute.Pointer)
value (Numeric)
- tilelang.contrib.cutedsl.atomic.AtomicAddRet(ptr, value, *, loc=None, ip=None)¶
Perform atomic addition and return the previous value.
This is the same as AtomicAdd since prims.atomicrmw always returns old value.
- Parameters:
ptr (cutlass.cute.Pointer)
value (Numeric)
- tilelang.contrib.cutedsl.atomic.AtomicAddx2(dst_ptr, src_values, *, loc=None, ip=None)¶
Vectorized atomic add for 2 consecutive elements.
Follows
AtomicAddx2insrc/tl_templates/cuda/atomic.h: float16 and bfloat16 use one packedf16x2/bf16x2atomic (a CAS loop for bf16 below sm_90), which also works on shared memory; float32 usesatom.global.add.v2.f32on sm_90+ and two scalar atomics below.- Parameters:
dst_ptr (cutlass.cute.Pointer) – Pointer to destination (2 consecutive elements)
src_values – Source values - can be TensorSSA (loaded tensor) or Pointer
- tilelang.contrib.cutedsl.atomic.AtomicAddx2Ret(dst_ptr, src_values, *, loc=None, ip=None)¶
Vectorized atomic add for 2 consecutive elements, returning the previous values.
Follows
AtomicAddx2Retinsrc/tl_templates/cuda/atomic.h:float16/bfloat16: one packed
f16x2/bf16x2atomic (a CAS loop for bf16 below sm_90) with generic addressing, so shared memory works too.float32: one
atom.global.add.v2.f32on sm_90+, two scalar atomics below.
- Parameters:
dst_ptr (cutlass.cute.Pointer) – Pointer to destination (2 consecutive elements)
src_values – Source values - can be TensorSSA (loaded tensor) or Pointer
- tilelang.contrib.cutedsl.atomic.AtomicAddx4(dst_ptr, src_values, *, loc=None, ip=None)¶
Vectorized atomic add for 4 consecutive elements.
Follows
AtomicAddx4insrc/tl_templates/cuda/atomic.h. On sm_90+ it is oneatom.globalvector atomic (v4.f32orv4.{f16,bf16}); below that, float32 becomes four scalar atomics and 16-bit types two packed pair atomics.- Parameters:
dst_ptr (cutlass.cute.Pointer) – Pointer to destination (4 consecutive elements)
src_values – Source values - can be TensorSSA (loaded tensor) or Pointer
- tilelang.contrib.cutedsl.atomic.AtomicAddx4Ret(dst_ptr, src_values, *, loc=None, ip=None)¶
Vectorized atomic add for 4 consecutive elements, returning the previous values.
Follows
AtomicAddx4Retinsrc/tl_templates/cuda/atomic.h:float32: one
atom.global.add.v4.f32on sm_90+, four scalar atomics below.float16/bfloat16: no x4 atomic exists, so two packed pair atomics (
f16x2/bf16x2; a CAS loop for bf16 below sm_90). The 8-byte destination is never written as 16 bytes.
- Parameters:
dst_ptr (cutlass.cute.Pointer) – Pointer to destination (4 consecutive elements)
src_values – Source values - can be TensorSSA (loaded tensor) or Pointer
- tilelang.contrib.cutedsl.atomic.AtomicMax(ptr, value, *, loc=None, ip=None)¶
Perform atomic maximum operation.
For integers, uses prims.atomicrmw with MAX. For floats, uses CAS loop since PTX doesn’t have atomic max for float32.
- Parameters:
ptr (cutlass.cute.Pointer)
value (Numeric)
- tilelang.contrib.cutedsl.atomic.AtomicMaxRet(ptr, value, *, loc=None, ip=None)¶
Perform atomic maximum and return the previous value.
- Parameters:
ptr (cutlass.cute.Pointer)
value (Numeric)
- tilelang.contrib.cutedsl.atomic.AtomicMin(ptr, value, *, loc=None, ip=None)¶
Perform atomic minimum operation.
For integers, uses prims.atomicrmw with MIN. For floats, uses CAS loop since PTX doesn’t have atomic min for float32.
- Parameters:
ptr (cutlass.cute.Pointer)
value (Numeric)
- tilelang.contrib.cutedsl.atomic.AtomicMinRet(ptr, value, *, loc=None, ip=None)¶
Perform atomic minimum and return the previous value.
- Parameters:
ptr (cutlass.cute.Pointer)
value (Numeric)
- tilelang.contrib.cutedsl.atomic.AtomicLoad(ptr, memory_order, *, loc=None, ip=None)¶
Perform atomic load with specified memory ordering.
- Parameters:
ptr (cutlass.cute.Pointer) – Pointer to load from
memory_order (int) – TileLang memory order ID (0=relaxed, 2=acquire, 5=seq_cst, etc.)
- Returns:
The loaded value
- NVVM mapping:
relaxed: relaxed.gpu acquire: acquire.gpu seq_cst: fence.sc.gpu + relaxed.gpu
- tilelang.contrib.cutedsl.atomic.AtomicStore(ptr, value, memory_order, *, loc=None, ip=None)¶
Perform atomic store with specified memory ordering.
- Parameters:
ptr (cutlass.cute.Pointer) – Pointer to store to
value (Numeric) – Value to store
memory_order (int) – TileLang memory order ID (0=relaxed, 3=release, 5=seq_cst, etc.)
- NVVM mapping:
relaxed: relaxed.gpu release: release.gpu seq_cst: fence.sc.gpu + relaxed.gpu