-
Notifications
You must be signed in to change notification settings - Fork 4
增加算子库构建环境报告 #33
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/add-mcoplib-build-env-report
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.
+146
−0
Open
增加算子库构建环境报告 #33
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,146 @@ | ||
| #!/usr/bin/env python3 | ||
| """Collect build-time diagnostics for mcoplib MACA environments.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
| import platform | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
|
|
||
| def _run(command: list[str]) -> dict[str, Any]: | ||
| executable = shutil.which(command[0]) | ||
| if executable is None: | ||
| return {"available": False, "path": None} | ||
|
|
||
| try: | ||
| proc = subprocess.run( | ||
| [executable, *command[1:]], | ||
| check=False, | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE, | ||
| text=True, | ||
| errors="replace", | ||
| timeout=10, | ||
| ) | ||
| except Exception as exc: # pragma: no cover - defensive diagnostics | ||
| return {"available": True, "path": executable, "error": str(exc)} | ||
|
|
||
| return { | ||
| "available": True, | ||
| "path": executable, | ||
| "returncode": proc.returncode, | ||
| "stdout": proc.stdout.strip(), | ||
| "stderr": proc.stderr.strip(), | ||
| } | ||
|
|
||
|
|
||
| def _python_package(name: str) -> dict[str, Any]: | ||
| try: | ||
| from importlib.metadata import PackageNotFoundError, version | ||
| except ImportError: # pragma: no cover - Python 3.9+ is required | ||
| return {"installed": False, "error": "importlib.metadata unavailable"} | ||
|
|
||
| try: | ||
| return {"installed": True, "version": version(name)} | ||
| except PackageNotFoundError: | ||
| return {"installed": False} | ||
|
|
||
|
|
||
| def _maca_version(maca_path: str | None) -> str | None: | ||
| if not maca_path: | ||
| return None | ||
|
|
||
| version_file = Path(maca_path) / "Version.txt" | ||
| if not version_file.is_file(): | ||
| return None | ||
|
|
||
| try: | ||
| first_line = version_file.read_text(encoding="utf-8").splitlines()[0] | ||
| except Exception: | ||
| return None | ||
|
|
||
| return first_line.split(":")[-1].strip() | ||
|
|
||
|
|
||
| def collect_env() -> dict[str, Any]: | ||
| maca_path = os.environ.get("MACA_PATH") | ||
| cuda_home = os.environ.get("CUDA_HOME") | ||
|
|
||
| report: dict[str, Any] = { | ||
| "platform": { | ||
| "system": platform.system(), | ||
| "release": platform.release(), | ||
| "machine": platform.machine(), | ||
| "python": sys.version, | ||
| "executable": sys.executable, | ||
| }, | ||
| "environment": { | ||
| "MACA_PATH": maca_path, | ||
| "CUDA_HOME": cuda_home, | ||
| "LD_LIBRARY_PATH": os.environ.get("LD_LIBRARY_PATH"), | ||
| "PATH": os.environ.get("PATH"), | ||
| }, | ||
| "maca": { | ||
| "version": _maca_version(maca_path), | ||
| "version_file": str(Path(maca_path) / "Version.txt") if maca_path else None, | ||
| "exists": bool(maca_path and Path(maca_path).exists()), | ||
| }, | ||
| "tools": { | ||
| "cmake_maca": _run(["cmake_maca", "--version"]), | ||
| "make_maca": _run(["make_maca", "--version"]), | ||
| "mxcc": _run(["mxcc", "--version"]), | ||
| "ninja": _run(["ninja", "--version"]), | ||
| "gcc": _run(["gcc", "--version"]), | ||
| "g++": _run(["g++", "--version"]), | ||
| }, | ||
| "python_packages": { | ||
| "torch": _python_package("torch"), | ||
| "pybind11": _python_package("pybind11"), | ||
| "packaging": _python_package("packaging"), | ||
| "ninja": _python_package("ninja"), | ||
| "setuptools": _python_package("setuptools"), | ||
| }, | ||
| } | ||
|
|
||
| try: | ||
| import torch | ||
|
|
||
| report["torch_runtime"] = { | ||
| "cuda": getattr(torch.version, "cuda", None), | ||
| "hip": getattr(torch.version, "hip", None), | ||
| "cuda_available": bool(torch.cuda.is_available()), | ||
| "device_count": torch.cuda.device_count() if torch.cuda.is_available() else 0, | ||
| } | ||
| except Exception as exc: | ||
| report["torch_runtime"] = {"error": str(exc)} | ||
|
|
||
| return report | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description="Collect mcoplib build environment diagnostics.") | ||
| parser.add_argument("--output", type=Path, help="Optional JSON output path.") | ||
| parser.add_argument("--pretty", action="store_true", help="Pretty-print JSON.") | ||
| args = parser.parse_args() | ||
|
|
||
| report = collect_env() | ||
| text = json.dumps(report, indent=2 if args.pretty else None, 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()) | ||
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.
在一些精简的容器环境或未正确配置本地化(Locale)的环境中(例如
LANG=C),系统默认编码可能为 ASCII。如果被调用的外部命令(如gcc或g++)输出中包含非 ASCII 字符(例如作者名字中的特殊字符或本地化的标点符号),subprocess.run在使用text=True时会因为解码失败而抛出UnicodeDecodeError,从而导致该工具的诊断信息获取失败。\n\n为了提高诊断脚本在各种复杂环境下的鲁棒性,建议在subprocess.run中显式指定errors="replace"。这样在遇到无法解码的字符时会将其替换为\ufffd,而不会中断执行。