Skip to content

增加算子库算子复杂度报告#40

Open
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/mcoplib-op-complexity-report
Open

增加算子库算子复杂度报告#40
ghangz wants to merge 2 commits into
MetaX-MACA:mainfrom
ghangz:mengz/mcoplib-op-complexity-report

Conversation

@ghangz

@ghangz ghangz commented Jun 10, 2026

Copy link
Copy Markdown

这次改动补上了算子库算子复杂度报告,主要是为了解决算子库构建和诊断流程里相关信息不够集中、人工整理成本较高的问题,让日常排查、验证和结果归档更直接。

实现上补充了对应工具或脚本逻辑,补上了对应测试,同时尽量保持现有用法不变,避免影响已有流程。

这一分支已经在沐曦算力环境完成实际验证,相关检查均已通过,现提交合入。

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +25 to +35
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],
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

当指定的 root 目录下不存在 op 子目录时,对 rglob 结果进行排序和迭代会抛出 FileNotFoundError 异常。为了提高脚本的健壮性,建议在构建报告前先检查 op 目录是否存在。如果不存在,可以直接返回一个空的报告结构,避免程序崩溃。此外,item["lines"] 本身已经是整型,无需在 sumsorted 中重复调用 int() 进行类型转换。

Suggested change
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],
}

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