-
Notifications
You must be signed in to change notification settings - Fork 40
Add Feature: golden-reference pipeline for FPGA/ASIC synthesis: online learning, quantization, arithmetic, export, verification, and RTL-matched PRNG#186
Open
ajyds wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds 6 new modules that transform torchhd from a pure prototyping
library into a golden-reference pipeline for RTL (FPGA/ASIC) synthesis.
Every operation can now be validated bit-accurately against what the
hardware ALU produces in Vivado/Quartus.
New Modules
torchhd.online
Streaming/online learning without batching.
HebbianAccumulator— running outer-product weight matrix withexponential moving average (lr < 1 forgets stale data).
StreamingCentroid— OnlineHD-style test-then-train centroid classifier,one sample per
step()call.torchhd.quantize
Fixed-point quantization and hardware memory export.
to_fixed_point/from_fixed_point— Q<M.N> signed/unsigned.quantize_bipolar— bipolar {−1, +1} and ternary {−1, 0, +1}.block_float_quantize— shared exponent per block.pack_bits/unpack_bits— dense bit-packing for BRAM storage.export_verilog,export_c_header,export_binary— writeout formats.torchhd.arith
Bit-accurate fixed-point ALU matching RTL behavior.
q_bundle,q_bind,q_permute,q_dot,q_cos_similarity,q_majority— all with configurable saturation (clamp/wrap) andaccumulator width.
torchhd.export
Basis/codebook extraction from embeddings + memory init file generation.
extract_basis,extract_codebook,extract_projection_matrixexport_coe(Xilinx blk_mem_gen),export_mif(Altera/Intel),export_hex($readmemh),export_bram_init(dep×ばつwidth image).torchhd.verif
Golden trace capture → SystemVerilog testbench generation.
GoldenTracerecords encode/step/forward events cycle-by-cycle.write_sv_stimulusemits aninitialblock replaying all inputsat correct clock offsets.
write_sv_checkeremits a parallelalwaysblock withassertstatements comparing RTL outputs to golden expected values.
torchhd.prng
Deterministic PRNGs matching RTL implementations.
LFSR— Galois (one-to-many), 8/10/12/16/24/32-bit, withpre-verified maximal-length polynomials.
XORShift32/XORShift64— Marsaglia xorshift.export_lfsr_verilog— emits a synthesizable Verilog modulebit-identical to the Python instance.
End-to-End Workflow
StreamingCentroid(or existingCentroid)to_fixed_pointq_bundle/q_dotagainst RTL ALU specexport_coeorexport_bram_initGoldenTrace.write_sv_stimulus+checkerLFSR→export_lfsr_verilogfor identicalhypervector generation in Python and Vivado sim
All modules are backwards-compatible; no existing APIs are modified.