GpuAtomicFetchAdd

Adds to an integer in device memory atomically, and gives its old value.

声明

语法

GpuAtomicFetchAdd(expr target, expr increment, ttype type, expr? value)

参数

Argument

描述

target

the integer(4) array element to add to; the array has to be in device memory.

increment

the integer(4) value to add.

type

the type of the expression, integer(4).

value

always nil: the expression has no compile time value.

返回值

The value target held just before the addition.

描述

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).

示例

(GpuAtomicFetchAdd
  (ArrayItem
    (Var 3 __gpu_heap_state)
    [(()
    (IntegerConstant 2 (Integer 4) Decimal)
    ())]
    (Integer 4)
    ColMajor
    ()
  )
  (Var 3 n)
  (Integer 4)
  ()
)

也可以看看

exec_space, GpuKernelLaunch, GpuThreadIndex