Skip to content

[Bug] get_maca_arch missing OSError catch and env var support for cross-compilation #31

Description

@zhanma666
  1. When maca_path/bin/macainfo binary does not exist, get_maca_arch() should gracefully fall back to the default architecture (xco re1000) instead of crashing.
    2. Users should be able to set MACA_ARCH environment variable (e.g. MACA_ARCH=xcore2000) to skip the macainfo command entirely fo
    r cross-compilation or non-GPU environments.
    3. Tests should use from tvm.contrib import mxcc directly via standard import instead of polluting sys.modules globally.

    Actual behavior

    1. subprocess.check_output raises FileNotFoundError (a subclass of OSError) when the binary is missing, but only subprocess.Call edProcessError is caught, causing a crash.
    2. No MACA_ARCH environment variable support — the only way to specify the architecture is by running macainfo, which requires a ph
      ysical GPU.
    3. The previous test file manually mocked sys.modules to inject fake tvm modules, which permanently pollutes sys.modules and caus
      es AttributeError in other tests running in the same process.

    Environment

    TVM 0.23.dev0, MetaX MACA 3.5.3.20, Python 3.10, Linux

    Steps to reproduce

    For the crash (OSError not caught):

    1. Set maca_path to a directory where bin/macainfo does not exist
    2. Call get_maca_arch(maca_path="/valid/path/without/macainfo")
    3. Observe FileNotFoundError / OSError crash

    For the test pollution:

    1. Run pytest tests/python/contrib/test_mxcc_arch.py in the same process as other TVM tests
    2. The fake tvm module injected via sys.modules leaks into subsequent tests
    3. Other tests fail with AttributeError on real tvm module attributes

    Fix

    Changes in PR fix/duplicate-maca-error-message (SHA: 485c4d1):

    • python/tvm/contrib/mxcc.py: catch (subprocess.CalledProcessError, OSError) instead of only CalledProcessError
    • python/tvm/contrib/mxcc.py: check MACA_ARCH env var first; if set, return its value immediately
    • python/tvm/contrib/mxcc.py: resolve maca_path from MACA_PATH env var as fallback
    • tests/python/contrib/test_mxcc_arch.py: rewrite to use from tvm.contrib import mxcc with unittest.mock.patch, covering 8 test c
      ases

    Triage

    • needs-triage
    • bug
    • meta-x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions