Skip to content

feat(vsa): ternary matmul kernel — XOR + popcount, 0 DSP - #12

Merged
gHashTag merged 1 commit into
mainfrom
feat/ternary-matmul-vsa
May 6, 2026
Merged

gHashTag merged 1 commit into
mainfrom
feat/ternary-matmul-vsa

Conversation

@gHashTag

@gHashTag gHashTag commented May 6, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #7 (Phase 2)

Ternary matrix-vector multiply over VSA ALU — pure LUT logic, zero DSP48 blocks.

Verilog (fpga/vsa/)

  • vsa_matmul.v — 64×64 sequential ternary matmul using VSA bind (element-wise ternary multiply) + popcount for signed dot product. Register-based weights, combinational bind+popcount, 1 row/clock latency.
  • tb_vsa_matmul.v — self-checking testbench: 64/64 PASS (iverilog 13.0)

Rust (rings/FP-01/)

  • Gf16Binary — parser for igla_champion_gf16.bin format (magic 0x47463136, multi-tensor)
  • TernaryWeightConverter — GF16 u16 → ternary {-1, 0, +1} quantization with configurable threshold
  • Packed trit format — 2 bits/trit (same encoding as vsa_bind.v), 32 trits/u64 word
  • write_verilog_mem() — generates $readmem-compatible .mem files for BRAM init

Verification

  • cargo test --workspace: 21/21 PASS (8 FP-00 + 9 FP-01 + 4 FP-02)
  • iverilog tb_vsa_matmul: 64/64 PASS
  • cargo clippy --workspace: 0 warnings

Architecture

x_vec[64 trits] ──┐
                  ├── bind (ternary multiply) ── popcount(+1) - popcount(-1) ── y[j]
W[j][64 trits] ───┘         (XOR-like LUT)           (add/sub tree)
                              0 DSP48                   0 DSP48

φ² + φ⁻² = 3 | TRINITY

Phase 2 of issue #7: ternary matmul over VSA ALU

Verilog:
- vsa_matmul.v: 64x64 ternary matmul using bind (ternary multiply)
  + popcount for dot product — 0 DSP48 blocks
- tb_vsa_matmul.v: testbench with self-test weights, 64/64 PASS

Rust (FP-01):
- Gf16Binary parser (magic + multi-tensor format)
- TernaryWeightConverter: GF16 → ternary {-1, 0, +1} quantization
- Packed trit output (2 bits/trit, 32 trits/u64) for Verilog
- Verilog .mem file writer for BRAM initialization

Tests: 21/21 cargo test, 64/64 iverilog, 0 clippy warnings
@gHashTag
gHashTag merged commit 452c07a into main May 6, 2026
18 of 32 checks passed
@gHashTag
gHashTag deleted the feat/ternary-matmul-vsa branch July 14, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 feat: IGLA Champion Model → FPGA Inference (v0.2-igla-fpga)

1 participant