18#ifdef ALPAKA_DISABLE_STD_ATOMIC_REF
19# include <boost/atomic.hpp>
26#if defined(ALPAKA_DISABLE_STD_ATOMIC_REF)
28 using atomic_ref = boost::atomic_ref<T>;
29 constexpr auto memory_order_relaxed = boost::memory_order_relaxed;
32 using atomic_ref = std::atomic_ref<T>;
33 constexpr auto memory_order_relaxed = std::memory_order_relaxed;
50 std::is_trivially_copyable_v<T> && detail::atomic_ref<T>::required_alignment <=
alignof(T),
51 "Type not supported by AtomicAtomicRef, please recompile defining "
52 "ALPAKA_DISABLE_ATOMIC_ATOMICREF.");
55 namespace internalCompute
58 template<
typename T,
typename T_Scope>
59 struct Atomic::Op<
operation::Add, internal::StlAtomic, T, T_Scope>
64 detail::atomic_ref<T> ref(*addr);
65 return ref.fetch_add(value, detail::memory_order_relaxed);
70 template<
typename T,
typename T_Scope>
71 struct Atomic::Op<
alpaka::operation::Sub, internal::StlAtomic, T, T_Scope>
76 detail::atomic_ref<T> ref(*addr);
77 return ref.fetch_sub(value, detail::memory_order_relaxed);
82 template<
typename T,
typename T_Scope>
83 struct Atomic::Op<
alpaka::operation::Min, internal::StlAtomic, T, T_Scope>
88 detail::atomic_ref<T> ref(*addr);
91 result = std::min(result, value);
92 while(!ref.compare_exchange_weak(old, result, detail::memory_order_relaxed))
95 result = std::min(result, value);
102 template<
typename T,
typename T_Scope>
103 struct Atomic::Op<
alpaka::operation::Max, internal::StlAtomic, T, T_Scope>
108 detail::atomic_ref<T> ref(*addr);
111 result = std::max(result, value);
112 while(!ref.compare_exchange_weak(old, result, detail::memory_order_relaxed))
115 result = std::max(result, value);
122 template<
typename T,
typename T_Scope>
123 struct Atomic::Op<
alpaka::operation::Exch, internal::StlAtomic, T, T_Scope>
128 detail::atomic_ref<T> ref(*addr);
131 while(!ref.compare_exchange_weak(old, result, detail::memory_order_relaxed))
140 template<
typename T,
typename T_Scope>
141 struct Atomic::Op<
alpaka::operation::Inc, internal::StlAtomic, T, T_Scope>
146 detail::atomic_ref<T> ref(*addr);
151 result = ((old >= value) ? T{0} : old + T{1});
152 }
while(!ref.compare_exchange_weak(old, result, detail::memory_order_relaxed));
158 template<
typename T,
typename T_Scope>
159 struct Atomic::Op<
alpaka::operation::Dec, internal::StlAtomic, T, T_Scope>
164 detail::atomic_ref<T> ref(*addr);
169 result = (old == T{0} || old > value) ? value : (old - T{1});
170 }
while(!ref.compare_exchange_weak(old, result, detail::memory_order_relaxed));
176 template<
typename T,
typename T_Scope>
177 struct Atomic::Op<
alpaka::operation::And, internal::StlAtomic, T, T_Scope>
182 detail::atomic_ref<T> ref(*addr);
183 return ref.fetch_and(value, detail::memory_order_relaxed);
188 template<
typename T,
typename T_Scope>
189 struct Atomic::Op<
alpaka::operation::Or, internal::StlAtomic, T, T_Scope>
194 detail::atomic_ref<T> ref(*addr);
195 return ref.fetch_or(value, detail::memory_order_relaxed);
200 template<
typename T,
typename T_Scope>
201 struct Atomic::Op<
alpaka::operation::Xor, internal::StlAtomic, T, T_Scope>
206 detail::atomic_ref<T> ref(*addr);
207 return ref.fetch_xor(value, detail::memory_order_relaxed);
212 template<
typename T,
typename T_Scope>
213 struct Atomic::Op<
alpaka::operation::Cas, internal::StlAtomic, T, T_Scope>
216 internal::StlAtomic
const&,
222 detail::atomic_ref<T> ref(*addr);
227#if ALPAKA_COMP_GNUC || ALPAKA_COMP_CLANG
228# pragma GCC diagnostic push
229# pragma GCC diagnostic ignored "-Wfloat-equal"
231 result = ((old == compare) ? value : old);
232#if ALPAKA_COMP_GNUC || ALPAKA_COMP_CLANG
233# pragma GCC diagnostic pop
235 }
while(!ref.compare_exchange_weak(old, result, detail::memory_order_relaxed));
The atomic ops based on atomic_ref for CPU accelerators.
#define ALPAKA_FN_HOST
All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_F...
functionality which is usable on the accelerator compute device from within a kernel.
constexpr auto atomicOp(auto const &acc, T *const addr, T const &value, T_Scope const scope=T_Scope()) -> T
Executes the given operation atomically.
void isSupportedByAtomicAtomicRef()
Contains functors with operation following the atomic operation semantics.