3#ifndef CUDA_BATTERY_MEMORY_HPP
4#define CUDA_BATTERY_MEMORY_HPP
16 #include <cuda/atomic>
33 this->store(other.load());
37 this->store(other.load());
43template <
bool read_only>
64 return std::exchange(a, std::move(v));
74template <cuda::thread_scope scope, cuda::memory_order mem_order = cuda::memory_order_relaxed>
75class atomic_memory_scoped {
78 constexpr static const bool sequential =
false;
81 CUDA INLINE static T load(
const atomic_type<T>& a) {
82 return a.load(mem_order);
86 CUDA INLINE static void store(atomic_type<T>& a, T v) {
87 a.store(v, mem_order);
91 CUDA INLINE static T exchange(atomic_type<T>& a, T v) {
92 return a.exchange(v, mem_order);
96using atomic_memory_block = atomic_memory_scoped<cuda::thread_scope_block>;
97using atomic_memory_grid = atomic_memory_scoped<cuda::thread_scope_device>;
98using atomic_memory_multi_grid = atomic_memory_scoped<cuda::thread_scope_system>;
106 using atomic_t = cuda::std::atomic<T>;
109 using memory_order = cuda::std::memory_order;
111 constexpr memory_order memory_order_relaxed = cuda::std::memory_order_relaxed;
113 constexpr memory_order memory_order_seq_cst = cuda::std::memory_order_seq_cst;
118 using atomic_t = std::atomic<T>;
121 using memory_order = std::memory_order;
123 constexpr memory_order memory_order_relaxed = std::memory_order_relaxed;
125 constexpr memory_order memory_order_seq_cst = std::memory_order_seq_cst;
129template <memory_order mem_order = memory_order_relaxed>
137 return a.load(mem_order);
142 a.store(v, mem_order);
147 return a.exchange(v, mem_order);
Definition memory.hpp:130
CUDA static INLINE void store(atomic_type< T > &a, T v)
Definition memory.hpp:141
CUDA static INLINE T load(const atomic_type< T > &a)
Definition memory.hpp:136
static constexpr const bool sequential
Definition memory.hpp:133
CUDA static INLINE T exchange(atomic_type< T > &a, T v)
Definition memory.hpp:146
copyable_atomic(copyable_atomic &&other)
Definition memory.hpp:31
copyable_atomic(const copyable_atomic &other)
Definition memory.hpp:30
copyable_atomic & operator=(copyable_atomic &&other)
Definition memory.hpp:36
copyable_atomic & operator=(const copyable_atomic &other)
Definition memory.hpp:32
copyable_atomic()=default
CUDA copyable_atomic(typename A::value_type x)
Definition memory.hpp:29
CUDA static INLINE constexpr T load(const atomic_type< T > &a)
Definition memory.hpp:53
static constexpr const bool sequential
Definition memory.hpp:49
T atomic_type
Definition memory.hpp:46
CUDA static INLINE constexpr std::enable_if_t<!read_only, void > store(atomic_type< T > &a, T v)
Definition memory.hpp:58
CUDA static INLINE constexpr std::enable_if_t<!read_only, T > exchange(atomic_type< T > &a, T v)
Definition memory.hpp:63
Definition algorithm.hpp:10
#define INLINE
Definition utility.hpp:63
#define CUDA
Definition utility.hpp:59