-
Notifications
You must be signed in to change notification settings - Fork 4
增加算子库算子源码清单 #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ghangz
wants to merge
2
commits into
MetaX-MACA:main
Choose a base branch
from
ghangz:mengz/mcoplib-op-source-inventory
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−0
Open
增加算子库算子源码清单 #41
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #!/usr/bin/env python3 | ||
| """Build a JSON inventory of mcoplib operator source groups.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| GROUPS = { | ||
| "vllm": "op/vllm", | ||
| "sglang": "op/sglang", | ||
| "lmdeploy": "op/lmdeploy", | ||
| "cv": "op/cv", | ||
| "native": "op", | ||
| } | ||
|
|
||
| SOURCE_SUFFIXES = {".cu", ".cuh", ".cpp", ".cc", ".h", ".hpp", ".py"} | ||
|
|
||
|
|
||
| def _sources(root: Path, relative_dir: str) -> list[str]: | ||
| base = root / relative_dir | ||
| if not base.exists(): | ||
| return [] | ||
| return sorted( | ||
| path.relative_to(root).as_posix() | ||
| for path in base.rglob("*") | ||
| if path.is_file() and path.suffix in SOURCE_SUFFIXES | ||
| ) | ||
|
|
||
|
|
||
| def build_inventory(root: Path) -> dict[str, object]: | ||
| raw_files: dict[str, list[str]] = {} | ||
| for name, relative_dir in GROUPS.items(): | ||
| raw_files[name] = _sources(root, relative_dir) | ||
|
|
||
| other_files: set[str] = set() | ||
| for name in GROUPS: | ||
| if name != "native": | ||
| other_files.update(raw_files[name]) | ||
| if "native" in raw_files: | ||
| raw_files["native"] = [path for path in raw_files["native"] if path not in other_files] | ||
|
|
||
| groups: dict[str, object] = {} | ||
| for name, relative_dir in GROUPS.items(): | ||
| files = raw_files[name] | ||
| groups[name] = {"root": relative_dir, "count": len(files), "files": files} | ||
| return {"root": str(root), "groups": groups} | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description="Create mcoplib operator source inventory.") | ||
| parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[1]) | ||
| parser.add_argument("--output", type=Path) | ||
| args = parser.parse_args() | ||
|
|
||
| payload = build_inventory(args.root.resolve()) | ||
| text = json.dumps(payload, indent=2, sort_keys=True) | ||
| if args.output: | ||
| args.output.parent.mkdir(parents=True, exist_ok=True) | ||
| args.output.write_text(text + "\n", encoding="utf-8") | ||
| else: | ||
| print(text) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import tempfile | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| from tools.op_source_inventory import build_inventory | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| class OpSourceInventoryTest(unittest.TestCase): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| def test_inventory_counts_group_sources(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| with tempfile.TemporaryDirectory() as tmp: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| root = Path(tmp) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (root / "op" / "vllm").mkdir(parents=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (root / "op" / "vllm" / "kernel.cu").write_text("", encoding="utf-8") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (root / "op" / "vllm" / "README.md").write_text("", encoding="utf-8") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| (root / "op" / "native_kernel.cu").write_text("", encoding="utf-8") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| inventory = build_inventory(root) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.assertEqual(inventory["groups"]["vllm"]["count"], 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.assertEqual(inventory["groups"]["vllm"]["files"], ["op/vllm/kernel.cu"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 为了配合对
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.assertEqual(inventory["groups"]["native"]["count"], 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.assertEqual(inventory["groups"]["native"]["files"], ["op/native_kernel.cu"]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| unittest.main() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在当前的实现中,
GROUPS中的"native"对应的路径是"op"。由于_sources函数内部使用了rglob("*")进行递归搜索,这会导致"op/vllm"、"op/sglang"等子目录下的所有源文件也被重复统计到"native"分组中。这不仅导致数据冗余,也使得"native"分组的计数和文件列表不准确。建议在构建清单时,从
"native"分组中排除已被其他更具体的分组(如vllm,sglang,lmdeploy,cv)包含的文件。