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(
35 stdexec::__mset_eq<
36 stdexec::__mset<stdexec::set_value_t()>,
38 >);
39 return true;
40}
41static_assert(test_add_nothing_empty_env());
42
44consteval bool test_add_error_empty_env() {
45 static_assert(stdexec::__mset_eq<
46 stdexec::__mset<stdexec::set_value_t(), stdexec::set_error_t(float)>,
48 sndr_t,
49 stdexec::completion_signatures<stdexec::set_error_t(float)>,
50 stdexec::env<>
51 >
52 >);
53 return true;
54}
55static_assert(test_add_error_empty_env());
56
57using env_with_stop_token_t = stdexec::prop<stdexec::get_stop_token_t, stdexec::inplace_stop_token>;
58
60consteval bool test_add_nothing_stop_env() {
61 static_assert(stdexec::__mset_eq<
62 stdexec::__mset<stdexec::set_value_t(), stdexec::set_stopped_t()>,
64 sndr_t,
65 stdexec::completion_signatures<>,
67 >
68 >);
69 return true;
70}
71static_assert(test_add_nothing_stop_env());
72
74consteval bool test_add_error_stop_env() {
75 static_assert(stdexec::__mset_eq<
76 stdexec::__mset<stdexec::set_value_t(), stdexec::set_stopped_t(), stdexec::set_error_t(float)>,
78 sndr_t,
79 stdexec::completion_signatures<stdexec::set_error_t(float)>,
81 >
82 >);
83
84 return true;
85}
86static_assert(test_add_error_stop_env());
87
89
95TEST_F(CompletionSignaturesTest, parallel_for) {
96 const view_s_t data(Kokkos::view_alloc("data - shared space"));
97
98 experimental::execution::single_thread_context stc{};
99
100 const context_t esc{exec};
101
102 stdexec::inplace_stop_source source;
103
104 auto stc_then_continues_on_esc_sndr = stdexec::schedule(stc.get_scheduler()) | stdexec::then([]() noexcept { })
105 | stdexec::continues_on(esc.get_scheduler());
106
108 static_assert(stdexec::__mset_eq<
109 stdexec::__mset<stdexec::set_value_t(), stdexec::set_stopped_t()>,
110 stdexec::__completion_signatures_of_t<decltype(stc_then_continues_on_esc_sndr), env_with_stop_token_t>
111 >);
112
113 auto stc_then_continues_on_esc_then_sndr =
114 std::move(stc_then_continues_on_esc_sndr) // NOLINT(performance-move-const-arg)
116
118 static_assert(
119 stdexec::__mset_eq<
120 stdexec::__mset<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr), stdexec::set_stopped_t()>,
121 stdexec::__completion_signatures_of_t<decltype(stc_then_continues_on_esc_then_sndr), env_with_stop_token_t>
122 >);
123
124 auto stc_then_continues_on_esc_then_then_sndr =
125 std::move(stc_then_continues_on_esc_then_sndr)
127
129 static_assert(
130 stdexec::__mset_eq<
131 stdexec::__mset<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr), stdexec::set_stopped_t()>,
132 stdexec::__completion_signatures_of_t<
133 decltype(stc_then_continues_on_esc_then_then_sndr),
135 >
136 >);
137
138 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
139
140 ASSERT_FALSE(source.stop_requested());
141
142 KOKKOS_EXECUTION_THREADS_THROWS_ON_SYNC_WAIT_ASSERT_AND_SKIP(stc_then_continues_on_esc_then_then_sndr)
143
144 const auto res_A = stdexec::sync_wait(
145 stc_then_continues_on_esc_then_then_sndr
146 | stdexec::write_env(stdexec::prop{stdexec::get_stop_token, source.get_token()}));
147
148 ASSERT_TRUE(res_A.has_value());
149
150 ASSERT_EQ(data(), 2);
151
152 source.request_stop();
153
154 const auto res_B = stdexec::sync_wait(
155 std::move(stc_then_continues_on_esc_then_then_sndr)
156 | stdexec::write_env(stdexec::prop{stdexec::get_stop_token, source.get_token()}));
157
158 ASSERT_FALSE(res_B.has_value());
159
160 ASSERT_EQ(data(), 2);
161}
162
163} // 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.
decltype(completion_signatures_add< Sndr, ExtraSigs, Env... >()) completion_signatures_add_t
consteval bool test_add_nothing_empty_env()
consteval bool test_add_error_stop_env()
decltype(stdexec::schedule(std::declval< experimental::execution::single_thread_context >().get_scheduler())|stdexec::then([]() noexcept { })) sndr_t
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