Skip to content

从 MACA 路径解析 mxcc#27

Open
ghangz wants to merge 1 commit into
MetaX-MACA:mainfrom
ghangz:mengz/resolve-mxcc-from-maca-path
Open

从 MACA 路径解析 mxcc#27
ghangz wants to merge 1 commit into
MetaX-MACA:mainfrom
ghangz:mengz/resolve-mxcc-from-maca-path

Conversation

@ghangz

@ghangz ghangz commented Jun 8, 2026

Copy link
Copy Markdown

该 PR 增加从 MACA 安装目录解析 mxcc 的逻辑,提升容器内工具链布局变化时的兼容性。

这个修改面向沐曦 GPU 适配场景中比较容易影响开发、构建或验证稳定性的环节,把原来需要人工排查的问题前移到工具链、运行前检查或基准脚本中处理。实现上保持对现有默认行为的兼容,只在检测到明确配置、输入或环境异常时给出更直接的诊断,避免引入额外运行依赖,也方便维护者独立审阅该分支。

已在沐曦算力环境中完成对应分支验证,验证记录包含真实运行日志、命令输出和失败路径检查,本地归档目录为:E:/Documents/muxi/测试报告/mcTVM_new_toolchain_validation_20260608。提交分支:mengz/resolve-mxcc-from-maca-path,目标仓库:MetaX-MACA/mcTVM

@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 helper function _find_mxcc to dynamically locate the mxcc compiler using the MACA_PATH environment variable or the system PATH, and adds corresponding unit tests. The review feedback suggests falling back to the default /opt/maca path when MACA_PATH is not set to align with CMake lookup logic, and mocking os.path.isfile in the unit tests to ensure test hermeticity regardless of the host environment.

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 +124 to +134
def _find_mxcc():
"""Find mxcc from MACA_PATH or PATH."""
maca_path = os.environ.get("MACA_PATH")
if maca_path:
candidate = os.path.join(maca_path, "mxgpu_llvm", "bin", "mxcc")
if os.path.isfile(candidate):
return candidate
mxcc = shutil.which("mxcc")
if mxcc:
return mxcc
raise RuntimeError("Cannot find mxcc. Set MACA_PATH or add mxcc to PATH.")

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

_find_mxcc 函数中,如果环境变量 MACA_PATH 未设置,当前实现只会尝试通过 shutil.which("mxcc")PATH 中查找。然而,根据 find_maca_path() 以及 FindMACA.cmake 中的逻辑,/opt/maca 是一个默认的 MACA 安装路径。如果用户没有设置 MACA_PATHmxcc 不在 PATH 中,但系统上存在默认的 /opt/maca/mxgpu_llvm/bin/mxcc,当前实现将会报错。

建议将 maca_path 的默认值设为 /opt/maca,以保持与现有默认行为和 CMake 查找逻辑的一致性。

Suggested change
def _find_mxcc():
"""Find mxcc from MACA_PATH or PATH."""
maca_path = os.environ.get("MACA_PATH")
if maca_path:
candidate = os.path.join(maca_path, "mxgpu_llvm", "bin", "mxcc")
if os.path.isfile(candidate):
return candidate
mxcc = shutil.which("mxcc")
if mxcc:
return mxcc
raise RuntimeError("Cannot find mxcc. Set MACA_PATH or add mxcc to PATH.")
def _find_mxcc():
"""Find mxcc from MACA_PATH or PATH."""
maca_path = os.environ.get("MACA_PATH") or "/opt/maca"
candidate = os.path.join(maca_path, "mxgpu_llvm", "bin", "mxcc")
if os.path.isfile(candidate):
return candidate
mxcc = shutil.which("mxcc")
if mxcc:
return mxcc
raise RuntimeError("Cannot find mxcc. Set MACA_PATH or add mxcc to PATH.")

Comment on lines +61 to +64
def test_find_mxcc_from_path(self):
with patch.dict(os.environ, {}, clear=True):
with patch.object(mxcc.shutil, "which", return_value="/usr/bin/mxcc"):
self.assertEqual(mxcc._find_mxcc(), "/usr/bin/mxcc")

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

为了确保单测的密闭性(Hermeticity),避免受到运行测试的宿主机上是否存在 /opt/maca/mxgpu_llvm/bin/mxcc 的影响,建议在 test_find_mxcc_from_path 中对 os.path.isfile 进行 mock,使其返回 False。这样可以确保测试始终能够走到 shutil.which 的分支。

Suggested change
def test_find_mxcc_from_path(self):
with patch.dict(os.environ, {}, clear=True):
with patch.object(mxcc.shutil, "which", return_value="/usr/bin/mxcc"):
self.assertEqual(mxcc._find_mxcc(), "/usr/bin/mxcc")
def test_find_mxcc_from_path(self):
with patch.dict(os.environ, {}, clear=True):
with patch.object(mxcc.os.path, "isfile", return_value=False):
with patch.object(mxcc.shutil, "which", return_value="/usr/bin/mxcc"):
self.assertEqual(mxcc._find_mxcc(), "/usr/bin/mxcc")

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