kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_let_value.cpp
Go to the documentation of this file.
2PRAGMA_DIAGNOSTIC_PUSH
4#include "exec/single_thread_context.hpp"
5PRAGMA_DIAGNOSTIC_POP
6
10
14
26
28
29using namespace Kokkos::utils::callbacks;
30
39
41TEST_F(LetValueTest, scoped_allocation) {
42 const view_s_t data(Kokkos::view_alloc(exec, "data - shared space"));
43
44 const context_t esc{exec};
45
46 experimental::execution::single_thread_context stc{};
47
48 using view_of_5_t = Kokkos::View<value_t[5], typename TEST_EXECUTION_SPACE::memory_space>;
49
51 auto allocate = stdexec::schedule(esc.get_scheduler())
52 | stdexec::let_value([this]() noexcept -> stdexec::sender auto {
53 return stdexec::just(
54 view_of_5_t{Kokkos::view_alloc(exec, "scratch", Kokkos::WithoutInitializing)});
55 });
56
57 static_assert(
58 Tests::Utils::has_completion_signatures<decltype(allocate), stdexec::__mset<stdexec::set_value_t(view_of_5_t)>>);
59
61#if defined(KOKKOS_COMPILER_CLANG) && defined(KOKKOS_ENABLE_CUDA)
64 decltype(allocate),
65 stdexec::__mset<stdexec::set_value_t(view_of_5_t), stdexec::set_error_t(std::exception_ptr)>,
66 stdexec::env<>
67 >);
68#else
71 decltype(allocate),
72 stdexec::__mset<stdexec::set_value_t(view_of_5_t)>,
73 stdexec::env<>
74 >);
75#endif
76
78 auto run = std::move(allocate) // NOLINT(performance-move-const-arg)
87 | stdexec::let_value([&esc, &data, &stc](auto&& scratch) noexcept -> stdexec::sender auto {
88 static_assert(std::same_as<decltype(scratch), view_of_5_t&>);
89 EXPECT_EQ(scratch.use_count(), 1);
90 return stdexec::schedule(esc.get_scheduler())
91 | stdexec::bulk(
92 stdexec::par,
93 5,
94 KOKKOS_LAMBDA<std::integral T>(const T index) {
101 KOKKOS_IF_ON_HOST(EXPECT_EQ(scratch.use_count(), 2);)
102 scratch(index) = index;
103 Kokkos::atomic_add(data.data(), scratch(index));
104 })
105 | stdexec::continues_on(stc.get_scheduler())
106 | stdexec::then([&scratch]() mutable -> Kokkos::utils::concepts::ViewOfRank<1> auto {
108 EXPECT_EQ(scratch.use_count(), 2);
109 return std::move(scratch);
110 });
111 });
112
114 decltype(run),
115 stdexec::__mset<stdexec::set_value_t(view_of_5_t), stdexec::set_error_t(std::exception_ptr)>,
116 stdexec::env<>
117 >);
118
120 auto check = std::move(run) // NOLINT(performance-move-const-arg)
121 | stdexec::let_value([&esc, &data](auto&& scratch) noexcept -> stdexec::sender auto {
122 static_assert(std::same_as<decltype(scratch), view_of_5_t&>);
137 EXPECT_EQ(scratch.use_count(), 2);
138 return stdexec::schedule(esc.get_scheduler())
139 | stdexec::bulk(
140 stdexec::par, 5, KOKKOS_LAMBDA<std::integral T>(const T index) {
141 Kokkos::atomic_add(data.data(), scratch(index));
148 KOKKOS_IF_ON_HOST(EXPECT_EQ(scratch.use_count(), 2);)
149 });
150 });
151
153 decltype(check),
154 stdexec::__mset<stdexec::set_value_t(), stdexec::set_error_t(std::exception_ptr)>,
155 stdexec::env<>
156 >);
157
158 ASSERT_EQ(data(), 0) << "Eager execution is not allowed.";
159
160 ASSERT_THAT(
161 recorder_listener_t::record([check = std::move(check)]() mutable { // NOLINT(performance-move-const-arg)
162 stdexec::sync_wait(std::move(check)); // NOLINT(performance-move-const-arg)
163 }),
166 testing::Field(
168 testing::Field(&Kokkos::utils::callbacks::AllocDescriptor::name, testing::StrEq("scratch")))),
174 testing::Field(
176 testing::Field(&Kokkos::utils::callbacks::AllocDescriptor::name, testing::StrEq("scratch"))))));
177
178 ASSERT_EQ(data(), 2 * (0 + 1 + 2 + 3 + 4));
179}
180
181} // 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< BeginFenceEvent, BeginParallelForEvent, AllocateDataEvent, DeallocateDataEvent > recorder_listener_t
typename recorder_listener_t::event_variant_t variant_t
#define KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
Basic list of ignored diagnostics when including anything from stdexec.
auto AAllocateDataEvent(Matchers &&... matchers)
auto ADeallocateDataEvent(Matchers &&... matchers)
auto ContainsInOrder(Matchers &&... matchers)
auto get_scheduler() const noexcept -> ExecutionSpaceImpl::Scheduler< Exec >
Kokkos::Execution::ExecutionSpaceContext< Exec > context_t
Definition context.hpp:25