Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/topic06-benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Topic 06 Compiler Benchmark

on:
push:
pull_request:

jobs:
topic06-benchmark:
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install ScratchV and benchmark dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[topic06]"

- name: Verify Topic 06 integration contracts
run: python -m pytest tests/topic06/test_integration.py -q

- name: Run supported correctness gates
run: |
python scripts/run_topic06_benchmarks.py --category activation --fail-on-test-failure
python scripts/run_topic06_benchmarks.py --category elementwise --fail-on-test-failure
python scripts/run_topic06_benchmarks.py --category loop --fail-on-test-failure

- name: Generate full diagnostic benchmark report
run: python scripts/run_topic06_benchmarks.py --benchmark 3

- name: Upload Topic 06 reports
if: always()
uses: actions/upload-artifact@v4
with:
name: topic06-benchmark-reports
path: |
benchmark_reports/topic06/report.md
benchmark_reports/topic06/report.json
benchmark_reports/topic06/cases/
benchmark_reports/topic06/failures/
benchmarks/topic06/baseline.json
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ScratchV developer makefile
.POSIX:

.PHONY: quick-start install test bench bench-cnn clean lint
.PHONY: quick-start install test bench bench-topic06 bench-cnn clean lint

# ── Beginner quick-start ─────────────────────────────────────────────────────

Expand Down Expand Up @@ -48,6 +48,11 @@ bench:
--output-json benchmark_reports/dsl_bench.json \
--output-html benchmark_reports/dsl_bench.html

# ── Topic 06 DSL correctness + TinyFive benchmark ─────────────────────────

bench-topic06:
python3 scripts/run_topic06_benchmarks.py --benchmark 3

# ── CNN RISC-V 编译 + 估算 ────────────────────────────────────────────────

bench-cnn:
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
```bash
make quick-start # 打印新手引导
make test # 运行全部测试
make bench-topic06 # 运行课题 06 TinyFive 性能测试套件
make bench-cnn # 编译 CNN 模型 + 性能估算
make bench-ci # 完整 CI 对比 (ScratchV vs LLVM)
make bench-reports # 生成 Dashboard + 优化历史
Expand All @@ -62,9 +63,9 @@ ScratchV/
│ ├── 00~04-*.md ← 新手入门 5 篇
│ ├── topics/ ← 30 个模块详解
│ └── topics/html/ ← 🌐 交互式课程站点
├── benchmarks/ ← 23 个 DSL 基准用例
├── tests/ ← 348 个单元测试
├── scripts/ ← 工具脚本
├── benchmarks/ ← 通用基准与课题 06 性能基线
├── tests/ ← 单元测试及课题 06 的 23 个 DSL 用例
├── scripts/ ← 工具脚本及课题 06 测试驱动
└── models/ ← 测试用 ONNX 模型
```

Expand Down Expand Up @@ -104,6 +105,7 @@ ONNX 模型 (.onnx)
| [📖 文档导航](docs/INDEX.md) | 全部 Markdown 文档索引 |
| [🏗️ 架构总览](docs/ARCHITECTURE.md) | ONNX→RISC-V 双路径详解 |
| [📊 性能仪表盘](https://scratchv-compiler.github.io/ScratchV/dashboard.html) | LLVM vs ScratchV 对比 |
| [课题 06 测试套件](docs/topics/06-性能测试套件使用说明.md) | TinyFive 正确性验证、Benchmark 与回归报告 |
| [📢 项目海报](https://scratchv-compiler.github.io/ScratchV/ScratchV.html) | 招募信息 + 3个月学习路线 + 课题精选 |

---
Expand Down
153 changes: 153 additions & 0 deletions benchmark_reports/topic06/cases/activation-add_relu_relu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
{
"mode": "benchmark",
"name": "add_relu_relu",
"category": "activation",
"path": "tests/topic06/cases/activation/add_relu_relu.dsl",
"status": "PASS",
"description": "Add input and bias, then apply ReLU twice.",
"expected_type": "scalar",
"output_dtype": null,
"output_shape": null,
"expected": 7,
"actual": 7,
"matched": true,
"verification_backend": "both",
"interpreter_status": "PASS",
"interpreter_actual": 7.0,
"interpreter_matched": true,
"interpreter_error": null,
"interpreter_failure_kind": null,
"interpreter_time_sec": 0.12910449993796647,
"backend_outputs_match": true,
"tinyfive_status": "PASS",
"tinyfive_failure_kind": null,
"tinyfive_input_abi_supported": true,
"tinyfive_input_abi_reason": null,
"simulation_error": null,
"initial_registers": {
"t0": -3,
"t1": 10
},
"register_map": "build/topic06/add_relu_relu.registers.json",
"backend": "tinyfive",
"instr_count": 7,
"static_asm_instruction_count": 5,
"machine_code_instruction_count": 11,
"code_size_bytes": 44,
"perf_counters": {
"total": 7,
"load": 0,
"store": 0,
"mul": 0,
"add": 4,
"madd": 0,
"branch": 2
},
"cost_model": {
"static_asm_instructions": 5,
"machine_instructions": 11,
"code_size_bytes": 44,
"dynamic_instructions": 7.0,
"dynamic_load": 0.0,
"dynamic_store": 0.0,
"dynamic_mul": 0.0,
"dynamic_add": 4.0,
"dynamic_madd": 0.0,
"dynamic_branch": 2.0
},
"cost_model_comparison": {
"static_asm_instructions": {
"current": 5,
"baseline": 5,
"delta": 0,
"delta_pct": 0.0,
"regressed": false
},
"machine_instructions": {
"current": 11,
"baseline": 11,
"delta": 0,
"delta_pct": 0.0,
"regressed": false
},
"code_size_bytes": {
"current": 44,
"baseline": 44,
"delta": 0,
"delta_pct": 0.0,
"regressed": false
},
"dynamic_instructions": {
"current": 7.0,
"baseline": 7.0,
"delta": 0.0,
"delta_pct": 0.0,
"regressed": false
},
"dynamic_load": {
"current": 0.0,
"baseline": 0.0,
"delta": 0.0,
"delta_pct": 0.0,
"regressed": false
},
"dynamic_store": {
"current": 0.0,
"baseline": 0.0,
"delta": 0.0,
"delta_pct": 0.0,
"regressed": false
},
"dynamic_mul": {
"current": 0.0,
"baseline": 0.0,
"delta": 0.0,
"delta_pct": 0.0,
"regressed": false
},
"dynamic_add": {
"current": 4.0,
"baseline": 4.0,
"delta": 0.0,
"delta_pct": 0.0,
"regressed": false
},
"dynamic_madd": {
"current": 0.0,
"baseline": 0.0,
"delta": 0.0,
"delta_pct": 0.0,
"regressed": false
},
"dynamic_branch": {
"current": 2.0,
"baseline": 2.0,
"delta": 0.0,
"delta_pct": 0.0,
"regressed": false
}
},
"cost_model_regressed": false,
"compile_returncode": 0,
"compile_timed_out": false,
"compile_error": null,
"compile_command": "'D:\\anaconda3\\python.exe' -m scratchv.main 'D:\\PycharmProjects\\ScratchV\\ScratchV\\tests\\topic06\\cases\\activation\\add_relu_relu.dsl' -o 'D:\\PycharmProjects\\ScratchV\\ScratchV\\build\\topic06\\add_relu_relu.s' --optimize all --emit-register-map 'D:\\PycharmProjects\\ScratchV\\ScratchV\\build\\topic06\\add_relu_relu.registers.json'",
"compile_log": null,
"compile_time_sec": 0.08510669996030629,
"simulation_time_sec": 0.14671280002221465,
"total_time_sec": 0.8289841000223532,
"benchmark_runs": 3,
"benchmark_stopped_reason": null,
"avg_instr_count": 7.0,
"min_instr_count": 7,
"max_instr_count": 7,
"ci95_instr_count": 0.0,
"baseline_instr_count": 7.0,
"delta": 0.0,
"delta_pct": 0.0,
"threshold_pct": 5.0,
"regressed": false,
"asm": "build/topic06/add_relu_relu.s",
"case_report_md": "benchmark_reports/topic06/cases/activation-add_relu_relu.md",
"case_report_json": "benchmark_reports/topic06/cases/activation-add_relu_relu.json"
}
65 changes: 65 additions & 0 deletions benchmark_reports/topic06/cases/activation-add_relu_relu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# add_relu_relu 测试详情

## 基本信息

- 类别: activation
- DSL: `tests/topic06/cases/activation/add_relu_relu.dsl`
- 描述: Add input and bias, then apply ReLU twice.
- 总体状态: PASS
- 验证模式: both

## 后端能力矩阵

| 后端 | 状态 | 实际输出 | 与期望匹配 | 失败类型 | 错误 |
|---|---|---|---|---|---|
| DSLInterpreter | PASS | 7.0 | True | null | null |
| TinyFive | PASS | 7 | True | null | null |

- 期望输出: 7
- 两后端输出一致: True
- TinyFive 输入 ABI 可用: True
- TinyFive 输入 ABI 说明: null

## 性能指标

- 静态汇编指令数: 5
- 编码后机器指令数: 11
- 代码大小(bytes): 44
- TinyFive 动态执行指令数: 7
- TinyFive 分类计数: {'total': 7, 'load': 0, 'store': 0, 'mul': 0, 'add': 4, 'madd': 0, 'branch': 2}
- 编译耗时(s): 0.085107
- 解释器耗时(s): 0.129104
- TinyFive 模拟耗时(s): 0.146713
- 总耗时(s): 0.828984
- 基线动态指令数: 7.0
- 动态指令变化率(%): 0.0
- 是否退化: False

- Cost model 指标: {'static_asm_instructions': 5, 'machine_instructions': 11, 'code_size_bytes': 44, 'dynamic_instructions': 7.0, 'dynamic_load': 0.0, 'dynamic_store': 0.0, 'dynamic_mul': 0.0, 'dynamic_add': 4.0, 'dynamic_madd': 0.0, 'dynamic_branch': 2.0}
- Cost model 对比: {'static_asm_instructions': {'current': 5, 'baseline': 5, 'delta': 0, 'delta_pct': 0.0, 'regressed': False}, 'machine_instructions': {'current': 11, 'baseline': 11, 'delta': 0, 'delta_pct': 0.0, 'regressed': False}, 'code_size_bytes': {'current': 44, 'baseline': 44, 'delta': 0, 'delta_pct': 0.0, 'regressed': False}, 'dynamic_instructions': {'current': 7.0, 'baseline': 7.0, 'delta': 0.0, 'delta_pct': 0.0, 'regressed': False}, 'dynamic_load': {'current': 0.0, 'baseline': 0.0, 'delta': 0.0, 'delta_pct': 0.0, 'regressed': False}, 'dynamic_store': {'current': 0.0, 'baseline': 0.0, 'delta': 0.0, 'delta_pct': 0.0, 'regressed': False}, 'dynamic_mul': {'current': 0.0, 'baseline': 0.0, 'delta': 0.0, 'delta_pct': 0.0, 'regressed': False}, 'dynamic_add': {'current': 4.0, 'baseline': 4.0, 'delta': 0.0, 'delta_pct': 0.0, 'regressed': False}, 'dynamic_madd': {'current': 0.0, 'baseline': 0.0, 'delta': 0.0, 'delta_pct': 0.0, 'regressed': False}, 'dynamic_branch': {'current': 2.0, 'baseline': 2.0, 'delta': 0.0, 'delta_pct': 0.0, 'regressed': False}}
- Cost model 是否退化: False

## 编译信息

- 命令: `'D:\anaconda3\python.exe' -m scratchv.main 'D:\PycharmProjects\ScratchV\ScratchV\tests\topic06\cases\activation\add_relu_relu.dsl' -o 'D:\PycharmProjects\ScratchV\ScratchV\build\topic06\add_relu_relu.s' --optimize all --emit-register-map 'D:\PycharmProjects\ScratchV\ScratchV\build\topic06\add_relu_relu.registers.json'`
- 返回码: 0
- 编译错误: null
- 失败日志: null
- 寄存器映射: `build/topic06/add_relu_relu.registers.json`
- 汇编文件: `build/topic06/add_relu_relu.s`

## 生成汇编

```asm
.text
.align 2
.globl main
.type main, @function
main:
.entry:
add t2, t0, t1
max t3, t2, 0
max t4, t3, 0
mv a0, t4 # return value
jalr zero, ra # ret
```
Loading
Loading