kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
test_operation_state.cpp
Go to the documentation of this file.
1
#include "
kokkos-execution/execution_space.hpp
"
2
3
#include "
tests/utils/execution_space_context.hpp
"
4
#include "
tests/utils/functors/labeled.hpp
"
5
#include "
tests/utils/functors/sum_indices.hpp
"
6
#include "
tests/utils/sink_receiver.hpp
"
7
#include "
tests/utils/stdexec.hpp
"
8
20
21
namespace
Tests::ExecutionSpaceImpl
{
22
23
class
OpStateTest
:
public
Tests::Utils::ExecutionSpaceContextTest
<TEST_EXECUTION_SPACE> { };
24
26
consteval
bool
test_op_state_traits
() {
28
using
schd_sndr_t =
typename
OpStateTest::schedule_sender_t
;
29
31
using
functor_t =
Tests::Utils::Functors::SumIndices<typename OpStateTest::view_s_t>
;
32
using
policy_t = Kokkos::RangePolicy<TEST_EXECUTION_SPACE>;
33
using
clsr_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure<std::string, functor_t, policy_t>
;
34
36
using
rcvr_t =
Tests::Utils::SinkReceiver
;
37
39
using
op_state_t =
Kokkos::Execution::ExecutionSpaceImpl::OpState<schd_sndr_t, rcvr_t, clsr_t>
;
40
42
static_assert
(
Tests::Utils::operation_state<op_state_t>
);
43
45
static_assert
(std::derived_from<op_state_t, Kokkos::Execution::Impl::Immovable>);
46
static_assert
(!std::move_constructible<op_state_t>);
47
static_assert
(!std::is_move_assignable_v<op_state_t>);
48
49
static_assert
(!std::copy_constructible<op_state_t>);
50
static_assert
(!std::is_copy_assignable_v<op_state_t>);
51
52
return
true
;
53
}
54
static_assert
(
test_op_state_traits
());
55
60
constexpr
bool
test_op_state_passed_by_const_ref
() {
61
using
sndr_t =
decltype
(
Kokkos::Execution::parallel_for
(
62
stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
63
"hello from pfor"
,
64
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
65
Tests::Utils::Functors::Labeled
<
'a'
>{}));
66
67
static_assert
(!std::is_const_v<sndr_t>);
68
70
using
op_state_from_sndr_const_ref_t = stdexec::connect_result_t<const sndr_t&, Tests::Utils::SinkReceiver>;
71
72
static_assert
(std::same_as<
73
op_state_from_sndr_const_ref_t,
74
Kokkos::Execution::ExecutionSpaceImpl::OpState
<
75
const
typename
OpStateTest::schedule_sender_t
&,
76
Tests::Utils::SinkReceiver
,
77
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
78
std::string,
79
Tests::Utils::Functors::Labeled
<
'a'
>,
80
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
81
>
82
>
83
>);
84
85
return
true
;
86
}
87
static_assert
(
test_op_state_passed_by_const_ref
());
88
90
TEST_F(
OpStateTest
, construct_query_and_start) {
91
constexpr
size_t
size = 10;
92
93
const
view_s_t
witness(Kokkos::view_alloc(
exec
,
"witness - shared space"
));
94
95
const
context_t
esc{
exec
};
96
97
Kokkos::Execution::Impl::ParallelForData
pfor_data{
98
"hello from pfor"
,
Tests::Utils::Functors::SumIndices
{.data = witness}, Kokkos::RangePolicy(
exec
, 2, size)};
99
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
clsr{.data = std::move(pfor_data)};
100
101
auto
op_state =
Kokkos::Execution::ExecutionSpaceImpl::OpState
{
102
stdexec::schedule(esc.
get_scheduler
()),
Tests::Utils::SinkReceiver
{}, std::move(clsr)};
103
104
ASSERT_EQ(
Kokkos::Execution::Impl::get_exec
(op_state).get(),
exec
);
105
106
op_state.start();
107
exec
.fence();
108
109
ASSERT_EQ(witness(), size / 2 * (size - 1) - 1);
110
}
111
113
consteval
bool
test_op_state_flattened_from_two
() {
114
using
sndr_t =
decltype
(
Kokkos::Execution::parallel_for
(
115
Kokkos::Execution::parallel_for
(
116
stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
117
"hello from pfor"
,
118
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
119
Tests::Utils::Functors::Labeled
<
'a'
>{}),
120
"hello again from pfor"
,
121
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
122
Tests::Utils::Functors::Labeled
<
'b'
>{}));
123
124
using
op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
125
126
using
clsr_0_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
127
std::string,
128
Tests::Utils::Functors::Labeled
<
'a'
>,
129
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
130
>;
131
using
clsr_1_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
132
std::string,
133
Tests::Utils::Functors::Labeled
<
'b'
>,
134
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
135
>;
136
137
static_assert
(std::same_as<
138
op_state_t,
139
Kokkos::Execution::ExecutionSpaceImpl::OpState
<
140
typename
OpStateTest::schedule_sender_t
,
141
Tests::Utils::SinkReceiver
,
142
clsr_0_t,
143
clsr_1_t
144
>
145
>);
146
147
static_assert
(!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t>);
148
149
static_assert
(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 2);
150
151
return
true
;
152
}
153
static_assert
(
test_op_state_flattened_from_two
());
154
156
consteval
bool
test_op_state_flattened_from_three
() {
157
using
sndr_t =
decltype
(
Kokkos::Execution::parallel_for
(
158
Kokkos::Execution::parallel_for
(
159
Kokkos::Execution::parallel_for
(
160
stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
161
"hello from pfor"
,
162
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
163
Tests::Utils::Functors::Labeled
<
'a'
>{}),
164
"hello again from pfor"
,
165
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
166
Tests::Utils::Functors::Labeled
<
'b'
>{}),
167
"hello one more time from pfor"
,
168
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
169
Tests::Utils::Functors::Labeled
<
'c'
>{}));
170
171
using
op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
172
173
using
clsr_0_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
174
std::string,
175
Tests::Utils::Functors::Labeled
<
'a'
>,
176
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
177
>;
178
using
clsr_1_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
179
std::string,
180
Tests::Utils::Functors::Labeled
<
'b'
>,
181
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
182
>;
183
using
clsr_2_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
184
std::string,
185
Tests::Utils::Functors::Labeled
<
'c'
>,
186
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
187
>;
188
189
static_assert
(std::same_as<
190
op_state_t,
191
Kokkos::Execution::ExecutionSpaceImpl::OpState
<
192
typename
OpStateTest::schedule_sender_t
,
193
Tests::Utils::SinkReceiver
,
194
clsr_0_t,
195
clsr_1_t,
196
clsr_2_t
197
>
198
>);
199
200
static_assert
(
201
!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
202
203
static_assert
(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
204
205
return
true
;
206
}
207
static_assert
(
test_op_state_flattened_from_three
());
208
210
consteval
bool
test_op_state_flattened_from_three_mixed_tags
() {
211
using
sndr_t =
decltype
(stdexec::then(
212
stdexec::bulk(
213
Kokkos::Execution::parallel_for
(
214
stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
215
"hello from pfor"
,
216
Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>(0, 10),
217
Tests::Utils::Functors::Labeled
<
'a'
>{}),
218
stdexec::par,
219
10,
220
Tests::Utils::Functors::Labeled
<
'b'
>{}),
221
Tests::Utils::Functors::Labeled
<
'c'
>{}));
222
223
using
op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
224
225
using
clsr_0_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
226
std::string,
227
Tests::Utils::Functors::Labeled
<
'a'
>,
228
Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>
229
>;
230
using
clsr_1_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
231
std::string_view,
232
Tests::Utils::Functors::Labeled
<
'b'
>,
233
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
234
>;
235
using
clsr_2_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
236
std::string_view,
237
Kokkos::Execution::ExecutionSpaceImpl::ThenWrapper
<
Tests::Utils::Functors::Labeled
<
'c'
>>,
238
Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::LaunchBounds<1>>
239
>;
240
241
static_assert
(std::same_as<
242
op_state_t,
243
Kokkos::Execution::ExecutionSpaceImpl::OpState
<
244
typename
OpStateTest::schedule_sender_t
,
245
Tests::Utils::SinkReceiver
,
246
clsr_0_t,
247
clsr_1_t,
248
clsr_2_t
249
>
250
>);
251
252
static_assert
(
253
!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
254
255
static_assert
(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
256
257
return
true
;
258
}
259
static_assert
(
test_op_state_flattened_from_three_mixed_tags
());
260
261
}
// namespace Tests::ExecutionSpaceImpl
Tests::ExecutionSpaceImpl::OpStateTest
Definition
test_operation_state.cpp:23
Tests::Utils::operation_state
A stricter variant of stdexec::operation_state.
Definition
stdexec.hpp:34
execution_space.hpp
execution_space_context.hpp
labeled.hpp
Kokkos::Execution::Impl::get_exec
constexpr get_exec_t get_exec
Definition
get_exec.hpp:19
Kokkos::Execution::parallel_for
constexpr parallel_for_t parallel_for
Definition
parallel_for.hpp:92
Tests::ExecutionSpaceImpl
Definition
test_any_sender.cpp:39
Tests::ExecutionSpaceImpl::test_op_state_flattened_from_three
consteval bool test_op_state_flattened_from_three()
Definition
test_operation_state.cpp:156
Tests::ExecutionSpaceImpl::test_op_state_traits
consteval bool test_op_state_traits()
Definition
test_operation_state.cpp:26
Tests::ExecutionSpaceImpl::test_op_state_passed_by_const_ref
constexpr bool test_op_state_passed_by_const_ref()
Definition
test_bulk.cpp:121
Tests::ExecutionSpaceImpl::test_op_state_flattened_from_two
consteval bool test_op_state_flattened_from_two()
Definition
test_operation_state.cpp:113
Tests::ExecutionSpaceImpl::test_op_state_flattened_from_three_mixed_tags
consteval bool test_op_state_flattened_from_three_mixed_tags()
Definition
test_operation_state.cpp:210
sink_receiver.hpp
Kokkos::Execution::ExecutionSpaceContext::get_scheduler
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< Exec >
Definition
execution_space.hpp:133
Kokkos::Execution::ExecutionSpaceImpl::OpState
Definition
operation_state.hpp:101
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
Definition
parallel_for.hpp:17
Kokkos::Execution::ExecutionSpaceImpl::ThenWrapper
Inspired by https://github.com/kokkos/kokkos/blob/69273c3a4e7b6adeb95066341ca201d62fe1e698/core/src/i...
Definition
then.hpp:16
Kokkos::Execution::Impl::ParallelForData
Definition
parallel_for.hpp:54
Kokkos::utils::tests::scoped::ExecutionSpace< Exec >::exec
Exec exec
Tests::Utils::ContextTest< Kokkos::Execution::ExecutionSpaceContext, Exec >::schedule_sender_t
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition
context.hpp:29
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
Tests::Utils::Functors::Labeled
Definition
labeled.hpp:11
Tests::Utils::Functors::SumIndices
Definition
sum_indices.hpp:14
Tests::Utils::SinkReceiver
A receiver that can handle all completions and does nothing with them.
Definition
sink_receiver.hpp:9
sum_indices.hpp
stdexec.hpp
tests
execution_space
test_operation_state.cpp
Generated on
for kokkos-execution by
1.18.0