kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_split.cpp
Go to the documentation of this file.
2PRAGMA_DIAGNOSTIC_PUSH
4#include "exec/split.hpp"
5#include "exec/static_thread_pool.hpp"
6PRAGMA_DIAGNOSTIC_POP
7
9
12
16
28
30
31using namespace Kokkos::utils::callbacks;
32
45
47TEST_F(SplitTest, split_and_sync_wait) {
48 const context_t esc{exec};
49
50 stdexec::sender auto chain = stdexec::schedule(esc.get_scheduler()) | experimental::execution::split();
51
52 ASSERT_THAT(
53 recorder_listener_t::record([chain = std::move(chain)]() mutable { stdexec::sync_wait(std::move(chain)); }),
54 testing::IsEmpty());
55}
56
61TEST_F(SplitTest, within) {
62 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
63
64 experimental::execution::static_thread_pool pool{4};
65 const context_t esc{exec};
66
67 stdexec::sender auto fork = stdexec::schedule(pool.get_scheduler()) | experimental::execution::split();
68
69 auto branch_a = fork | stdexec::continues_on(esc.get_scheduler()) | THEN_INCREMENT_ATOMIC(data)
71 auto branch_b = fork | stdexec::continues_on(pool.get_scheduler()) | THEN_INCREMENT_ATOMIC(data);
72 auto branch_c = std::move(fork) | stdexec::continues_on(esc.get_scheduler()) | THEN_INCREMENT_ATOMIC(data)
74
75 auto chain = stdexec::when_all(std::move(branch_a), std::move(branch_b), std::move(branch_c))
76 | stdexec::then([&data]() {
77 if (data() != 5)
78 Kokkos::abort("Synchronization issue.");
79 });
80
81 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
82
83 const auto recorded_events = recorder_listener_t::record(
84 [chain = std::move(chain)]() mutable { stdexec::sync_wait(std::move(chain)); });
85
88 ASSERT_THAT(recorded_events, ::testing::SizeIs(8));
89 ASSERT_THAT(
90 recorded_events, ::testing::Contains(MATCHER_FOR_BEGIN_PFOR(exec, dispatch_label(exec, "then"))).Times(4));
91 ASSERT_THAT(recorded_events, ::testing::Contains(MATCHER_FOR_RECORD_EVENT(exec)).Times(2));
92 std::ranges::for_each(
93 recorded_events | std::views::filter([](const auto& event) -> bool {
94 return std::holds_alternative<Kokkos::Execution::Impl::RecordEvent>(event);
95 }),
96 [&](const auto& event) {
97 ASSERT_THAT(recorded_events, ::testing::Contains(MATCHER_FOR_WAIT_EVENT(event)).Times(1));
98 });
99 } else {
100 ASSERT_THAT(
101 recorded_events,
102 testing::UnorderedElementsAre(
105 MATCHER_FOR_BEGIN_FENCE(exec, dispatch_label(exec, "after dispatch")),
108 MATCHER_FOR_BEGIN_FENCE(exec, dispatch_label(exec, "after dispatch"))));
109 }
110
111 ASSERT_EQ(data(), 5);
112}
113
114} // 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
#define KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
Basic list of ignored diagnostics when including anything from stdexec.
#define THEN_INCREMENT_ATOMIC(_data_)
Same as THEN_INCREMENT, using Tests::Utils::atomic_add. // NOLINTNEXTLINE(cppcoreguidelines-macro-usa...
Definition increment.hpp:39
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
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:25