3#ifndef CUDA_BATTERY_MEMORY_HPP
4#define CUDA_BATTERY_MEMORY_HPP
16 #include <cuda/atomic>
28 struct value_type_of {
29 using type =
typename T::value_type;
32 template <
class V, cuda::thread_scope Scope>
33 struct value_type_of<cuda::atomic<V, Scope>> {
43 using value_type =
typename impl::value_type_of<A>::type;
49 this->store(other.load());
53 this->store(other.load());
59template <
bool read_only>
80 return std::exchange(
a, std::move(
v));
90template <cuda::thread_scope scope, cuda::memory_order mem_order = cuda::memory_order_relaxed>
91class atomic_memory_scoped {
94 constexpr static const bool sequential =
false;
97 CUDA INLINE static T load(
const atomic_type<T>& a) {
98 return a.load(mem_order);
102 CUDA INLINE static void store(atomic_type<T>& a, T v) {
103 a.store(v, mem_order);
107 CUDA INLINE static T exchange(atomic_type<T>& a, T v) {
108 return a.exchange(v, mem_order);
112using atomic_memory_block = atomic_memory_scoped<cuda::thread_scope_block>;
113using atomic_memory_grid = atomic_memory_scoped<cuda::thread_scope_device>;
114using atomic_memory_multi_grid = atomic_memory_scoped<cuda::thread_scope_system>;
122 using atomic_t = cuda::std::atomic<T>;
125 using memory_order = cuda::std::memory_order;
127 constexpr memory_order memory_order_relaxed = cuda::std::memory_order_relaxed;
129 constexpr memory_order memory_order_seq_cst = cuda::std::memory_order_seq_cst;
134 using atomic_t = std::atomic<T>;
137 using memory_order = std::memory_order;
139 constexpr memory_order memory_order_relaxed = std::memory_order_relaxed;
141 constexpr memory_order memory_order_seq_cst = std::memory_order_seq_cst;
145template <memory_order mem_order = memory_order_relaxed>
Definition memory.hpp:146
CUDA static INLINE void store(atomic_type< T > &a, T v)
Definition memory.hpp:157
CUDA static INLINE T load(const atomic_type< T > &a)
Definition memory.hpp:152
static constexpr const bool sequential
Definition memory.hpp:149
CUDA static INLINE T exchange(atomic_type< T > &a, T v)
Definition memory.hpp:162
copyable_atomic< impl::atomic_t< T > > atomic_type
Definition memory.hpp:148
typename impl::value_type_of< A >::type value_type
Definition memory.hpp:43
copyable_atomic(copyable_atomic &&other)
Definition memory.hpp:47
copyable_atomic(const copyable_atomic &other)
Definition memory.hpp:46
copyable_atomic & operator=(copyable_atomic &&other)
Definition memory.hpp:52
CUDA copyable_atomic(value_type x)
Definition memory.hpp:45
copyable_atomic & operator=(const copyable_atomic &other)
Definition memory.hpp:48
copyable_atomic()=default
CUDA static INLINE constexpr T load(const atomic_type< T > &a)
Definition memory.hpp:69
static constexpr const bool sequential
Definition memory.hpp:65
T atomic_type
Definition memory.hpp:62
CUDA static INLINE constexpr std::enable_if_t<!read_only, void > store(atomic_type< T > &a, T v)
Definition memory.hpp:74
CUDA static INLINE constexpr std::enable_if_t<!read_only, T > exchange(atomic_type< T > &a, T v)
Definition memory.hpp:79
Definition algorithm.hpp:10
#define INLINE
Definition utility.hpp:63
#define CUDA
Definition utility.hpp:59