Last updated: 2026-09-07
Decode Planning
Compute Graph
Represent decode work as a dependency graph that can be topologically ordered.
Graph builders use this module to describe fused operations, dependencies, and dispatch metadata before any Vulkan command recording happens.
12 exports shown
enum
ExecDomain
pub const ExecDomain = enum Where a graph node executes: GPU compute, GPU transfer, or CPU host.
enum
BottleneckKind
pub const BottleneckKind = enum Classification of the dominant performance bottleneck for a graph node.
struct
HardwareInfo
pub const HardwareInfo = struct Hardware parameters used by bottleneck and utilization heuristics.
enum
OpType
pub const OpType = enum Operation types that a compute graph node can represent.
Each variant maps to one GPU shader dispatch or fused kernel invocation during decode-time execution.
struct
Node
pub const Node = struct A single operation node in the compute dependency graph.
Each node carries dispatch metadata (workgroups, push constants) and dependency edges so the graph can be topologically sorted before recording.
struct
Edge
pub const Edge = struct Directed dependency edge between two graph nodes.
struct
OpCount
pub const OpCount = struct Count of nodes that share the same operation type.
struct
CriticalPathNode
pub const CriticalPathNode = struct Critical-path node annotated with its dependency depth.
struct
NodeAnalysis
pub const NodeAnalysis = struct Per-node structural metrics derived from the dependency graph.
struct
Hotspot
pub const Hotspot = struct A node ranked among the top contributors to estimated decode time.
struct
GraphAnalysis
pub const GraphAnalysis = struct Computed summary of the graph structure used by visualization and debugging tools.
Methods
1method
GraphAnalysis.deinit
pub fn deinit(self: *GraphAnalysis) void Release the arrays allocated for the analysis result.
struct
Graph
pub const Graph = struct Static compute graph for a transformer layer or full decode pass.
Methods
20method
Graph.init
pub fn init(allocator: std.mem.Allocator, name: []const u8) Graph Initialize an empty graph with a human-readable name.
method
Graph.deinit
pub fn deinit(self: *Graph) void Release all graph nodes owned by the graph.
method
Graph.addNode
pub fn addNode(self: *Graph, op: OpType, name: []const u8) !u32 Append a node to the graph and assign it the next dense node ID.
method
Graph.setInputs
pub fn setInputs(self: *Graph, node_id: u32, inputs: []const u32) void Set the input buffer table indices consumed by a node.
method
Graph.setOutput
pub fn setOutput(self: *Graph, node_id: u32, output: u32) void Set the output buffer table index produced by a node.
method
Graph.setWorkgroups
pub fn setWorkgroups(self: *Graph, node_id: u32, x: u32, y: u32, z: u32) void Set the workgroup dimensions that should be used when dispatching a node.
method
Graph.setLayerIndex
pub fn setLayerIndex(self: *Graph, node_id: u32, layer_index: ?u32) void Assign a transformer layer index to a node for per-layer diagnostics.
method
Graph.setExecDomain
pub fn setExecDomain(self: *Graph, node_id: u32, domain: ExecDomain) void Override the execution domain for a node (defaults to `gpu_compute`).
method
Graph.setThreadsPerWorkgroup
pub fn setThreadsPerWorkgroup(self: *Graph, node_id: u32, threads_per_workgroup: u32) void Set the number of threads per workgroup for occupancy estimates.
method
Graph.setCostEstimate
pub fn setCostEstimate(self: *Graph, node_id: u32, read_bytes: u64, write_bytes: u64, weight_bytes: u64, flops: u64) void Attach byte-traffic and FLOP cost estimates used by the bottleneck heuristics.
method
Graph.setHostSync
pub fn setHostSync(self: *Graph, node_id: u32, requires_host_sync: bool) void Mark whether a node requires host-visible synchronization or readback.
method
Graph.setNote
pub fn setNote(self: *Graph, node_id: u32, note: ?[]const u8) void Attach an optional static diagnostic note to a node.
method
Graph.setAssumedDecodeSeqLen
pub fn setAssumedDecodeSeqLen(self: *Graph, assumed_decode_seq_len: u32) void Record the sequence length assumed when building decode-time cost estimates.
method
Graph.setHardwareContext
pub fn setHardwareContext(self: *Graph, hardware: HardwareInfo) void Provide hardware parameters used by occupancy and bandwidth heuristics.
method
Graph.addDependency
pub fn addDependency(self: *Graph, node_id: u32, depends_on: u32) void Declare that one node must execute after another.
method
Graph.topologicalOrder
pub fn topologicalOrder(self: *const Graph, allocator: std.mem.Allocator) ![]u32 Compute a valid execution order for the current dependency graph.
method
Graph.nodeCount
pub fn nodeCount(self: *const Graph) usize Return the number of nodes currently stored in the graph.
method
Graph.analyze
pub fn analyze(self: *const Graph, allocator: std.mem.Allocator) !GraphAnalysis Analyze dependency structure for visualization and optimization work.
method
Graph.writeJsonReport
pub fn writeJsonReport(self: *const Graph, writer: *std.Io.Writer, allocator: std.mem.Allocator) !void Serialize a graph-analysis JSON payload suitable for custom viewers and scripts.
method
Graph.writeDot
pub fn writeDot(self: *const Graph, writer: *std.Io.Writer, allocator: std.mem.Allocator) !void Serialize the graph as Graphviz DOT for quick local rendering.