kokkos-execution
0.0.1
Toggle main menu visibility
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
4
#include "
kokkos-execution/stdexec.hpp
"
5
6
#include "
kokkos-execution/execution_space/execution_space_fwd.hpp
"
7
8
#include "
kokkos-execution/execution_space/operation_state.hpp
"
9
#include "
kokkos-execution/execution_space/sender_concepts.hpp
"
10
#include "
kokkos-execution/impl/attributes.hpp
"
11
#include "
kokkos-execution/impl/sender_introspection.hpp
"
12
#include "
kokkos-execution/parallel_for.hpp
"
13
14
namespace
Kokkos::Execution::ExecutionSpaceImpl
{
15
16
template
<
typename
Label,
typename
Functor, Kokkos::ExecutionPolicy ExecPolicy>
17
struct
ParallelForClosure
{
18
using
policy_t
= ExecPolicy;
19
using
execution_space
=
typename
policy_t::execution_space;
20
21
Kokkos::Execution::Impl::ParallelForData<Label, Functor, policy_t>
data
;
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
36
template
<
typename
Tag, stdexec::sender Sndr,
typename
Label,
typename
Functor, Kokkos::ExecutionPolicy ExecPolicy>
37
struct
ParallelForSender
{
38
using
sender_concept
= stdexec::sender_tag;
39
40
using
closure_t
=
ParallelForClosure<Label, Functor, ExecPolicy>
;
41
using
execution_space
=
typename
closure_t::execution_space
;
42
43
closure_t
clsr
;
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
56
KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV
(Sndr,
sndr
)
57
};
58
59
template
<>
60
struct
TransformSenderFor
<
Kokkos
::
Execution::parallel_for_t
> {
61
template
<
typename
Env,
typename
Data,
typename
Sndr>
62
using
trnsfrmd_sndr_t
=
ParallelForSender
<
63
parallel_for_t
,
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<
74
trnsfrmd_sndr_t<Env, Data, Sndr>
,
75
typename
trnsfrmd_sndr_t<Env, Data, Sndr>::closure_t
&&,
76
Sndr&&
77
>) {
78
if
constexpr
(
execution_space_completing_sender<Sndr, Env>
) {
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
,
87
typename
trnsfrmd_sndr_t<Env, Data, Sndr>::closure_t::execution_space
88
>,
89
"The policy's execution space type must be the same as the completion scheduler's execution space "
90
"type."
);
91
92
return
trnsfrmd_sndr_t<Env, Data, Sndr>
{
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
{
99
return
no_execution_space_scheduler_in_env<parallel_for_t, Sndr, Env>
();
100
}
101
}
102
};
103
104
}
// namespace Kokkos::Execution::ExecutionSpaceImpl
105
106
#endif
// KOKKOS_EXECUTION_EXECUTION_SPACE_PARALLEL_FOR_HPP
attributes.hpp
KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV
#define KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV(_type_, _obj_)
Definition
attributes.hpp:30
KOKKOS_EXECUTION_COMPL_SIGS_ADD
#define KOKKOS_EXECUTION_COMPL_SIGS_ADD(_decayed_self_type_, _sndr_type_,...)
Definition
completion_signatures.hpp:32
Kokkos::Execution::ExecutionSpaceImpl::execution_space_completing_sender
Concept for a sender whose completion scheduler is Kokkos::Execution::ExecutionSpaceImpl::Scheduler.
Definition
sender_concepts.hpp:12
operation_state.hpp
sender_concepts.hpp
execution_space_fwd.hpp
stdexec.hpp
Kokkos::Execution::ExecutionSpaceImpl
Definition
execution_space.hpp:22
Kokkos::Execution::ExecutionSpaceImpl::no_execution_space_scheduler_in_env
auto no_execution_space_scheduler_in_env() noexcept
Show a better compile diagnostic when there is no Kokkos::Execution::ExecutionSpaceImpl::Scheduler fo...
Definition
sender_concepts.hpp:31
Kokkos::Execution::ExecutionSpaceImpl::op_state_t
typename make_op_state_t< Sndr, Rcvr, Clsrs... >::type op_state_t
Definition
operation_state.hpp:138
Kokkos::Execution::ExecutionSpaceImpl::make_op_state_t
Impl::MakeOpState< Domain, OpState >::Huddle< Sndr, Rcvr, Clsrs... > make_op_state_t
Definition
operation_state.hpp:135
Kokkos
parallel_for.hpp
sender_introspection.hpp
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure
Definition
parallel_for.hpp:17
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure::get_policy
const policy_t & get_policy() const &noexcept
Definition
parallel_for.hpp:31
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure::policy_t
ExecPolicy policy_t
Definition
parallel_for.hpp:18
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure::submit
void submit() const &
Definition
parallel_for.hpp:23
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure::execution_space
typename policy_t::execution_space execution_space
Definition
parallel_for.hpp:19
Kokkos::Execution::ExecutionSpaceImpl::ParallelForClosure::data
Kokkos::Execution::Impl::ParallelForData< Label, Functor, policy_t > data
Definition
parallel_for.hpp:21
Kokkos::Execution::ExecutionSpaceImpl::ParallelForSender
Definition
parallel_for.hpp:37
Kokkos::Execution::ExecutionSpaceImpl::ParallelForSender< stdexec::bulk_t, Sndr, std::string_view, typename Kokkos::Execution::Impl::bulk_traits< Data >::functor_t, Kokkos::RangePolicy< Impl::exec_of_t< Sndr, Env > > >::sndr
Sndr sndr
Definition
parallel_for.hpp:44
Kokkos::Execution::ExecutionSpaceImpl::ParallelForSender< stdexec::bulk_t, Sndr, std::string_view, typename Kokkos::Execution::Impl::bulk_traits< Data >::functor_t, Kokkos::RangePolicy< Impl::exec_of_t< Sndr, Env > > >::closure_t
ParallelForClosure< std::string_view, typename Kokkos::Execution::Impl::bulk_traits< Data >::functor_t, ExecPolicy > closure_t
Definition
parallel_for.hpp:40
Kokkos::Execution::ExecutionSpaceImpl::ParallelForSender< stdexec::bulk_t, Sndr, std::string_view, typename Kokkos::Execution::Impl::bulk_traits< Data >::functor_t, Kokkos::RangePolicy< Impl::exec_of_t< Sndr, Env > > >::execution_space
typename closure_t::execution_space execution_space
Definition
parallel_for.hpp:41
Kokkos::Execution::ExecutionSpaceImpl::ParallelForSender< stdexec::bulk_t, Sndr, std::string_view, typename Kokkos::Execution::Impl::bulk_traits< Data >::functor_t, Kokkos::RangePolicy< Impl::exec_of_t< Sndr, Env > > >::clsr
closure_t clsr
Definition
parallel_for.hpp:43
Kokkos::Execution::ExecutionSpaceImpl::ParallelForSender< stdexec::bulk_t, Sndr, std::string_view, typename Kokkos::Execution::Impl::bulk_traits< Data >::functor_t, Kokkos::RangePolicy< Impl::exec_of_t< Sndr, Env > > >::sender_concept
stdexec::sender_tag sender_concept
Definition
parallel_for.hpp:38
Kokkos::Execution::ExecutionSpaceImpl::ParallelForSender::connect
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 >
Definition
parallel_for.hpp:49
Kokkos::Execution::ExecutionSpaceImpl::TransformSenderFor< Kokkos::Execution::parallel_for_t >::trnsfrmd_sndr_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
Definition
parallel_for.hpp:62
Kokkos::Execution::ExecutionSpaceImpl::TransformSenderFor< Kokkos::Execution::parallel_for_t >::operator()
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 && >)
Definition
parallel_for.hpp:72
Kokkos::Execution::ExecutionSpaceImpl::TransformSenderFor
Definition
execution_space_fwd.hpp:12
Kokkos::Execution::Impl::ParallelForData
Definition
parallel_for.hpp:54
Kokkos::Execution::Impl::ParallelForData::policy
policy_t policy
Definition
parallel_for.hpp:61
Kokkos::Execution::Impl::ParallelForData::label
label_t label
Definition
parallel_for.hpp:59
Kokkos::Execution::Impl::ParallelForData::functor
functor_t functor
Definition
parallel_for.hpp:60
Kokkos::Execution::parallel_for_t
Custom algorithm for the Kokkos::parallel_for construct.
Definition
parallel_for.hpp:18
execution_space
Kokkos::DefaultExecutionSpace execution_space
kokkos-execution
execution_space
parallel_for.hpp
Generated on
for kokkos-execution by
1.18.0