kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
operation_state.hpp
Go to the documentation of this file.
1
#ifndef KOKKOS_EXECUTION_EXECUTION_SPACE_OPERATION_STATE_HPP
2
#define KOKKOS_EXECUTION_EXECUTION_SPACE_OPERATION_STATE_HPP
3
4
#include "
kokkos-execution/stdexec.hpp
"
5
6
#include "
kokkos-execution/execution_space/domain.hpp
"
7
#include "
kokkos-execution/impl/completion_signal.hpp
"
8
#include "
kokkos-execution/impl/env.hpp
"
9
#include "
kokkos-execution/impl/get_exec.hpp
"
10
#include "
kokkos-execution/impl/immovable.hpp
"
11
#include "
kokkos-execution/impl/make_op_state.hpp
"
12
#include "
kokkos-execution/impl/receiver.hpp
"
13
#include "
kokkos-execution/impl/sender_concepts.hpp
"
14
#include "
kokkos-execution/impl/submitted.hpp
"
15
#include "
kokkos-execution/impl/sync_wait.hpp
"
16
17
namespace
Kokkos::Execution::ExecutionSpaceImpl
{
18
19
template
<
typename
Clsr>
20
concept
Closure
=
requires
(
const
Clsr& clsr) {
21
typename
Clsr::execution_space;
22
23
{ clsr.submit() } -> std::same_as<void>;
24
25
{ clsr.get_policy() };
26
requires
Kokkos::ExecutionPolicy<std::remove_cvref_t<
decltype
(clsr.get_policy())>>;
27
28
requires
std::same_as<std::remove_cvref_t<
decltype
(clsr.get_policy().space())>,
typename
Clsr::execution_space>;
29
};
30
31
template
<
typename
Exec,
typename
Rcvr>
32
consteval
auto
select_completion_signal_policy
() {
33
if
constexpr
(
Impl::supports_submitted_order_on<Rcvr>
) {
34
return
Impl::SubmittedPolicy::OrderOnExec
{};
35
}
else
if
constexpr
(
Impl::supports_submitted_depend_on<Rcvr, Exec>
) {
36
return
Impl::SubmittedPolicy::DependOnEvent
{};
37
}
else
if
constexpr
(
38
Impl::has_non_blocking_dispatch<Exec>
39
&& stdexec::__queryable_with<stdexec::env_of_t<Rcvr>, stdexec::get_delegation_scheduler_t>) {
40
return
Impl::SyncPolicy::ScheduleWaitEvent
{};
41
}
else
{
42
return
Impl::SyncPolicy::InlineFenceExec
{};
43
}
44
}
45
46
template
<stdexec::receiver Rcvr, Closure Clsr, Closure... Clsrs>
47
requires
(std::same_as<typename Clsr::execution_space, typename Clsrs::execution_space> && ...)
48
struct
OpStateBase
{
49
using
execution_space
=
typename
Clsr::execution_space;
50
51
using
completion_signal_policy_t
=
decltype
(
select_completion_signal_policy<execution_space, Rcvr>
());
52
using
completion_signal_t
=
Impl::CompletionSignal<completion_signal_policy_t, execution_space, Rcvr>
;
53
using
closures_t
= stdexec::__tuple<Clsr, Clsrs...>;
54
55
completion_signal_t
completion_signal
;
56
closures_t
clsrs
;
57
58
constexpr
explicit
OpStateBase
(Rcvr rcvr, Clsr clsr_, Clsrs... clsrs_)
noexcept
(
59
std::is_nothrow_constructible_v<completion_signal_t, Rcvr&&> && std::is_nothrow_move_constructible_v<Clsr>
60
&& (std::is_nothrow_move_constructible_v<Clsrs> && ...))
61
:
completion_signal
(std::move(rcvr))
62
,
clsrs
(std::move(clsr_), std::move(clsrs_)...) {
63
}
64
65
void
complete
(stdexec::set_value_t)
noexcept
{
66
this->
submit
();
67
}
68
69
template
<
typename
Error>
70
void
complete
(stdexec::set_error_t, Error&& error)
noexcept
{
71
stdexec::set_error(std::move(
completion_signal
.rcvr), std::forward<Error>(error));
72
}
73
74
void
complete
(stdexec::set_stopped_t)
noexcept
{
75
stdexec::set_stopped(std::move(
completion_signal
.rcvr));
76
}
77
78
void
submit
() noexcept {
79
try
{
80
stdexec::__apply([](
auto
&... clsr) { (clsr.submit(), ...); },
clsrs
);
81
}
catch
(...) {
82
this->
complete
(stdexec::set_error, std::current_exception());
83
return
;
84
}
85
completion_signal
.propagate(this->
query
(
Impl::get_exec
).get());
86
}
87
89
[[nodiscard]]
90
constexpr
auto
query
(
Impl::get_exec_t
)
const
noexcept
->
Impl::ExecutionSpaceRef<execution_space>
{
91
return
Impl::ExecutionSpaceRef<execution_space>
{stdexec::__get<0>(
clsrs
).get_policy().space()};
92
}
93
94
KOKKOS_EXECUTION_GET_ENV
(Rcvr, this->completion_signal.rcvr)
95
};
96
97
template
<stdexec::sender Sndr, stdexec::receiver Rcvr,
Closure
... Clsrs>
98
requires
(!
Impl::dispatching_sender<Sndr>
)
99
struct
OpState
100
: public
Impl
::
Immovable
101
, public
OpStateBase
<Rcvr, Clsrs...> {
102
using
operation_state_concept
=
Impl::SubmittedOperationStateTag
;
103
104
using
base_t
=
OpStateBase
<Rcvr, Clsrs...>;
105
using
rcvr_t
=
Impl::Receiver<base_t>
;
106
107
using
inner_op_state_t
= stdexec::connect_result_t<Sndr, rcvr_t>;
108
109
static
constexpr
bool
op_state_base_is_nothrow_constructible
=
110
std::is_nothrow_constructible_v<
base_t
, Rcvr&&, Clsrs&&...>;
111
112
static
constexpr
bool
inner_op_state_is_nothrow_constructible
= stdexec::__nothrow_connectable<Sndr&&, rcvr_t>;
113
114
inner_op_state_t
inner_op_state
;
115
117
#if defined(KOKKOS_EXECUTION_IMPL_OP_STATE_IMMOVABLE_FIX)
118
STDEXEC_IMMOVABLE(
OpState
);
119
#endif
120
121
constexpr
explicit
OpState
(
122
Sndr&& sndr,
// NOLINT(cppcoreguidelines-rvalue-reference-param-not-moved)
123
Rcvr rcvr_,
124
Clsrs... clsrs_)
noexcept
(
op_state_base_is_nothrow_constructible
&&
inner_op_state_is_nothrow_constructible
)
125
:
base_t
(std::move(rcvr_), std::move(clsrs_)...)
126
,
inner_op_state
(
stdexec
::connect(std::forward<Sndr>(sndr),
rcvr_t
{this})) {
127
}
128
129
void
start
() &
noexcept
{
130
stdexec::start(
inner_op_state
);
131
}
132
};
133
134
template
<
typename
Sndr,
typename
Rcvr,
typename
... Clsrs>
135
using
make_op_state_t
=
Impl::MakeOpState<Domain, OpState>::Huddle
<Sndr, Rcvr, Clsrs...>;
136
137
template
<
typename
Sndr,
typename
Rcvr,
typename
... Clsrs>
138
using
op_state_t
=
typename
make_op_state_t
<Sndr, Rcvr, Clsrs...>::type;
139
140
}
// namespace Kokkos::Execution::ExecutionSpaceImpl
141
142
#endif
// KOKKOS_EXECUTION_EXECUTION_SPACE_OPERATION_STATE_HPP
completion_signal.hpp
Kokkos::Execution::ExecutionSpaceImpl::Closure
Definition
operation_state.hpp:20
Kokkos::Execution::Impl::dispatching_sender
Concept that constrains the type of a sender that dispatches a functor for execution.
Definition
sender_concepts.hpp:11
Kokkos::Execution::Impl::has_non_blocking_dispatch
Definition
event.hpp:48
Kokkos::Execution::Impl::supports_submitted_depend_on
Definition
submitted.hpp:24
Kokkos::Execution::Impl::supports_submitted_order_on
Definition
submitted.hpp:19
get_exec.hpp
immovable.hpp
env.hpp
KOKKOS_EXECUTION_GET_ENV
#define KOKKOS_EXECUTION_GET_ENV(_type_, _obj_)
Retrieve the environment of _obj_. // NOLINTNEXTLINE(cppcoreguidelines-macro-usage).
Definition
env.hpp:14
sender_concepts.hpp
domain.hpp
sync_wait.hpp
stdexec.hpp
make_op_state.hpp
Kokkos::Execution::ExecutionSpaceImpl
Definition
execution_space.hpp:22
Kokkos::Execution::ExecutionSpaceImpl::select_completion_signal_policy
consteval auto select_completion_signal_policy()
Definition
operation_state.hpp:32
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::Execution::Impl
Definition
attributes.hpp:6
Kokkos::Execution::Impl::get_exec
constexpr get_exec_t get_exec
Definition
get_exec.hpp:19
stdexec
Definition
when_all.hpp:16
receiver.hpp
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase< Rcvr, Clsrs... >::submit
void submit() noexcept
Definition
operation_state.hpp:78
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase::completion_signal_t
Impl::CompletionSignal< completion_signal_policy_t, execution_space, Rcvr > completion_signal_t
Definition
operation_state.hpp:52
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase< Rcvr, Clsrs... >::query
constexpr auto query(Impl::get_exec_t) const noexcept -> Impl::ExecutionSpaceRef< execution_space >
Definition
operation_state.hpp:90
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase::execution_space
typename Clsr::execution_space execution_space
Definition
operation_state.hpp:49
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase< Rcvr, Clsrs... >::clsrs
closures_t clsrs
Definition
operation_state.hpp:56
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase::complete
void complete(stdexec::set_stopped_t) noexcept
Definition
operation_state.hpp:74
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase::closures_t
stdexec::__tuple< Clsr, Clsrs... > closures_t
Definition
operation_state.hpp:53
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase::completion_signal_policy_t
decltype(select_completion_signal_policy< execution_space, Rcvr >()) completion_signal_policy_t
Definition
operation_state.hpp:51
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase::OpStateBase
constexpr OpStateBase(Rcvr rcvr, Clsr clsr_, Clsrs... clsrs_) noexcept(std::is_nothrow_constructible_v< completion_signal_t, Rcvr && > &&std::is_nothrow_move_constructible_v< Clsr > &&(std::is_nothrow_move_constructible_v< Clsrs > &&...))
Definition
operation_state.hpp:58
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase::complete
void complete(stdexec::set_error_t, Error &&error) noexcept
Definition
operation_state.hpp:70
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase< Rcvr, Clsrs... >::completion_signal
completion_signal_t completion_signal
Definition
operation_state.hpp:55
Kokkos::Execution::ExecutionSpaceImpl::OpStateBase::complete
void complete(stdexec::set_value_t) noexcept
Definition
operation_state.hpp:65
Kokkos::Execution::ExecutionSpaceImpl::OpState::operation_state_concept
Impl::SubmittedOperationStateTag operation_state_concept
Definition
operation_state.hpp:102
Kokkos::Execution::ExecutionSpaceImpl::OpState::start
void start() &noexcept
Definition
operation_state.hpp:129
Kokkos::Execution::ExecutionSpaceImpl::OpState::rcvr_t
Impl::Receiver< base_t > rcvr_t
Definition
operation_state.hpp:105
Kokkos::Execution::ExecutionSpaceImpl::OpState::inner_op_state_t
stdexec::connect_result_t< Sndr, rcvr_t > inner_op_state_t
Definition
operation_state.hpp:107
Kokkos::Execution::ExecutionSpaceImpl::OpState::op_state_base_is_nothrow_constructible
static constexpr bool op_state_base_is_nothrow_constructible
Definition
operation_state.hpp:109
Kokkos::Execution::ExecutionSpaceImpl::OpState::base_t
OpStateBase< Rcvr, Clsrs... > base_t
Definition
operation_state.hpp:104
Kokkos::Execution::ExecutionSpaceImpl::OpState::inner_op_state_is_nothrow_constructible
static constexpr bool inner_op_state_is_nothrow_constructible
Definition
operation_state.hpp:112
Kokkos::Execution::ExecutionSpaceImpl::OpState::OpState
constexpr OpState(Sndr &&sndr, Rcvr rcvr_, Clsrs... clsrs_) noexcept(op_state_base_is_nothrow_constructible &&inner_op_state_is_nothrow_constructible)
Definition
operation_state.hpp:121
Kokkos::Execution::ExecutionSpaceImpl::OpState::inner_op_state
inner_op_state_t inner_op_state
Definition
operation_state.hpp:114
Kokkos::Execution::Impl::CompletionSignal
Definition
completion_signal.hpp:58
Kokkos::Execution::Impl::ExecutionSpaceRef
Wrap a Kokkos execution space to make it cheap to copy/move in new environments.
Definition
get_exec.hpp:47
Kokkos::Execution::Impl::Immovable::Immovable
Immovable()=default
Kokkos::Execution::Impl::MakeOpState::Huddle
Definition
make_op_state.hpp:14
Kokkos::Execution::Impl::Receiver
Receiver for an object parent_op that implements complete.
Definition
receiver.hpp:13
Kokkos::Execution::Impl::SubmittedOperationStateTag
Definition
submitted.hpp:30
Kokkos::Execution::Impl::SubmittedPolicy::DependOnEvent
Definition
completion_signal.hpp:167
Kokkos::Execution::Impl::SubmittedPolicy::OrderOnExec
Definition
completion_signal.hpp:166
Kokkos::Execution::Impl::SyncPolicy::InlineFenceExec
Definition
completion_signal.hpp:70
Kokkos::Execution::Impl::SyncPolicy::ScheduleWaitEvent
Definition
completion_signal.hpp:71
Kokkos::Execution::Impl::get_exec_t
Definition
get_exec.hpp:15
submitted.hpp
kokkos-execution
execution_space
operation_state.hpp
Generated on
for kokkos-execution by
1.18.0