Skip to content
Merged
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
102 changes: 47 additions & 55 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,80 +7,72 @@ on:
branches: [main]

jobs:
# ═════════════════════════════════════════════════════════════════════════
# 课题功能测试:所有14个模块的单元测试 + 集成测试
# ═════════════════════════════════════════════════════════════════════════
test:
runs-on: self-hosted
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Install
run: |
python${{ matrix.python-version }} -m pip install --upgrade pip
python${{ matrix.python-version }} -m pip install -e ".[all]"

- name: Run tests
run: python${{ matrix.python-version }} -m pytest tests/ -v --tb=short

lint:
runs-on: self-hosted
timeout-minutes: 10
steps:
- uses: actions/checkout@v4

- name: Install
- name: Install dependencies
run: |
python3.12 -m pip install --upgrade pip
python3.12 -m pip install -e ".[all]"
python3.12 -m pip install flake8 mypy

- name: flake8
run: python3.12 -m flake8 scratchv/ scratchv_dag/ tests/

- name: mypy
run: python3.12 -m mypy scratchv/ scratchv_dag/ --ignore-missing-imports
- name: Run all topic tests
run: python3.12 -m pytest tests/ -v --tb=short

coverage:
# ═════════════════════════════════════════════════════════════════════════
# 模型性能测试:ONNX模型管线 + DSL用例 + CNN RISC-V编译
# ═════════════════════════════════════════════════════════════════════════
benchmark:
runs-on: self-hosted
timeout-minutes: 30
steps:
- uses: actions/checkout@v4

- name: Install
- name: Install dependencies
run: |
python3.12 -m pip install --upgrade pip
python3.12 -m pip install -e ".[all]"
python3.12 -m pip install pytest-cov

- name: Run tests with coverage
run: python3.12 -m pytest tests/ --cov=scratchv --cov=scratchv_dag --cov-report=term --cov-report=xml

smoke:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
# ── 3.1 ONNX 模型管线基准测试 ──────────────────────────────────────
- name: ONNX model pipeline benchmarks
run: python3.12 -m pytest benchmarks/test_benchmark.py -v --tb=short

- name: Install
# ── 3.2 DSL 用例编译 + 模拟基准 ────────────────────────────────────
- name: DSL case compilation benchmarks
run: |
python3.12 -m pip install --upgrade pip
python3.12 -m pip install -e ".[all]"

- name: Smoke test - DSL compilation
mkdir -p benchmark_reports
python3.12 benchmarks/bench_runner.py benchmarks/cases \
--output-json benchmark_reports/dsl_bench.json \
--output-html benchmark_reports/dsl_bench.html \
--output-md benchmark_reports/dsl_bench.md

# ── 3.3 CNN RISC-V 编译 + 性能估算(模型存在才跑)─────────────────
- name: CNN RISC-V compilation & estimation
run: |
python3.12 -m scratchv examples/simple_add.dsl -o /tmp/simple_add.s --dump-ir
python3.12 -m scratchv examples/relu_test.dsl -o /tmp/relu.s --optimize all
python3.12 -m scratchv examples/matmul_test.dsl -o /tmp/matmul.s --optimize all

benchmark:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- name: Install
if [ -f models/graph/cnn.onnx ]; then
mkdir -p benchmark_reports
python3.12 scratchv/standalone/onnx_to_riscv_standalone.py \
models/graph/cnn.onnx \
-o /tmp/cnn_riscv.bin \
--estimate \
--report
else
echo "models/graph/cnn.onnx not found, skipping CNN benchmark"
fi

# ── 上报 ──────────────────────────────────────────────────────────
- name: Upload benchmark reports
uses: actions/upload-artifact@v4
with:
name: benchmark-reports
path: benchmark_reports/
retention-days: 30

- name: Write job summary
run: |
python3.12 -m pip install --upgrade pip
python3.12 -m pip install -e ".[all]"

- name: Run benchmark tests
run: python3.12 -m pytest benchmarks/test_benchmark.py -v --tb=short
cat benchmark_reports/github_summary.md >> $GITHUB_STEP_SUMMARY
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ venv/
.venv/
.claude/
scratchv.egg-info/
benchmark_reports/
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
language_version: python3.12
args: ["--line-length=88"]

- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile=black", "--line-length=88"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: ruff
args: ["--fix", "--exit-non-zero-on-fix"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
args: ["--ignore-missing-imports", "--follow-imports=silent"]
additional_dependencies:
- types-setuptools
exclude: "^tests/|^benchmarks/|^examples/"
files: "^scratchv/"
51 changes: 22 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,52 +1,45 @@
# ScratchV developer makefile
.POSIX:

.PHONY: install test clean lint check docs examples
.PHONY: install test bench bench-cnn clean lint

# ── Installation ──────────────────────────────────────────────────────────────
# ── Installation ──────────────────────────────────────────────────────────

install:
pip install -e .
pip install -e ".[all]" 2>/dev/null || pip install -e .

# ── Testing ───────────────────────────────────────────────────────────────────
# ── 课题功能测试 ──────────────────────────────────────────────────────────

test:
python3 -m pytest tests/ -v --tb=short

test-coverage:
python3 -m pytest tests/ --cov=scratchv --cov=scratchv_dag --cov-report=term
# ── 模型性能基准 ──────────────────────────────────────────────────────────

# ── Lint ──────────────────────────────────────────────────────────────────────
bench:
python3 -m pytest benchmarks/test_benchmark.py -v --tb=short
python3 benchmarks/bench_runner.py benchmarks/cases \
--output-json benchmark_reports/dsl_bench.json \
--output-html benchmark_reports/dsl_bench.html

lint:
-python3 -m flake8 scratchv/ scratchv_dag/ tests/ 2>/dev/null || echo "install flake8: pip install flake8"
-python3 -m mypy scratchv/ scratchv_dag/ --ignore-missing-imports 2>/dev/null || echo "install mypy: pip install mypy"
# ── CNN RISC-V 编译 + 估算 ────────────────────────────────────────────────

bench-cnn:
python3 scratchv/standalone/onnx_to_riscv_standalone.py models/graph/cnn.onnx \
-o /tmp/cnn_riscv.bin --estimate --report
@echo "Reports: benchmark_reports/"

# ── Clean ─────────────────────────────────────────────────────────────────────
# ── Clean ─────────────────────────────────────────────────────────────────

clean:
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null
find . -type f -name '*.pyc' -delete
rm -rf .pytest_cache
rm -rf scratchv.egg-info scratchv_dag.egg-info
rm -rf dist build
rm -rf .pytest_cache scratchv.egg-info scratchv_dag.egg-info dist build
rm -f output.s output.ll
rm -rf benchmark_reports

# ── Checks (runs before PR) ───────────────────────────────────────────────────

check: clean test

# ── Quick examples ────────────────────────────────────────────────────────────
# ── Lint (development only) ───────────────────────────────────────────────

examples:
@echo "=== DSL examples ==="
python3 -m scratchv examples/simple_add.dsl -o /tmp/simple_add.s --dump-ir
python3 -m scratchv examples/relu_test.dsl -o /tmp/relu.s --optimize all
python3 -m scratchv examples/matmul_test.dsl -o /tmp/matmul.s --optimize all

# ── Build docs preview (if pandoc is available) ────────────────────────────────

docs:
@echo "Documentation is markdown — no build required."
@ls docs/*.md
lint:
-python3 -m flake8 scratchv/ scratchv_dag/ tests/ 2>/dev/null || echo "pip install flake8"
-python3 -m mypy scratchv/ scratchv_dag/ --ignore-missing-imports 2>/dev/null || echo "pip install mypy"
Loading
Loading