7#if defined(ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED) || defined(ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLED) \
8 || defined(ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLED) || defined(ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLED) \
9 || defined(ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED)
16# include <type_traits>
18# ifndef ALPAKA_DISABLE_ATOMIC_ATOMICREF
19# ifndef ALPAKA_HAS_STD_ATOMIC_REF
20# include <boost/atomic.hpp>
27# if defined(ALPAKA_HAS_STD_ATOMIC_REF)
50 "Type not supported by AtomicAtomicRef, please recompile defining "
51 "ALPAKA_DISABLE_ATOMIC_ATOMICREF.");
57 template<
typename T,
typename THierarchy>
58 struct AtomicOp<AtomicAdd, AtomicAtomicRef, T, THierarchy>
62 isSupportedByAtomicAtomicRef<T>();
64 return ref.fetch_add(value);
69 template<
typename T,
typename THierarchy>
70 struct AtomicOp<AtomicSub, AtomicAtomicRef, T, THierarchy>
74 isSupportedByAtomicAtomicRef<T>();
76 return ref.fetch_sub(value);
81 template<
typename T,
typename THierarchy>
82 struct AtomicOp<AtomicMin, AtomicAtomicRef, T, THierarchy>
86 isSupportedByAtomicAtomicRef<T>();
90 result = std::min(result, value);
91 while(!ref.compare_exchange_weak(old, result))
94 result = std::min(result, value);
101 template<
typename T,
typename THierarchy>
102 struct AtomicOp<AtomicMax, AtomicAtomicRef, T, THierarchy>
106 isSupportedByAtomicAtomicRef<T>();
110 result = std::max(result, value);
111 while(!ref.compare_exchange_weak(old, result))
114 result = std::max(result, value);
121 template<
typename T,
typename THierarchy>
122 struct AtomicOp<AtomicExch, AtomicAtomicRef, T, THierarchy>
126 isSupportedByAtomicAtomicRef<T>();
130 while(!ref.compare_exchange_weak(old, result))
139 template<
typename T,
typename THierarchy>
140 struct AtomicOp<AtomicInc, AtomicAtomicRef, T, THierarchy>
144 isSupportedByAtomicAtomicRef<T>();
147 T result = ((old >= value) ? 0 : static_cast<T>(old + 1));
148 while(!ref.compare_exchange_weak(old, result))
150 result = ((old >= value) ? 0 : static_cast<T>(old + 1));
157 template<
typename T,
typename THierarchy>
158 struct AtomicOp<AtomicDec, AtomicAtomicRef, T, THierarchy>
162 isSupportedByAtomicAtomicRef<T>();
165 T result = ((old >= value) ? 0 : static_cast<T>(old - 1));
166 while(!ref.compare_exchange_weak(old, result))
168 result = ((old >= value) ? 0 : static_cast<T>(old - 1));
175 template<
typename T,
typename THierarchy>
176 struct AtomicOp<AtomicAnd, AtomicAtomicRef, T, THierarchy>
180 isSupportedByAtomicAtomicRef<T>();
182 return ref.fetch_and(value);
187 template<
typename T,
typename THierarchy>
188 struct AtomicOp<AtomicOr, AtomicAtomicRef, T, THierarchy>
192 isSupportedByAtomicAtomicRef<T>();
194 return ref.fetch_or(value);
199 template<
typename T,
typename THierarchy>
200 struct AtomicOp<AtomicXor, AtomicAtomicRef, T, THierarchy>
204 isSupportedByAtomicAtomicRef<T>();
206 return ref.fetch_xor(value);
211 template<
typename T,
typename THierarchy>
212 struct AtomicOp<AtomicCas, AtomicAtomicRef, T, THierarchy>
215 AtomicAtomicRef
const&,
220 isSupportedByAtomicAtomicRef<T>();
226# if ALPAKA_COMP_GNUC || ALPAKA_COMP_CLANG
227# pragma GCC diagnostic push
228# pragma GCC diagnostic ignored "-Wfloat-equal"
230 result = ((old == compare) ? value : old);
231# if ALPAKA_COMP_GNUC || ALPAKA_COMP_CLANG
232# pragma GCC diagnostic pop
234 }
while(!ref.compare_exchange_weak(old, result));
The atomic ops based on atomic_ref for CPU accelerators.
boost::atomic_ref< T > atomic_ref
The alpaka accelerator library.
void isSupportedByAtomicAtomicRef()
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto atomicOp(TAtomic const &atomic, T *const addr, T const &value, THierarchy const &=THierarchy()) -> T
Executes the given operation atomically.