gpucoder.atomicCAS
Atomically compare and swap value of variable in global or shared memory
Since R2021b
Description
The gpucoder.atomicCAS function reads a value from a global or
shared GPU memory location, compares the value to a second value, and, if the two values are
equal, writes a third value back to the memory location. In generated GPU
code, the operation is atomic, which means that a GPU thread performs the
read-modify-write operation without interference from other threads.
A = gpucoder.atomicCAS(
compares A,B,C)B to the value of A and, if the values are
the same, writes the value of C into A.
Call
the gpucoder.atomicCAS function directly inside a for-loop that
you want to execute on the GPU in the generated CUDA® code. Each iteration of the loop must be able to read and write to
A.
Use the
coder.gpu.kernel pragma before the loop that contains
gpucoder.atomicCAS.
Examples
Input Arguments
Extended Capabilities
Version History
Introduced in R2021b