cl::sycl::atomic< T, addressSpace > Struct Template Reference
Atomic class template. More...
#include <atomic.h>
Public Member Functions | |
template<typename pointerT > | |
atomic (multi_ptr< pointerT, addressSpace > ptr) | |
Constructs an instance of SYCL atomic which is associated with the pointer ptr, converted to a pointer of data type T. More... | |
void | store (T operand, memory_order mem_order=memory_order::relaxed) const noexcept |
Atomically store operand in m_data. More... | |
T | load (memory_order mem_order=memory_order::relaxed) const |
Atomically load from m_data. More... | |
T | exchange (T operand, memory_order mem_order=memory_order::relaxed) const noexcept |
Atomically exchange operand with *m_data. More... | |
cl_bool | compare_exchange_strong (T &expected, T desired, memory_order success=memory_order::relaxed, memory_order fail=memory_order::relaxed) const noexcept |
Atomically compare and optionally exchange expected with *m_data. More... | |
T | fetch_add (difference_t operand, memory_order mem_order=memory_order::relaxed) const noexcept |
Atomically add operand to *m_data. More... | |
T | fetch_sub (difference_t operand, memory_order mem_order=memory_order::relaxed) const noexcept |
Atomically subtract operand from *m_data. More... | |
T | fetch_and (T operand, memory_order mem_order=memory_order::relaxed) const noexcept |
Atomically bitwise-and operand with *m_data. More... | |
T | fetch_or (T operand, memory_order=memory_order::relaxed) const noexcept |
Atomically bitwise-or operand with *m_data. More... | |
T | fetch_xor (T operand, memory_order mem_order=memory_order::relaxed) const noexcept |
Atomically bitwise-XOR operand with *m_data. More... | |
T | fetch_min (T operand, memory_order mem_order=memory_order::relaxed) const noexcept |
Atomically compare operand to *m_data, storing the smaller of the two in *m_data. More... | |
T | fetch_max (T operand, memory_order mem_order=memory_order::relaxed) const noexcept |
Atomically compare operand to *m_data, storing the larger of the two in *m_data. More... | |
Detailed Description
template<typename T, access::address_space addressSpace>
struct cl::sycl::atomic< T, addressSpace >
Atomic class template.
Implementation of the SYCL atomic class according to 1.2 spec.
This template class specifies the interface and internal data of atomics as specified by SYCL. It offers several different atomic operations, including min/max which are not otherwise available in C++ 11 code. Most of the file is visible to the device compiler only; this is so that the runtime can call the appropriate atomic function based on the type of the elements. A portion is visible to both (class declaration and global functions) with a small section for the host-only implementation. The device compiler section has separate specializations for each pair of template parameters. They are organized primarily by type (cl_int, cl_uint etc.) and secondarily by address space (global then local). It is done like this because the SPIR function to be called is different based on the type and address space of the atomic.
(section 3.8). On host, calls C++ atomic functions on an std::atomic; on device uses SPIR-mangled OpenCL 1.2 functions to achieve same result.
Constructor & Destructor Documentation
◆ atomic()
|
inline |
Constructs an instance of SYCL atomic which is associated with the pointer ptr, converted to a pointer of data type T.
Permitted data types for pointerT is any valid scalar data type which is the same size in bytes as T.
- Template Parameters
-
pointerT Underlying type of the pointer ptr
- Parameters
-
ptr Pointer to be used in an atomic manner
Member Function Documentation
◆ compare_exchange_strong()
|
noexcept |
Atomically compare and optionally exchange expected with *m_data.
Calls C++11 equivalent on host, has to be implemented "by hand" on device because OpenCL 1.2 and C++ 11 have different semantics for compare and exchange. If *m_data == expected, performs *m_data = desired and returns true. Otherwise, performs expected = *m_data and returns false.
- Parameters
-
expected The value to compare against *m_data. desired The value to store in *m_data on success. success the ordering to use when comparison succeeds. Can only be memory_order_relaxed. fail the ordering to use when comparison fails. Can only be memory_order_relaxed.
- Returns
- True if comparison succeeds, false if it fails.
◆ exchange()
|
noexcept |
Atomically exchange operand with *m_data.
- Parameters
-
operand the value to store in *m_data. mem_order the ordering to use. Can only be memory_order_relaxed.
- Returns
- The old value of *m_data.
◆ fetch_add()
|
noexcept |
Atomically add operand to *m_data.
param operand the value to add to *m_data. param mem_order the ordering to use. Can only be memory_order_relaxed. return the old value of *m_data.
◆ fetch_and()
|
noexcept |
Atomically bitwise-and operand with *m_data.
- Parameters
-
operand the value to and with *m_data. mem_order the ordering to use. Can only be memory_order_relaxed.
- Returns
- the old value of *m_data.
◆ fetch_max()
|
noexcept |
Atomically compare operand to *m_data, storing the larger of the two in *m_data.
- Parameters
-
operand the value to compare to *m_data. mem_order the ordering to use. Can only be memory_order_relaxed.
- Returns
- the old value of *m_data.
◆ fetch_min()
|
noexcept |
Atomically compare operand to *m_data, storing the smaller of the two in *m_data.
- Parameters
-
operand the value to compare to *m_data. mem_order the ordering to use. Can only be memory_order_relaxed.
- Returns
- the old value of *m_data.
◆ fetch_or()
|
noexcept |
Atomically bitwise-or operand with *m_data.
- Parameters
-
operand the value to or with *m_data. mem_order the ordering to use. Can only be memory_order_relaxed.
- Returns
- the old value of *m_data.
◆ fetch_sub()
|
noexcept |
Atomically subtract operand from *m_data.
- Parameters
-
operand the value to subtract from *m_data. mem_order the ordering to use. Can only be memory_order_relaxed.
- Returns
- the old value of m_data.
◆ fetch_xor()
|
noexcept |
Atomically bitwise-XOR operand with *m_data.
- Parameters
-
operand the value to XOR with *m_data. mem_order the ordering to use. Can only be memory_order_relaxed.
- Returns
- the old value of *m_data.
◆ load()
T cl::sycl::atomic< T, addressSpace >::load | ( | memory_order | mem_order = memory_order::relaxed | ) | const |
Atomically load from m_data.
Calls C++11 equivalent on host, on device it either calls atomic_add with operand = 0, discarding the result.
- Parameters
-
mem_order the ordering to use. Can only be memory_order_relaxed.
- Returns
- The value loaded from m_data.
◆ store()
|
noexcept |
Atomically store operand in m_data.
Calls C++11 equivalent on host, on device it calls exchange, discarding the result.
- Parameters
-
operand the value to store in m_data. mem_order the ordering to use. Can only be memory_order_relaxed.
The documentation for this struct was generated from the following file: