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}
40
41static_assert(test_add_nothing_empty_env());
42
44consteval bool test_add_error_empty_env() {
45 static_assert(
47 sndr_t,
48 stdexec::completion_signatures<stdexec::set_error_t(float)>,
49 stdexec::env<>
50 >()
51 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_error_t(float)>{});
52
53 return true;
54}
55
56static_assert(test_add_error_empty_env());
57
58using env_with_stop_token_t = stdexec::prop<stdexec::get_stop_token_t, stdexec::inplace_stop_token>;
59
61consteval bool test_add_nothing_stop_env() {
62 static_assert(
64 sndr_t,
65 stdexec::completion_signatures<>,
67 >()
68 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_stopped_t()>{});
69
70 return true;
71}
72
73static_assert(test_add_nothing_stop_env());
74
76consteval bool test_add_error_stop_env() {
77 static_assert(
79 sndr_t,
80 stdexec::completion_signatures<stdexec::set_error_t(float)>,
82 >()
83 == stdexec::completion_signatures<
84 stdexec::set_value_t(),
85 stdexec::set_error_t(float),
86 stdexec::set_stopped_t()
87 >{});
88
89 return true;
90}
91
92static_assert(test_add_error_stop_env());
93
95
101TEST_F(CompletionSignaturesTest, parallel_for) {
102 const view_s_t data(Kokkos::view_alloc("data - shared space"));
103
104 experimental::execution::single_thread_context stc{};
105
106 const context_t esc{exec};
107
108 stdexec::inplace_stop_source source;
109
110 auto stc_then_continues_on_esc_sndr = stdexec::schedule(stc.get_scheduler()) | stdexec::then([]() noexcept { })
111 | stdexec::continues_on(esc.get_scheduler());
112
114 static_assert(
115 stdexec::get_completion_signatures<decltype(stc_then_continues_on_esc_sndr), env_with_stop_token_t>()
116 == stdexec::completion_signatures<stdexec::set_value_t(), stdexec::set_stopped_t()>{});
117
118 auto stc_then_continues_on_esc_then_sndr =
119 std::move(stc_then_continues_on_esc_sndr) // NOLINT(performance-move-const-arg)
121
123 static_assert(
124 stdexec::get_completion_signatures<decltype(stc_then_continues_on_esc_then_sndr), env_with_stop_token_t>()
125 == stdexec::completion_signatures<
126 stdexec::set_value_t(),
127 stdexec::set_error_t(std::exception_ptr),
128 stdexec::set_stopped_t()
129 >{});
130
131 auto stc_then_continues_on_esc_then_then_sndr =
132 std::move(stc_then_continues_on_esc_then_sndr)
134
136 static_assert(
137 stdexec::get_completion_signatures<decltype(stc_then_continues_on_esc_then_then_sndr), env_with_stop_token_t>()
138 == stdexec::completion_signatures<
139 stdexec::set_value_t(),
140 stdexec::set_error_t(std::exception_ptr),
141 stdexec::set_stopped_t()
142 >{});
143
144 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
145
146 ASSERT_FALSE(source.stop_requested());
147
148 KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(stc_then_continues_on_esc_then_then_sndr)
149
150 const auto res_A = stdexec::sync_wait(
151 stc_then_continues_on_esc_then_then_sndr
152 | stdexec::write_env(stdexec::prop{stdexec::get_stop_token, source.get_token()}));
153
154 ASSERT_TRUE(res_A.has_value());
155
156 ASSERT_EQ(data(), 2);
157
158 source.request_stop();
159
160 const auto res_B = stdexec::sync_wait(
161 std::move(stc_then_continues_on_esc_then_then_sndr)
162 | stdexec::write_env(stdexec::prop{stdexec::get_stop_token, source.get_token()}));
163
164 ASSERT_FALSE(res_B.has_value());
165
166 ASSERT_EQ(data(), 2);
167}
168
169} // namespace Tests::Impl
#define KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(_sndr_)
Definition context.hpp:76
#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< execution_space >
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:33