kokkos-execution 0.0.1
Loading...
Searching...
No Matches
increment.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_TESTS_UTILS_FUNCTORS_INCREMENT_HPP
2#define KOKKOS_EXECUTION_TESTS_UTILS_FUNCTORS_INCREMENT_HPP
3
4#include <type_traits>
5
7
8#include "Kokkos_Macros.hpp"
9#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
10import kokkos.core;
11#else
12# include "Kokkos_Core.hpp"
13#endif
14
16
18
19namespace Tests::Utils::Functors {
20
22template <
23 Kokkos::utils::concepts::ViewOfRank<0> ViewType,
24 bool MayThrow = true,
25 bool Atomic = false,
26 typename MemoryScope = desul::MemoryScopeDevice
27>
28struct Increment {
29 typename ViewType::non_const_type data;
30
31 KOKKOS_FUNCTION
32 void operator()() const noexcept(!MayThrow) requires(Atomic == false)
33 {
34 ++data();
35 }
36
37 KOKKOS_FUNCTION
38 void operator()() const noexcept(!MayThrow) requires(Atomic == true)
39 {
41 data.data(), 1);
42 }
43};
44
45template <
47 bool MayThrow = true,
48 typename MemoryScope = desul::MemoryScopeDevice
49>
51 typename ViewType::non_const_type counter, value;
52
53 KOKKOS_FUNCTION
54 void operator()() const noexcept(!MayThrow) {
56 MemoryScope,
57 desul::MemoryOrderRelaxed,
58 typename ViewType::non_const_value_type
59 >(counter.data(), 1);
60 }
61};
62
64#define THEN_INCREMENT(_data_) \
65 stdexec::then(Tests::Utils::Functors::Increment<std::remove_cvref_t<decltype(_data_)>, true, false>{.data = _data_})
66
68#define THEN_INCREMENT_ATOMIC(_scope_, _data_) \
69 stdexec::then( \
70 Tests::Utils::Functors::Increment< \
71 std::remove_cvref_t<decltype(_data_)>, \
72 true, \
73 true, \
74 desul::MemoryScope##_scope_ \
75 >{.data = _data_})
76
77} // namespace Tests::Utils::Functors
78
79#endif // KOKKOS_EXECUTION_TESTS_UTILS_FUNCTORS_INCREMENT_HPP
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
ViewType::non_const_type value
Definition increment.hpp:51
ViewType::non_const_type counter
Definition increment.hpp:51
void operator()() const noexcept(!MayThrow)
Definition increment.hpp:54
void operator()() const noexcept(!MayThrow)
Definition increment.hpp:32
ViewType::non_const_type data
Definition increment.hpp:29
void operator()() const noexcept(!MayThrow)
Definition increment.hpp:38