Skip to content

Add topic 06 benchmark test suite - #46

Open
2813183274-cloud wants to merge 1 commit into
ScratchV-Compiler:mainfrom
2813183274-cloud:topic06-test-clean
Open

Add topic 06 benchmark test suite#46
2813183274-cloud wants to merge 1 commit into
ScratchV-Compiler:mainfrom
2813183274-cloud:topic06-test-clean

Conversation

@2813183274-cloud

Copy link
Copy Markdown

No description provided.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

🤖 AI Code Review

共审查 10 个变更文件
⚠️ 另有 20 个文件超过上限(最多 10 个)未审查

📁 ScratchV-topic06-deliverable/.github/workflows/benchmark.yml

🔴 Bug: 缺少并发/超时控制run_tests.py --benchmark 3 无超时或失败退出条件,若基准测试挂起则 CI 无限运行。建议在 workflow 中设置 timeout-minutes 或让脚本内部处理超时。

🟡 Suggestion: 依赖安装顺序pip install -e . 后安装 requirements-topic06.txt,若该文件包含与包冲突的依赖可能覆盖已装版本。建议先安装 requirements 再安装 -e .,或使用 --no-deps 安装包。

🟡 Suggestion: 缺少失败时的 artifact 保留 — 若 run_tests.py 失败(非零退出),后续 upload-artifact 仍会执行,但报告可能不完整。建议在 if: always() 中上传,或明确失败时保留失败报告。

🟡 Suggestion: 未限制触发分支on: pushon: pull_request 对所有分支触发,可能浪费资源。建议限定 branches: [main, develop] 或使用 paths 过滤对相关代码的变更。

💭 Nit: 报告路径硬编码reports/ 目录若脚本未创建则上传失败,建议在步骤前添加 mkdir -p reports 或检查脚本是否自动创建。


📁 ScratchV-topic06-deliverable/LICENSE

此文件无问题。


📁 ScratchV-topic06-deliverable/README.md

🔴 文档开头定位不清 — 第一段说“本测试套件不是独立项目,需要放在 ScratchV 仓库根目录下运行”,但标题和内容均围绕此套件,容易让读者误以为此目录就是项目根。建议明确“将本目录放置在 ScratchV 仓库根目录(与 scratchv 包同级)”。

🟡 性能退化计算方式未说明 — 文中提到“默认退化阈值 5%”,但未解释退化率如何计算。建议补充公式,如:退化率 = (当前平均指令数 - 基线平均指令数) / 基线平均指令数

🟡 依赖文件内容未列出 — 给出了两个 requirements 文件,但未说明各自包含哪些包。建议在“运行依赖”部分列出 requirements-topic06.txt 包含 tinyfivepytestrequirements-topic06-full.txt 额外包含 jinja2matplotlib

🟡 超时参数未说明可配置性 — 编译超时 30 秒、模拟超时 5 秒是硬编码还是可调?建议说明是否支持通过命令行参数调整,或至少提及默认值含义。

🟡 退出码含义不完整 — 子集测试部分提到“没有匹配用例时脚本返回退出码 2”,但未说明成功(0)和失败(1)的约定。建议补充。

🟡 meta.json 示例缺少 description 字段 — 示例中未包含 description,但该字段在文字描述中提及。建议在示例中添加或明确标注为可选。

💭 第一段冗余 — “当前程序在原始自动编译……进一步增加了……”可精简为“在原有功能基础上,新增了……”,更直接。

💭 结构优化建议 — 可将“运行依赖”和“目录结构”合并,或将“添加测试用例”提前,因为用户可能更关注如何扩展测试。

💭 未注明《课题6设计文档.md》是否包含在交付中 — 建议说明该文件是随本套件提供,还是仅作为引用。

💭 CI 部分可补充测试范围 — 可明确说明工作流会运行全部 23 个用例,还是仅运行子集,避免歧义。


📁 ScratchV-topic06-deliverable/reports/benchmark_baseline.json

💭 文件末尾缺少换行符 — JSON 文件最后一行没有换行符,建议在文件末尾添加一个换行符以符合 POSIX 规范。


📁 ScratchV-topic06-deliverable/reports/report.json

🔴 Bug: Branch tests timeout — 所有三个 branch 测试 (if_else, if_relu, if_then) 均因 backend: "timeout" 失败,simulation_time_sec 约 5 秒。说明生成的汇编代码中存在无限循环或死循环,需检查分支逻辑的跳转标号/条件。

🔴 Bug: Reduction/tensor 测试返回 0dot_4, dot_8, dot_relu_8, matmul_2x2, matmul_4x4, matmul_add_2x2, matmul_relu_2x2actual 均为 0 且 instr_count 异常低(3-5 条),表明编译器未能正确生成乘法/累加指令,或代码生成阶段被跳过。需检查后端是否支持乘法和循环。

🟡 硬编码绝对路径pathasm 字段包含了完整的 Windows 路径 D:\PycharmProjects\...,在 CI 或他人机器上不可移植。建议在生成报告时使用相对路径或仅保留文件名。


📁 ScratchV-topic06-deliverable/reports/report.md

🔴 性能数据缺失 — 报告标题为“性能测试报告”,但所有基准相关列(Benchmark 次数、平均指令数、置信区间、基线条数、变化率等)均为 null,实际未运行基准对比。建议在“测试概览”中明确说明“基准未运行”或提供原因,避免误导读者。

🟡 失败用例缺少诊断信息branch 类用例模拟超时(模拟耗时 5s),reduction/tensor 用例输出为 0,但“编译错误摘要”和“编译失败日志”均为 null,未提供任何失败原因分析。建议补充超时原因(如死循环、无限循环生成)和输出为 0 的初步排查结论。

🟡 绝对路径可移植性差 — 报告中的测试目录、汇编输出路径、基线文件均为 Windows 绝对路径(D:\PycharmProjects\...),换环境后无法复用。建议改为相对路径或环境变量引用。

🟡 缺少失败总结 — 报告仅列出数据,未归纳失败模式(如 branch 全部超时、reduction/tensor 全部输出 0),建议在末尾添加“失败分析”小节,便于读者快速定位问题类别。

💭 日期异常 — 生成时间 2026-08-08 为未来日期,可能是系统时钟错误,建议核实。


📁 ScratchV-topic06-deliverable/requirements-topic06-full.txt

🟡 建议固定版本号 — 未指定 jinja2matplotlib 的版本,可能导致不同环境安装不一致。建议添加版本约束,如 jinja2>=3.0,<4.0matplotlib>=3.5,<4.0


📁 ScratchV-topic06-deliverable/requirements-topic06.txt

🔴 Missing version pinning — Both tinyfive and pytest lack version constraints. This will cause builds to break when new major versions are released. Use pytest>=7.0,<8.0 (or a specific version) and similarly pin tinyfive if it's truly needed.

🟡 Unclear dependency tinyfive — This package is not commonly used and may be a typo (e.g., tinyfive vs tinyfive?). If it's a custom test utility, consider documenting it or moving it to a [test] extra. If it's not needed, remove it.

💭 Consider -r or separate test requirements — If tinyfive is only for tests, place it in a requirements-test.txt or use a [test] section in pyproject.toml to keep production dependencies clean.


📁 ScratchV-topic06-deliverable/run_tests.py

🔴 严重重复代码generate_report_text 被定义了 4 次(第 192, 310, 447, 533 行附近),write_html_report 被定义了 3 次(第 260, 480, 589 行),generate_report_text_cnwrite_html_report_cn 各定义了 2 次。后续定义覆盖前者,导致大量无用代码,且极易引入不一致。解决方案:只保留最后(或最完整)的一个版本,删除所有冗余定义。

🟡 run_compile 超时处理可能丢失输出 — 第 47-56 行:exc.stdoutexc.stderrsubprocess.TimeoutExpired 中可能为 None(当 capture_output=False 时),但此处默认 capture_output=True,它们应为 bytes。不过 isinstance(exc.stdout, bytes) 的检查不必要,且如果输出为 None.decode() 会抛出 AttributeError建议:直接使用 exc.stdout.decode("utf-8", errors="ignore") 并确保 capture_output=True 时不会为 None;或使用 getattr(exc, 'stdout', b'') 保护。

🟡 run_simulation 使用内联代码字符串 — 第 111-122 行:将 Python 代码构建为字符串并通过 -c 执行,这增加了调试难度,且字符串中的缩进和格式容易出错。建议:将模拟逻辑提取为独立模块或函数,通过 -m 或直接调用(如果可能)来避免动态代码执行。

🟡 infer_initial_registers 依赖 IR 输出顺序 — 第 135-155 行:从 IR 文本中通过正则匹配变量名并假设出现顺序即寄存器分配顺序,这并非可靠方式。优化器可能重排指令,导致寄存器分配顺序与预期不符。建议:改用编译器输出的显式寄存器分配信息(如 ; register allocation: 注释)或直接读取编译器生成的映射文件。

🟡 load_metadataexpected_returnNone 的情况处理不明确 — 第 77-80 行:当 expected_returnNone 时,values_equal 比较 NoneNone 会返回 True,但可能掩盖测试未设置预期输出的事实。建议:在 metadata_error_metadata_error 中明确要求提供预期输出,或在 None 情况下视为失败。

🟡 benchmark 模式中 regression["regressed"] 的初始值问题 — 第 1751-1762 行:当 benchmark_summary["avg_instr_count"] is not Nonebenchmark_stopped_reason is None 时,设置 regression["regressed"] = False,但随后若 baseline_entry 存在又会被 detect_regression 覆盖。逻辑上没问题,但初始值 False 可能被误用。建议:保持 regression 字典初始值为 None,只在明确计算后赋值。

💭 _validate_output_dtypebool 类型的处理过于严格 — 第 67-68 行:isinstance(item, bool) 在 Python 中 boolint 的子类,因此 int 分支会先被 isinstance(item, bool) 排除,但 dtype.startswith("int") 分支中用了 isinstance(item, bool) or not isinstance(item, int),这会将 TrueFalse 视为非法整数。但预期输出为 int 时,True/False 可能是有意为之?建议:明确预期输出类型,若需要使用 int(True) 转换,或允许 bool 作为整数子集。

💭 _markdown_cell 函数只替换了换行和竖线,但未处理反斜杠或星号 — 第 306 行:Markdown 表格中,|\n 是必须转义的,但其他特殊字符如 \* 也可能导致渲染问题。建议:使用更全面的转义,例如 str(value).replace('\\', '\\\\').replace('|', '\\|').replace('\n', ' ')

💭 write_chart 使用临时目录 MPLCONFIGDIR — 第 583 行:设置环境变量可能影响同一进程中的其他模块。建议:使用 with 语句临时设置环境变量,或使用 matplotlib.get_configdir() 管理。

💭 parse_args--benchmark 参数类型为 int,但未限制最小值 — 应为 non_negative_intpositive_int,否则 --benchmark=0 可以通过但不会执行任何 benchmark。建议:使用 type=int 并在 main 中处理 0 的情况。


📁 ScratchV-topic06-deliverable/setup.py

🔴 Missing required metadatasetup() called without any arguments. This will fail with ValueError: Missing 'name' in setup().
Suggestion: Provide at minimum name, version, and packages (or py_modules).

🟡 No package discovery — Without packages or find_packages(), no Python modules will be installed.
Suggestion: Use setuptools.find_packages() to auto-discover packages.

💭 Consider adding install_requires — Even if empty, specifying dependencies upfront avoids surprises later.



⚠️ 未审查的文件

  • ScratchV-topic06-deliverable/tests_main/activation/add_relu_relu.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/add_relu_relu.meta.json
  • ScratchV-topic06-deliverable/tests_main/activation/relu_add.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/relu_add.meta.json
  • ScratchV-topic06-deliverable/tests_main/activation/relu_only.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/relu_only.meta.json
  • ScratchV-topic06-deliverable/tests_main/activation/relu_twice.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/relu_twice.meta.json
  • ScratchV-topic06-deliverable/tests_main/branch/if_else.dsl
  • ScratchV-topic06-deliverable/tests_main/branch/if_else.meta.json
  • ScratchV-topic06-deliverable/tests_main/branch/if_relu.dsl
  • ScratchV-topic06-deliverable/tests_main/branch/if_relu.meta.json
  • ScratchV-topic06-deliverable/tests_main/branch/if_then.dsl
  • ScratchV-topic06-deliverable/tests_main/branch/if_then.meta.json
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain.dsl
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain.meta.json
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain_3.dsl
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain_3.meta.json
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_fan_in_4.dsl
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_fan_in_4.meta.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant