nx_compute_graph.nx
buildroot/runtime/nx_compute_graph.nx
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
imports: nx_syscalls.nxnx_tier.nxnx_compute_node.nx
imported by: nx_compute_graph_test.nxnx_compute_runner.nxnx_compute_runner_test.nx
structs
| 59 | struct ComputeGraph |
consts
| 41 | const NX_CG_OK: nx_int = 0 |
| 42 | const NX_CG_ERR_CYCLE: nx_int = 1 // cycle detected |
| 43 | const NX_CG_ERR_BAD_EDGE: nx_int = 2 // edge references non-existent node |
| 44 | const NX_CG_ERR_BAD_PORT: nx_int = 3 // port index out of range |
| 45 | const NX_CG_ERR_DANGLING_INPUT: nx_int = 4 // node input slot not wired |
| 46 | const NX_CG_ERR_NODE_LIMIT: nx_int = 5 // node cap exceeded |
| 47 | const NX_CG_ERR_UNKNOWN_KIND: nx_int = 6 // node kind sealed-enum invalid |
| 48 | const NX_CG_ERR_UNKNOWN_OP: nx_int = 7 // op_code sealed-enum invalid |
| 49 | const NX_CG_N_VERDICTS: nx_int = 8 |
| 68 | const NX_CG_BYTES: nx_int = 48 // 6 fields * 8 |
functions
| 51 | func nx_cg_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 72 | func nx_cg_alloc(cap_nodes: nx_int) -> *ComputeGraph |
| 93 | func nx_cg_add_node(g: *ComputeGraph, n: *ComputeNode) -> nx_int |
| 107 | func nx_cg_get_node(g: *ComputeGraph, id: nx_int) -> *ComputeNode |
| 124 | func nx_cg_validate(g: *ComputeGraph) -> nx_int called by 2: mainmain calls 4: nx_cg_get_nodenx_cn_node_kind_is_validnx_cn_op_is_validnx_cn_kernel_is_valid |
| 187 | func nx_cg_toposort(g: *ComputeGraph) -> nx_int |
| 257 | func nx_cg_topo_at(g: *ComputeGraph, idx: nx_int) -> nx_int |
| 274 | func nx_cg_root_hash(g: *ComputeGraph, out_hash: *u8) -> nx_int |