YOrch
1.0.0
Loading...
Searching...
No Matches
node_entry.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstddef>
4
#include <type_traits>
5
#include <utility>
6
7
#include "../../context.hpp"
8
#include "../../executor/concepts.hpp"
// IWYU pragma: keep
9
#include "../../result.hpp"
10
#include "
fanout.hpp
"
11
#include "
result.hpp
"
12
13
namespace
yorch::detail
{
14
15
template
<
typename
T>
16
struct
exec_context_traits
;
17
18
template
<
typename
Ctx,
typename
Prev>
19
struct
exec_context_traits
<
exec_context
<
Ctx
,
Prev
>> {
20
using
ctx_type
=
Ctx
;
21
using
prev_type
=
Prev
;
22
};
23
24
template
<
typename
Ctx>
25
[[
nodiscard
]]
constexpr
auto
make_exec_context
(
Ctx
& ctx,
no_prev
)
noexcept
26
->
exec_context<Ctx>
{
27
return
{ctx};
28
}
29
30
template
<
typename
Ctx,
typename
Prev>
31
[[
nodiscard
]]
constexpr
auto
make_exec_context
(
Ctx
& ctx,
Prev
prev)
noexcept
32
->
exec_context<Ctx, Prev>
{
33
return
{ctx, prev};
34
}
35
36
[[
nodiscard
]]
constexpr
auto
make_exec_context
(
no_prev
)
noexcept
37
->
exec_context<void>
{
38
return
{};
39
}
40
41
template
<
typename
Prev>
42
[[
nodiscard
]]
constexpr
auto
make_exec_context
(
Prev
prev)
noexcept
43
->
exec_context<void, Prev>
{
44
return
{prev};
45
}
46
47
template
<
typename
Plan, std::
size_t
I,
typename
Slots,
typename
FanoutState>
48
[[
nodiscard
]]
constexpr
auto
make_node_prev_view
(
Slots
& slots,
FanoutState
& fanout) {
49
if
constexpr
(Plan::template
parent_index<I>
== Plan::no_parent) {
50
return
no_prev
{};
51
}
else
{
52
constexpr
auto
parent
= Plan::template
parent_index<I>
;
53
54
if
constexpr
(std::is_void_v<typename Plan::template output_type<parent>>) {
55
return
no_prev
{};
56
}
else
if
constexpr
(
node_uses_staged_copy_prev_v<Plan, I>
) {
57
// The shared stage is still a readonly upstream source. `copy_prev(...)`
58
// resolves an owned value from it without granting mutable prev access.
59
return
std::as_const(fanout).template
staged_prev_view_for_parent<parent>
();
60
}
else
if
constexpr
(
task_uses_exclusive_prev_access_v<typename Plan::template task_type<I>
>) {
61
return
slots.template
prev_view_for<parent>
();
62
}
else
{
63
return
std::as_const(slots).template
prev_view_for<parent>
();
64
}
65
}
66
}
67
68
template
<
typename
Plan,
typename
Slots, std::
size_t
I>
69
using
node_prev_view_t
=
70
decltype
(
make_node_prev_view<Plan, I>
(
71
std::declval<Slots&>(),
72
std::declval<
plan_fanout_state<Plan>
&>()));
73
74
struct
node_enter_result
{
75
step_result
step
=
step_result::success
();
76
bool
payload_live
=
false
;
77
};
78
79
template
<std::
size_t
I,
typename
Plan,
typename
Slots,
typename
Ec>
80
[[
nodiscard
]]
constexpr
node_enter_result
enter_node_with_exec_context
(
81
Plan
&
plan
,
82
Slots
& slots,
83
Ec
&
ec
) {
84
using
task_t
=
typename
Plan::template
task_type<I>
;
85
using
exec_traits_t
=
exec_context_traits<std::remove_cvref_t<Ec>
>;
86
using
raw_result_t
=
typename
Plan::template
raw_result_type<I>
;
87
88
static_assert
(
89
executable_task
<
90
task_t
&,
91
typename
exec_traits_t::ctx_type,
92
typename
exec_traits_t::prev_type> ||
93
executable_direct_output_task
<
94
task_t
&,
95
typename
exec_traits_t::ctx_type,
96
typename
exec_traits_t::prev_type>,
97
"Plan nodes executed through run_plan(...) must expose a noexcept invoke_raw(exec_context<...>&) or invoke_into(exec_context<...>&, direct_out<...>) surface"
);
98
99
auto
&
task
=
plan
.template
entry<I>
().task;
100
node_enter_result
result
{};
101
102
if
constexpr
(
executable_direct_output_task
<
103
task_t
&,
104
typename
exec_traits_t::ctx_type,
105
typename
exec_traits_t::prev_type>) {
106
result
.
step
=
finalize_direct_output_step<I>
(
107
slots,
108
task
.invoke_into(
ec
, slots.template
out<I>
()));
109
result
.payload_live =
result
.step.ok();
110
}
else
if
constexpr
(std::is_void_v<raw_result_t>) {
111
task
.invoke_raw(
ec
);
112
}
else
{
113
auto
raw
=
task
.invoke_raw(
ec
);
114
result
.step =
extract_step_result
(
raw
);
115
116
if
(
result
.step.ok()) {
117
result
.payload_live =
store_node_output<I>
(slots,
raw
);
118
}
119
}
120
121
return
result
;
122
}
123
124
template
<std::
size_t
I,
typename
Plan,
typename
Slots>
125
[[
nodiscard
]]
constexpr
node_enter_result
enter_node
(
126
Plan
&
plan
,
127
Slots
& slots,
128
plan_fanout_state<Plan>
& fanout) {
129
auto
prev =
make_node_prev_view<Plan, I>
(slots, fanout);
130
auto
ec
=
make_exec_context
(prev);
131
return
enter_node_with_exec_context<I>
(
plan
, slots,
ec
);
132
}
133
134
template
<std::
size_t
I,
typename
Plan,
typename
Slots,
typename
Ctx>
135
[[
nodiscard
]]
constexpr
node_enter_result
enter_node
(
136
Plan
&
plan
,
137
Slots
& slots,
138
plan_fanout_state<Plan>
& fanout,
139
Ctx
& ctx) {
140
auto
prev =
make_node_prev_view<Plan, I>
(slots, fanout);
141
auto
ec
=
make_exec_context
(ctx, prev);
142
return
enter_node_with_exec_context<I>
(
plan
, slots,
ec
);
143
}
144
145
}
// namespace yorch::detail
yorch::executable_direct_output_task
Definition
concepts.hpp:37
yorch::executable_task
Describes the main execution protocol accepted by run_task(...).
Definition
concepts.hpp:27
fanout.hpp
yorch::detail
Definition
adapters.hpp:48
yorch::detail::make_node_prev_view
constexpr auto make_node_prev_view(Slots &slots, FanoutState &fanout)
Definition
node_entry.hpp:48
yorch::detail::extract_step_result
constexpr step_result extract_step_result(R &&r)
Definition
result.hpp:38
yorch::detail::enter_node_with_exec_context
constexpr node_enter_result enter_node_with_exec_context(Plan &plan, Slots &slots, Ec &ec)
Definition
node_entry.hpp:80
yorch::detail::enter_node
constexpr node_enter_result enter_node(Plan &plan, Slots &slots, plan_fanout_state< Plan > &fanout)
Definition
node_entry.hpp:125
yorch::detail::make_exec_context
constexpr auto make_exec_context(Ctx &ctx, no_prev) noexcept -> exec_context< Ctx >
Definition
node_entry.hpp:25
yorch::detail::is_adapter_descriptor_v
constexpr bool is_adapter_descriptor_v
Definition
adapters.hpp:63
yorch::detail::node_prev_view_t
decltype(make_node_prev_view< Plan, I >(std::declval< Slots & >(), std::declval< plan_fanout_state< Plan > & >())) node_prev_view_t
Definition
node_entry.hpp:72
yorch::task
constexpr auto task(F &&f)
Definition
core.hpp:207
result.hpp
yorch::detail::exec_context_traits< exec_context< Ctx, Prev > >::ctx_type
Ctx ctx_type
Definition
node_entry.hpp:20
yorch::detail::exec_context_traits< exec_context< Ctx, Prev > >::prev_type
Prev prev_type
Definition
node_entry.hpp:21
yorch::detail::exec_context_traits
Definition
node_entry.hpp:16
yorch::detail::node_enter_result
Definition
node_entry.hpp:74
yorch::detail::node_enter_result::payload_live
bool payload_live
Definition
node_entry.hpp:76
yorch::detail::node_enter_result::step
step_result step
Definition
node_entry.hpp:75
yorch::detail::plan_fanout_state
Definition
fanout.hpp:183
yorch::exec_context
Lightweight borrowed view used during execution.
Definition
context.hpp:187
yorch::no_prev
Sentinel view indicating that the current execution has no direct parent output.
Definition
context.hpp:27
yorch::step_result
Represents the basic outcome of a task step.
Definition
result.hpp:42
yorch::step_result::success
static constexpr step_result success() noexcept
Creates a successful result.
Definition
result.hpp:46
include
yorch
detail
executor
node_entry.hpp
Generated by
1.9.8