code wiki / (root) / nx_tensor.nx

nx_tensor.nx

buildroot/runtime/nx_tensor.nx

11961 B370 linesdepth 2pulls 2 transitivereach 300 importersview sourcekind librarytopic tensor
docsdependenciesstructsconstsfunctions

about

nx_tensor.nx -- n-dimensional strided array primitive. Foundation brick of the sovereign-from-bits-up ML substrate per nxc2/docs/MULTIMODAL_ORCHESTRATOR_ROADMAP.md iteration I1. Every future ML kernel (BLAS, conv, attention, norm, activation) hangs off this type. Dtype enum + 8-dim shape + row-major strides give us the API contract that survives every future evolution -- new dtypes, SIMD intrinsics, GPU backends -- without breaking callers. Per the sovereign-from-bits-up cardinal: NO GGML, NO PyTorch dependency. Pure NishiLang on sys_mmap. The element storage is a flat *u8 byte-buffer; the dtype tag tells callers how to interpret it. Current build supports I64-backed only (Q-format fixed-point per the Q10 substrate convention); future iterations add I32/I16/I8/F16/BF16/F32/F64/Q4_0/Q4_K/Q5_K/Q8_0 in lock-step with the compiler's f-type and SIMD landings. genealogy_id: ggml_internal_design + numpy_ndarray + dlpack lineage_id: sovereign_tensor_v1

dependencies 2 imports · 119 importers

nx_syscalls.nx nx_tier.nx nx_tensor.nx nx_activation_steer.nx nx_actor_role_llm.nx nx_actor_role_llm_test.nx nx_actor_role_llm_v2_real_test.nx nx_attention.nx nx_attention_test.nx nx_attn_window.nx nx_attribution.nx nx_bench_v1_vs_v2_test.nx nx_blas_i64.nx

diagram shows first 10 each side; +0 more imports, +109 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nx

imported by: nx_activation_steer.nxnx_actor_role_llm.nxnx_actor_role_llm_test.nxnx_actor_role_llm_v2_real_test.nxnx_attention.nxnx_attention_test.nxnx_attn_window.nxnx_attribution.nxnx_bench_v1_vs_v2_test.nxnx_blas_i64.nxnx_coder_swap_gate.nxnx_companion_compose_test.nxnx_compute_node.nxnx_compute_runner.nxnx_compute_runner_test.nxnx_conv2d.nxnx_dispatcher.nxnx_dual_companion_compose_test.nxnx_embedding.nxnx_flash_attention.nxnx_flash_attention_test.nxnx_gelu.nxnx_gguf_dequant_kat_gate.nxnx_gguf_load.nxnx_gguf_load_block.nxnx_gguf_load_block_test.nxnx_gguf_load_lazy.nxnx_gguf_load_lazy_test.nxnx_gguf_load_model.nxnx_gguf_load_model_test.nxnx_gguf_load_q4k_test.nxnx_gguf_load_test.nxnx_gguf_type_census_gate.nxnx_gpu_export.nxnx_gpu_serve_gate.nxnx_groupnorm.nxnx_layernorm.nxnx_live_fire_gguf.nxnx_live_fire_gguf_test.nxnx_llm_capcheck.nxnx_llm_loopb_gate.nxnx_llm_ppl_bench_gate.nxnx_llm_run.nxnx_llm_run_v2.nxnx_llm_run_v2_test.nxnx_nofloat_arch_config_gate.nxnx_nofloat_arch_moe_gate.nxnx_nofloat_llm.nxnx_nofloat_moe_real_gate.nxnx_nofloat_olmoe_forward_gate.nxnx_nofloat_olmoe_gate.nxnx_nofloat_q6k_gate.nxnx_nofloat_qwen_bias_probe.nxnx_nofloat_qwen_decode_gate.nxnx_nofloat_qwen_diag_gate.nxnx_nofloat_qwen_dqprobe_gate.nxnx_nofloat_qwen_encode_gate.nxnx_nofloat_qwen_encode_prep_gate.nxnx_nofloat_qwen_fastgen_gate.nxnx_nofloat_qwen_fastgen_i32_gate.nxnx_nofloat_qwen_fastgen_i8_gate.nxnx_nofloat_qwen_fidelity_gate.nxnx_nofloat_qwen_forward_gate.nxnx_nofloat_qwen_gen_gate.nxnx_nofloat_qwen_kvgen_gate.nxnx_nofloat_qwen_rope_h2h_gate.nxnx_nofloat_qwen_stack_gate.nxnx_nofloat_qwen_text_gate.nxnx_nofloat_qwen_tok_gate.nxnx_nofloat_qwen_wload_gate.nxnx_nofloat_serve_core.nxnx_nofloat_tok.nxnx_numeric_oracle.nxnx_numeric_oracle_test.nxnx_olmoe_recon2_gate.nxnx_olmoe_recon_gate.nxnx_placement.nxnx_placement_test.nxnx_q4k_dot_simd.nxnx_q4k_gemm_mt.nxnx_q4k_linear.nxnx_q4k_linear_hp.nxnx_q4k_real_gemm.nxnx_q4k_speed_bench.nxnx_q5k_dot_simd.nxnx_quad_companion_compose_test.nxnx_quant_block.nxnx_quant_block_q8.nxnx_quant_block_test.nxnx_quant_q4k.nxnx_quant_q4k_test.nxnx_qwen_blk0_types.nxnx_qwen_hybrid_attn.nxnx_qwen_hybrid_ffn.nxnx_qwen_hybrid_qkv.nxnx_real_gguf_test.nxnx_rmsnorm.nxnx_sampler.nxnx_silu.nxnx_sparse_tensor.nx +19 more (shown cap 100 declared)

structs

101struct NxTensor

consts

48const NX_DT_I64: nx_int = 0 // 8 bytes per element
49const NX_DT_I32: nx_int = 1 // 4
50const NX_DT_I16: nx_int = 2 // 2
51const NX_DT_I8: nx_int = 3 // 1
52const NX_DT_F32: nx_int = 4 // 4 (compiler-gated)
53const NX_DT_F16: nx_int = 5 // 2
54const NX_DT_BF16: nx_int = 6 // 2
55const NX_DT_F64: nx_int = 7 // 8
56const NX_DT_Q4_0: nx_int = 8 // packed 4-bit + 1 fp scale per block
57const NX_DT_Q4_K: nx_int = 9
58const NX_DT_Q5_K: nx_int = 10
59const NX_DT_Q8_0: nx_int = 11
60const NX_DT_N_KINDS: nx_int = 12
99const NX_T_MAX_NDIM: nx_int = 8
115const NX_T_BYTES: nx_int = 64 // 8 fields * 8
116const NX_T_SHAPE_BYTES: nx_int = 64 // NX_T_MAX_NDIM * 8
123const NX_T_OK: nx_int = 0
124const NX_T_ERR_BAD_DTYPE: nx_int = 1 // unknown or out-of-range dtype
125const NX_T_ERR_DTYPE_GATED: nx_int = 2 // dtype known but compiler/codec not yet supports it
126const NX_T_ERR_BAD_NDIM: nx_int = 3 // ndim < 0 or > NX_T_MAX_NDIM
127const NX_T_ERR_BAD_SHAPE: nx_int = 4 // any shape[i] <= 0
128const NX_T_ERR_OVERFLOW: nx_int = 5 // numel overflow i64
129const NX_T_ERR_N_VERDICTS: nx_int = 6

functions

62func nx_dt_is_valid(d: nx_int) -> nx_int
called by 2: nx_t_allocmain
72func nx_dt_element_bytes(d: nx_int) -> nx_int
88func nx_dt_is_implemented(d: nx_int) -> nx_int
called by 1: main calls 1: nx_dt_element_bytes
131func nx_t_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
142func nx_t_compute_strides_rowmajor(shape: *i64, ndim: nx_int, stride_out: *i64) -> nx_int
159func nx_t_alloc(dtype: nx_int, shape_in: *i64, ndim: nx_int,
229func nx_t_fill_zero(t: *NxTensor) -> nx_int
243func nx_t_flat_offset(t: *NxTensor, idx: *i64) -> nx_int
254func nx_t_get_i64(t: *NxTensor, idx: *i64) -> nx_int
262func nx_t_set_i64(t: *NxTensor, idx: *i64, v: nx_int) -> nx_int
called by 4: mainmainmainmain calls 1: nx_t_flat_offset
275func nx_t_is_contiguous(t: *NxTensor) -> nx_int
293func nx_t_reshape(t: *NxTensor, new_shape: *i64, new_ndim: nx_int) -> nx_int
334func nx_t_permute(t: *NxTensor, permute_axes: *i64) -> *NxTensor