code wiki / (root) / nx_dot_simd_demo.nx

nx_dot_simd_demo.nx

buildroot/runtime/nx_dot_simd_demo.nx

5827 B165 linesdepth 8pulls 16 transitivereach 0 importersview sourcekind sketch/demo
docsdependenciesstructsconstsfunctions

about

nx_dot_simd_demo.nx -- parallel SIMD dot product demo. dot(a, b) = sum(a[i] * b[i]) for i in 0..N Three implementations, all bit-exact: 1. scalar: trivial for-loop 2. SIMD: i32x8 vmul + vreduce_sum per chunk; i64 accumulator 3. parallel+SIMD: split chunks across pool workers, each worker does SIMD inner loop, atomic FAA into shared acc Composes L7 nx_parallel + L8 SIMD i32x8 into a real ML-class dot-product kernel.

dependencies 7 imports · 0 importers

nx_kernel_v2.nx nx_log.nx nx_atom.nx nx_clock.nx nx_thread_pool.nx nx_parallel.nx nx_hw.nx nx_dot_simd_demo.nx

imports: nx_kernel_v2.nxnx_log.nxnx_atom.nxnx_clock.nxnx_thread_pool.nxnx_parallel.nxnx_hw.nx

imported by: nobody (leaf or entry point)

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

main nx_clock_monotonic_ns sys_mmap sys_clock_gettime_mono scalar_dot simd_dot nx_hw_worker_count nx_hw_cpu_count sys_mmap ↻ sys_munmap nx_pool_new nx_hw_worker_count ↻ sys_mmap ↻ nx_chan_new sys_mmap ↻ _nx_chan_cell sys_thread_create nx_thread_spawn sys_mmap ↻ nx_thread_spawn_fn sys_mmap ↻ _set_dot_ctx nx_parallel_for sys_mmap ↻ nx_atom_load_i64 _nx_chunk_start _nx_chunk_end nx_pool_submit nx_atom_faa_i64 nx_chan_send nx_chan_try_send _nx_chan_cell ↻ nx_thread_yield _pool_futex_wake_all sys_futex_wake nx_atom_load_i64 ↻ nx_pool_shutdown nx_atom_faa_i64 ↻ nx_chan_send ↻ _pool_futex_wake_all ↻

structs

none

consts

28const N: i64 = 8192

functions

31func scalar_dot(a_i32: *u8, b_i32: *u8, n: i64) -> i64
called by 1: main
50func simd_dot(a_i32: *u8, b_i32: *u8, n: i64) -> i64
called by 1: main
73func _set_dot_ctx(a: i64, b: i64, acc: i64, chunk: i64) -> i64
called by 1: main
81func _read_dot_a() -> i64 { return DOT_A_PTR }
called by 1: simd_dot_worker
82func _read_dot_b() -> i64 { return DOT_B_PTR }
called by 1: simd_dot_worker
83func _read_dot_acc() -> i64 { return DOT_ACC_PTR }
called by 1: simd_dot_worker
84func _read_dot_chunk() -> i64 { return DOT_CHUNK_SIZE }
called by 1: simd_dot_worker
87func simd_dot_worker(chunk_idx: i64) -> i64
110func main() -> nx_exit