gpucoder.atomicAdd
Description
The gpucoder.atomicAdd function reads a value from a global or
shared GPU memory location, adds to the value, and writes the result 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.atomicAdd(
atomically adds the value in the global or shared GPU memory location, A,B)A,
to the value of B and writes the results back into A.
Call
the gpucoder.atomicAdd 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.
[A,oldA] = gpucoder.atomicAdd(
returns
the previous value of A,B)A as oldA. When you use this syntax,
use the coder.gpu.kernel pragma before the loop that contains
gpucoder.atomicAdd.
Examples
Input Arguments
Extended Capabilities
Version History
Introduced in R2021b