增加算子库算子复杂度报告#40
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new tool op_complexity_report.py and its corresponding unit tests to analyze and report the complexity of CUDA/MACA operator source files. The feedback suggests checking for the existence of the op directory to improve robustness and removing redundant int() type conversions since the line count is already an integer.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def build_report(root: Path) -> dict[str, object]: | ||
| files = [ | ||
| analyze_file(path, root) | ||
| for path in sorted((root / "op").rglob("*")) | ||
| if path.is_file() and path.suffix in SOURCE_SUFFIXES | ||
| ] | ||
| return { | ||
| "file_count": len(files), | ||
| "total_lines": sum(int(item["lines"]) for item in files), | ||
| "top_by_lines": sorted(files, key=lambda item: int(item["lines"]), reverse=True)[:20], | ||
| } |
There was a problem hiding this comment.
当指定的 root 目录下不存在 op 子目录时,对 rglob 结果进行排序和迭代会抛出 FileNotFoundError 异常。为了提高脚本的健壮性,建议在构建报告前先检查 op 目录是否存在。如果不存在,可以直接返回一个空的报告结构,避免程序崩溃。此外,item["lines"] 本身已经是整型,无需在 sum 和 sorted 中重复调用 int() 进行类型转换。
| def build_report(root: Path) -> dict[str, object]: | |
| files = [ | |
| analyze_file(path, root) | |
| for path in sorted((root / "op").rglob("*")) | |
| if path.is_file() and path.suffix in SOURCE_SUFFIXES | |
| ] | |
| return { | |
| "file_count": len(files), | |
| "total_lines": sum(int(item["lines"]) for item in files), | |
| "top_by_lines": sorted(files, key=lambda item: int(item["lines"]), reverse=True)[:20], | |
| } | |
| def build_report(root: Path) -> dict[str, object]: | |
| op_dir = root / "op" | |
| if not op_dir.is_dir(): | |
| return { | |
| "file_count": 0, | |
| "total_lines": 0, | |
| "top_by_lines": [], | |
| } | |
| files = [ | |
| analyze_file(path, root) | |
| for path in sorted(op_dir.rglob("*")) | |
| if path.is_file() and path.suffix in SOURCE_SUFFIXES | |
| ] | |
| return { | |
| "file_count": len(files), | |
| "total_lines": sum(item["lines"] for item in files), | |
| "top_by_lines": sorted(files, key=lambda item: item["lines"], reverse=True)[:20], | |
| } |
这次改动补上了算子库算子复杂度报告,主要是为了解决算子库构建和诊断流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。
实现上补充了对应工具或脚本逻辑,补上了对应测试,同时尽量保持现有用法不变,避免影响已有流程。
这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。