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_GRAPH_PARALLEL_FOR_HPP
2
#define KOKKOS_EXECUTION_GRAPH_PARALLEL_FOR_HPP
3
4
#include "
kokkos-execution/stdexec.hpp
"
5
6
#include "
kokkos-execution/graph/operation_state.hpp
"
7
#include "
kokkos-execution/graph/sender_concepts.hpp
"
8
#include "
kokkos-execution/impl/attributes.hpp
"
9
#include "
kokkos-execution/impl/sender_introspection.hpp
"
10
#include "
kokkos-execution/parallel_for.hpp
"
11
12
namespace
Kokkos::Execution::GraphImpl
{
13
14
template
<
typename
Label,
typename
Functor, Kokkos::ExecutionPolicy ExecPolicy>
15
struct
ParallelForClosure
{
16
using
execution_space
=
typename
ExecPolicy::execution_space;
17
using
device_handle_t
= Kokkos::Impl::DeviceHandle<execution_space>;
18
using
node_props_t
=
typename
Kokkos::Impl::NodeCtorProps<Label, device_handle_t>::uniform_type;
19
20
template
<NodeRef Predecessor>
21
using
node_t
=
decltype
(std::declval<const Predecessor&>().then_parallel_for(
22
std::declval<node_props_t&&>(),
23
std::declval<ExecPolicy&&>(),
24
std::declval<Functor&&>()));
25
27
template
<NodeRef Predecessor>
28
auto
add_node
(
const
Predecessor& predecessor) &&
noexcept
(
false
) ->
node_t<Predecessor>
{
29
const
auto
device_handle = Kokkos::Impl::get_property<device_handle_t>(
node_props
);
30
auto
node = predecessor.then_parallel_for(
31
std::move(
node_props
), std::forward<ExecPolicy>(
policy
), std::forward<Functor>(
functor
));
32
KOKKOS_EXECUTION_IMPL_GRAPH_ADD_NODE_DEBUG_LOGGING
(
"parallel_for"
, node, predecessor)
33
graph_add_node_event
(predecessor, node, device_handle);
34
return
node;
35
}
36
node_props_t
node_props
;
37
Functor
functor
;
// NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
38
ExecPolicy
policy
;
39
};
40
41
template
<stdexec::sender Sndr,
typename
Label,
typename
Functor, Kokkos::ExecutionPolicy ExecPolicy>
42
struct
ParallelForSender
{
43
using
sender_concept
= stdexec::sender_tag;
44
45
using
closure_t
=
ParallelForClosure<Label, Functor, ExecPolicy>
;
46
47
KOKKOS_EXECUTION_COMPL_SIGS_ADD
(
ParallelForSender
, Sndr, stdexec::set_error_t(std::exception_ptr))
48
49
KOKKOS_EXECUTION_GRAPH_OPERATION_STATE_CONNECT
50
51
KOKKOS_EXECUTION_IMPL_FORWARDING_ATTRIBUTES_GET_ENV
(Sndr,
sndr
)
52
53
closure_t
clsr
;
54
Sndr
sndr
;
// NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members)
55
};
56
57
template <>
58
struct
TransformSenderFor
<
Kokkos
::
Execution
::
parallel_for_t
> {
59
template
<
typename
Env,
typename
Data,
typename
Sndr>
60
using
trnsfrmd_sndr_t
=
ParallelForSender
<
61
Sndr,
62
typename
std::remove_cvref_t<Data>::label_t,
63
typename
std::remove_cvref_t<Data>::functor_t,
64
typename
std::remove_cvref_t<Data>::policy_t
65
>;
66
67
template
<
typename
Env,
typename
Data,
typename
Sndr>
68
requires
stdexec::__sends<stdexec::set_value_t, Sndr, Env>
69
auto
operator()
(
70
const
Env& env,
71
Kokkos::Execution::parallel_for_t
,
72
Data&& data,
// NOLINT(cppcoreguidelines-missing-std-forward)
73
Sndr&&
sndr
)
const
74
noexcept
(std::is_nothrow_constructible_v<
75
trnsfrmd_sndr_t<Env, Data, Sndr>
,
76
typename
trnsfrmd_sndr_t<Env, Data, Sndr>::closure_t
&&,
77
Sndr&&
78
>) {
79
if
constexpr
(
graph_completing_sender<Sndr, Env>
) {
80
auto
& [label, functor, policy] = data;
81
82
const
auto
schd = stdexec::get_completion_scheduler<stdexec::set_value_t>(stdexec::get_env(
sndr
), env);
83
84
return
trnsfrmd_sndr_t<Env, Data, Sndr>
{
85
.clsr =
86
{.node_props = Kokkos::Experimental::node_props(
87
stdexec::__forward_like<Data>(label),
88
Kokkos::Experimental::get_device_handle(schd.state->exec)),
89
.functor = stdexec::__forward_like<Data>(functor),
90
.policy = stdexec::__forward_like<Data>(policy)},
91
.sndr = std::forward<Sndr>(
sndr
)
92
};
93
}
else
{
94
return
no_graph_scheduler_in_env<parallel_for_t, Sndr, Env>
();
95
}
96
}
97
};
98
99
}
// namespace Kokkos::Execution::GraphImpl
100
101
// NOLINTBEGIN(bugprone-reserved-identifier)
102
namespace
stdexec::__detail
{
103
template
<stdexec::sender Sndr,
typename
Label,
typename
Functor, Kokkos::ExecutionPolicy ExecPolicy>
104
extern
__mtype<Kokkos::Execution::GraphImpl::ParallelForSender<__demangle_t<Sndr>, Label, Functor, ExecPolicy>>
105
__demangle_v<Kokkos::Execution::GraphImpl::ParallelForSender<Sndr, Label, Functor, ExecPolicy>>;
106
}
// namespace stdexec::__detail
107
// NOLINTEND(bugprone-reserved-identifier)
108
109
#endif
// KOKKOS_EXECUTION_GRAPH_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::GraphImpl::graph_completing_sender
Concept for a sender whose completion scheduler is Kokkos::Execution::GraphImpl::Scheduler.
Definition
sender_concepts.hpp:12
operation_state.hpp
KOKKOS_EXECUTION_IMPL_GRAPH_ADD_NODE_DEBUG_LOGGING
#define KOKKOS_EXECUTION_IMPL_GRAPH_ADD_NODE_DEBUG_LOGGING(_type_, _node_, _predecessor_)
Definition
operation_state.hpp:311
KOKKOS_EXECUTION_GRAPH_OPERATION_STATE_CONNECT
#define KOKKOS_EXECUTION_GRAPH_OPERATION_STATE_CONNECT
Definition
operation_state.hpp:297
sender_concepts.hpp
stdexec.hpp
Kokkos::Execution::GraphImpl
Definition
graph.hpp:20
Kokkos::Execution::GraphImpl::graph_add_node_event
void graph_add_node_event(const Predecessor &predecessor, const NodeType &node, const Kokkos::Impl::DeviceHandle< Exec > &device_handle)
Record an event for a node added after predecessor.
Definition
events.hpp:132
Kokkos::Execution::GraphImpl::no_graph_scheduler_in_env
auto no_graph_scheduler_in_env() noexcept
Show a better compile diagnostic when there is no Kokkos::Execution::GraphImpl::Scheduler found.
Definition
sender_concepts.hpp:31
Kokkos::Execution
Definition
execution_space.hpp:20
Kokkos
stdexec::__detail
Definition
operation_state.hpp:316
parallel_for.hpp
sender_introspection.hpp
Kokkos::Execution::GraphImpl::ParallelForClosure
Definition
parallel_for.hpp:15
Kokkos::Execution::GraphImpl::ParallelForClosure::execution_space
typename ExecPolicy::execution_space execution_space
Definition
parallel_for.hpp:16
Kokkos::Execution::GraphImpl::ParallelForClosure::node_props_t
typename Kokkos::Impl::NodeCtorProps< Label, device_handle_t >::uniform_type node_props_t
Definition
parallel_for.hpp:18
Kokkos::Execution::GraphImpl::ParallelForClosure::device_handle_t
Kokkos::Impl::DeviceHandle< execution_space > device_handle_t
Definition
parallel_for.hpp:17
Kokkos::Execution::GraphImpl::ParallelForClosure::add_node
auto add_node(const Predecessor &predecessor) &&noexcept(false) -> node_t< Predecessor >
Definition
parallel_for.hpp:28
Kokkos::Execution::GraphImpl::ParallelForClosure::policy
ExecPolicy policy
Definition
parallel_for.hpp:38
Kokkos::Execution::GraphImpl::ParallelForClosure::functor
Functor functor
Definition
parallel_for.hpp:37
Kokkos::Execution::GraphImpl::ParallelForClosure::node_t
decltype(std::declval< const Predecessor & >().then_parallel_for( std::declval< node_props_t && >(), std::declval< ExecPolicy && >(), std::declval< Functor && >())) node_t
Definition
parallel_for.hpp:21
Kokkos::Execution::GraphImpl::ParallelForClosure::node_props
node_props_t node_props
Definition
parallel_for.hpp:36
Kokkos::Execution::GraphImpl::ParallelForSender
Definition
parallel_for.hpp:42
Kokkos::Execution::GraphImpl::ParallelForSender< Sndr, std::string, 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:43
Kokkos::Execution::GraphImpl::ParallelForSender< Sndr, std::string, typename Kokkos::Execution::Impl::bulk_traits< Data >::functor_t, Kokkos::RangePolicy< Impl::exec_of_t< Sndr, Env > > >::sndr
Sndr sndr
Definition
parallel_for.hpp:54
Kokkos::Execution::GraphImpl::ParallelForSender< Sndr, std::string, 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:53
Kokkos::Execution::GraphImpl::ParallelForSender< Sndr, std::string, typename Kokkos::Execution::Impl::bulk_traits< Data >::functor_t, Kokkos::RangePolicy< Impl::exec_of_t< Sndr, Env > > >::closure_t
ParallelForClosure< std::string, typename Kokkos::Execution::Impl::bulk_traits< Data >::functor_t, ExecPolicy > closure_t
Definition
parallel_for.hpp:45
Kokkos::Execution::GraphImpl::TransformSenderFor< Kokkos::Execution::parallel_for_t >::trnsfrmd_sndr_t
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
Definition
parallel_for.hpp:60
Kokkos::Execution::GraphImpl::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:69
Kokkos::Execution::GraphImpl::TransformSenderFor
Definition
graph_fwd.hpp:21
Kokkos::Execution::parallel_for_t
Custom algorithm for the Kokkos::parallel_for construct.
Definition
parallel_for.hpp:18
kokkos-execution
graph
parallel_for.hpp
Generated on
for kokkos-execution by
1.18.0