kokkos-execution
0.0.1
Toggle main menu visibility
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
6
#include "
kokkos-execution/stdexec.hpp
"
7
8
#include "Kokkos_Macros.hpp"
9
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
10
import
kokkos.core;
11
#else
12
# include "Kokkos_Core.hpp"
13
#endif
14
15
#include "
kokkos-utils/concepts/View.hpp
"
16
17
#include "
tests/utils/atomic.hpp
"
18
19
namespace
Tests::Utils::Functors
{
20
22
template
<
23
Kokkos::utils::concepts::ViewOfRank<0> ViewType,
24
bool
MayThrow =
true
,
25
bool
Atomic =
false
,
26
typename
MemoryScope = desul::MemoryScopeDevice
27
>
28
struct
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
{
40
Tests::Utils::atomic_fetch_add<MemoryScope, desul::MemoryOrderRelaxed, typename ViewType::non_const_value_type>
(
41
data
.data(), 1);
42
}
43
};
44
45
template
<
46
Kokkos::utils::concepts::ViewOfRank<0>
ViewType,
47
bool
MayThrow =
true
,
48
typename
MemoryScope = desul::MemoryScopeDevice
49
>
50
struct
FetchIncrement
{
51
typename
ViewType::non_const_type
counter
,
value
;
52
53
KOKKOS_FUNCTION
54
void
operator()
() const noexcept(!MayThrow) {
55
value
() =
Tests::Utils::atomic_fetch_add
<
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
atomic.hpp
Kokkos::utils::concepts::ViewOfRank
View.hpp
stdexec.hpp
Tests::Utils::Functors
Definition
counter.hpp:11
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::Functors::FetchIncrement
Definition
increment.hpp:50
Tests::Utils::Functors::FetchIncrement::value
ViewType::non_const_type value
Definition
increment.hpp:51
Tests::Utils::Functors::FetchIncrement::counter
ViewType::non_const_type counter
Definition
increment.hpp:51
Tests::Utils::Functors::FetchIncrement::operator()
void operator()() const noexcept(!MayThrow)
Definition
increment.hpp:54
Tests::Utils::Functors::Increment
Increment data.
Definition
increment.hpp:28
Tests::Utils::Functors::Increment::operator()
void operator()() const noexcept(!MayThrow)
Definition
increment.hpp:32
Tests::Utils::Functors::Increment::data
ViewType::non_const_type data
Definition
increment.hpp:29
Tests::Utils::Functors::Increment::operator()
void operator()() const noexcept(!MayThrow)
Definition
increment.hpp:38
tests
utils
functors
increment.hpp
Generated on
for kokkos-execution by
1.18.0