kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_bulk.cpp
Go to the documentation of this file.
4
7
20
32
33namespace Tests::GraphImpl {
34
35using namespace Kokkos::utils::callbacks;
36
55
57consteval bool test_sndr_traits() {
59 using schd_sndr_t = typename BulkTest::schedule_sender_t;
60
63 using bulk_sndr_t = stdexec::transform_sender_result_t<
64 decltype(stdexec::bulk(std::declval<schd_sndr_t>(), stdexec::par, 42, std::declval<functor_t>())),
65 stdexec::env<>
66 >;
67
70 static_assert(std::same_as<Kokkos::Execution::Impl::exec_of_t<bulk_sndr_t>, TEST_EXECUTION_SPACE>);
71
74
75 return true;
76}
77static_assert(test_sndr_traits());
78
81 typename BulkTest::scheduler_t,
82 stdexec::bulk_t,
83 stdexec::parallel_policy,
84 int,
86>());
87
90 using sndr_bulk_t =
91 decltype(stdexec::schedule(std::declval<typename BulkTest::scheduler_t>()) | stdexec::bulk(stdexec::par, 42, Tests::Utils::Functors::NoOp<false, false, false>{}));
92
93 static_assert(std::same_as<
94 stdexec::__demangle_t<sndr_bulk_t>,
96 stdexec::bulk_t,
97 stdexec::__data_of<sndr_bulk_t>,
99 >
100 >);
101
102 static_assert(stdexec::__detail::__has_nothrow_transform_sender<
104 stdexec::set_value_t,
105 sndr_bulk_t&&,
106 stdexec::env<>
107 >);
108
109 using sndr_bulk_maythrow_on_move_t =
110 decltype(stdexec::schedule(std::declval<typename BulkTest::scheduler_t>()) | stdexec::bulk(stdexec::par, 42, Tests::Utils::Functors::NoOp<false, false, true>{}));
111
112 static_assert(!stdexec::__detail::__has_nothrow_transform_sender<
114 stdexec::set_value_t,
115 sndr_bulk_maythrow_on_move_t&&,
116 stdexec::env<>
117 >);
118
119 return true;
120}
121static_assert(test_sndr_nothrow_transformable());
122
126 static_assert(!std::is_nothrow_constructible_v<Kokkos::Experimental::Graph<TEST_EXECUTION_SPACE>>);
127
128 using sndr_bulk_t =
129 decltype(stdexec::schedule(std::declval<typename BulkTest::scheduler_t>()) | stdexec::bulk(stdexec::par, 42, Tests::Utils::Functors::NoOp<false, false, false>{}));
130
131 static_assert(!stdexec::__nothrow_connectable<sndr_bulk_t, Tests::Utils::SinkReceiver>);
132
133 return true;
134}
135static_assert(test_sndr_nothrow_connectable());
136
138consteval bool test_bulk_opstate_traits() {
140
141 using sndr_t =
142 decltype(stdexec::schedule(std::declval<typename BulkTest::scheduler_t>()) | stdexec::bulk(stdexec::par, 42, functor_t{}) | stdexec::bulk(stdexec::par, 42, functor_t{}));
143 using connect_result_t = stdexec::connect_result_t<sndr_t, Tests::Utils::SinkReceiver>;
144
145 static_assert(stdexec::__is_instance_of<connect_result_t, Kokkos::Execution::GraphImpl::OpState>);
146
147 using root_t = typename BulkTest::graph_t::root_t;
148 using range_policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::Impl::IsGraphKernelTag>;
149 using bulk_A_t = Kokkos::Experimental::GraphNodeRef<
150 TEST_EXECUTION_SPACE,
151 Kokkos::Impl::GraphNodeKernelImpl<TEST_EXECUTION_SPACE, range_policy_t, functor_t, Kokkos::ParallelForTag>,
152 root_t
153 >;
154 using bulk_B_t = Kokkos::Experimental::GraphNodeRef<
155 TEST_EXECUTION_SPACE,
156 Kokkos::Impl::GraphNodeKernelImpl<TEST_EXECUTION_SPACE, range_policy_t, functor_t, Kokkos::ParallelForTag>,
157 bulk_A_t
158 >;
159
160 static_assert(std::same_as<typename connect_result_t::predecessor_t, root_t>);
161 static_assert(std::same_as<typename connect_result_t::node_t, bulk_B_t>);
162
163 return true;
164}
165static_assert(test_bulk_opstate_traits());
166
171TEST_F(BulkTest, bulk_schedule) {
172 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
173
174 const context_t gctx{exec};
175
178
179 auto sndr = stdexec::schedule(gctx.get_scheduler()) | BULK_SUM_INDICES(4, data)
180 | stdexec::then(load_check_add_t{.prev = 6, .value = 3, .data = data.data()}) | BULK_SUM_INDICES(4, data);
181
182 using sndr_t = decltype(sndr);
183
184 using bulk_data_t = stdexec::__data_of<sndr_t>;
185
186 static_assert(
187 std::same_as<
188 stdexec::__demangle_t<stdexec::transform_sender_result_t<sndr_t, stdexec::env<>>>,
191 stdexec::then_t,
192 load_check_add_t,
194 >,
195 std::string,
196 sum_indices_t,
197 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
198 >
199 >);
200
202 static_assert(std::same_as<stdexec::__domain_of_t<stdexec::env_of_t<sndr_t>>, stdexec::default_domain>);
203 static_assert(std::same_as<
204 stdexec::__detail::__completing_domain_t<stdexec::set_value_t, sndr_t>,
206 >);
207
209 static_assert(std::same_as<
211 typename BulkTest::scheduler_t
212 >);
213
214 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
215
216 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(
217 std::move(sndr)); // NOLINT(performance-move-const-arg)
218
219 ASSERT_THAT(
220 recorded_events,
221 testing::ElementsAre(
223 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
225 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(1))),
227 recorded_events.at(0), device_handle, MATCHER_FOR_GRAPH_NODE_OF(recorded_events.at(2))),
228 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
230
231 ASSERT_EQ(data(), 15);
232}
233
238TEST_F(BulkTest, bulk_starts_on) {
239 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
240
241 const context_t gctx{exec};
242
244 auto work = stdexec::just() | BULK_SUM_INDICES(5, data);
245
248 using work_t = decltype(work);
249
252 work_t,
253 stdexec::__mset<stdexec::set_error_t(std::exception_ptr), stdexec::set_value_t()>
254 >);
255 static_assert(
256 std::same_as<stdexec::__completion_domain_of_t<stdexec::set_value_t, work_t>, stdexec::indeterminate_domain<>>);
257
259 auto sndr = stdexec::starts_on(gctx.get_scheduler(), std::move(work));
260
261 using sndr_t = decltype(sndr);
262
264 static_assert(stdexec::dependent_sender<sndr_t>);
266 static_assert(std::same_as<
268 typename BulkTest::scheduler_t
269 >);
271 sndr_t,
272 stdexec::__mset<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>,
273 stdexec::env<>
274 >);
275
277 static_assert(std::same_as<
278 stdexec::__completion_domain_of_t<stdexec::set_value_t, sndr_t, stdexec::env<>>,
280 >);
281
282 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
283
284 const auto recorded_events = Tests::Utils::record_sync_wait<recorder_listener_t>(std::move(sndr));
285
286 ASSERT_THAT(
287 recorded_events,
288 testing::ElementsAre(
290 MATCHER_FOR_GRAPH_ADDNODE(recorded_events.at(0), device_handle, nullptr),
291 MATCHER_FOR_GRAPH_SUBMIT(exec, recorded_events.at(0)),
293
294 ASSERT_EQ(data(), 10);
295}
296
297} // namespace Tests::GraphImpl
constexpr std::string dispatch_label(const Exec &, Label &&label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
RecorderListener< ConjunctionMatcher< EventDiscardMatcher< TEST_EXECUTION_SPACE >, GraphEventDiscardMatcher< TEST_EXECUTION_SPACE > >, BeginFenceEvent, BeginParallelForEvent, AllocateDataEvent, DeallocateDataEvent, Kokkos::Execution::Impl::RecordEvent, Kokkos::Execution::Impl::WaitEvent, Kokkos::Execution::GraphImpl::GraphAddNodeEvent, Kokkos::Execution::GraphImpl::GraphCreateEvent, Kokkos::Execution::GraphImpl::GraphInstantiateEvent, Kokkos::Execution::GraphImpl::GraphSubmitEvent > recorder_listener_t
Definition test_bulk.cpp:41
Concept for a sender whose completion scheduler is Kokkos::Execution::GraphImpl::Scheduler.
Concept that constrains the type of a sender that dispatches a functor for execution.
std::invoke_result_t< stdexec::get_completion_scheduler_t< Tag >, stdexec::env_of_t< Sndr >, Env... > completion_scheduler_of_t
Retrieve the completion scheduler for a given completion tag.
consteval bool test_sndr_nothrow_transformable()
Definition test_bulk.cpp:89
consteval bool test_bulk_opstate_traits()
consteval bool test_sndr_traits()
Definition test_bulk.cpp:57
consteval bool test_sndr_nothrow_connectable()
typename stdexec::__basic_sender< Args... >::type basic_sender_t
See https://github.com/NVIDIA/stdexec/pull/1873#discussion_r2834863237.
Definition stdexec.hpp:12
auto record_sync_wait(Sndr &&sndr)
Definition sync_wait.hpp:14
consteval bool check_continues_on_after_just_stopped()
auto get_scheduler() const noexcept -> GraphImpl::Scheduler< Exec >
Definition graph.hpp:117
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph node is added.
Definition events.hpp:33
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:14
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is instantiated.
Definition events.hpp:48
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is submitted.
Definition events.hpp:59
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition event.hpp:52
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Definition event.hpp:73
Similar to EventDiscardMatcher, for graph-related events.
Definition events.hpp:60
decltype(std::declval< const context_t >().get_scheduler()) scheduler_t
Definition context.hpp:28
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition context.hpp:29
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition context.hpp:32
Load the value at data and check it is equal to prev. Then, add value to it.
#define BULK_SUM_INDICES(_size_, _data_)
Add a bulk using Tests::Utils::Functors::SumIndices. // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)...
#define MATCHER_FOR_GRAPH_CREATE(_device_handle_)
Definition events.hpp:16
#define MATCHER_FOR_GRAPH_SUBMIT(_exec_, _graph_create_event_variant_)
Definition events.hpp:47
#define MATCHER_FOR_GRAPH_ADDNODE(_graph_create_event_variant_, _device_handle_, _predecessor_)
Definition events.hpp:23
#define MATCHER_FOR_GRAPH_NODE_OF(_graph_add_node_event_)
Definition events.hpp:35