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_Core.hpp"
5
6
#if defined(KOKKOS_ENABLE_CUDA)
7
# include <cuda/atomic>
8
#elif defined(KOKKOS_ENABLE_HIP)
9
# include "desul/atomics/Adapt_HIP.hpp"
10
#elif defined(KOKKOS_ENABLE_SYCL)
11
# include "desul/atomics/Adapt_SYCL.hpp"
12
#endif
13
33
34
#if defined(KOKKOS_ENABLE_CUDA)
35
namespace
desul::Impl {
36
template
<
class
MemoryScope>
37
struct
CudaMemoryScope;
38
39
template
<>
40
struct
CudaMemoryScope<MemoryScopeDevice> {
41
static
constexpr
auto
value = cuda::thread_scope_device;
42
};
43
44
template
<>
45
struct
CudaMemoryScope<MemoryScopeSystem> {
46
static
constexpr
auto
value = cuda::thread_scope_system;
47
};
48
49
template
<
class
MemoryOrder>
50
struct
CudaMemoryOrder;
51
52
template
<>
53
struct
CudaMemoryOrder<MemoryOrderRelaxed> {
54
static
constexpr
auto
value = cuda::memory_order_relaxed;
55
};
56
}
// namespace desul::Impl
57
#endif
58
59
namespace
Tests::Utils
{
60
62
template
<
typename
Scope,
typename
Order,
typename
T>
63
KOKKOS_FUNCTION
auto
atomic_fetch_add
(T* ptr,
const
T val) {
64
#if defined(KOKKOS_ENABLE_CUDA)
65
return
cuda::atomic_ref<T, desul::Impl::CudaMemoryScope<Scope>::value>(*ptr)
66
.fetch_add(val, desul::Impl::CudaMemoryOrder<Order>::value);
67
#elif defined(KOKKOS_ENABLE_HIP)
68
return
__hip_atomic_fetch_add(
69
ptr, val, desul::Impl::HIPMemoryOrder<Order>::value, desul::Impl::HIPMemoryScope<Scope>::value);
70
#elif defined(KOKKOS_ENABLE_SYCL)
71
return
desul::Impl::sycl_atomic_ref<T, Order, Scope>{*ptr}.fetch_add(val);
72
#else
73
static_assert
(std::same_as<Order, desul::MemoryOrderRelaxed>);
74
return
std::atomic_ref<T>(*ptr).fetch_add(val, std::memory_order_relaxed);
75
#endif
76
}
77
78
}
// namespace Tests::Utils
79
80
#endif
// KOKKOS_EXECUTION_TESTS_UTILS_ATOMIC_HPP
Tests::Utils
Definition
atomic.hpp:59
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:63
tests
utils
atomic.hpp
Generated on
for kokkos-execution by
1.18.0