Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (138 loc) · 8.8 KB
/
Copy pathMakefile
File metadata and controls
177 lines (138 loc) · 8.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# ScratchV developer makefile
.POSIX:
# Interpreter for every recipe. CI exports PY=python3.12: the self-hosted
# runner's /usr/bin/python3 is 3.10, which has none of the dependencies
# installed. Hardcoding python3 here made the same target pass on
# ubuntu-latest and fail on that runner.
PY ?= python3
.PHONY: quick-start install test test-peephole ci-peephole bench bench-topic06 bench-cnn bench-ir-verifier clean lint docs
# ── Beginner quick-start ─────────────────────────────────────────────────────
quick-start:
@echo "╔══════════════════════════════════════════╗"
@echo "║ ⚡ ScratchV — 快速上手 ║"
@echo "╠══════════════════════════════════════════╣"
@echo "║ ║"
@echo "║ 1. 创建虚拟环境 ║"
@echo "║ python3 -m venv .venv ║"
@echo "║ source .venv/bin/activate ║"
@echo "║ ║"
@echo "║ 2. 安装 ScratchV ║"
@echo "║ pip install -e . ║"
@echo "║ ║"
@echo "║ 3. 运行测试 (确认环境正确) ║"
@echo "║ make test ║"
@echo "║ ║"
@echo "║ 4. 编译你的第一个 AI 模型 ║"
@echo "║ make bench-cnn ║"
@echo "║ ║"
@echo "║ 5. 打开交互式课程 (浏览器) ║"
@echo "║ make docs ║"
@echo "║ xdg-open docs/topics/html/index.html ║"
@echo "║ ║"
@echo "║ 📖 详细教程: docs/guide/ (00~04) ║"
@echo "╚══════════════════════════════════════════╝"
# ── Course site (generated, not committed) ────────────────────────────────
docs:
$(PY) scripts/build_docs_html.py
# ── Installation ──────────────────────────────────────────────────────────
install:
pip install -e .
pip install -e ".[all]" 2>/dev/null || pip install -e .
# ── 课题功能测试 ──────────────────────────────────────────────────────────
test:
$(PY) -m pytest tests/ -v --tb=short
# ── Topic 13 窥孔优化器(本地 / CI 对齐) ─────────────────────────────────
test-peephole:
$(PY) -m pytest tests/test_asm_peephole*.py tests/test_bench_asm_peephole.py tests/test_compare_peephole.py tests/test_standalone_peephole.py tests/test_cnn_peephole_benchmark.py -v --tb=short
$(PY) -m scratchv.backend.asm_peephole --list-rules
$(PY) -m scratchv.backend.asm_peephole \
tests/fixtures/asm_peephole/input_addi_fusion.s \
-o /tmp/peephole_out.s --report --json
ci-peephole: test-peephole
@mkdir -p benchmark_reports
$(PY) benchmarks/bench_asm_peephole.py \
--sizes 1 2 100 --fusion-ratio 0.3 --repeats 2 \
--output benchmark_reports/peephole_raw.json
$(PY) benchmarks/compare_peephole.py \
--json benchmark_reports/peephole_compare.json \
--markdown benchmark_reports/peephole_compare.md
$(PY) benchmarks/compare_peephole_html.py \
--repeats 2 --output-dir benchmark_reports
$(PY) benchmarks/compare_peephole_cnn.py \
--model models/graph/cnn.onnx \
--json benchmark_reports/cnn_peephole_compare.json
$(PY) benchmarks/compare_peephole_html.py --unified \
--micro-json benchmark_reports/peephole_compare_html.json \
--dsl-json benchmark_reports/peephole_compare.json \
--cnn-json benchmark_reports/cnn_peephole_compare.json \
--output-html benchmark_reports/peephole_benchmark.html \
--summary-output benchmark_reports/peephole_summary.md
@echo "Peephole CI checks done."
# ── 模型性能基准 ──────────────────────────────────────────────────────────
bench:
$(PY) -m pytest benchmarks/test_benchmark.py -v --tb=short
$(PY) benchmarks/bench_runner.py benchmarks/cases \
--output-json benchmark_reports/dsl_bench.json \
--output-html benchmark_reports/dsl_bench.html
# ── Topic 21 IR verification overhead ────────────────────────────────────
bench-ir-verifier:
$(PY) -m benchmarks.bench_ir_verifier
# ── Topic 06 DSL correctness + TinyFive benchmark ─────────────────────────
bench-topic06:
$(PY) scripts/run_topic06_benchmarks.py
$(PY) scripts/generate_topic06_report.py
# ── CNN RISC-V 编译 + 估算 ────────────────────────────────────────────────
bench-cnn:
$(PY) scratchv/standalone/onnx_to_riscv_standalone.py models/graph/cnn.onnx \
-o /tmp/cnn_riscv.bin --estimate --report
@echo "Reports: benchmark_reports/"
# ── CNN RISC-V 编译 + TinyFive 仿真验证 ───────────────────────────────────
bench-tinyfive:
$(PY) scratchv/standalone/onnx_to_riscv_standalone.py models/graph/cnn.onnx \
-o /tmp/cnn_riscv.bin --estimate --tinyfive --tinyfive-max-instr 200000
@echo "TinyFive simulation complete."
# ── CI Benchmark (LLVM + TinyFive + 可视化仪表盘) ──────────────────────────
bench-ci:
@mkdir -p benchmark_reports
$(PY) scratchv/ci/ci_benchmark.py \
--model-registry ci_models.json \
--output-dir benchmark_reports/ \
--html dashboard.html \
--json-out ci_data.json \
--md github_summary.md \
--embed-json \
--skip-cache
@echo ""
@echo "Dashboard: benchmark_reports/dashboard.html"
@echo "JSON data: benchmark_reports/ci_data.json"
@echo "GitHub summary: benchmark_reports/github_summary.md"
# ── ONNX 模型拆分 ────────────────────────────────────────────────────────
split-models:
$(PY) scripts/split_cnn_to_single_ops.py
@echo "Single-op models: models/single_op/"
# ── 单算子 Benchmark ─────────────────────────────────────────────────────
bench-single-ops: split-models
$(PY) scripts/bench_single_ops.py
@echo "Single-op benchmark: benchmark_reports/single_op_bench.json"
# ── Dashboard (仅指令集维度 + 算子粒度) ──────────────────────────────────
bench-dashboard:
$(PY) scratchv/ci/dashboard.py --run -o benchmark_reports/dashboard.html
@echo "Dashboard: benchmark_reports/dashboard.html"
# ── 优化历史页面 ─────────────────────────────────────────────────────────
bench-history:
$(PY) scratchv/ci/history_page.py -o benchmark_reports/history.html
@echo "History page: benchmark_reports/history.html"
# ── 全量报告 (dashboard + history) ───────────────────────────────────────
bench-reports: bench-dashboard bench-history
@echo "All reports generated in benchmark_reports/"
# ── Clean ─────────────────────────────────────────────────────────────────
clean:
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null
find . -type f -name '*.pyc' -delete
rm -rf .pytest_cache scratchv.egg-info scratchv_dag.egg-info dist build
rm -f output.s output.ll
rm -rf benchmark_reports
# ── Lint (development only) ───────────────────────────────────────────────
lint:
-$(PY) -m flake8 scratchv/ scratchv_dag/ tests/ 2>/dev/null || echo "pip install flake8"
-$(PY) -m mypy scratchv/ scratchv_dag/ --ignore-missing-imports 2>/dev/null || echo "pip install mypy"