kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_completion_signatures.cpp
Go to the documentation of this file.
1#include "gmock/gmock.h"
2
4PRAGMA_DIAGNOSTIC_PUSH
6#include "exec/single_thread_context.hpp"
7PRAGMA_DIAGNOSTIC_POP
8
10
14
25
26namespace Tests::Impl {
27
28using sndr_t =
29 decltype(stdexec::schedule(std::declval<experimental::execution::single_thread_context>().get_scheduler()) | stdexec::then([]() noexcept {
30 }));
31
34 static_assert(
36 == stdexec::completion_signatures<stdexec::set_value_t()>{});
37
38 return true;
39}
40static_assert(test_add_nothing_empty_env());
41
43consteval bool test_add_error_empty_env() {
44 static_assert(
46 sndr_t,
47 stdexec::completion_signatures<stdexec::set_error_t(float)>,
48 stdexec::env<>
49 >()
50 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(float)>{});
51
52 return true;
53}
54static_assert(test_add_error_empty_env());
55
56using env_with_stop_token_t = stdexec::prop<stdexec::get_stop_token_t, stdexec::inplace_stop_token>;
57
59consteval bool test_add_nothing_stop_env() {
60 static_assert(
62 sndr_t,
63 stdexec::completion_signatures<>,
65 >()
66 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_stopped_t()>{});
67
68 return true;
69}
70static_assert(test_add_nothing_stop_env());
71
73consteval bool test_add_error_stop_env() {
74 static_assert(
76 sndr_t,
77 stdexec::completion_signatures<stdexec::set_error_t(float)>,
79 >()
80 == stdexec::completion_signatures<
81 stdexec::set_value_t(),
82 stdexec::set_error_t(float),
83 stdexec::set_stopped_t()
84 >{});
85
86 return true;
87}
88static_assert(test_add_error_stop_env());
89
91
97TEST_F(CompletionSignaturesTest, parallel_for) {
98 const view_s_t data(Kokkos::view_alloc("data - shared space"));
99
100 experimental::execution::single_thread_context stc{};
101
102 const context_t esc{exec};
103
104 stdexec::inplace_stop_source source;
105
106 auto stc_then_continues_on_esc_sndr = stdexec::schedule(stc.get_scheduler()) | stdexec::then([]() noexcept { })
107 | stdexec::continues_on(esc.get_scheduler());
108
110 static_assert(
111 stdexec::get_completion_signatures<decltype(stc_then_continues_on_esc_sndr), env_with_stop_token_t>()
112 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_stopped_t()>{});
113
114 auto stc_then_continues_on_esc_then_sndr =
115 std::move(stc_then_continues_on_esc_sndr) // NOLINT(performance-move-const-arg)
117
119 static_assert(
120 stdexec::get_completion_signatures<decltype(stc_then_continues_on_esc_then_sndr), env_with_stop_token_t>()
121 == stdexec::completion_signatures<
122 stdexec::set_value_t(),
123 stdexec::set_error_t(std::exception_ptr),
124 stdexec::set_stopped_t()
125 >{});
126
127 auto stc_then_continues_on_esc_then_then_sndr =
128 std::move(stc_then_continues_on_esc_then_sndr)
130
132 static_assert(
133 stdexec::get_completion_signatures<decltype(stc_then_continues_on_esc_then_then_sndr), env_with_stop_token_t>()
134 == stdexec::completion_signatures<
135 stdexec::set_value_t(),
136 stdexec::set_error_t(std::exception_ptr),
137 stdexec::set_stopped_t()
138 >{});
139
140 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
141
142 ASSERT_FALSE(source.stop_requested());
143
144 KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(stc_then_continues_on_esc_then_then_sndr)
145
146 const auto res_A = stdexec::sync_wait(
147 stc_then_continues_on_esc_then_then_sndr
148 | stdexec::write_env(stdexec::prop{stdexec::get_stop_token, source.get_token()}));
149
150 ASSERT_TRUE(res_A.has_value());
151
152 ASSERT_EQ(data(), 2);
153
154 source.request_stop();
155
156 const auto res_B = stdexec::sync_wait(
157 std::move(stc_then_continues_on_esc_then_then_sndr)
158 | stdexec::write_env(stdexec::prop{stdexec::get_stop_token, source.get_token()}));
159
160 ASSERT_FALSE(res_B.has_value());
161
162 ASSERT_EQ(data(), 2);
163}
164
165} // namespace Tests::Impl
#define KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(_sndr_)
Definition context.hpp:69
#define KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
Basic list of ignored diagnostics when including anything from stdexec.
consteval auto completion_signatures_add()
Concatenate Sndr completion signatures with ExtraSigs if Sndr sends on the value channel; otherwise r...
decltype(stdexec::schedule(std::declval< experimental::execution::single_thread_context >().get_scheduler())|stdexec::then([]() noexcept { })) sndr_t
consteval bool test_add_nothing_empty_env()
consteval bool test_add_error_stop_env()
consteval bool test_add_error_empty_env()
stdexec::prop< stdexec::get_stop_token_t, stdexec::inplace_stop_token > env_with_stop_token_t
consteval bool test_add_nothing_stop_env()
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< Exec >
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:27