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, Sndr, stdexec::set_error_t(std::exception_ptr))
47
48 template <stdexec::receiver Rcvr>
49 constexpr auto connect(Rcvr rcvr) && noexcept(noexcept(make_op_state_t<Sndr, Rcvr, closure_t>{}(
50 std::declval<Sndr>(),
51 std::declval<Rcvr>(),
52 std::declval<closure_t>()))) -> op_state_t<Sndr, Rcvr, closure_t> {
53 return make_op_state_t<Sndr, Rcvr, closure_t>{}(std::forward<Sndr>(sndr), std::move(rcvr), std::move(clsr));
54 }
55
57};
58
59template <>
61 template <typename Env, typename Data, typename Sndr>
64 Sndr,
65 typename std::remove_cvref_t<Data>::label_t,
66 typename std::remove_cvref_t<Data>::functor_t,
67 typename std::remove_cvref_t<Data>::policy_t
68 >;
69
70 template <typename Env, typename Data, typename Sndr>
71 requires stdexec::__sends<stdexec::set_value_t, Sndr, Env>
72 auto operator()(const Env& env, Kokkos::Execution::parallel_for_t, Data&& data, Sndr&& sndr) const
73 noexcept(std::is_nothrow_constructible_v<
76 Sndr&&
77 >) {
79 auto [label, functor, policy] = std::forward<Data>(data);
80
81 const auto schd = stdexec::get_completion_scheduler<stdexec::set_value_t>(stdexec::get_env(sndr), env);
82
84 static_assert(
85 std::same_as<
86 typename decltype(schd)::execution_space,
88 >,
89 "The policy's execution space type must be the same as the completion scheduler's execution space "
90 "type.");
91
93 {{std::move(label),
94 std::move(functor),
95 typename std::remove_cvref_t<Data>::policy_t(
96 Kokkos::Impl::PolicyUpdate{}, std::move(policy), schd.state->exec)}},
97 std::forward<Sndr>(sndr)};
98 } else {
100 }
101 }
102};
103
104} // namespace Kokkos::Execution::ExecutionSpaceImpl
105
106#endif // KOKKOS_EXECUTION_EXECUTION_SPACE_PARALLEL_FOR_HPP
#define KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV(_type_, _obj_)
#define KOKKOS_EXECUTION_COMPL_SIGS_ADD(_decayed_self_type_, _sndr_type_,...)
Concept for a sender whose completion scheduler is Kokkos::Execution::ExecutionSpaceImpl::Scheduler.
auto no_execution_space_scheduler_in_env() noexcept
Show a better compile diagnostic when there is no Kokkos::Execution::ExecutionSpaceImpl::Scheduler fo...
typename make_op_state_t< Sndr, Rcvr, Clsrs... >::type op_state_t
Impl::MakeOpState< Domain, OpState >::Huddle< Sndr, Rcvr, Clsrs... > make_op_state_t
Kokkos::Execution::Impl::ParallelForData< Label, Functor, policy_t > data
constexpr auto connect(Rcvr rcvr) &&noexcept(noexcept(make_op_state_t< Sndr, Rcvr, closure_t >{}(std::declval< Sndr >(), std::declval< Rcvr >(), std::declval< closure_t >()))) -> op_state_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