Supported Atomic Operations

Numba-dpex supports some of the atomic operations supported in DPC++. Those that are presently implemented are as follows:

class numba_dpex.ocl.stubs.atomic
add(ary, idx, val)

Performs atomic addition ary[idx] += val.

Parameters:
ary: An array on which the atomic operation is performed.

Allowed types: int32, int64, float32, or float64

idx (int): Index of the array element, on which atomic operation is performed

val: The value of an increment.

Its type must match the type of array elements, ary[]

Returns:

The old value at the index location ary[idx] as if it is loaded atomically.

Raises:

None

sub(ary, idx, val)

Performs atomic subtraction ary[idx] -= val.

Parameters:
ary: An array on which the atomic operation is performed.

Allowed types: int32, int64, float32, or float64

idx (int): Index of the array element, on which atomic operation is performed

val: The value of a decrement.

Its type must match the type of array elements, ary[]

Returns:

The old value at the index location ary[idx] as if it is loaded atomically.

Raises:

None

Example

Example usage of atomic operations

Note

The numba_dpex.atomic.add function is analogous to The numba.cuda.atomic.add provided by the numba.cuda backend.

Generating Native FP Atomics

Numba-dpex supports generating native floating-point atomics. This feature is experimental. Users will need to provide the following environment variables to activate it.

NUMBA_DPEX_ACTIVATE_ATOMICS_FP_NATIVE=1

Example command:

NUMBA_DPEX_ACTIVATE_ATOMICS_FP_NATIVE=1 \
python program.py

Full examples

  • numba_dpex/examples/atomic_op.py