code wiki / (root) / nx_tensor_lower.nx

nx_tensor_lower.nx

buildroot/runtime/nx_tensor_lower.nx

11975 B380 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind tooltopic tensor
docsdependenciesstructsconstsfunctions

about

tensor_lower.nx -- TirGraph -> RV64 asm lowering pass. Bridges the fusion pass (tensor_ir.nx) to actual machine code. Walks the TirGraph in topological order, emitting asm into an OutBuf for each non-fused node. Fused producers are inlined into their consumer's kernel emit -- the headline "comptime fusion" win. v0.0.1 covers: - Element-wise unary/binary ops on i32/i64 tensors (loops) - LOAD: data pointer comes from caller (we just expose it) - PARAM: tensor is a function parameter, address in a-register Out of scope for v0.0.1 (subsequent commits): - MATMUL (triple-nested loop with tile blocking) - ATTENTION (fused softmax+matmul) - fp16/fp32 (waiting on F-extension codegen) - SIMD intrinsics (waiting on RVV codegen) - GPU backends (CUDA / SPIR-V) Each emit follows the standard nxc2 codegen ABI: a0..a7 hold input tensor data pointers the function emits a loop that computes element-by-element

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_outbuf.nx nx_tensor_ir.nx nx_tensor_lower.nx

imports: nx_syscalls.nxnx_outbuf.nxnx_tensor_ir.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main tir_graph_new sys_mmap sys_mmap ↻ tir_add_tensor tir_tensor_at tir_bytes tir_numel tir_dtype_bits tir_tensor_at ↻ tir_bytes ↻ tir_add_node tir_node_at tir_tensor_at ↻ out_new sys_mmap ↻ tir_lower_node tir_node_at ↻ tir_op_is_unary_ew tir_lower_unary_ew tir_numel ↻ tir_dtype_bits ↻ out_str out_char out_i64 out_char ↻ sys_mmap ↻ tir_op_is_binary_ew tir_lower_binary_ew tir_numel ↻ tir_dtype_bits ↻ out_str ↻ out_i64 ↻ tir_lower_matmul tir_tensor_at ↻ tir_dtype_bits ↻ out_str ↻ out_i64 ↻ ew_substr

structs

none

consts

34const K_MAGIC_8192: i64 = 8192

functions

57func tir_lower_unary_ew(g: *TirGraph, n: *TirNode,
105func tir_lower_binary_ew(g: *TirGraph, n: *TirNode,
176func tir_lower_matmul(g: *TirGraph, n: *TirNode,
300func tir_lower_node(g: *TirGraph, node_id: i64,
326func ew_substr(buf: *u8, len: i64, needle: *u8, nlen: i64) -> i64
called by 1: main
341func main() -> i64