nx_blas_i64.nx
buildroot/runtime/nx_blas_i64.nx
about
nx_blas_i64.nx -- BLAS Level-1/2/3 reference kernels on i64+Q10.
First kernel module on the sovereign-from-bits-up ML stack.
Iteration I3 per nxc2/docs/MULTIMODAL_ORCHESTRATOR_ROADMAP.md.
Per the "world class without the comfyui annoyance but the power
and more" framing: we ship the CORRECT version first (slow, simple,
auditable). AlphaTensor-discovered (Fawzi 2022) / AlphaEvolve-
proposed (Romera-Paredes 2025) variants land later as alternative
implementations of the same kernel, gated by nx_numeric_oracle
verdict against this reference.
Layout: row-major contiguous tensors only (v1). Strided / view
support lands when permute becomes a hot path.
Operations shipped:
gemm -- C = alpha * A @ B + beta * C (Level 3)
matmul -- gemm with alpha=1, beta=0
dot -- scalar = sum(x[i] * y[i]) (Level 1)
axpy -- y = alpha * x + y (Level 1)
scale -- x = alpha * x (Level 1, BLAS-1 _scal)
gemv -- y = alpha * A @ x + beta * y (Level 2)
Q-format convention: alpha and beta are Q10 scaling factors;
tensor elements are plain i64 (NOT pre-scaled). Result element =
(raw_dot * alpha_q10 + raw_c * beta_q10) / 1024.
genealogy_id: blis_van_zee_2015 + goto_2008_matmul +
alphatensor_fawzi_2022 + strassen_1969 +
ieee_754_kahan_1965
lineage_id: substrate_blas_i64_v1
dependencies 3 imports · 7 importers
imports: nx_syscalls.nxnx_tier.nxnx_tensor.nx
imported by: nx_actor_role_llm.nxnx_attention.nxnx_compute_runner.nxnx_compute_runner_test.nxnx_llm_run_v2.nxnx_sparse_tensor_test.nxnx_transformer_block.nx
structs
| none |
consts
| 43 | const NX_BLAS_Q10: nx_int = 1024 |
| 47 | const NX_BLAS_OK: nx_int = 0 |
| 48 | const NX_BLAS_ERR_BAD_DTYPE: nx_int = 1 // not I64 |
| 49 | const NX_BLAS_ERR_BAD_NDIM: nx_int = 2 // matmul needs ndim==2 |
| 50 | const NX_BLAS_ERR_SHAPE_MISMATCH: nx_int = 3 // K dimension or M/N mismatch |
| 51 | const NX_BLAS_ERR_NOT_CONTIGUOUS: nx_int = 4 // v1 row-major only |
| 52 | const NX_BLAS_N_VERDICTS: nx_int = 5 |
functions
| 54 | func nx_blas_verdict_is_valid(v: nx_int) -> nx_int |
| 62 | func _blas_check_matmul(a: *NxTensor, b: *NxTensor, c: *NxTensor) -> nx_int |
| 91 | func nx_blas_gemm(a: *NxTensor, b: *NxTensor, c: *NxTensor, |
| 130 | func nx_blas_matmul(a: *NxTensor, b: *NxTensor, c: *NxTensor) -> nx_int |
| 140 | func nx_blas_dot(x: *NxTensor, y: *NxTensor, out: *i64) -> nx_int calls 1: nx_t_is_contiguous |
| 166 | func nx_blas_axpy(alpha_q10: nx_int, x: *NxTensor, y: *NxTensor) -> nx_int calls 1: nx_t_is_contiguous |
| 189 | func nx_blas_scale(alpha_q10: nx_int, x: *NxTensor) -> nx_int calls 1: nx_t_is_contiguous |
| 206 | func nx_blas_gemv(a: *NxTensor, x: *NxTensor, y: *NxTensor, calls 1: nx_t_is_contiguous |