4#include "exec/single_thread_context.hpp"
38using namespace Kokkos::utils::callbacks;
61 const view_s_t data(Kokkos::view_alloc(
exec,
"data - shared space"));
67 static_assert(std::same_as<
68 decltype(stdexec::get_completion_domain<stdexec::set_value_t>(stdexec::get_env(sndr))),
76 ASSERT_EQ(data(), 0) <<
"Eager execution is not allowed.";
78 const auto recorded_events = recorder_listener_t::record(
79 [sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); });
82 ASSERT_EQ(recorded_events.size(), 3);
108 const view_s_t data(Kokkos::view_alloc(
exec,
"data - shared space"));
115 ASSERT_EQ(data(), 0) <<
"Eager execution is not allowed.";
118 recorder_listener_t::record([sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); }),
119 testing::ElementsAre(
124 ASSERT_EQ(data(), 2);
137 const view_s_t data(Kokkos::view_alloc(
exec,
"data - shared space"));
140 experimental::execution::single_thread_context stc{};
142 auto sndr = stdexec::when_all(
144 | stdexec::continues_on(stc.get_scheduler()) |
THEN_INCREMENT(data))
147 ASSERT_EQ(data(), 0) <<
"Eager execution is not allowed.";
150 recorder_listener_t::record([sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); }),
151 testing::ElementsAre(
157 ASSERT_EQ(data(), 3);
168TEST_F(
WhenAllTest, single_branch_followed_by_other_and_finish_on_self) {
169 const view_s_t data(Kokkos::view_alloc(
exec,
"data - shared space"));
172 experimental::execution::single_thread_context stc{};
175 | stdexec::continues_on(stc.get_scheduler()) |
THEN_INCREMENT(data)
178 ASSERT_EQ(data(), 0) <<
"Eager execution is not allowed.";
180 const auto recorded_events = recorder_listener_t::record(
181 [sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); });
184 ASSERT_EQ(recorded_events.size(), 5);
193 testing::ElementsAre(
200 ASSERT_EQ(data(), 3);
214 const view_s_t data(Kokkos::view_alloc(
"data - shared space"));
217 experimental::execution::single_thread_context stc{};
219 auto w_a = stdexec::when_all(
225 decltype(stdexec::get_completion_domain<stdexec::set_value_t>(stdexec::get_env(w_a), stdexec::env<>{})),
226 stdexec::default_domain
231 ASSERT_EQ(data(), 0) <<
"Eager execution is not allowed.";
234 recorder_listener_t::record([sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); }),
235 testing::ElementsAre(
240 ASSERT_EQ(data(), 3);
254 const view_s_t data(Kokkos::view_alloc(
exec,
"data - shared space"));
256 const auto [exec_A, exec_B] = Kokkos::Experimental::partition_space(
exec, 1, 1);
258 const context_t esc_A{exec_A}, esc_B{exec_B};
260 auto sndr = stdexec::when_all(
265 ASSERT_EQ(data(), 0) <<
"Eager execution is not allowed.";
267 const auto recorded_events = recorder_listener_t::record(
268 [sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); });
273 testing::ElementsAre(
279 ASSERT_EQ(recorded_events.size(), 6);
289 testing::ElementsAre(
297 ASSERT_EQ(data(), 3);
314 const view_s_t data(Kokkos::view_alloc(
"data - shared space"));
319 const context_h_t esc_h{exec_h};
321 auto sndr = stdexec::when_all(
326 ASSERT_EQ(data(), 0) <<
"Eager execution is not allowed.";
328 const auto recorded_events = recorder_listener_t::record(
329 [sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); });
334 testing::ElementsAre(
340 ASSERT_EQ(recorded_events.size(), 6);
350 testing::ElementsAre(
358 ASSERT_EQ(data(), 3);
372TEST_F(
WhenAllTest, two_mixed_branches_followed_by_other_and_finish_on_self) {
373 const view_s_t data(Kokkos::view_alloc(
"data - shared space"));
376 experimental::execution::single_thread_context stc{};
378 auto sndr = stdexec::when_all(
381 | stdexec::continues_on(stc.get_scheduler()) |
THEN_INCREMENT(data)
384 ASSERT_EQ(data(), 0) <<
"Eager execution is not allowed.";
386 const auto recorded_events = recorder_listener_t::record(
387 [sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); });
390 ASSERT_EQ(recorded_events.size(), 5);
399 testing::ElementsAre(
406 ASSERT_EQ(data(), 4);
424 const view_s_t data(Kokkos::view_alloc(
"data - shared space"));
427 experimental::execution::single_thread_context stc{};
438 recorder_listener_t::record([sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); }),
439 testing::ElementsAre(
446 ASSERT_EQ(data(), 4);
461 const auto [exec_A, exec_B, exec_C] = Kokkos::Experimental::partition_space(
exec, 1, 1, 1);
463 const context_t esc_A{exec_A}, esc_B{exec_B}, esc_C{exec_C};
466 auto br_B = ::stdexec::schedule(esc_B.get_scheduler()) |
THEN_LABELED_PFOR(TEST_EXECUTION_SPACE,
'B');
467 auto br_C = ::stdexec::schedule(esc_C.get_scheduler()) |
THEN_LABELED_PFOR(TEST_EXECUTION_SPACE,
'C');
469 auto when_AB_then_D = ::stdexec::when_all(std::move(br_A), std::move(br_B))
472 auto sndr = ::stdexec::when_all(std::move(when_AB_then_D), std::move(br_C));
474 const auto recorded_events = recorder_listener_t::record(
475 [sndr = std::move(sndr)]()
mutable { stdexec::sync_wait(std::move(sndr)); });
480 testing::ElementsAre(
488 ASSERT_EQ(recorded_events.size(), 10);
502 testing::ElementsAre(
constexpr std::string dispatch_label(const Exec &, Label &&label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_WAIT_EVENT(_record_event_variant_)
#define MATCHER_FOR_BEGIN_PFOR(_exec_, _label_)
#define MATCHER_FOR_RECORD_EVENT(_exec_)
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
RecorderListener< EventDiscardMatcher< TEST_EXECUTION_SPACE >, BeginFenceEvent, BeginParallelForEvent, Kokkos::Execution::Impl::RecordEvent, Kokkos::Execution::Impl::WaitEvent > recorder_listener_t
Concept for a sender whose completion scheduler is Kokkos::Execution::ExecutionSpaceImpl::Scheduler.
#define KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
Basic list of ignored diagnostics when including anything from stdexec.
#define THEN_INCREMENT(_data_)
Add a then using Tests::Utils::Functors::Increment that may throw. // NOLINTNEXTLINE(cppcoreguideline...
#define THEN_INCREMENT_ATOMIC(_data_)
Same as THEN_INCREMENT, using Tests::Utils::atomic_add. // NOLINTNEXTLINE(cppcoreguidelines-macro-usa...
#define THEN_LABELED_PFOR(_exec_, _id_)
Add a Kokkos::Execution::parallel_for using Tests::Utils::Functors::Labeled. // NOLINTNEXTLINE(cppcor...
constexpr check_rcvr_env_queryable_with_t< true, Queries... > check_rcvr_env_queryable_with
bool are_same_instances(const Exec &exec, const OtherExec &other_exec)
Matcher to filter out events that are just noise for tests.
Execution context using a Kokkos execution space under the hood.
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< Exec >
Event to be sent to Kokkos::utils::callbacks::dispatch when an event is recorded on an execution spac...
Event to be sent to Kokkos::utils::callbacks::dispatch when an event is being waited for.
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Kokkos::DefaultHostExecutionSpace host_execution_space