kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_transfer_when_all.cpp
Go to the documentation of this file.
2PRAGMA_DIAGNOSTIC_PUSH
4#include "exec/single_thread_context.hpp"
5PRAGMA_DIAGNOSTIC_POP
6
8
11
16
28
30
31using namespace Kokkos::utils::callbacks;
32
45
48 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
49
50 const auto [exec_A, exec_B] = Kokkos::Experimental::partition_space(exec, 1, 1);
51
52 const context_t esc_A{exec_A}, esc_B{exec_B};
53
54 auto w_a = stdexec::transfer_when_all(
55 esc_A.get_scheduler(),
56 stdexec::schedule(esc_A.get_scheduler()) | THEN_INCREMENT_ATOMIC(data),
57 stdexec::schedule(esc_B.get_scheduler()) | THEN_INCREMENT_ATOMIC(data));
58
59 static_assert(std::same_as<
60 decltype(stdexec::get_completion_domain<stdexec::set_value_t>(stdexec::get_env(w_a))),
62 >);
63
65 static_assert(std::same_as<
66 decltype(stdexec::get_completion_scheduler<stdexec::set_value_t>(stdexec::get_env(w_a))),
68 >);
70
71 auto sndr = std::move(w_a) | THEN_INCREMENT(data);
72
73 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
74
75 const auto recorded_events = recorder_listener_t::record(
76 [sndr = std::move(sndr)]() mutable { stdexec::sync_wait(std::move(sndr)); });
77
78 if (Tests::Utils::are_same_instances(exec_A, exec_B)) {
79 ASSERT_THAT(
80 recorded_events,
81 testing::ElementsAre(
82 MATCHER_FOR_BEGIN_PFOR(exec_A, dispatch_label(exec_A, "then")),
83 MATCHER_FOR_BEGIN_PFOR(exec_B, dispatch_label(exec_B, "then")),
84 MATCHER_FOR_BEGIN_PFOR(exec_A, dispatch_label(exec_A, "then")),
85 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec_A, "sync_wait"))));
87 ASSERT_EQ(recorded_events.size(), 6);
88 ASSERT_THAT(recorded_events.at(0), MATCHER_FOR_BEGIN_PFOR(exec_A, dispatch_label(exec_A, "then")));
89 ASSERT_THAT(recorded_events.at(1), MATCHER_FOR_BEGIN_PFOR(exec_B, dispatch_label(exec_B, "then")));
90 ASSERT_THAT(recorded_events.at(2), MATCHER_FOR_RECORD_EVENT(exec_B));
91 ASSERT_THAT(recorded_events.at(3), MATCHER_FOR_WAIT_EVENT(recorded_events.at(2)));
92 ASSERT_THAT(recorded_events.at(4), MATCHER_FOR_BEGIN_PFOR(exec_A, dispatch_label(exec_A, "then")));
93 ASSERT_THAT(recorded_events.at(5), MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec_A, "sync_wait")));
94 } else {
95 ASSERT_THAT(
96 recorded_events,
97 testing::ElementsAre(
98 MATCHER_FOR_BEGIN_PFOR(exec_A, dispatch_label(exec_A, "then")),
99 MATCHER_FOR_BEGIN_PFOR(exec_B, dispatch_label(exec_B, "then")),
100 MATCHER_FOR_BEGIN_FENCE(exec_B, dispatch_label(exec_B, "after dispatch")),
101 MATCHER_FOR_BEGIN_PFOR(exec_A, dispatch_label(exec_A, "then")),
102 MATCHER_FOR_BEGIN_FENCE(exec_A, dispatch_label(exec_A, "sync_wait"))));
103 }
104
105 ASSERT_EQ(data(), 3);
106}
107
108} // namespace Tests::ExecutionSpaceImpl
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...
Definition increment.hpp:35
#define THEN_INCREMENT_ATOMIC(_data_)
Same as THEN_INCREMENT, using Tests::Utils::atomic_add. // NOLINTNEXTLINE(cppcoreguidelines-macro-usa...
Definition increment.hpp:39
bool are_same_instances(const Exec &exec, const OtherExec &other_exec)
Definition kokkos.hpp:13
Matcher to filter out events that are just noise for tests.
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...
Definition event.hpp:46
Event to be sent to Kokkos::utils::callbacks::dispatch when an event is being waited for.
Definition event.hpp:63
decltype(std::declval< const context_t >().get_scheduler()) scheduler_t
Definition context.hpp:26
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:25