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
<
34
TEST_EXECUTION_SPACE,
35
Kokkos::Execution::Impl::ParallelForData<functor_t, policy_t, Kokkos::Execution::Impl::Label<std::string_view>
>
36
>;
37
39
using
rcvr_t =
Tests::Utils::SinkReceiver
;
40
42
using
op_state_t =
Kokkos::Execution::ExecutionSpaceImpl::OpState<schd_sndr_t, rcvr_t, clsr_t>
;
43
45
static_assert
(
Tests::Utils::operation_state<op_state_t>
);
46
48
static_assert
(std::derived_from<op_state_t, Kokkos::Execution::Impl::Immovable>);
49
static_assert
(!std::move_constructible<op_state_t>);
50
static_assert
(!std::is_move_assignable_v<op_state_t>);
51
52
static_assert
(!std::copy_constructible<op_state_t>);
53
static_assert
(!std::is_copy_assignable_v<op_state_t>);
54
55
return
true
;
56
}
57
58
static_assert
(
test_op_state_traits
());
59
64
constexpr
bool
test_op_state_passed_by_const_ref
() {
65
using
sndr_t =
decltype
(
Kokkos::Execution::parallel_for
(
66
stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
67
Kokkos::Execution::label
(
"hello from pfor"
),
68
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
69
Tests::Utils::Functors::Labeled
<
'a'
>{}));
70
71
static_assert
(!std::is_const_v<sndr_t>);
72
74
using
op_state_from_sndr_const_ref_t = stdexec::connect_result_t<const sndr_t&, Tests::Utils::SinkReceiver>;
75
76
static_assert
(std::same_as<
77
op_state_from_sndr_const_ref_t,
78
Kokkos::Execution::ExecutionSpaceImpl::OpState
<
79
const
typename
OpStateTest::schedule_sender_t
&,
80
Tests::Utils::SinkReceiver
,
81
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
82
TEST_EXECUTION_SPACE,
83
Kokkos::Execution::Impl::ParallelForData
<
84
Tests::Utils::Functors::Labeled
<
'a'
>,
85
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
86
Kokkos::Execution::Impl::Label<std::string_view>
87
>
88
>
89
>
90
>);
91
92
return
true
;
93
}
94
95
static_assert
(
test_op_state_passed_by_const_ref
());
96
98
TEST_F(
OpStateTest
, construct_query_and_start) {
99
constexpr
size_t
size = 10;
100
101
const
view_s_t
witness(Kokkos::view_alloc(
exec
,
"witness - shared space"
));
102
103
const
context_t
esc{
exec
};
104
105
using
functor_t =
Tests::Utils::Functors::SumIndices<view_s_t>
;
106
107
Kokkos::Execution::Impl::ParallelForData
<
108
functor_t,
109
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
110
Kokkos::Execution::Impl::Label<std::string>
111
>
112
pfor_data{{
"hello from pfor"
}, functor_t{.data = witness}, Kokkos::RangePolicy(
exec
, 2, size)};
113
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
clsr{.state = &esc.
m_state
, .data = std::move(pfor_data)};
114
115
auto
op_state =
Kokkos::Execution::ExecutionSpaceImpl::OpState
{
116
stdexec::schedule(esc.
get_scheduler
()),
Tests::Utils::SinkReceiver
{}, std::move(clsr)};
117
118
ASSERT_EQ(
Kokkos::Execution::Impl::get_exec
(op_state).get(),
exec
);
119
120
op_state.start();
121
exec
.fence();
122
123
ASSERT_EQ(witness(), size / 2 * (size - 1) - 1);
124
}
125
127
consteval
bool
test_op_state_flattened_from_two
() {
128
using
sndr_t =
decltype
(
Kokkos::Execution::parallel_for
(
129
Kokkos::Execution::parallel_for
(
130
stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
131
"hello from pfor"
,
132
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
133
Tests::Utils::Functors::Labeled
<
'a'
>{}),
134
"hello again from pfor"
,
135
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
136
Tests::Utils::Functors::Labeled
<
'b'
>{}));
137
138
using
op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
139
140
using
clsr_0_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
141
TEST_EXECUTION_SPACE,
142
Kokkos::Execution::Impl::ParallelForData
<
143
Tests::Utils::Functors::Labeled
<
'a'
>,
144
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
145
Kokkos::Execution::Impl::Label<std::string>
146
>
147
>;
148
using
clsr_1_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
149
TEST_EXECUTION_SPACE,
150
Kokkos::Execution::Impl::ParallelForData
<
151
Tests::Utils::Functors::Labeled
<
'b'
>,
152
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
153
Kokkos::Execution::Impl::Label<std::string>
154
>
155
>;
156
157
static_assert
(std::same_as<
158
op_state_t,
159
Kokkos::Execution::ExecutionSpaceImpl::OpState
<
160
typename
OpStateTest::schedule_sender_t
,
161
Tests::Utils::SinkReceiver
,
162
clsr_0_t,
163
clsr_1_t
164
>
165
>);
166
167
static_assert
(!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t>);
168
169
static_assert
(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 2);
170
171
return
true
;
172
}
173
174
static_assert
(
test_op_state_flattened_from_two
());
175
177
consteval
bool
test_op_state_flattened_from_three
() {
178
using
sndr_t =
decltype
(
Kokkos::Execution::parallel_for
(
179
Kokkos::Execution::parallel_for
(
180
Kokkos::Execution::parallel_for
(
181
stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
182
"hello from pfor"
,
183
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
184
Tests::Utils::Functors::Labeled
<
'a'
>{}),
185
"hello again from pfor"
,
186
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
187
Tests::Utils::Functors::Labeled
<
'b'
>{}),
188
"hello one more time from pfor"
,
189
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>(0, 10),
190
Tests::Utils::Functors::Labeled
<
'c'
>{}));
191
192
using
op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
193
194
using
clsr_0_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
195
TEST_EXECUTION_SPACE,
196
Kokkos::Execution::Impl::ParallelForData
<
197
Tests::Utils::Functors::Labeled
<
'a'
>,
198
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
199
Kokkos::Execution::Impl::Label<std::string>
200
>
201
>;
202
using
clsr_1_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
203
TEST_EXECUTION_SPACE,
204
Kokkos::Execution::Impl::ParallelForData
<
205
Tests::Utils::Functors::Labeled
<
'b'
>,
206
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
207
Kokkos::Execution::Impl::Label<std::string>
208
>
209
>;
210
using
clsr_2_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
211
TEST_EXECUTION_SPACE,
212
Kokkos::Execution::Impl::ParallelForData
<
213
Tests::Utils::Functors::Labeled
<
'c'
>,
214
Kokkos::RangePolicy<TEST_EXECUTION_SPACE>,
215
Kokkos::Execution::Impl::Label<std::string>
216
>
217
>;
218
219
static_assert
(std::same_as<
220
op_state_t,
221
Kokkos::Execution::ExecutionSpaceImpl::OpState
<
222
typename
OpStateTest::schedule_sender_t
,
223
Tests::Utils::SinkReceiver
,
224
clsr_0_t,
225
clsr_1_t,
226
clsr_2_t
227
>
228
>);
229
230
static_assert
(
231
!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
232
233
static_assert
(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
234
235
return
true
;
236
}
237
238
static_assert
(
test_op_state_flattened_from_three
());
239
241
consteval
bool
test_op_state_flattened_from_three_mixed_tags
() {
242
using
sndr_t =
decltype
(stdexec::then(
243
stdexec::bulk(
244
Kokkos::Execution::parallel_for
(
245
stdexec::schedule(std::declval<typename OpStateTest::context_t>().get_scheduler()),
246
Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>(0, 10),
247
Tests::Utils::Functors::Labeled
<
'a'
>{}),
248
stdexec::par,
249
char(10),
250
Tests::Utils::Functors::Labeled
<
'b'
>{}),
251
Tests::Utils::Functors::Labeled
<
'c'
>{}));
252
253
using
op_state_t = stdexec::connect_result_t<sndr_t&&, Tests::Utils::SinkReceiver>;
254
255
using
clsr_0_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
256
TEST_EXECUTION_SPACE,
257
Kokkos::Execution::Impl::ParallelForData
<
258
Tests::Utils::Functors::Labeled
<
'a'
>,
259
Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<size_t>>
260
>
261
>;
262
using
clsr_1_t =
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
<
263
TEST_EXECUTION_SPACE,
264
Kokkos::Execution::Impl::ParallelForData
<
265
Tests::Utils::Functors::Labeled
<
'b'
>,
266
Kokkos::RangePolicy<TEST_EXECUTION_SPACE, Kokkos::IndexType<char>>,
267
Kokkos::Execution::Impl::Label<std::string_view>
268
>
269
>;
270
using
clsr_2_t =
Kokkos::Execution::ExecutionSpaceImpl::ThenClosure
<
271
TEST_EXECUTION_SPACE,
272
std::string_view,
273
Tests::Utils::Functors::Labeled
<
'c'
>
274
>;
275
276
static_assert
(std::same_as<
277
op_state_t,
278
Kokkos::Execution::ExecutionSpaceImpl::OpState
<
279
typename
OpStateTest::schedule_sender_t
,
280
Tests::Utils::SinkReceiver
,
281
clsr_0_t,
282
clsr_1_t,
283
clsr_2_t
284
>
285
>);
286
287
static_assert
(
288
!std::is_nothrow_constructible_v<op_state_t, sndr_t, Tests::Utils::SinkReceiver, clsr_0_t, clsr_1_t, clsr_2_t>);
289
290
static_assert
(stdexec::__tuple_size_v<typename op_state_t::closures_t> == 3);
291
292
return
true
;
293
}
294
295
static_assert
(
test_op_state_flattened_from_three_mixed_tags
());
296
297
}
// 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:30
execution_space.hpp
execution_space_context.hpp
labeled.hpp
Kokkos::Execution::Impl::get_exec
constexpr get_exec_t get_exec
Definition
get_exec.hpp:24
Kokkos::Execution::label
consteval Impl::Label< std::string_view > label(std::string_view str) noexcept
Definition
label.hpp:91
Kokkos::Execution::parallel_for
constexpr parallel_for_t parallel_for
Definition
parallel_for.hpp:170
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:177
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:139
Tests::ExecutionSpaceImpl::test_op_state_flattened_from_two
consteval bool test_op_state_flattened_from_two()
Definition
test_operation_state.cpp:127
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:241
sink_receiver.hpp
Kokkos::Execution::ExecutionSpaceContext::m_state
state_t m_state
Definition
execution_space.hpp:135
Kokkos::Execution::ExecutionSpaceContext::get_scheduler
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< execution_space >
Definition
execution_space.hpp:141
Kokkos::Execution::ExecutionSpaceImpl::OpState
Definition
operation_state.hpp:101
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
Definition
parallel_for.hpp:19
Kokkos::Execution::ExecutionSpaceImpl::ThenClosure
Definition
then.hpp:15
Kokkos::Execution::Impl::Label
Label property.
Definition
label.hpp:44
Kokkos::Execution::Impl::ParallelForData
Definition
parallel_for.hpp:116
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:35
Tests::Utils::ContextTest< Kokkos::Execution::ExecutionSpaceContext, Exec >::view_s_t
Kokkos::View< value_t, Kokkos::SharedSpace > view_s_t
Definition
context.hpp:38
Tests::Utils::ContextTest< Kokkos::Execution::ExecutionSpaceContext, Exec >::context_t
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition
context.hpp:33
Tests::Utils::ExecutionSpaceContextTest
Definition
execution_space_context.hpp:12
Tests::Utils::Functors::Labeled
Definition
labeled.hpp:16
Tests::Utils::Functors::SumIndices
Definition
sum_indices.hpp:19
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