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
13namespace yorch::detail {
14
15template <typename T>
17
18template <typename Ctx, typename Prev>
23
24template <typename Ctx>
25[[nodiscard]] constexpr auto make_exec_context(Ctx& ctx, no_prev) noexcept
27 return {ctx};
28}
29
30template <typename Ctx, typename Prev>
31[[nodiscard]] constexpr auto make_exec_context(Ctx& ctx, Prev prev) noexcept
33 return {ctx, prev};
34}
35
36[[nodiscard]] constexpr auto make_exec_context(no_prev) noexcept
38 return {};
39}
40
41template <typename Prev>
42[[nodiscard]] constexpr auto make_exec_context(Prev prev) noexcept
44 return {prev};
45}
46
47template <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>();
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
68template <typename Plan, typename Slots, std::size_t I>
71 std::declval<Slots&>(),
72 std::declval<plan_fanout_state<Plan>&>()));
73
78
79template <std::size_t I, typename Plan, typename Slots, typename Ec>
81 Plan& plan,
82 Slots& slots,
83 Ec& ec) {
84 using task_t = typename Plan::template task_type<I>;
86 using raw_result_t = typename Plan::template raw_result_type<I>;
87
88 static_assert(
90 task_t&,
91 typename exec_traits_t::ctx_type,
92 typename exec_traits_t::prev_type> ||
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;
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>) {
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);
115
116 if (result.step.ok()) {
117 result.payload_live = store_node_output<I>(slots, raw);
118 }
119 }
120
121 return result;
122}
123
124template <std::size_t I, typename Plan, typename Slots>
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);
132}
133
134template <std::size_t I, typename Plan, typename Slots, typename Ctx>
136 Plan& plan,
137 Slots& slots,
139 Ctx& ctx) {
140 auto prev = make_node_prev_view<Plan, I>(slots, fanout);
141 auto ec = make_exec_context(ctx, prev);
143}
144
145} // namespace yorch::detail
Describes the main execution protocol accepted by run_task(...).
Definition concepts.hpp:27
constexpr auto make_node_prev_view(Slots &slots, FanoutState &fanout)
constexpr step_result extract_step_result(R &&r)
Definition result.hpp:38
constexpr node_enter_result enter_node_with_exec_context(Plan &plan, Slots &slots, Ec &ec)
constexpr node_enter_result enter_node(Plan &plan, Slots &slots, plan_fanout_state< Plan > &fanout)
constexpr auto make_exec_context(Ctx &ctx, no_prev) noexcept -> exec_context< Ctx >
constexpr bool is_adapter_descriptor_v
Definition adapters.hpp:63
decltype(make_node_prev_view< Plan, I >(std::declval< Slots & >(), std::declval< plan_fanout_state< Plan > & >())) node_prev_view_t
constexpr auto task(F &&f)
Definition core.hpp:207
Lightweight borrowed view used during execution.
Definition context.hpp:187
Sentinel view indicating that the current execution has no direct parent output.
Definition context.hpp:27
Represents the basic outcome of a task step.
Definition result.hpp:42
static constexpr step_result success() noexcept
Creates a successful result.
Definition result.hpp:46