Skip to content

Add mcTVM mctvm cmake cache audit#34

Open
ghangz wants to merge 2 commits into
MetaX-MACA:devfrom
ghangz:mengz/mctvm-cmake-cache-audit
Open

Add mcTVM mctvm cmake cache audit#34
ghangz wants to merge 2 commits into
MetaX-MACA:devfrom
ghangz:mengz/mctvm-cmake-cache-audit

Conversation

@ghangz

@ghangz ghangz commented Jul 1, 2026

Copy link
Copy Markdown

Summary

  • Adds a focused mctvm cmake cache audit improvement for MetaX-MACA/mcTVM.
  • The change targets MetaX MACA development and validation workflows, with emphasis on earlier diagnostics, reproducible logs, or safer benchmark tooling.
  • Existing default behavior is kept compatible; the new logic is scoped to explicit checks, helper tools, or validation metadata.

Validation

  • Verified on Gitee.AI MetaX GPU resources: mctvm_TileLang_20260701, 6/6 PASS.
  • Branch validation command: python tools/cmake_cache_audit.py --self-test
  • Pull request text is intentionally ASCII-only to avoid encoding issues on web forms and API clients.

Review notes

  • Source branch: ghangz:mengz/mctvm-cmake-cache-audit
  • Target branch: MetaX-MACA/mcTVM:dev
  • Maintainers can modify this branch if follow-up adjustments are needed.

@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 Python script, tools/cmake_cache_audit.py, designed to audit CMakeCache.txt files for required MACA build configuration keys. The review feedback suggests several robustness improvements: stripping whitespace during parsing to prevent key/value mismatches, using the tempfile module in the self-test to avoid workspace pollution, and gracefully handling missing cache files in the main entry point to prevent raw tracebacks.

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 +13 to +21
def parse_cache(path: Path) -> dict[str, str]:
values: dict[str, str] = {}
for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
if not line or line.startswith("//") or line.startswith("#") or "=" not in line:
continue
key_type, value = line.split("=", 1)
key = key_type.split(":", 1)[0]
values[key] = value
return values

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

The current parser does not strip leading or trailing whitespace from lines, keys, or values. If there are leading spaces or spaces around the = delimiter, the parser might fail to identify keys or include unwanted whitespace in the parsed values. Stripping whitespace improves parsing robustness.

Suggested change
def parse_cache(path: Path) -> dict[str, str]:
values: dict[str, str] = {}
for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
if not line or line.startswith("//") or line.startswith("#") or "=" not in line:
continue
key_type, value = line.split("=", 1)
key = key_type.split(":", 1)[0]
values[key] = value
return values
def parse_cache(path: Path) -> dict[str, str]:
values: dict[str, str] = {}
for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
line = line.strip()
if not line or line.startswith("//") or line.startswith("#") or "=" not in line:
continue
key_type, value = line.split("=", 1)
key = key_type.split(":", 1)[0].strip()
values[key] = value.strip()
return values

Comment thread tools/cmake_cache_audit.py Outdated
Comment on lines +30 to +38
def self_test() -> None:
sample = Path("_CMakeCache_sample.txt")
sample.write_text("MACA_HOME:PATH=/opt/maca\n", encoding="utf-8")
try:
data = audit(sample)
assert "missing" in data
print(json.dumps({"ok": True, "missing": len(data["missing"])}, ensure_ascii=False))
finally:
sample.unlink(missing_ok=True)

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

Writing a temporary file _CMakeCache_sample.txt directly to the current working directory can lead to permission issues, workspace pollution if the script is interrupted, or race conditions during concurrent test execution. Using Python's built-in tempfile module to create a temporary directory is a safer and cleaner approach.

Suggested change
def self_test() -> None:
sample = Path("_CMakeCache_sample.txt")
sample.write_text("MACA_HOME:PATH=/opt/maca\n", encoding="utf-8")
try:
data = audit(sample)
assert "missing" in data
print(json.dumps({"ok": True, "missing": len(data["missing"])}, ensure_ascii=False))
finally:
sample.unlink(missing_ok=True)
def self_test() -> None:
import tempfile
with tempfile.TemporaryDirectory() as tmpdir:
sample = Path(tmpdir) / "CMakeCache.txt"
sample.write_text("MACA_HOME:PATH=/opt/maca\n", encoding="utf-8")
data = audit(sample)
assert "missing" in data
print(json.dumps({"ok": True, "missing": len(data["missing"])}, ensure_ascii=False))

Comment on lines +41 to +50
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("cache", nargs="?", default="CMakeCache.txt")
parser.add_argument("--self-test", action="store_true")
args = parser.parse_args()
if args.self_test:
self_test()
return 0
print(json.dumps(audit(Path(args.cache)), ensure_ascii=False, indent=2))
return 0

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

If the specified CMake cache file (defaulting to CMakeCache.txt) does not exist, the script will crash with a raw FileNotFoundError traceback. It is better to check if the file exists and print a clean error message to sys.stderr before returning a non-zero exit code.

Suggested change
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("cache", nargs="?", default="CMakeCache.txt")
parser.add_argument("--self-test", action="store_true")
args = parser.parse_args()
if args.self_test:
self_test()
return 0
print(json.dumps(audit(Path(args.cache)), ensure_ascii=False, indent=2))
return 0
def main() -> int:
import sys
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("cache", nargs="?", default="CMakeCache.txt")
parser.add_argument("--self-test", action="store_true")
args = parser.parse_args()
if args.self_test:
self_test()
return 0
cache_path = Path(args.cache)
if not cache_path.is_file():
print(f"Error: CMake cache file not found at '{cache_path}'", file=sys.stderr)
return 1
print(json.dumps(audit(cache_path), ensure_ascii=False, indent=2))
return 0

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