GpuAtomicFetchAdd¶
Adds to an integer in device memory atomically, and gives its old value.
Declaration¶
Syntax¶
GpuAtomicFetchAdd(expr target, expr increment, ttype type, expr? value)
Arguments¶
Argument |
Description |
|---|---|
|
the |
|
the |
|
the type of the expression, |
|
always |
Return values¶
The value target held just before the addition.
Description¶
The addition and the read of the old value are one indivisible operation
with relaxed memory ordering: when several threads add to the same target,
every thread gets a different old value, and the target ends up holding the
sum of all the increments. It is how device code takes memory from the
device heap (see "Allocating on the device" in the GPU offloading design).
The verifier checks that it is in device code (a procedure that runs only on
the device), that target is an element of an array, and that target,
increment and type are integer(4).
Examples¶
(GpuAtomicFetchAdd
(ArrayItem
(Var 3 __gpu_heap_state)
[(()
(IntegerConstant 2 (Integer 4) Decimal)
())]
(Integer 4)
ColMajor
()
)
(Var 3 n)
(Integer 4)
()
)