vecmem 1.14.0
Loading...
Searching...
No Matches
cuda_device_atomic_ref.hpp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2022-2024 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8#pragma once
9
10// Local include(s).
11#include "vecmem/memory/device_address_space.hpp"
12#include "vecmem/memory/memory_order.hpp"
13#include "vecmem/utils/types.hpp"
14
15// System include(s).
16#include <type_traits>
17
18namespace vecmem {
19namespace cuda {
20
32template <typename T,
33 device_address_space address = device_address_space::global>
35
36public:
39
41 typedef T value_type;
48
50
53
54 static_assert(
55 std::is_integral<value_type>::value,
56 "vecmem::cuda::atomic_ref only accepts built-in integral types");
57
59
61 VECMEM_HOST_AND_DEVICE
64 VECMEM_HOST_AND_DEVICE
66
69
72
77 VECMEM_HOST_AND_DEVICE
79
81 VECMEM_HOST_AND_DEVICE
82 void store(value_type data,
83 memory_order order = memory_order::seq_cst) const;
85 VECMEM_HOST_AND_DEVICE
86 value_type load(memory_order order = memory_order::seq_cst) const;
87
89 VECMEM_HOST_AND_DEVICE
91 memory_order order = memory_order::seq_cst) const;
92
94 VECMEM_HOST_AND_DEVICE
97 memory_order failure) const;
99 VECMEM_HOST_AND_DEVICE
102 memory_order order = memory_order::seq_cst) const;
103
105
108
110 VECMEM_HOST_AND_DEVICE
112 memory_order order = memory_order::seq_cst) const;
114 VECMEM_HOST_AND_DEVICE
116 memory_order order = memory_order::seq_cst) const;
117
119 VECMEM_HOST_AND_DEVICE
121 memory_order order = memory_order::seq_cst) const;
123 VECMEM_HOST_AND_DEVICE
125 memory_order order = memory_order::seq_cst) const;
127 VECMEM_HOST_AND_DEVICE
129 memory_order order = memory_order::seq_cst) const;
130
132
133private:
135 pointer m_ptr;
136
137}; // class device_atomic_ref
138
139} // namespace cuda
140} // namespace vecmem
141
142// Include the implementation.
143#include "vecmem/memory/impl/cuda_device_atomic_ref.ipp"
Custom implementation for atomic operations in CUDA device code.
Definition cuda_device_atomic_ref.hpp:34
VECMEM_HOST_AND_DEVICE value_type fetch_and(value_type data, memory_order order=memory_order::seq_cst) const
Replace the current value with the specified value AND-ed to it.
Definition cuda_device_atomic_ref.ipp:128
VECMEM_HOST_AND_DEVICE value_type fetch_sub(value_type data, memory_order order=memory_order::seq_cst) const
Substitute a chosen value from the stored variable.
Definition cuda_device_atomic_ref.ipp:121
VECMEM_HOST_AND_DEVICE value_type fetch_add(value_type data, memory_order order=memory_order::seq_cst) const
Add a chosen value to the stored variable.
Definition cuda_device_atomic_ref.ipp:114
VECMEM_HOST_AND_DEVICE void store(value_type data, memory_order order=memory_order::seq_cst) const
Set the variable to the desired value.
Definition cuda_device_atomic_ref.ipp:48
value_type difference_type
Difference between two objects.
Definition cuda_device_atomic_ref.hpp:43
device_atomic_ref & operator=(const device_atomic_ref &)=delete
Disable the assignment operator.
T value_type
Type managed by the object.
Definition cuda_device_atomic_ref.hpp:41
VECMEM_HOST_AND_DEVICE bool compare_exchange_strong(reference expected, value_type desired, memory_order success, memory_order failure) const
Compare against the current value, and exchange only if different.
Definition cuda_device_atomic_ref.ipp:94
VECMEM_HOST_AND_DEVICE value_type fetch_or(value_type data, memory_order order=memory_order::seq_cst) const
Replace the current value with the specified value OR-d to it.
Definition cuda_device_atomic_ref.ipp:135
VECMEM_HOST_AND_DEVICE value_type load(memory_order order=memory_order::seq_cst) const
Get the value of the variable.
Definition cuda_device_atomic_ref.ipp:57
value_type & reference
Reference to a value given by the user.
Definition cuda_device_atomic_ref.hpp:47
value_type * pointer
Pointer to the value in global memory.
Definition cuda_device_atomic_ref.hpp:45
VECMEM_HOST_AND_DEVICE value_type exchange(value_type data, memory_order order=memory_order::seq_cst) const
Exchange the current value of the variable with a different one.
Definition cuda_device_atomic_ref.ipp:70
VECMEM_HOST_AND_DEVICE value_type fetch_xor(value_type data, memory_order order=memory_order::seq_cst) const
Replace the current value with the specified value XOR-d to it.
Definition cuda_device_atomic_ref.ipp:142
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
device_address_space
Custom definition for the device memory adress space.
Definition device_address_space.hpp:12
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35
memory_order
Custom (dummy) definition for the memory order.
Definition memory_order.hpp:31