code wiki / (root) / nx_compute_graph.nx

nx_compute_graph.nx

buildroot/runtime/nx_compute_graph.nx

10148 B293 linesdepth 6pulls 7 transitivereach 3 importersview sourcekind librarytopic compute
docsdependenciesstructsconstsfunctions

about

nx_compute_graph.nx -- typed DAG container for compute nodes. The ComfyUI-power-without-annoyance core. ComfyUI's graph is a JSON dict that gets executed by a Python orchestrator; nodes are untyped, edges are stringly-named, cycle detection is best-effort, caching is opaque. Ours: * **typed DAG** -- nodes carry NodeKind + OpCode/KernelKind sealed enums; edges are (src_node, src_port) -> (dst_node, dst_port) index pairs with bounds-checked validity. * **content-addressed** -- every node has a SHA-256 hash from nx_compute_node.nx; two graphs with the same shape have the same root hash, computed at sort time. * **structurally valid** -- nx_cg_validate refuses cycles + dangling inputs + unwired output dependencies. Bad graphs cannot run. * **topo-sorted** -- nx_cg_toposort produces deterministic order via Kahn's algorithm; cycle = REFUSED with sealed verdict. Runner lives in a separate module once kernels exist. This file is the data structure + invariants + topo sort. genealogy_id: comfyui_workflow_dag + onnx_graph + mlir_module + kahn_1962_toposort lineage_id: substrate_compute_graph_v1

dependencies 3 imports · 3 importers

nx_syscalls.nx nx_tier.nx nx_compute_node.nx nx_compute_graph.nx nx_compute_graph_test.nx nx_compute_runner.nx nx_compute_runner_test.nx

imports: nx_syscalls.nxnx_tier.nxnx_compute_node.nx

imported by: nx_compute_graph_test.nxnx_compute_runner.nxnx_compute_runner_test.nx

structs

59struct ComputeGraph

consts

41const NX_CG_OK: nx_int = 0
42const NX_CG_ERR_CYCLE: nx_int = 1 // cycle detected
43const NX_CG_ERR_BAD_EDGE: nx_int = 2 // edge references non-existent node
44const NX_CG_ERR_BAD_PORT: nx_int = 3 // port index out of range
45const NX_CG_ERR_DANGLING_INPUT: nx_int = 4 // node input slot not wired
46const NX_CG_ERR_NODE_LIMIT: nx_int = 5 // node cap exceeded
47const NX_CG_ERR_UNKNOWN_KIND: nx_int = 6 // node kind sealed-enum invalid
48const NX_CG_ERR_UNKNOWN_OP: nx_int = 7 // op_code sealed-enum invalid
49const NX_CG_N_VERDICTS: nx_int = 8
68const NX_CG_BYTES: nx_int = 48 // 6 fields * 8

functions

51func nx_cg_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
72func nx_cg_alloc(cap_nodes: nx_int) -> *ComputeGraph
called by 2: mainmain calls 1: sys_mmap
93func nx_cg_add_node(g: *ComputeGraph, n: *ComputeNode) -> nx_int
called by 2: mainmain
107func nx_cg_get_node(g: *ComputeGraph, id: nx_int) -> *ComputeNode
124func nx_cg_validate(g: *ComputeGraph) -> nx_int
187func nx_cg_toposort(g: *ComputeGraph) -> nx_int
called by 2: mainmain calls 2: sys_mmapnx_cg_get_node
257func nx_cg_topo_at(g: *ComputeGraph, idx: nx_int) -> nx_int
called by 2: mainnx_cr_run
274func nx_cg_root_hash(g: *ComputeGraph, out_hash: *u8) -> nx_int
called by 1: main calls 2: sys_mmapnx_cg_get_node