Add opt-in C kernel for spectrum-native holographic trace memory#2
Add opt-in C kernel for spectrum-native holographic trace memory#2atimics wants to merge 18 commits into
Conversation
65b2e6d to
344d4cb
Compare
C VSA program-layer updateAdded
This moves the VSA program decode/execute loop into C for straight-line/core programs: materialize the program spectrum once, unbind each instruction position, clean opcode/operand against C-side codebooks, and update ACC inside one C loop. Validation
Python VM vs C VSA Program RunnerCommand: Benchmark compares Python
Program-layer geomean across all 12 cases: 4.42x faster than the Python VM, with exact trace parity and accumulator parity. The important boundary is still the same: this does not make all VSA programs C-native. It gives the core algebraic VM path a C executor; richer host-bound instructions remain Python-side because they call Python handlers, function libraries, or exact host state. |
9495a04 to
b21e93e
Compare
|
Updated PR #2 with What changed:
Validation:
Local microbenchmarks on the DCC/FPE path:
This keeps the DCC/procedural layer in Python/NumPy, but accelerates the shared FPE field kernel it now leans on. |
|
Performance update after rebasing PR2 on
Validation:
Local microbench on this 14-CPU machine, serial
This should help the new DCC/procedural layer from |
|
Follow-up to the parallel-core pass: Updated local microbench on the same 14-CPU machine, serial
Validation after the scheduler refinement remains green:
|
|
Another speed pass: What changed:
Validation:
Local microbench on the same 14-CPU machine:
This should make the new main-branch DCC terrain/heightfield workflows feel much less like they are dragging a full point cloud through every grid sample. |
|
Real-time renderer pass: What landed:
Validation:
This turns the earlier offline asteroid-belt preview into an actual realtime renderer foothold inside the repo. |
c7985e5 to
d136d9d
Compare
d136d9d to
73efcbe
Compare
Summary
HOLOSTUFF_USE_C=1can replacebind,bind_fixed,weighted_sum,unbind, andHolographicMemorywhile default NumPy behavior remains unchangedbind_fixedpath for small fixed-vector row stacks, while leaving wider stacks on NumPy's batched real FFT by defaultlearn()now accumulatesFFT(state) * FFT(action)directly, while.trace/save/load materialize the real trace lazily for compatibilityc-kernel-evidenceCI job that compiles/tests the scalar C path, gates C-vs-NumPy trace speedups, and uploads raw JSONL plus a Markdown evidence reportUpdate
Rebased onto upstream
mainatde13c31on 2026-06-28. The newer upstream work adds sparse/FPE field faculties, mesh bridge/QEM updates, unified integration, tour updates, and freshbind_fixedusage in integration coverage. This PR still keepsbind_batchon NumPy and accelerates only the fixed-vector row-stack case where the C backend measured well. The default cutoff is 8 rows and can be tuned withHOLOSTUFF_C_BIND_FIXED_MAX_ROWS.Latest Update
Added
4f5b013after checking the latest upstream field work: the C backend now exports an unnormalizedweighted_sumprimitive,holographic_ai.bundle()layers normalization on top of that shared accumulator, andVectorFunctionEncoder.bundle()uses vectorizedencode_many()plus chunked weighted accumulation for FPE function/field builds. This keeps symbolic bundles normalized while preserving raw amplitudes for function-valued FPE fields.Representative local timing on the 12^3 / dim-2048 FPE field build:
Latest Performance Comparison
Fresh local run on 2026-06-29 from
codex/c-kernel-planusing/Users/ratimics/develop/.venvs/holostuff/bin/python.Accelerate C trace vs Python/NumPy
Command:
make c-bench PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/pythonThis compares the Python/NumPy
HolographicMemorytrace path against the C trace/action-index benchmark built with the macOS Accelerate backend. Workload:pairs=8,actions=8,queries=1024,repeats=5. Accuracy was 1.0 for both Python/NumPy and C on every row.Scalar C trace gate vs Python/NumPy
Command:
make c-ci-evidence PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/pythonThis is the same portable scalar path the CI job gates. Workload:
pairs=8,actions=8,queries=2048,repeats=7. Accuracy was 1.0 for both Python/NumPy and C on every row.Geomean across gated scalar dimensions: 3.63x store, 3.34x query. The gate passed: every measured dimension exceeded the 1.05x store/query thresholds with 1.0 C accuracy.
bind_fixed support rows
bind_fixedis intentionally narrower than the trace path. Accelerate C wins on the small row stacks where the bridge routes to C, while row-32 uses the NumPy fallback by default because batched NumPy real FFT is generally better for wider stacks.The important distinction is that the trace win is not merely "C instead of Python." The baseline Python path is already NumPy, so much of it runs inside compiled FFT/vector kernels. The C path wins where this PR changes ownership of the hot loop and representation: spectrum-native trace storage, C-owned action-index lookup, and fewer Python/NumPy intermediate transitions.
Why
The architectural hot path for this project is holographic bind/unbind trace memory plus repeated binding against a fixed trace, role, or key. This keeps the Python research surface intact while adding an optional hardware-aware substrate for repeated store/recall and small fixed-role batch workloads.
The latest kernel change stores trace memory in the representation the algebra actually consumes: frequency-space bound pairs. That removes an inverse FFT from every trace store and avoids transforming the real trace back into frequency space before recall.
CI Evidence
The new
c-kernel-evidencejob runs on Ubuntu with the portable scalar C backend. It:cunit tests withHOLO_USE_ACCELERATE=0bind_fixedrows as supporting evidence without gating on them, because scalar Linux performance there is platform-sensitivec/build/ci-evidence/report.mdto the GitHub Actions job summaryraw.jsonl,summary.jsonl, andreport.mdas thec-kernel-evidenceartifactCurrent upstream PR Actions run is waiting for maintainer approval because this is a forked PR: https://github.com/AnOversizedMooseWithSocks/holostuff/actions/runs/28319664732. Once approved, the CI job will compile and publish the evidence in the run summary/artifact.
Latest local dry run of the same evidence target passed:
make c-ci-evidence PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/pythonBefore the spectrum-native trace rewrite, the same local evidence target reported about 2.598x store / 3.397x query geomean. The spectrum-native change specifically improves the trace-store side while keeping query throughput and accuracy intact.
Validation
Latest validation on 2026-06-29:
git diff --check de13c3187a5f8b10cee097d032948bb2867768d1...HEAD-> cleanmake c-test PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/python->test_core ok,test_trace okmake c-bench PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/python-> PASS; Accelerate trace speedups listed abovemake c-ci-evidence PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/python-> PASS; scalar gate speedups listed aboveHOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 /Users/ratimics/develop/.venvs/holostuff/bin/python -m pytest -q test_holographic_c_backend.py test_holographic_fpe.py-> 16 passedEarlier validation after
4f5b013:git diff --checkmake c PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/pythonmake c-test PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/python->test_core ok,test_trace okmake -C c test HOLO_USE_ACCELERATE=0 PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/python->test_core ok,test_trace okHOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 /Users/ratimics/develop/.venvs/holostuff/bin/python -m pytest test_holographic_c_backend.py test_holographic_fpe.py test_holographic_fpefield.py -q-> 22 passedHOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 /Users/ratimics/develop/.venvs/holostuff/bin/python -m pytest test_holographic_fpe.py test_holographic_fpefield.py test_holographic_sparsefield.py test_holographic_meshbridge.py test_holographic_meshqem.py test_holographic_mesh.py test_holographic_lod.py -q-> 84 passedHOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 /Users/ratimics/develop/.venvs/holostuff/bin/python -m pytest -q <latest FS/mesh integration slice>-> 10 passed344d4cb, so they appear to be baseline/environment failures rather than regressions from this update.Post-rebase validation on
de13c31base:git diff --checkmake c-test->test_core ok,test_trace okmake -C c test HOLO_USE_ACCELERATE=0 PYTHON=/Users/ratimics/develop/.venvs/holostuff/bin/python->test_core ok,test_trace ok/Users/ratimics/develop/.venvs/holostuff/bin/python -m pytest test_holographic_c_backend.py -q-> 5 passedHOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 /Users/ratimics/develop/.venvs/holostuff/bin/python -m pytest test_holographic_fpe.py test_holographic_fpefield.py test_holographic_sparsefield.py test_holographic_meshbridge.py test_holographic_meshqem.py test_holographic_mesh.py test_holographic_lod.py -q-> 83 passedHOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 /Users/ratimics/develop/.venvs/holostuff/bin/python -m pytest -q <latest FS/mesh integration slice>-> 10 passedCurrent validation before the latest base refresh:
git diff --checkmake -C c clean && make -C c test HOLO_USE_ACCELERATE=0 PYTHON=/tmp/holostuff-pr2-venv/bin/python->test_core ok,test_trace okmake c-test PYTHON=/tmp/holostuff-pr2-venv/bin/python->test_core ok,test_trace okmake c PYTHON=/tmp/holostuff-pr2-venv/bin/pythonHOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 /tmp/holostuff-pr2-venv/bin/python -m pytest -q test_holographic_c_backend.py-> 5 passedHOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 /tmp/holostuff-pr2-venv/bin/python -m pytest -q test_integration.py::test_exact_matmul_is_exact_where_superposition_is_lossy_and_range_federates-> 1 passedmake c-ci-evidence PYTHON=/tmp/holostuff-pr2-venv/bin/python-> PASSEarlier benchmark/check coverage before the upstream rebase:
HOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 python -m pytest test_holographic.py -q-> 43 passedHOLOSTUFF_USE_C=1 HOLOSTUFF_C_STRICT=1 python -m pytest test_holographic_c_backend.py test_algebra_properties.py::test_bind_batch_and_fixed_match_scalar_bind test_isa_conformance.py::test_bind_batch_is_value_conformant test_holographic_compute.py test_holographic_superposed.py test_holographic_rns.py test_holographic_array.py test_holographic_creature_batch.py -q-> 18 passedmake c-benchBenchmark Notes
bind_fixedbenchmark, Accelerate C path enabled for rows <= 8: row-1 speedup ranged about 1.42x-1.49x; row-8 speedup ranged about 1.09x-1.30x; max absolute error stayed below 2e-16.Notes
HOLOSTUFF_USE_C=1orholographic_c.install(...).requirements-experiments.txt.HOLOSTUFF_USE_C=1pytest run previously had 5 failures, and the same 5 targeted tests failed without the C backend; they appear to be upstream/baseline suite issues rather than regressions from this PR.