Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
graph_runtime_levelization.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstdint>
6#include <vector>
7
8namespace pulp::graph {
9
10// Off-RT levelization of a GraphRuntimePlan for static multicore scheduling.
11//
12// A node's LEVEL is the length of its longest dependency chain: 0 for a node
13// with no feedforward dependencies, otherwise one more than the maximum level of
14// any node it depends on through a non-feedback connection (audio, event, or
15// automation — every edge that requires the source to run before the dest).
16// Feedback connections are excluded (they read the previous block, like the
17// topological sort), so they never raise a level or create a cycle.
18//
19// Nodes sharing a level are mutually independent — no dependency path connects
20// them — so a parallel executor can run them concurrently, synchronizing only at
21// level boundaries. This is the static schedule masterwork §6.1 precomputes at
22// plan time; the serial executor ignores it (its processing order already
23// respects dependencies), and a future parallel executor consumes it behind the
24// canonical seam.
26 // Per dense node index (matches GraphRuntimePlan::nodes order): the node's
27 // level.
28 std::vector<std::uint32_t> node_level;
29 // Number of distinct levels (0 for an empty plan).
30 std::uint32_t level_count = 0;
31 // CSR grouping of node indices by level: the nodes at level L are
32 // level_nodes[level_offsets[L] .. level_offsets[L + 1]). level_offsets has
33 // level_count + 1 entries; level_nodes has one entry per node.
34 std::vector<std::uint32_t> level_offsets;
35 std::vector<std::uint32_t> level_nodes;
36 // Per level (level_count entries): a static, deterministic work-weight =
37 // sum of graph_runtime_node_cost_weight() over the level's nodes. A coarse
38 // shape score (per-channel work proxy), NOT a CPU-cycle estimate; multiplied
39 // by the runtime frame count it gives a "channel-samples" figure a parallel
40 // executor compares against a fork/join break-even threshold to decide
41 // whether dispatching the level across workers is worth the overhead.
42 std::vector<std::uint64_t> level_work_weight;
43 bool ok = false;
44};
45
46// Static per-node work weight feeding level_work_weight: the per-channel work a
47// node does, approximated as max(input_ports, output_ports) for audio-processing
48// kinds (Processor / Utility / Custom) and 0 for pure I/O (AudioInput /
49// AudioOutput / MidiInput / MidiOutput), which neither justify a worker hop nor
50// (for AudioOutput) ever run in parallel. Deterministic and allocation-free.
51// NOTE: Gain and hosted-plugin nodes both map to Processor, so this cannot tell a
52// cheap gain from an expensive plugin — per-node DSP-cost discrimination needs
53// the runtime measured-load feed (masterwork §6.4), a later refinement.
55 std::uint32_t input_ports,
56 std::uint32_t output_ports) noexcept;
57
58// Compute the levelization for `plan`. Returns ok=false only on allocation
59// failure or a malformed plan (processing order not covering every node); an
60// empty plan yields ok=true with level_count=0.
62
63} // namespace pulp::graph
Definition graph_runtime_buffer_assignment.hpp:8
GraphRuntimeNodeKind
Definition graph_runtime_plan.hpp:12
GraphRuntimeLevelization build_graph_runtime_levelization(const GraphRuntimePlan &plan)
std::uint64_t graph_runtime_node_cost_weight(GraphRuntimeNodeKind kind, std::uint32_t input_ports, std::uint32_t output_ports) noexcept
Definition graph_runtime_levelization.hpp:25
std::vector< std::uint32_t > level_offsets
Definition graph_runtime_levelization.hpp:34
std::uint32_t level_count
Definition graph_runtime_levelization.hpp:30
std::vector< std::uint64_t > level_work_weight
Definition graph_runtime_levelization.hpp:42
std::vector< std::uint32_t > node_level
Definition graph_runtime_levelization.hpp:28
std::vector< std::uint32_t > level_nodes
Definition graph_runtime_levelization.hpp:35
bool ok
Definition graph_runtime_levelization.hpp:43
Definition graph_runtime_plan.hpp:169