code wiki / (root) / nx_compute_node.nx

nx_compute_node.nx

buildroot/runtime/nx_compute_node.nx

12133 B326 linesdepth 5pulls 6 transitivereach 4 importersview sourcekind librarytopic compute
docsdependenciesstructsconstsfunctions

about

nx_compute_node.nx -- typed compute node, foundation of the ComfyUI-replacement DAG. ComfyUI's node is a Python class with INPUT_TYPES / RETURN_TYPES + a `def execute(self, **kwargs)`. Stringly-typed everywhere; the type system only catches mismatches at runtime; the workflow JSON is opaque; failures have no audit trail. Our compute node is: * **typed** -- NodeKind sealed enum + OpCode sealed enum + typed input/output ports. Type mismatches caught at graph-build time. * **content-addressed** -- each node carries a 32-byte SHA-256 hash of (op_code, params, input hashes). Identical sub-graphs produce identical hashes -> deterministic caching. * **audit-able** -- every node carries a stable id; the runner emits a span per execution (compose with nx_trace_emit). * **flat-array layout** -- inputs/params live in i64 buffers per the substrate convention; no Python dict-of-anything. This module ships the NODE primitive only. nx_compute_graph adds the DAG container + topo sort. The runner (executes a graph against tensor inputs) lands once we have real kernels. genealogy_id: comfyui_node_pattern + mlir_op + tvm_relay + jax_jaxpr + onnx_node + tensorflow_xla_hlo lineage_id: substrate_compute_node_v1

dependencies 4 imports · 4 importers

nx_syscalls.nx nx_tier.nx nx_tensor.nx nx_sha256.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_tensor.nxnx_sha256.nx

imported by: nx_compute_graph.nxnx_compute_graph_test.nxnx_compute_runner.nxnx_compute_runner_test.nx

structs

139struct ComputeNode

consts

44const NX_CN_NODE_CONST: nx_int = 0 // pre-loaded tensor (weight blob)
45const NX_CN_NODE_INPUT: nx_int = 1 // graph-level input port
46const NX_CN_NODE_OUTPUT: nx_int = 2 // graph-level output port
47const NX_CN_NODE_TENSOR_OP: nx_int = 3 // elementwise / reduction / shape
48const NX_CN_NODE_KERNEL: nx_int = 4 // heavy op dispatched to a kernel
49const NX_CN_NODE_CONTROL: nx_int = 5 // sub-graph / scheduler hook
50const NX_CN_NODE_N_KINDS: nx_int = 6
64const NX_CN_OP_ADD: nx_int = 0
65const NX_CN_OP_SUB: nx_int = 1
66const NX_CN_OP_MUL: nx_int = 2
67const NX_CN_OP_DIV: nx_int = 3
68const NX_CN_OP_NEG: nx_int = 4
69const NX_CN_OP_RELU: nx_int = 5
70const NX_CN_OP_GELU: nx_int = 6
71const NX_CN_OP_SILU: nx_int = 7
72const NX_CN_OP_SWISH: nx_int = 8
73const NX_CN_OP_SOFTMAX: nx_int = 9
74const NX_CN_OP_SIGMOID: nx_int = 10
75const NX_CN_OP_TANH: nx_int = 11
76const NX_CN_OP_RESHAPE: nx_int = 12
77const NX_CN_OP_PERMUTE: nx_int = 13
78const NX_CN_OP_SLICE: nx_int = 14
79const NX_CN_OP_CONCAT: nx_int = 15
80const NX_CN_OP_SPLIT: nx_int = 16
81const NX_CN_OP_SUM_REDUCE: nx_int = 17
82const NX_CN_OP_MEAN_REDUCE: nx_int = 18
83const NX_CN_OP_MAX_REDUCE: nx_int = 19
84const NX_CN_OP_MIN_REDUCE: nx_int = 20
85const NX_CN_OP_TRANSPOSE: nx_int = 21
86const NX_CN_OP_VIEW: nx_int = 22
87const NX_CN_OP_N_OPS: nx_int = 23
100const NX_CN_K_MATMUL: nx_int = 0 // standard matmul (gemm)
101const NX_CN_K_GEMM: nx_int = 1 // alpha*A@B + beta*C
102const NX_CN_K_DOT: nx_int = 2 // 1-D dot product
103const NX_CN_K_CONV2D: nx_int = 3
104const NX_CN_K_CONV2D_DEPTHWISE: nx_int = 4
105const NX_CN_K_CONV2D_TRANSPOSE: nx_int = 5
106const NX_CN_K_LAYERNORM: nx_int = 6
107const NX_CN_K_RMSNORM: nx_int = 7
108const NX_CN_K_GROUPNORM: nx_int = 8
109const NX_CN_K_BATCHNORM: nx_int = 9
110const NX_CN_K_ATTENTION_QKV: nx_int = 10 // self-attention
111const NX_CN_K_ATTENTION_CROSS: nx_int = 11 // cross-attention
112const NX_CN_K_EMBEDDING_LOOKUP: nx_int = 12
113const NX_CN_K_ROTARY_EMBED: nx_int = 13 // RoPE
114const NX_CN_K_FFT: nx_int = 14
115const NX_CN_K_IFFT: nx_int = 15
116const NX_CN_K_N_KINDS: nx_int = 16
134const NX_CN_MAX_INPUTS: nx_int = 8 // covers attention's Q+K+V+mask+...
135const NX_CN_MAX_OUTPUTS: nx_int = 4 // most ops are 1; split takes a few
136const NX_CN_MAX_PARAMS: nx_int = 16 // axis, scale, dim, etc.
137const NX_CN_HASH_BYTES: nx_int = 32 // SHA-256
158const NX_CN_BYTES: nx_int = 88 // 11 fields * 8
273const NX_CN_HASH_HDR_BYTES: nx_int = 24 // kind + op + n_inputs + n_params (each 8 bytes? or 4?)

functions

52func nx_cn_node_kind_is_valid(k: nx_int) -> nx_int
called by 2: nx_cg_validatemain
89func nx_cn_op_is_valid(o: nx_int) -> nx_int
called by 2: nx_cg_validatemain
118func nx_cn_kernel_is_valid(k: nx_int) -> nx_int
called by 2: nx_cg_validatemain
167func nx_cn_alloc(node_id: nx_int, kind: nx_int, op_code: nx_int,
called by 2: mainmain calls 1: sys_mmap
204func nx_cn_set_input(n: *ComputeNode, input_slot: nx_int,
called by 2: mainmain
216func nx_cn_set_param(n: *ComputeNode, slot: nx_int, value: nx_int) -> nx_int
called by 1: main
229func nx_cn_set_output_tensor_id(n: *ComputeNode, port: nx_int,
239func nx_cn_get_input_src_node(n: *ComputeNode, slot: nx_int) -> nx_int
245func nx_cn_get_input_src_port(n: *ComputeNode, slot: nx_int) -> nx_int
251func nx_cn_get_param(n: *ComputeNode, slot: nx_int) -> nx_int
257func nx_cn_get_output_tensor_id(n: *ComputeNode, port: nx_int) -> nx_int
277func _cn_write_i64_le(buf: *u8, off: nx_int, value: nx_int) -> nx_int
called by 1: nx_cn_compute_hash
291func nx_cn_compute_hash(n: *ComputeNode) -> nx_int