12 #include <type_traits>
14 #ifndef ALPAKA_DISABLE_ATOMIC_ATOMICREF
15 # ifndef ALPAKA_HAS_STD_ATOMIC_REF
16 # include <boost/atomic.hpp>
23 # if defined(ALPAKA_HAS_STD_ATOMIC_REF)
46 "Type not supported by AtomicAtomicRef, please recompile defining "
47 "ALPAKA_DISABLE_ATOMIC_ATOMICREF.");
53 template<
typename T,
typename THierarchy>
58 isSupportedByAtomicAtomicRef<T>();
60 return ref.fetch_add(value);
65 template<
typename T,
typename THierarchy>
70 isSupportedByAtomicAtomicRef<T>();
72 return ref.fetch_sub(value);
77 template<
typename T,
typename THierarchy>
82 isSupportedByAtomicAtomicRef<T>();
87 while(!ref.compare_exchange_weak(old, result))
97 template<
typename T,
typename THierarchy>
102 isSupportedByAtomicAtomicRef<T>();
107 while(!ref.compare_exchange_weak(old, result))
117 template<
typename T,
typename THierarchy>
122 isSupportedByAtomicAtomicRef<T>();
126 while(!ref.compare_exchange_weak(old, result))
135 template<
typename T,
typename THierarchy>
140 isSupportedByAtomicAtomicRef<T>();
143 T result = ((old >= value) ? 0 :
static_cast<T
>(old + 1));
144 while(!ref.compare_exchange_weak(old, result))
146 result = ((old >= value) ? 0 :
static_cast<T
>(old + 1));
153 template<
typename T,
typename THierarchy>
158 isSupportedByAtomicAtomicRef<T>();
161 T result = ((old >= value) ? 0 :
static_cast<T
>(old - 1));
162 while(!ref.compare_exchange_weak(old, result))
164 result = ((old >= value) ? 0 :
static_cast<T
>(old - 1));
171 template<
typename T,
typename THierarchy>
176 isSupportedByAtomicAtomicRef<T>();
178 return ref.fetch_and(value);
183 template<
typename T,
typename THierarchy>
188 isSupportedByAtomicAtomicRef<T>();
190 return ref.fetch_or(value);
195 template<
typename T,
typename THierarchy>
200 isSupportedByAtomicAtomicRef<T>();
202 return ref.fetch_xor(value);
207 template<
typename T,
typename THierarchy>
216 isSupportedByAtomicAtomicRef<T>();
222 # if BOOST_COMP_GNUC || BOOST_COMP_CLANG
223 # pragma GCC diagnostic push
224 # pragma GCC diagnostic ignored "-Wfloat-equal"
226 result = ((old == compare) ? value : old);
227 # if BOOST_COMP_GNUC || BOOST_COMP_CLANG
228 # pragma GCC diagnostic pop
230 }
while(!ref.compare_exchange_weak(old, result));
The atomic ops based on atomic_ref for CPU accelerators.
boost::atomic_ref< T > atomic_ref
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto max(T const &max_ctx, Tx const &x, Ty const &y)
Returns the larger of two arguments. NaNs are treated as missing data (between a NaN and a numeric va...
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto min(T const &min_ctx, Tx const &x, Ty const &y)
Returns the smaller of two arguments. NaNs are treated as missing data (between a NaN and a numeric v...
The alpaka accelerator library.
void isSupportedByAtomicAtomicRef()
The addition function object.
The compare and swap function object.
The decrement function object.
The exchange function object.
The increment function object.
The maximum function object.
The minimum function object.
The subtraction function object.
The exclusive or function object.
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &compare, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
static ALPAKA_FN_HOST auto atomicOp(AtomicAtomicRef const &, T *const addr, T const &value) -> T
The atomic operation trait.