Atomic Compare-and-Swap Memory

Atomically compare a memory location to an expected value and, if equal, replace it with a new value.

Vendor-Neutral Definition

tmp = *addr; if (tmp == compare) { *addr = swap }; return tmp - the read, compare, and conditional write happen as one indivisible memory operation.
⚠️ Cross-vendor mappings describe semantic relationships and are not guaranteed one-to-one compiler translations.
equivalent with restrictions Both atomically compare-and-conditionally-replace a memory location; PTX exposes this as its atom family's '.cas' modifier where AMDGPU has dedicated, per-address-space cmpswap/cmpstore mnemonics.
Property NVIDIA PTX AMDGPU
Instruction atom global_atomic_cmpswap, flat_atomic_cmpswap, ds_cmpstore_b32
ISA Layer Virtual Native
Data Types b32, b64, f32, f64, s32, u32, u64 b32
Version / Target Introduced PTX ISA 1.1 gfx1100, gfx1100

Important Differences

  • PTX's atom.space.cas.type is one family selected by a modifier on the generic atom mnemonic; AMDGPU has separate mnemonics per address space (global_atomic_cmpswap for global memory, ds_cmpstore_b32 for LDS/shared memory, flat_atomic_cmpswap for the flat/generic aperture) with no single unified mnemonic.
  • The returned value's exact semantics (old value vs. success flag) should be checked per-instruction against the cited sources rather than assumed identical across vendors.

Source Evidence

Verification method: documentation