kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_bulk.cpp
Go to the documentation of this file.
3
12
24
26
27using namespace Kokkos::utils::callbacks;
28
36
38consteval bool test_sndr_traits() {
40 using schd_sndr_t = typename BulkTest::schedule_sender_t;
41
44 using bulk_sndr_t = stdexec::transform_sender_result_t<
45 decltype(stdexec::bulk(std::declval<schd_sndr_t>(), stdexec::par, 1, std::declval<functor_t>())),
46 stdexec::env<>
47 >;
48
49 static_assert(std::same_as<
50 bulk_sndr_t,
52 schd_sndr_t,
53 std::string_view,
54 functor_t,
55 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
56 >
57 >);
58
61 static_assert(std::same_as<Kokkos::Execution::ExecutionSpaceImpl::exec_of_t<bulk_sndr_t>, TEST_EXECUTION_SPACE>);
62
65
66 return true;
67}
68static_assert(test_sndr_traits());
69
72 using sndr_bulk_t =
73 decltype(stdexec::schedule(std::declval<typename BulkTest::scheduler_t>()) | stdexec::bulk(stdexec::par, 1, Tests::Utils::Functors::NoOp<false, false, false>{}));
74
75 static_assert(stdexec::__detail::__has_nothrow_transform_sender<
77 stdexec::set_value_t,
78 sndr_bulk_t&&,
79 stdexec::env<>
80 >);
81
82 using sndr_bulk_maythrow_on_move_t =
83 decltype(stdexec::schedule(std::declval<typename BulkTest::scheduler_t>()) | stdexec::bulk(stdexec::par, 1, Tests::Utils::Functors::NoOp<false, false, true>{}));
84
85 static_assert(!stdexec::__detail::__has_nothrow_transform_sender<
87 stdexec::set_value_t,
88 sndr_bulk_maythrow_on_move_t&&,
89 stdexec::env<>
90 >);
91
92 return true;
93}
95
101 using sndr_t = decltype(stdexec::bulk(
102 stdexec::schedule(std::declval<typename BulkTest::context_t>().get_scheduler()),
103 stdexec::par,
104 1,
106
107 static_assert(!std::is_const_v<sndr_t>);
108
110 using op_state_from_sndr_const_ref_t = stdexec::connect_result_t<const sndr_t&, Tests::Utils::SinkReceiver>;
111
112 static_assert(std::same_as<
113 op_state_from_sndr_const_ref_t,
115 const typename BulkTest::schedule_sender_t&,
118 std::string_view,
120 Kokkos::RangePolicy<TEST_EXECUTION_SPACE>
121 >
122 >
123 >);
124
125 return true;
126}
127static_assert(test_op_state_passed_by_const_ref());
128
130TEST_F(BulkTest, bulk) {
131 constexpr size_t size = 10;
132
133 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
134
135 const context_t esc{exec};
136
137 auto chain = stdexec::schedule(esc.get_scheduler()) | BULK_SUM_INDICES(size, data);
138
139 using chain_t = decltype(chain);
140
142 static_assert(std::same_as<stdexec::__domain_of_t<stdexec::env_of_t<chain_t>>, stdexec::default_domain>);
143 static_assert(std::same_as<
144 stdexec::__detail::__completing_domain_t<stdexec::set_value_t, chain_t>,
146 >);
147
149 static_assert(std::same_as<
150 decltype(stdexec::get_completion_scheduler<stdexec::set_value_t>(stdexec::get_env(chain))),
152 >);
153
154 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
155
156 ASSERT_THAT(
157 recorder_listener_t::record([chain = std::move(chain)]() mutable { stdexec::sync_wait(std::move(chain)); }),
158 testing::ElementsAre(
161
162 ASSERT_EQ(data(), size / 2 * (size - 1));
163}
164
166TEST_F(BulkTest, no_spurious_copy_on_connect) {
167 const context_t esc{exec};
168
170
171 {
172 auto lvalue = stdexec::schedule(esc.get_scheduler())
173 | stdexec::bulk(stdexec::par, 42, Tests::Utils::Functors::Counter{});
174
175 [[maybe_unused]]
176 auto lopstate = stdexec::connect(lvalue, Tests::Utils::SinkReceiver{});
177
181 }
182
184
185 {
186 auto rvalue = stdexec::schedule(esc.get_scheduler())
187 | stdexec::bulk(stdexec::par, 42, Tests::Utils::Functors::Counter{});
188
189 [[maybe_unused]]
190 auto ropstate = stdexec::connect(std::move(rvalue), Tests::Utils::SinkReceiver{});
191
195 }
196}
197
198} // namespace Tests::ExecutionSpaceImpl
constexpr std::string dispatch_label(const Exec &, Label &&label)
Get the dispatch label from Exec and label.
#define MATCHER_FOR_BEGIN_PFOR(_exec_, _label_)
#define MATCHER_FOR_BEGIN_FENCE(_exec_, _label_)
RecorderListener< EventDiscardMatcher< TEST_EXECUTION_SPACE >, BeginFenceEvent, BeginParallelForEvent > recorder_listener_t
Definition test_bulk.cpp:33
Concept for a sender whose completion scheduler is Kokkos::Execution::ExecutionSpaceImpl::Scheduler.
Concept that constrains the type of a sender that dispatches a functor for execution.
constexpr bool test_op_state_passed_by_const_ref()
consteval bool test_sndr_no_throw_transformable()
Definition test_bulk.cpp:71
consteval bool test_sndr_traits()
Definition test_bulk.cpp:38
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< Exec >
decltype(std::declval< const context_t >().get_scheduler()) scheduler_t
Definition context.hpp:26
decltype(stdexec::schedule(std::declval< scheduler_t >())) schedule_sender_t
Definition context.hpp:27
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:25
Count construction, move/copy construction, move/copy assignment and destruction atomically on host.
Definition counter.hpp:9
static std::atomic< unsigned int > move_assignments
Definition counter.hpp:15
static std::atomic< unsigned int > copy_constructions
Definition counter.hpp:12
static std::atomic< unsigned int > copy_assignments
Definition counter.hpp:13
A receiver that can handle all completions and does nothing with them.
#define BULK_SUM_INDICES(_size_, _data_)
Add a bulk using Tests::Utils::Functors::SumIndices. // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)...