kokkos-execution 0.0.1
Loading...
Searching...
No Matches
parallel_for.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_EXECUTION_SPACE_PARALLEL_FOR_HPP
2#define KOKKOS_EXECUTION_EXECUTION_SPACE_PARALLEL_FOR_HPP
3
5
7
13
15
16template <typename Label, typename Functor, Kokkos::ExecutionPolicy ExecPolicy>
18 using policy_t = ExecPolicy;
19 using execution_space = typename policy_t::execution_space;
20
22
23 void submit() const & {
24 if constexpr (std::convertible_to<Label, std::string>) {
25 Kokkos::parallel_for(data.label, data.policy, data.functor);
26 } else {
27 Kokkos::parallel_for(std::string{data.label}, data.policy, data.functor);
28 }
29 }
30
31 const policy_t& get_policy() const & noexcept {
32 return data.policy;
33 }
34};
35
36template <typename Tag, stdexec::sender Sndr, typename Label, typename Functor, Kokkos::ExecutionPolicy ExecPolicy>
38 using sender_concept = stdexec::sender_tag;
39
42
44 Sndr sndr; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
45
46 KOKKOS_EXECUTION_COMPL_SIGS_ADD(ParallelForSender, stdexec::set_error_t(std::exception_ptr))
47
48 template <stdexec::receiver Rcvr>
49 constexpr auto connect(Rcvr rcvr) && noexcept(noexcept(
50 make_opstate_t<Sndr, Rcvr, closure_t>{}(std::declval<Sndr>(), std::declval<Rcvr>(), std::declval<closure_t>())))
52 return make_opstate_t<Sndr, Rcvr, closure_t>{}(std::forward<Sndr>(sndr), std::move(rcvr), std::move(clsr));
53 }
54
56};
57
58template <>
60 template <typename Env, typename Data, typename Sndr>
63 Sndr,
64 typename std::remove_cvref_t<Data>::label_t,
65 typename std::remove_cvref_t<Data>::functor_t,
66 typename std::remove_cvref_t<Data>::policy_t
67 >;
68
69 template <typename Env, typename Data, typename Sndr>
70 requires stdexec::__sends<stdexec::set_value_t, Sndr, Env>
71 auto operator()(const Env& env, Kokkos::Execution::parallel_for_t, Data&& data, Sndr&& sndr) const
72 noexcept(std::is_nothrow_constructible_v<
75 Sndr&&
76 >) {
78 auto [label, functor, policy] = std::forward<Data>(data);
79
80 auto schd = stdexec::get_completion_scheduler<stdexec::set_value_t>(stdexec::get_env(sndr), env);
81
83 static_assert(
84 std::same_as<
85 typename decltype(schd)::execution_space,
87 >,
88 "The policy's execution space type must be the same as the completion scheduler's execution space "
89 "type.");
90
92 {{std::move(label),
93 std::move(functor),
94 typename std::remove_cvref_t<Data>::policy_t(
95 Kokkos::Impl::PolicyUpdate{}, std::move(policy), schd.state->exec)}},
96 std::forward<Sndr>(sndr)};
97 } else {
99 }
100 }
101};
102
103} // namespace Kokkos::Execution::ExecutionSpaceImpl
104
105#endif // KOKKOS_EXECUTION_EXECUTION_SPACE_PARALLEL_FOR_HPP
#define KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV(_type_, _obj_)
#define KOKKOS_EXECUTION_COMPL_SIGS_ADD(_sndr_type_,...)
Completion signatures of _sndr_type_.
Concept for a sender whose completion scheduler is Kokkos::Execution::ExecutionSpaceImpl::Scheduler.
typename make_opstate_t< Sndr, Rcvr, Clsrs... >::type opstate_t
Impl::MakeOpState< Domain, OpState >::Huddle< Sndr, Rcvr, Clsrs... > make_opstate_t
auto no_execution_space_scheduler_in_env() noexcept
Show a better compile diagnostic when there is no Kokkos::Execution::ExecutionSpaceImpl::Scheduler fo...
Kokkos::Execution::Impl::ParallelForData< Label, Functor, policy_t > data
constexpr auto connect(Rcvr rcvr) &&noexcept(noexcept(make_opstate_t< Sndr, Rcvr, closure_t >{}(std::declval< Sndr >(), std::declval< Rcvr >(), std::declval< closure_t >()))) -> opstate_t< Sndr, Rcvr, closure_t >
ParallelForSender< parallel_for_t, Sndr, typename std::remove_cvref_t< Data >::label_t, typename std::remove_cvref_t< Data >::functor_t, typename std::remove_cvref_t< Data >::policy_t > trnsfrmd_sndr_t
auto operator()(const Env &env, Kokkos::Execution::parallel_for_t, Data &&data, Sndr &&sndr) const noexcept(std::is_nothrow_constructible_v< trnsfrmd_sndr_t< Env, Data, Sndr >, typename trnsfrmd_sndr_t< Env, Data, Sndr >::closure_t &&, Sndr && >)
Custom algorithm for the Kokkos::parallel_for construct.
Kokkos::DefaultExecutionSpace execution_space