Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
anticipation_partition.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstdint>
7#include <span>
8#include <vector>
9
10namespace pulp::host {
11
12struct GraphNode;
13struct Connection;
14
15// An edge leaving the anticipation-eligible interior: its source is a node that
16// can be rendered ahead, its destination is NOT (a live/non-eligible node, or a
17// live sink such as AudioOutput/MidiOutput). These are the splice points — the
18// outputs the anticipative renderer pre-computes into a ring and the live graph
19// reads instead of running the interior synchronously.
21 NodeId source_node = 0; // in the eligible interior
23 NodeId dest_node = 0; // outside the interior
25};
26
27// The renderable eligible subgraph carved out of a graph: the interior nodes the
28// renderer would run ahead, and the boundary edges whose pre-rendered output the
29// live graph consumes. A partition is only worth anticipating if it both has
30// interior nodes and feeds something outside the interior at non-trivial cost.
32 // Indices into the input `nodes` span: every eligible node EXCEPT the live
33 // sinks (AudioOutput / MidiOutput), which are consumed at the real deadline
34 // and must not be written ahead. (Live SOURCES never appear — 6a already
35 // excludes them.)
36 std::vector<std::size_t> interior_nodes;
37 std::vector<AnticipationBoundary> boundary;
38 // Sum of a coarse static per-node cost weight over the interior (max(in,out)
39 // ports for processing nodes, 0 for I/O) — the same proxy the parallel cost
40 // gate uses. A worthiness signal, not a CPU-cycle estimate.
41 std::uint64_t cost_weight = 0;
42 bool ok = false;
43
44 // Worth pre-rendering only if there is interior work that something outside
45 // the interior actually consumes, at non-zero cost. An interior with no
46 // boundary produces nothing the live graph reads; a zero-cost interior is not
47 // worth the ring + scheduler overhead.
48 bool worth_anticipating() const {
49 return ok && !interior_nodes.empty() && !boundary.empty() && cost_weight > 0;
50 }
51};
52
53// Carve the anticipation-eligible interior + its boundary edges out of a graph,
54// given 6a's eligibility classification. Pure, deterministic, allocation-bounded;
55// no prepared/live graph required. Returns ok=false if `eligibility` is not ok or
56// does not match `nodes`, if `nodes` contains a duplicate id, or if a connection
57// names a node absent from `nodes` (the absent-id case is normally already caught
58// by 6a, which leaves `eligibility.ok == false`).
59//
60// This identifies WHAT a future anticipative renderer would render ahead and
61// WHERE its output splices into the live graph. It performs no rendering and
62// changes no real-time path. Like 6a it is a static safety/structure analysis;
63// the host-time clearance still applies on top before anything is rendered ahead.
65 std::span<const GraphNode> nodes, std::span<const Connection> connections,
66 const AnticipationEligibility& eligibility);
67
68} // namespace pulp::host
std::uint32_t NodeId
Definition graph_types.hpp:7
std::uint32_t PortIndex
Definition graph_types.hpp:8
Bounded event contracts shared by host ingress and graph-authored nodes.
Definition anticipation_eligibility.hpp:9
AnticipationPartition build_anticipation_partition(std::span< const GraphNode > nodes, std::span< const Connection > connections, const AnticipationEligibility &eligibility)
Definition anticipation_partition.hpp:20
NodeId source_node
Definition anticipation_partition.hpp:21
PortIndex source_port
Definition anticipation_partition.hpp:22
NodeId dest_node
Definition anticipation_partition.hpp:23
PortIndex dest_port
Definition anticipation_partition.hpp:24
Definition anticipation_eligibility.hpp:36
Definition anticipation_partition.hpp:31
bool worth_anticipating() const
Definition anticipation_partition.hpp:48
std::uint64_t cost_weight
Definition anticipation_partition.hpp:41
bool ok
Definition anticipation_partition.hpp:42
std::vector< std::size_t > interior_nodes
Definition anticipation_partition.hpp:36
std::vector< AnticipationBoundary > boundary
Definition anticipation_partition.hpp:37
Definition signal_graph_connection.hpp:18
Definition signal_graph_node.hpp:126