vecmem 1.26.0
Loading...
Searching...
No Matches
device_atomic_ref.hpp
1/*
2 * VecMem project, part of the ACTS project (R&D line)
3 *
4 * (c) 2022-2026 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
13// System include(s).
14#include <atomic>
15
16#if defined(CL_SYCL_LANGUAGE_VERSION) || defined(SYCL_LANGUAGE_VERSION) || \
17 defined(__ADAPTIVECPP__)
18#if defined(VECMEM_HAVE_SYCL_ATOMIC_REF)
19
20// Local include(s).
21#include "vecmem/memory/details/sycl_builtin_device_atomic_ref.hpp"
22
23namespace vecmem {
24
26template <typename T,
27 device_address_space address = device_address_space::global>
28using device_atomic_ref = sycl::builtin_device_atomic_ref<T, address>;
29
30} // namespace vecmem
31
32#else // defined(VECMEM_HAVE_SYCL_ATOMIC_REF)
33
34// Local include(s).
35#include "vecmem/memory/details/sycl_custom_device_atomic_ref.hpp"
36
37namespace vecmem {
38
40template <typename T,
41 device_address_space address = device_address_space::global>
42using device_atomic_ref = sycl::custom_device_atomic_ref<T, address>;
43
44} // namespace vecmem
45
46#endif // defined(VECMEM_HAVE_SYCL_ATOMIC_REF)
47#elif defined(__CUDACC__)
48
49// Local include(s).
50#include "vecmem/memory/details/cuda_device_atomic_ref.hpp"
51
52namespace vecmem {
53
55template <typename T,
56 device_address_space address = device_address_space::global>
57using device_atomic_ref = cuda::device_atomic_ref<T, address>;
58
59} // namespace vecmem
60
61#elif defined(__HIPCC__)
62
63// Local include(s).
64#include "vecmem/memory/details/hip_device_atomic_ref.hpp"
65
66namespace vecmem {
67
69template <typename T,
70 device_address_space address = device_address_space::global>
71using device_atomic_ref = hip::device_atomic_ref<T, address>;
72
73} // namespace vecmem
74
75#elif defined(__cpp_lib_atomic_ref) && defined(__cpp_lib_atomic_min_max)
76
77namespace vecmem {
78
80template <typename T, device_address_space = device_address_space::global>
81using device_atomic_ref = std::atomic_ref<T>;
82
83} // namespace vecmem
84
85#elif defined(VECMEM_SUPPORT_POSIX_ATOMIC_REF)
86
87// Local include(s).
88#include "vecmem/memory/details/posix_device_atomic_ref.hpp"
89
90namespace vecmem {
91
93template <typename T,
94 device_address_space address = device_address_space::global>
95using device_atomic_ref = posix_device_atomic_ref<T, address>;
96
97} // namespace vecmem
98
99#else
100
101// Local include(s).
102#include "vecmem/memory/details/dummy_device_atomic_ref.hpp"
103
104namespace vecmem {
105
107template <typename T,
108 device_address_space address = device_address_space::global>
110
111} // namespace vecmem
112
113#endif
114
115// Test that the selected class would fulfill the atomic_ref concept.
116#if __cpp_concepts >= 201907L
117#include "vecmem/concepts/atomic_ref.hpp"
118static_assert(
119 vecmem::concepts::atomic_ref<vecmem::device_atomic_ref<uint32_t> >,
120 "Atomic reference on uint32_t is incompletely defined.");
121static_assert(
122 vecmem::concepts::atomic_ref<vecmem::device_atomic_ref<uint64_t> >,
123 "Atomic reference on uint64_t is incompletely defined.");
124static_assert(
125 vecmem::concepts::atomic_ref<vecmem::device_atomic_ref<std::size_t> >,
126 "Atomic reference on std::size_t is incompletely defined.");
127#endif
An allocator class that wraps a memory resource.
Definition allocator.hpp:37
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
dummy_device_atomic_ref< T, address > device_atomic_ref
Use vecmem::dummy_device_atomic_ref as a fallback.
Definition device_atomic_ref.hpp:109