0Pricing
CUDA Academy · Lesson

Custom Atomics with atomicCAS

Compare-and-swap for any update.

When Built-Ins Run Out

The built-in atomics cover add, max, exchange and more. But what if you need an atomic update they do not provide? Meet atomicCAS. 🔁

Compare-And-Swap

atomicCAS means compare-and-swap. It writes a new value only if the current value matches what you expected, all in one atomic step.

atomicCAS(addr, expected, desired);

All lessons in this course

  1. Race Conditions on the GPU
  2. atomicAdd and Friends
  3. Building a Histogram
  4. Custom Atomics with atomicCAS
← Back to CUDA Academy