kokkos-execution 0.0.1
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#endif
9
29
30namespace Tests::Utils {
31
33template <typename T>
34KOKKOS_FUNCTION void atomic_add(T* ptr, const T val) {
35#if defined(KOKKOS_ENABLE_CUDA)
36 cuda::atomic_ref<T, cuda::thread_scope_system>(*ptr).fetch_add(val, cuda::memory_order_relaxed);
37#elif defined(KOKKOS_ENABLE_HIP)
38 __hip_atomic_fetch_add(ptr, val, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM);
39#else
40 std::atomic_ref<T>(*ptr).fetch_add(val, std::memory_order_relaxed);
41#endif
42}
43
44} // namespace Tests::Utils
45
46#endif // KOKKOS_EXECUTION_TESTS_UTILS_ATOMIC_HPP
void atomic_add(T *ptr, const T val)
Atomically add val to *ptr using system scope and relaxed memory order.
Definition atomic.hpp:34