3#ifndef CUDA_BATTERY_MEMORY_HPP
4#define CUDA_BATTERY_MEMORY_HPP
16 #include <cuda/atomic>
26template <
bool read_only>
47 return std::exchange(a, std::move(v));
57template <cuda::thread_scope scope, cuda::memory_order mem_order = cuda::memory_order_relaxed>
58class atomic_memory_scoped {
60 template <
class T>
using atomic_type = cuda::atomic<T, scope>;
61 constexpr static const bool sequential =
false;
64 CUDA INLINE static T load(
const atomic_type<T>& a) {
65 return a.
load(mem_order);
69 CUDA INLINE static void store(atomic_type<T>& a, T v) {
70 a.store(v, mem_order);
74 CUDA INLINE static T exchange(atomic_type<T>& a, T v) {
75 return a.exchange(v, mem_order);
79using atomic_memory_block = atomic_memory_scoped<cuda::thread_scope_block>;
80using atomic_memory_grid = atomic_memory_scoped<cuda::thread_scope_device>;
81using atomic_memory_multi_grid = atomic_memory_scoped<cuda::thread_scope_system>;
89 using atomic_t = cuda::std::atomic<T>;
92 using memory_order = cuda::std::memory_order;
94 constexpr memory_order memory_order_relaxed = cuda::std::memory_order_relaxed;
96 constexpr memory_order memory_order_seq_cst = cuda::std::memory_order_seq_cst;
101 using atomic_t = std::atomic<T>;
104 using memory_order = std::memory_order;
106 constexpr memory_order memory_order_relaxed = std::memory_order_relaxed;
108 constexpr memory_order memory_order_seq_cst = std::memory_order_seq_cst;
112template <memory_order mem_order = memory_order_relaxed>
120 return a.load(mem_order);
125 a.store(v, mem_order);
130 return a.exchange(v, mem_order);
Definition memory.hpp:113
CUDA static INLINE void store(atomic_type< T > &a, T v)
Definition memory.hpp:124
CUDA static INLINE T load(const atomic_type< T > &a)
Definition memory.hpp:119
static constexpr const bool sequential
Definition memory.hpp:116
CUDA static INLINE T exchange(atomic_type< T > &a, T v)
Definition memory.hpp:129
impl::atomic_t< T > atomic_type
Definition memory.hpp:115
CUDA static INLINE constexpr T load(const atomic_type< T > &a)
Definition memory.hpp:36
static constexpr const bool sequential
Definition memory.hpp:32
T atomic_type
Definition memory.hpp:29
CUDA static INLINE constexpr std::enable_if_t<!read_only, void > store(atomic_type< T > &a, T v)
Definition memory.hpp:41
CUDA static INLINE constexpr std::enable_if_t<!read_only, T > exchange(atomic_type< T > &a, T v)
Definition memory.hpp:46
Definition algorithm.hpp:10
#define INLINE
Definition utility.hpp:63
#define CUDA
Definition utility.hpp:59