Implement all 14 topic modules with interfaces, docs, tests, benchmarks - #5
Merged
Merged
Conversation
Backend modules (7): - asm_beautifier.py: RISC-V assembly beautifier with alignment/commenting - inst_counter.py: instruction category counter with charts/HTML reports - asm_peephole.py: assembly-level peephole optimizer (5 default rules) - const_merge.py: constant load merge (lui+addi fusion, redundancy elimination) - regalloc_linear.py: linear scan register allocator with spill code - inst_scheduler.py: list scheduler with DAG construction and latency model - inst_select_ext.py: extended instruction selection (sqrt/min/max/abs/fp64) Frontend/infra modules (7): - dsl_extended.py: DSL enhancer with if/else and while support - dsl_errors.py: gcc-style error beautifier with fix suggestions - logger.py: colored logging system with file output and phase timing - cfg_builder.py: CFG builder with dominator tree and loop detection - ir_verifier.py: IR verifier with 7 rule categories - bench_runner.py: benchmark suite with 23 DSL test cases and HTML reports - Code standards: .pre-commit-config.yaml + CODING_STANDARDS.md Each topic includes: module + docs/topics/ guide + tests + benchmarks Total: 125 files, 12655 insertions, 348 tests passing, lint clean Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
README: document all 14 new topic modules, analysis/ and utils/ directories, benchmarks/, updated test count (348), CNN pipeline, extended DSL usage, and topic table with module paths. ScratchV.html: update topic table to include all 14 topics with links to both implementation guides and original topic proposals. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Replace all MachineOp.CALL placeholders with inline RV32IM instruction sequences. Every ONNX operator now maps directly to real RISC-V: - Conv: mv(bias) + mul(x*w) + add(acc) (MAC) - Gemm: mv(bias) + mul(a*w) + add(acc) (MAC) - ReLU: max rd, rs, 0 - MaxPool: slt + bnez + li + j (branch-based max) - Sigmoid: slt + bnez + li + j (piecewise clamp [0,1]) - Reshape: mv rd, rs - Exp: addi + max (linear approx) - GELU: max + mul + div (simplified) - Softmax: mv (passthrough) - MatMul/Dot: mul Add 15 single-precision float MachineOp codes (FADD_S, FMUL_S, etc.) for future RV32F support. Fix branch/jump emission to output target labels as operands instead of comments. Use .L prefix for local labels (GAS convention). 0 call instructions remaining. 96 pure RISC-V instructions for CNN. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Complete self-contained CNN compiler: ONNX protobuf -> RISC-V RV32IM binary. Zero external library dependencies (Python 3.8+ stdlib only). Features: - Manual protobuf wire-format parser (no 'onnx' package needed) - Q16.16 fixed-point weight conversion - Memory planner for intermediate tensors - Inline RISC-V codegen for all 15 CNN operators: Conv2D (6-deep nested loops), MaxPool (5-deep nested loops), Gemm/FC (3-deep nested loops), ReLU (branch-free, 3 instructions), Sigmoid (piecewise linear), Reshape (element-wise copy) - Direct RISC-V machine code encoding (no assembler needed) - Generated binary has zero runtime library calls (bare-metal ready) - Position-independent code via AUIPC data addressing Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tor) Library-free RV32IM emulator with inline performance counters: - Dynamic instruction mix (ALU/memory/branch/jump/upper percentages) - Memory access stats (loads, stores, L/S ratio) - Compute-to-memory ratio (CNN workload classification) - Branch behaviour (taken/not-taken rate) - Top-10 hottest PC addresses (sampled every 1024 insns) - Per-operator (per-label) instruction counts - Progress logging every 10M instructions - Host execution time and simulated MIPS Analytical instruction estimator (instant, no emulation): - Estimates total dynamic instructions from CNN dimensions - Per-layer breakdown with percentages - Estimated hardware execution time @50/100MHz Usage: python onnx_to_riscv_standalone.py model.onnx --benchmark --max-instr 10000000 python onnx_to_riscv_standalone.py model.onnx --estimate Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
New bench_report.py generates three output formats: - HTML: self-contained page with CSS bar charts, C/M gauge, per-layer breakdown, summary cards (zero JS dependencies) - JSON: machine-parseable for CI dashboards and metrics tracking - GitHub Actions job summary: markdown table for CI step summary CI integration: - New 'cnn-benchmark' job in ci.yml: compiles cnn.onnx to RISC-V, generates all reports, uploads HTML artifact (30-day retention), writes GitHub step summary - Makefile: 'make bench-cnn' (estimate + reports) and 'make bench-cnn-emu' (emulation + reports) - .gitignore: exclude benchmark_reports/ CLI: --report flag on standalone pipeline generates all formats. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- bench_report.py: HTML/JSON/GitHub summary report generator - benchmark.py: RV32IM emulator with inline performance counters - onnx_to_riscv_standalone.py: --benchmark, --estimate, --report flags - CI: cnn-benchmark job with HTML artifact upload - Makefile: bench-cnn, bench-cnn-emu targets - riscv_encoder.py: minor updates - PPT and gen_ppt scripts for project presentation Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Four configurable RISC-V microarchitecture profiles: single: CPI=1.00 (baseline, all ops 1 cycle) fast: CPI=1.06 (MUL=1, DIV=4, LW=1, branch-taken=2) basic: CPI=1.55 (MUL=4, DIV=34, LW=2, branch-taken=3) slow: CPI=5.02 (MUL=32, DIV=34, LW=5, branch-taken=3) Features: - MicroArch class with per-category cycle costs (ALU_R, ALU_I, SHIFT, MUL, DIV, LOAD, STORE, BRANCH taken/not, JUMP, JALR) - Emulator hot-loop tracks cycles per instruction inline - PerfCounters tracks total_cycles, cat_cycles[], CPI - Cycle distribution in benchmark report (bar chart) - Analytical estimator projects cycles for all 4 profiles - --uarch CLI flag (single|fast|basic|slow, default: basic) CNN model estimates (basic profile): CPI=1.55, 12.1B cycles, 242s @50MHz, 121s @100MHz (vs CPI=1.0 single-cycle: 7.8B cycles, 156s @50MHz) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
CI restructured from 6 jobs to 2: test: all 14 topic module tests (pytest tests/, single python3.12) benchmark: model perf tests (ONNX pipeline + 23 DSL cases + CNN RISC-V) Removed: - Python version matrix (3.9/3.10/3.11/3.12) → single python3.12 - lint job (flake8/mypy — kept in Makefile for dev use) - coverage job - smoke job (DSL examples — covered by DSL bench cases) Makefile simplified to match: make test → topic tests make bench → model benchmarks make bench-cnn → CNN RISC-V compilation + estimation make lint → dev-only linting make clean → cleanup including benchmark_reports/ Also add examples/cnn_model.dsl (ONNX→DSL conversion output). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jizhenjun
approved these changes
Jun 1, 2026
k1nsom
added a commit
that referenced
this pull request
Jun 4, 2026
#1+#2 dashboard数据管线: _run()从--json-output路径读取,generate_dashboard_html接收参数 #4 CI CNN benchmark: 模型不存在时自动生成最小CNN onnx,不再静默跳过 #5 tinyfive CI兼容: --scratchv-asm/--llvm-asm CLI参数,文件不存在容错 #6 estimator参数化: estimate_cnn_model接受model_spec dict #8 LLVM TinyFive内核: 用真实LLVM O3汇编提取的指令序列替代手写 #9 import统一: llvm_cache_compare使用绝对路径导入cache_model 未修(需更大重构): #3 run_spike_bench field() bug (需dataclass重构,影响力低) #10 CPU仿真器重复代码 (需提取共享模块) #7 缓存分析模型 (需trace-driven,实现成本高) 348 tests passed Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 task
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.
Backend modules (7):
Frontend/infra modules (7):
Each topic includes: module + docs/topics/ guide + tests + benchmarks
Total: 125 files, 12655 insertions, 348 tests passing, lint clean