vecmem 1.14.0
Loading...
Searching...
No Matches
atomic.hpp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2021-2022 CERN for the benefit of the ACTS project
5 *
6 * Mozilla Public License Version 2.0
7 */
8#pragma once
9
10// VecMem include(s).
11#include "vecmem/utils/types.hpp"
12
13// System include(s).
14#include <type_traits>
15
16// Provide a different implementation for modern SYCL and everything else
17#if (defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION)) && \
18 defined(VECMEM_HAVE_SYCL_ATOMIC_REF)
19
20namespace vecmem {
21
28template <typename T>
29class atomic
30 : public ::sycl::atomic_ref<T, ::sycl::memory_order::relaxed,
31 ::sycl::memory_scope::device,
32 ::sycl::access::address_space::global_space> {
33
34public:
37
39 typedef T value_type;
43 typedef value_type* pointer;
45 typedef value_type& reference;
46
48
50 VECMEM_HOST_AND_DEVICE
51 atomic(pointer ptr)
52 : ::sycl::atomic_ref<T, ::sycl::memory_order::relaxed,
53 ::sycl::memory_scope::device,
55 *ptr) {}
56
57}; // class atomic
58
59} // namespace vecmem
60
61#else
62
63namespace vecmem {
64
75template <typename T>
76class atomic {
77
78public:
81
83 typedef T value_type;
90
92
95
96 static_assert(std::is_integral<value_type>::value,
97 "vecmem::atomic only accepts built-in integral types");
98
100
102 VECMEM_HOST_AND_DEVICE
103 atomic(pointer ptr);
104
107
109 VECMEM_HOST_AND_DEVICE
110 void store(value_type data);
112 VECMEM_HOST_AND_DEVICE
113 value_type load() const;
114
116 VECMEM_HOST_AND_DEVICE
118
120 VECMEM_HOST_AND_DEVICE
122
124
127
129 VECMEM_HOST_AND_DEVICE
132 VECMEM_HOST_AND_DEVICE
134
136 VECMEM_HOST_AND_DEVICE
139 VECMEM_HOST_AND_DEVICE
142 VECMEM_HOST_AND_DEVICE
144
146
147private:
149 pointer m_ptr;
150
151}; // class atomic
152
153} // namespace vecmem
154
155// Include the implementation.
156#include "vecmem/memory/impl/atomic.ipp"
157
158#endif // sycl::atomic_ref
Class providing atomic operations for the VecMem code.
Definition atomic.hpp:76
VECMEM_HOST_AND_DEVICE value_type fetch_and(value_type data)
Replace the current value with the specified value AND-ed to it.
Definition atomic.ipp:140
VECMEM_HOST_AND_DEVICE value_type fetch_sub(value_type data)
Substitute a chosen value from the stored variable.
Definition atomic.ipp:124
VECMEM_HOST_AND_DEVICE value_type load() const
Get the value of the variable.
Definition atomic.ipp:55
value_type * pointer
Pointer to the value in global memory.
Definition atomic.hpp:87
value_type difference_type
Difference between two objects.
Definition atomic.hpp:85
VECMEM_HOST_AND_DEVICE value_type exchange(value_type data)
Exchange the current value of the variable with a different one.
Definition atomic.ipp:72
VECMEM_HOST_AND_DEVICE void store(value_type data)
Set the variable to the desired value.
Definition atomic.ipp:40
value_type & reference
Reference to a value given by the user.
Definition atomic.hpp:89
VECMEM_HOST_AND_DEVICE atomic(pointer ptr)
Constructor, with a pointer to the managed variable.
Definition atomic.ipp:37
T value_type
Type managed by the object.
Definition atomic.hpp:83
VECMEM_HOST_AND_DEVICE value_type fetch_xor(value_type data)
Replace the current value with the specified value XOR-d to it.
Definition atomic.ipp:171
VECMEM_HOST_AND_DEVICE value_type fetch_or(value_type data)
Replace the current value with the specified value OR-d to it.
Definition atomic.ipp:156
VECMEM_HOST_AND_DEVICE bool compare_exchange_strong(reference expected, value_type desired)
Compare against the current value, and exchange only if different.
Definition atomic.ipp:87
VECMEM_HOST_AND_DEVICE value_type fetch_add(value_type data)
Add a chosen value to the stored variable.
Definition atomic.ipp:108
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
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