kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
test_transfer_when_all.cpp
Go to the documentation of this file.
1
#include "
kokkos-execution/utils/ignore_warnings.hpp
"
2
PRAGMA_DIAGNOSTIC_PUSH
3
KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
4
#include "exec/single_thread_context.hpp"
5
PRAGMA_DIAGNOSTIC_POP
6
7
#include "
kokkos-utils/callbacks/RecorderListener.hpp
"
8
#include "
kokkos-utils/tests/scoped/callbacks/Manager.hpp
"
9
10
#include "
kokkos-execution/execution_space.hpp
"
11
12
#include "
tests/utils/callback_matchers.hpp
"
13
#include "
tests/utils/execution_space_context.hpp
"
14
#include "
tests/utils/functors/increment.hpp
"
15
#include "
tests/utils/kokkos.hpp
"
16
#include "
tests/utils/sync_wait.hpp
"
17
29
30
namespace
Tests::ExecutionSpaceImpl
{
31
32
using namespace
Kokkos::utils::callbacks;
33
34
class
TransferWhenAllTest
35
:
public
Tests::Utils::ExecutionSpaceContextTest
<TEST_EXECUTION_SPACE>
36
,
public
Kokkos::utils::tests::scoped::callbacks::Manager
{
37
public
:
38
using
recorder_listener_t
=
RecorderListener
<
39
EventDiscardMatcher<TEST_EXECUTION_SPACE>
,
40
BeginFenceEvent
,
41
BeginParallelForEvent
,
42
Kokkos::Execution::Impl::RecordEvent
,
43
Kokkos::Execution::Impl::WaitEvent
44
>;
45
};
46
48
TEST_F(
TransferWhenAllTest
, Y) {
49
const
view_s_t
data(Kokkos::view_alloc(
exec
,
"data - shared space"
));
50
51
const
auto
[exec_A, exec_B] = Kokkos::Experimental::partition_space(
exec
, 1, 1);
52
53
const
context_t
esc_A{exec_A}, esc_B{exec_B};
54
55
auto
w_a = stdexec::transfer_when_all(
56
esc_A.
get_scheduler
(),
57
stdexec::schedule(esc_A.
get_scheduler
()) |
THEN_INCREMENT_ATOMIC
(Device, data),
58
stdexec::schedule(esc_B.get_scheduler()) |
THEN_INCREMENT_ATOMIC
(Device, data));
59
60
static_assert
(std::same_as<
61
decltype
(stdexec::get_completion_domain<stdexec::set_value_t>(stdexec::get_env(w_a))),
62
Kokkos::Execution::ExecutionSpaceImpl::Domain
63
>);
64
66
static_assert
(std::same_as<
67
decltype
(stdexec::get_completion_scheduler<stdexec::set_value_t>(stdexec::get_env(w_a))),
68
scheduler_t
69
>);
70
static_assert
(
Kokkos::Execution::ExecutionSpaceImpl::execution_space_completing_sender
<
decltype
(w_a)>);
71
72
auto
sndr = std::move(w_a) |
THEN_INCREMENT
(data);
73
74
ASSERT_EQ(data(), 0) <<
"Eager execution is not allowed."
;
75
76
const
auto
recorded_events =
Tests::Utils::record_sync_wait<recorder_listener_t>
(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"
))));
86
}
else
{
87
ASSERT_THAT(recorded_events, [&]() {
88
if
constexpr
(
Kokkos::Execution::Impl::has_non_blocking_dispatch<TEST_EXECUTION_SPACE>
) {
89
return
testing::ElementsAre(
90
MATCHER_FOR_BEGIN_PFOR
(exec_A,
dispatch_label
(exec_A,
"then"
)),
91
MATCHER_FOR_BEGIN_PFOR
(exec_B,
dispatch_label
(exec_B,
"then"
)),
92
MATCHER_FOR_RECORD_EVENT
(exec_B),
93
MATCHER_FOR_WAIT_EVENT
(recorded_events.at(2)),
94
MATCHER_FOR_BEGIN_PFOR
(exec_A,
dispatch_label
(exec_A,
"then"
)),
95
MATCHER_FOR_BEGIN_FENCE
(exec_A,
dispatch_label
(exec_A,
"sync_wait"
)));
96
}
else
{
97
return
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
}
106
107
ASSERT_EQ(data(), 3);
108
}
109
110
}
// namespace Tests::ExecutionSpaceImpl
RecorderListener.hpp
callback_matchers.hpp
dispatch_label
constexpr std::string dispatch_label(const Exec &, Label &&label)
Get the dispatch label from Exec and label.
Definition
callback_matchers.hpp:47
MATCHER_FOR_WAIT_EVENT
#define MATCHER_FOR_WAIT_EVENT(_record_event_variant_)
Definition
callback_matchers.hpp:63
MATCHER_FOR_BEGIN_PFOR
#define MATCHER_FOR_BEGIN_PFOR(_exec_, _label_)
Definition
callback_matchers.hpp:30
MATCHER_FOR_RECORD_EVENT
#define MATCHER_FOR_RECORD_EVENT(_exec_)
Definition
callback_matchers.hpp:57
MATCHER_FOR_BEGIN_FENCE
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
Definition
callback_matchers.hpp:28
Kokkos::utils::callbacks::RecorderListener
Tests::ExecutionSpaceImpl::TransferWhenAllTest
Definition
test_transfer_when_all.cpp:36
Tests::ExecutionSpaceImpl::TransferWhenAllTest::recorder_listener_t
RecorderListener< EventDiscardMatcher< TEST_EXECUTION_SPACE >, BeginFenceEvent, BeginParallelForEvent, Kokkos::Execution::Impl::RecordEvent, Kokkos::Execution::Impl::WaitEvent > recorder_listener_t
Definition
test_transfer_when_all.cpp:38
Kokkos::Execution::ExecutionSpaceImpl::execution_space_completing_sender
Concept for a sender whose completion scheduler is Kokkos::Execution::ExecutionSpaceImpl::Scheduler.
Definition
sender_concepts.hpp:12
Kokkos::Execution::Impl::has_non_blocking_dispatch
Definition
event.hpp:48
execution_space.hpp
execution_space_context.hpp
ignore_warnings.hpp
KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
#define KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
Basic list of ignored diagnostics when including anything from stdexec.
Definition
ignore_warnings.hpp:38
increment.hpp
THEN_INCREMENT
#define THEN_INCREMENT(_data_)
Add a then using Tests::Utils::Functors::Increment that may throw. // NOLINTNEXTLINE(cppcoreguideline...
Definition
increment.hpp:59
THEN_INCREMENT_ATOMIC
#define THEN_INCREMENT_ATOMIC(_scope_, _data_)
Same as THEN_INCREMENT, using Tests::Utils::atomic_fetch_add. // NOLINTNEXTLINE(cppcoreguidelines-mac...
Definition
increment.hpp:63
kokkos.hpp
Tests::ExecutionSpaceImpl
Definition
test_any_sender.cpp:39
Tests::Utils::record_sync_wait
auto record_sync_wait(Sndr &&sndr)
Definition
sync_wait.hpp:14
Tests::Utils::are_same_instances
bool are_same_instances(const Exec &exec, const OtherExec &other_exec)
Definition
kokkos.hpp:13
EventDiscardMatcher
Matcher to filter out events that are just noise for tests.
Definition
callback_matchers.hpp:83
Kokkos::Execution::ExecutionSpaceContext::get_scheduler
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< Exec >
Definition
execution_space.hpp:133
Kokkos::Execution::ExecutionSpaceImpl::Domain
Definition
domain.hpp:13
Kokkos::Execution::Impl::RecordEvent
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition
event.hpp:54
Kokkos::Execution::Impl::WaitEvent
Event to be sent to Kokkos::utils::callbacks::dispatch when calling wait.
Definition
event.hpp:75
Kokkos::utils::callbacks::BeginFenceEvent
Kokkos::utils::callbacks::BeginParallelForEvent
Kokkos::utils::tests::scoped::ExecutionSpace< Exec >::exec
Exec exec
Kokkos::utils::tests::scoped::callbacks::Manager
Tests::Utils::ContextTest< Kokkos::Execution::ExecutionSpaceContext, Exec >::scheduler_t
decltype(std::declval< const context_t >().get_scheduler()) scheduler_t
Definition
context.hpp:28
Tests::Utils::ContextTest< Kokkos::Execution::ExecutionSpaceContext, Exec >::view_s_t
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition
context.hpp:32
Tests::Utils::ContextTest< Kokkos::Execution::ExecutionSpaceContext, Exec >::context_t
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition
context.hpp:27
Tests::Utils::ExecutionSpaceContextTest
Definition
execution_space_context.hpp:12
Manager.hpp
sync_wait.hpp
tests
execution_space
test_transfer_when_all.cpp
Generated on
for kokkos-execution by
1.18.0