kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
atomic.hpp
Go to the documentation of this file.
1
#ifndef KOKKOS_EXECUTION_TESTS_UTILS_ATOMIC_HPP
2
#define KOKKOS_EXECUTION_TESTS_UTILS_ATOMIC_HPP
3
4
#include "Kokkos_Macros.hpp"
5
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
6
import
kokkos.core;
7
#else
8
# include "Kokkos_Core.hpp"
9
#endif
10
11
#if defined(KOKKOS_ENABLE_CUDA)
12
# include <cuda/atomic>
13
#elif defined(KOKKOS_ENABLE_HIP)
14
# include "desul/atomics/Adapt_HIP.hpp"
15
#elif defined(KOKKOS_ENABLE_SYCL)
16
# include "desul/atomics/Adapt_SYCL.hpp"
17
#endif
18
38
39
#if defined(KOKKOS_ENABLE_CUDA)
40
namespace
desul::Impl {
41
template
<
class
MemoryScope>
42
struct
CudaMemoryScope;
43
44
template
<>
45
struct
CudaMemoryScope<MemoryScopeDevice> {
46
static
constexpr
auto
value = cuda::thread_scope_device;
47
};
48
49
template
<>
50
struct
CudaMemoryScope<MemoryScopeSystem> {
51
static
constexpr
auto
value = cuda::thread_scope_system;
52
};
53
54
template
<
class
MemoryOrder>
55
struct
CudaMemoryOrder;
56
57
template
<>
58
struct
CudaMemoryOrder<MemoryOrderRelaxed> {
59
static
constexpr
auto
value = cuda::memory_order_relaxed;
60
};
61
}
// namespace desul::Impl
62
#endif
63
64
namespace
Tests::Utils
{
65
67
template
<
typename
Scope,
typename
Order,
typename
T>
68
KOKKOS_FUNCTION
auto
atomic_fetch_add
(T* ptr,
const
T val) {
69
#if defined(KOKKOS_ENABLE_CUDA)
70
return
cuda::atomic_ref<T, desul::Impl::CudaMemoryScope<Scope>::value>(*ptr)
71
.fetch_add(val, desul::Impl::CudaMemoryOrder<Order>::value);
72
#elif defined(KOKKOS_ENABLE_HIP)
73
return
__hip_atomic_fetch_add(
74
ptr, val, desul::Impl::HIPMemoryOrder<Order>::value, desul::Impl::HIPMemoryScope<Scope>::value);
75
#elif defined(KOKKOS_ENABLE_SYCL)
76
return
desul::Impl::sycl_atomic_ref<T, Order, Scope>{*ptr}.fetch_add(val);
77
#else
78
static_assert
(std::same_as<Order, desul::MemoryOrderRelaxed>);
79
return
std::atomic_ref<T>(*ptr).fetch_add(val, std::memory_order_relaxed);
80
#endif
81
}
82
83
}
// namespace Tests::Utils
84
85
#endif
// KOKKOS_EXECUTION_TESTS_UTILS_ATOMIC_HPP
Tests::Utils
Definition
test_sync_wait.cpp:20
Tests::Utils::atomic_fetch_add
auto atomic_fetch_add(T *ptr, const T val)
Same effect as Kokkos::atomic_fetch_add, given memory scope and order.
Definition
atomic.hpp:68
tests
utils
atomic.hpp
Generated on
for kokkos-execution by
1.18.0