kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
check_sync_wait.hpp
Go to the documentation of this file.
1
#ifndef KOKKOS_EXECUTION_TESTS_UTILS_CHECK_SYNC_WAIT_HPP
2
#define KOKKOS_EXECUTION_TESTS_UTILS_CHECK_SYNC_WAIT_HPP
3
4
#include "gtest/gtest.h"
5
6
#include "Kokkos_Macros.hpp"
7
#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
8
import
kokkos.core;
9
#else
10
# include "Kokkos_Core.hpp"
11
#endif
12
13
#include "
kokkos-utils/callbacks/RecorderListener.hpp
"
14
#include "
kokkos-utils/tests/scoped/ExecutionSpace.hpp
"
15
#include "
kokkos-utils/tests/scoped/callbacks/Manager.hpp
"
16
17
#include "
kokkos-execution/graph/events.hpp
"
18
19
#include "
tests/utils/callback_matchers.hpp
"
20
#include "
tests/utils/category.hpp
"
21
#include "
tests/utils/check_completion_scheduler_type.hpp
"
22
#include "
tests/utils/functors/store_thread_id.hpp
"
23
#include "
tests/utils/functors/throws_when_copied.hpp
"
24
#include "
tests/utils/schedulers/stopped.hpp
"
25
#include "
tests/utils/stdexec.hpp
"
26
27
namespace
Tests::Utils
{
28
30
template
<
typename
Domain, stdexec::sender Sndr>
31
consteval
bool
check_nothrow_apply_sender
() {
32
static_assert
(stdexec::__never_sends<stdexec::set_error_t, Sndr>);
33
static_assert
(
Tests::Utils::has_nothrow_apply_sender<Domain, stdexec::sync_wait_t, Sndr>
);
34
static_assert
(!
Tests::Utils::has_nothrow_apply_sender<stdexec::sync_wait_t, Sndr>
);
35
return
true
;
36
}
37
38
template
<
typename
ContextType>
39
struct
TEST_CATEGORY(SyncWaitTest)
40
:
public
virtual
testing::Test
41
,
public
Kokkos::utils::tests::scoped::ExecutionSpace
<typename ContextType::execution_space>
42
,
public
Kokkos::utils::tests::scoped::callbacks::Manager
{
43
using
execution_space
=
typename
ContextType::execution_space;
44
45
using
recorder_listener_t
=
Kokkos::utils::callbacks::RecorderListener
<
46
EventDiscardMatcher<execution_space>
,
47
Kokkos::utils::callbacks::BeginFenceEvent
,
48
Kokkos::utils::callbacks::BeginSingleEvent
,
49
Kokkos::utils::callbacks::BeginParallelForEvent
,
50
Kokkos::utils::callbacks::BeginParallelReduceEvent
,
51
Kokkos::Execution::Impl::RecordEvent
,
52
Kokkos::Execution::GraphImpl::GraphCreateEvent
53
>;
54
55
const
ContextType
ctx
{this->
exec
};
56
};
57
58
TYPED_TEST_SUITE_P(
TEST_CATEGORY
(
SyncWaitTest
));
59
64
TYPED_TEST_P(
TEST_CATEGORY
(
SyncWaitTest
),
get_start_scheduler
) {
65
std::thread::id tid;
66
67
auto
sndr = stdexec::read_env(stdexec::get_start_scheduler)
68
| stdexec::let_value([&](
auto
schd) {
return
stdexec::schedule(schd) |
THEN_STORE_THREAD_ID
(&tid); })
69
|
Tests::Utils::check_completion_scheduler_type<stdexec::set_value_t, stdexec::run_loop::scheduler>
()
70
| stdexec::continues_on(this->
ctx
.get_scheduler());
71
72
stdexec::sync_wait(std::move(sndr));
// NOLINT(performance-move-const-arg)
73
74
ASSERT_EQ(tid, std::this_thread::get_id());
75
}
76
81
TYPED_TEST_P(
TEST_CATEGORY
(
SyncWaitTest
),
just
) {
82
std::thread::id tid;
83
84
auto
sndr = stdexec::just() |
THEN_STORE_THREAD_ID
(&tid)
85
|
Tests::Utils::check_completion_scheduler_type<stdexec::set_value_t, stdexec::run_loop::scheduler>
()
86
| stdexec::continues_on(this->
ctx
.get_scheduler());
87
88
stdexec::sync_wait(std::move(sndr));
// NOLINT(performance-move-const-arg)
89
90
ASSERT_EQ(tid, std::this_thread::get_id());
91
}
92
94
TYPED_TEST_P(
TEST_CATEGORY
(
SyncWaitTest
),
set_value_no_spurious_fence
) {
95
auto
sndr = stdexec::schedule(this->
ctx
.get_scheduler());
96
97
ASSERT_THAT(
98
TestFixture::recorder_listener_t::record(
99
[sndr = std::move(sndr)]()
mutable
{
// NOLINT(performance-move-const-arg)
100
const
auto
value = stdexec::sync_wait(std::move(sndr));
// NOLINT(performance-move-const-arg)
101
static_assert
(std::same_as<
decltype
(value),
const
std::optional<std::tuple<>>>);
102
ASSERT_TRUE(value.has_value());
103
}),
104
testing::IsEmpty());
105
}
106
108
TYPED_TEST_P(
TEST_CATEGORY
(
SyncWaitTest
),
set_stopped_no_spurious_fence
) {
109
auto
sndr = stdexec::schedule(
Tests::Utils::Schedulers::Stopped
{})
110
| stdexec::continues_on(this->
ctx
.get_scheduler());
111
112
ASSERT_THAT(
113
TestFixture::recorder_listener_t::record(
114
[sndr = std::move(sndr)]()
mutable
{
// NOLINT(performance-move-const-arg)
115
const
auto
value = stdexec::sync_wait(std::move(sndr));
// NOLINT(performance-move-const-arg)
116
static_assert
(std::same_as<
decltype
(value),
const
std::optional<std::tuple<>>>);
117
ASSERT_FALSE(value.has_value());
118
}),
119
testing::IsEmpty());
120
}
121
123
TYPED_TEST_P(
TEST_CATEGORY
(
SyncWaitTest
),
rethrows
) {
124
auto
sndr = stdexec::schedule(this->
ctx
.get_scheduler())
125
| stdexec::then(
Tests::Utils::Functors::ThrowsWhenCopied
{});
126
127
ASSERT_THAT(
128
Tests::Utils::Functors::MutableMoveToSyncWait
{.sndr = std::move(sndr)},
129
testing::ThrowsMessage<std::runtime_error>(testing::StrEq(
"ThrowsWhenCopied: Throwing in copy constructor!"
)));
130
}
131
132
REGISTER_TYPED_TEST_SUITE_P(
133
TEST_CATEGORY
(
SyncWaitTest
),
134
get_start_scheduler
,
135
just
,
136
set_value_no_spurious_fence
,
137
set_stopped_no_spurious_fence
,
138
rethrows
);
139
140
}
// namespace Tests::Utils
141
142
#endif
// KOKKOS_EXECUTION_TESTS_UTILS_CHECK_SYNC_WAIT_HPP
ExecutionSpace.hpp
RecorderListener.hpp
callback_matchers.hpp
category.hpp
TEST_CATEGORY
#define TEST_CATEGORY(_name_)
Definition
category.hpp:10
check_completion_scheduler_type.hpp
Kokkos::utils::callbacks::RecorderListener
Tests::Utils::gtest_suite_SyncWaitTest_::get_start_scheduler
Definition
check_sync_wait.hpp:64
Tests::Utils::gtest_suite_SyncWaitTest_::just
Definition
check_sync_wait.hpp:81
Tests::Utils::gtest_suite_SyncWaitTest_::rethrows
Definition
check_sync_wait.hpp:123
Tests::Utils::gtest_suite_SyncWaitTest_::set_stopped_no_spurious_fence
Definition
check_sync_wait.hpp:108
Tests::Utils::gtest_suite_SyncWaitTest_::set_value_no_spurious_fence
Definition
check_sync_wait.hpp:94
Tests::Utils::has_nothrow_apply_sender
Check that apply_sender is noexcept.
Definition
stdexec.hpp:42
events.hpp
Tests::Utils
Definition
test_sync_wait.cpp:20
Tests::Utils::check_nothrow_apply_sender
consteval bool check_nothrow_apply_sender()
Definition
check_sync_wait.hpp:31
Tests::Utils::check_completion_scheduler_type
constexpr check_completion_scheduler_type_t< Tag, Schd > check_completion_scheduler_type
Definition
check_completion_scheduler_type.hpp:76
stopped.hpp
store_thread_id.hpp
THEN_STORE_THREAD_ID
#define THEN_STORE_THREAD_ID(__id__)
Add a stdexec::then calling Tests::Utils::Functors::StoreThreadID. // NOLINTNEXTLINE(cppcoreguideline...
Definition
store_thread_id.hpp:20
EventDiscardMatcher
Matcher to filter out events that are just noise for tests.
Definition
callback_matchers.hpp:99
Kokkos::Execution::GraphImpl::GraphCreateEvent
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition
events.hpp:28
Kokkos::Execution::Impl::RecordEvent
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition
event.hpp:59
Kokkos::utils::callbacks::BeginFenceEvent
Kokkos::utils::callbacks::BeginParallelForEvent
Kokkos::utils::callbacks::BeginParallelReduceEvent
Kokkos::utils::callbacks::BeginSingleEvent
Kokkos::utils::tests::scoped::ExecutionSpace
Kokkos::utils::tests::scoped::ExecutionSpace::exec
Exec exec
Kokkos::utils::tests::scoped::callbacks::Manager
Tests::Utils::Functors::MutableMoveToSyncWait
Definition
throws_when_copied.hpp:21
Tests::Utils::Functors::ThrowsWhenCopied
This helper struct throws when copy constructed.
Definition
throws_when_copied.hpp:35
Tests::Utils::Schedulers::Stopped
Scheduler that returns a sender that always completes on the stop channel.
Definition
stopped.hpp:22
Tests::Utils::SyncWaitTest
Definition
check_sync_wait.hpp:42
Tests::Utils::SyncWaitTest< gtest_TypeParam_ >::ctx
const gtest_TypeParam_ ctx
Definition
check_sync_wait.hpp:55
Tests::Utils::SyncWaitTest::recorder_listener_t
Kokkos::utils::callbacks::RecorderListener< EventDiscardMatcher< execution_space >, Kokkos::utils::callbacks::BeginFenceEvent, Kokkos::utils::callbacks::BeginSingleEvent, Kokkos::utils::callbacks::BeginParallelForEvent, Kokkos::utils::callbacks::BeginParallelReduceEvent, Kokkos::Execution::Impl::RecordEvent, Kokkos::Execution::GraphImpl::GraphCreateEvent > recorder_listener_t
Definition
check_sync_wait.hpp:45
Tests::Utils::SyncWaitTest::execution_space
typename ContextType::execution_space execution_space
Definition
check_sync_wait.hpp:43
Manager.hpp
stdexec.hpp
throws_when_copied.hpp
tests
utils
check_sync_wait.hpp
Generated on
for kokkos-execution by
1.18.0