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 execute() 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 <stdexec::sender Sndr, typename Label, typename Functor, Kokkos::ExecutionPolicy ExecPolicy>
38 using sender_concept = stdexec::sender_t;
39
42
45 Sndr sndr; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
46
47 KOKKOS_EXECUTION_COMPL_SIGS_ADD(ParallelForSender, stdexec::set_error_t(std::exception_ptr))
48
49 template <stdexec::receiver Rcvr>
50 constexpr auto connect(Rcvr rcvr) && noexcept(noexcept(
51 MakeOpStateFn<Sndr, Rcvr, closure_t>{}(std::declval<Sndr>(), std::declval<Rcvr>(), std::declval<closure_t>())))
53 return MakeOpStateFn<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>
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, execution_space_completing_sender<Env> Sndr>
70 auto operator()(const Env& env, Kokkos::Execution::parallel_for_t, Data&& data, Sndr&& sndr) const
71 noexcept(std::is_nothrow_constructible_v<
75 Sndr&&
76 >) {
77 auto [label, functor, policy] = std::forward<Data>(data);
78
79 auto schd = stdexec::get_completion_scheduler<stdexec::set_value_t>(stdexec::get_env(sndr), env);
80
82 static_assert(
83 std::same_as<
84 typename decltype(schd)::execution_space,
86 >,
87 "The policy's execution space type must be the same as the completion scheduler's execution space type.");
88
91 {{std::move(label),
92 std::move(functor),
93 typename std::remove_cvref_t<Data>::policy_t(
94 Kokkos::Impl::PolicyUpdate{}, std::move(policy), schd.state->exec)}},
95 std::forward<Sndr>(sndr)};
96 }
97};
98
99} // namespace Kokkos::Execution::ExecutionSpaceImpl
100
101#if !STDEXEC_HAS_BUILTIN(__builtin_structured_binding_size)
102namespace stdexec {
103
105template <stdexec::sender Sndr, typename Label, typename Functor, Kokkos::ExecutionPolicy ExecPolicy>
106inline constexpr auto __structured_binding_size_v< // NOLINT(bugprone-reserved-identifier)
108> = 3;
109
110} // namespace stdexec
111#endif
112
113#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_.
typename MakeOpStateFn< Sndr, Rcvr, Clsrs... >::type opstate_t
Kokkos::Execution::Impl::ParallelForData< Label, Functor, policy_t > data
constexpr auto connect(Rcvr rcvr) &&noexcept(noexcept(MakeOpStateFn< Sndr, Rcvr, closure_t >{}(std::declval< Sndr >(), std::declval< Rcvr >(), std::declval< closure_t >()))) -> opstate_t< Sndr, Rcvr, closure_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 >, parallel_for_t, typename trnsfrmd_sndr_t< Env, Data, Sndr >::closure_t &&, Sndr && >)
ParallelForSender< 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
Custom algorithm for the Kokkos::parallel_for construct.
Kokkos::DefaultExecutionSpace execution_space