Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,18 @@ jobs:
rm -rf pytest-results
popd
- name: Run Python MetaXGPU unit tests
continue-on-error: true
shell: bash -l {0}
run: >-
./tests/scripts/task_python_unittest.sh
env:
PYTEST_ADDOPTS: "-m gpu"
TVM_TEST_TARGETS: maca
TVM_UNITTEST_TESTSUITE_NAME: python-unittest-gpu
PLATFORM: gpu
- name: Test Summary
uses: test-summary/action@v2
with:
paths: "build/pytest-results/**/*.xml"

Linux_CPU_Test:
if: ${{ false && github.repository == 'MetaX-MACA/mcTVM' }}
Expand Down
23 changes: 12 additions & 11 deletions python/tvm/support/mxcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,20 @@ def have_wmma(compute_version=None):
return False


def have_fp16(compute_version):
"""Either fp16 support is provided in the compute capability or not
def have_fp16(compute_version): # pylint: disable=unused-argument
"""Whether fp16 support is provided in the specified compute capability or not."""
return True

Parameters
----------
compute_version: str
compute capability of a GPU (e.g. "6.0")
"""
major, minor = parse_compute_version(compute_version) # pylint: disable=unused-variable
if major >= 10:
return True

return False
def have_int8(compute_version): # pylint: disable=unused-argument
"""Whether int8 support is provided in the specified compute capability or not."""
return True


@tvm_ffi.register_global_func("tvm.support.mxcc.supports_bf16")
def have_bf16(compute_version): # pylint: disable=unused-argument
"""Whether bf16 support is provided in the specified compute capability or not."""
return True


@tvm_ffi.register_global_func("tvm_callback_maca_get_arch")
Expand Down
31 changes: 30 additions & 1 deletion python/tvm/testing/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_my_cuda_kernel():
usable device of a given kind is present;
* **build-support** probes (``has_cudnn`` …, ``build_flag_enabled`` …) ask whether
an optional library was compiled into the runtime;
* **version / capability** probes (``has_cuda_compute``,
* **version / capability** probes (``has_cuda_compute``, ``has_maca_compute``,
``has_nvcc_version`` …) ask about a finer capability of a present device
or toolchain.
"""
Expand Down Expand Up @@ -72,6 +72,7 @@ def test_my_cuda_kernel():
"has_llvm",
"has_llvm_min_version",
"has_maca",
"has_maca_compute",
"has_matrixcore",
"has_metal",
"has_multi_gpu",
Expand Down Expand Up @@ -296,6 +297,34 @@ def has_cuda_compute(major: int, minor: int = 0, exact: bool = False) -> bool:
return compute >= want


@functools.cache
def _maca_compute_version() -> tuple:
"""Return the (major, minor) MACA compute version, or (0, 0) if unknown."""
try:
from tvm.support import mxcc # pylint: disable=import-outside-toplevel

arch = mxcc.get_target_compute_version()
return mxcc.parse_compute_version(arch)
except Exception: # pylint: disable=broad-except
return (0, 0)


def has_maca_compute(major: int, minor: int = 0, exact: bool = False) -> bool:
"""True if the MACA compute capability satisfies ``(major, minor)``.

When ``exact`` is False (default) the check is ``compute >= (major,
minor)``; when True it requires an exact match. Returns False when no
MACA device is present, so it implies :func:`has_maca`.
"""
if not has_maca():
return False
compute = _maca_compute_version()
want = (major, minor)
if exact:
return compute == want
return compute >= want


@functools.cache
def _nvcc_version() -> tuple:
"""Return the (major, minor, release) nvcc version, or (0, 0, 0)."""
Expand Down
4 changes: 2 additions & 2 deletions tests/python/codegen/test_codegen_error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def func(a: T.Buffer((128, 128), "float32"), b: T.Buffer((128, 128), "float32"))


@pytest.mark.gpu
@pytest.mark.skipif(not env.has_cuda(), reason="need cuda")
@pytest.mark.skipif(not env.has_maca(), reason="need maca")
def test_device_mismatch_error():
"""Passing GPU tensor to CPU function raises ValueError."""

Expand All @@ -292,7 +292,7 @@ def func(a: T.Buffer((128,), "float32"), b: T.Buffer((128,), "float32")):
b_ok = tvm.runtime.tensor(np.zeros(128, dtype="float32"))
lib(a_ok, b_ok) # correct input should pass

a_gpu = tvm.runtime.tensor(np.zeros(128, dtype="float32"), device=tvm.cuda(0))
a_gpu = tvm.runtime.tensor(np.zeros(128, dtype="float32"), device=tvm.maca(0))
b = tvm.runtime.tensor(np.zeros(128, dtype="float32"))

with pytest.raises(
Expand Down
12 changes: 9 additions & 3 deletions tests/python/codegen/test_inject_ptx_ldg32.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ def vector_add(A: T.Buffer((16), "float32"), B: T.Buffer((32), "float32")) -> No


@pytest.mark.gpu
@pytest.mark.skipif(not env.has_cuda(), reason="need cuda")
@pytest.mark.skipif(not env.has_maca(), reason="need maca")
@pytest.mark.xfail(
reason=(
"TODO(maca): [ptx-ldg32] support PTX ldg32-style load injection or an equivalent MACA pass"
),
strict=False,
)
def test_inject_ptx_intrin():
f = vector_add
arch = tvm.support.nvcc.get_target_compute_version()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Since this test is skipped if not env.has_maca(), when it runs, it will execute on a MACA device. However, tvm.support.nvcc.get_target_compute_version() is NVIDIA-specific and will fail or return incorrect results on a MACA device.

Please update this to use tvm.support.mxcc.get_target_compute_version() instead.

Suggested change
arch = tvm.support.nvcc.get_target_compute_version()
from tvm.support import mxcc
arch = mxcc.get_target_compute_version()

Expand All @@ -50,10 +56,10 @@ def test_inject_ptx_intrin():
# Require at least SM80
return
with tvm.transform.PassContext(config={"tirx.ptx.ldg32": True}):
mod = tvm.compile(f, target="cuda")
mod = tvm.compile(f, target="maca")
A_np = np.random.rand(16).astype("float32")
B_np = np.zeros(32).astype("float32")
dev = tvm.cuda(0)
dev = tvm.maca(0)
A_nd = tvm.runtime.tensor(A_np, device=dev)
B_nd = tvm.runtime.tensor(B_np, device=dev)
mod(A_nd, B_nd)
Expand Down
6 changes: 3 additions & 3 deletions tests/python/codegen/test_target_codegen_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_cuda_multi_lib():

# test combining two system lib together
# each contains a fatbin component in cuda
dev = tvm.cuda(0)
dev = tvm.maca(0)
for device in ["llvm", "cuda"]:
if not tvm.testing.device_enabled(device):
print(f"skip because {device} is not enabled...")
Expand Down Expand Up @@ -63,7 +63,7 @@ def my_inplace_update(x: T.Buffer((12), "float32")) -> None:
x[tx] = x[tx] + 2

temp = utils.tempdir()
target = tvm.target.Target("cuda", host="llvm")
target = tvm.target.Target("maca", host="llvm")
libA = tvm.compile(ModA, target=target)
libB = tvm.compile(ModB, target=target)

Expand All @@ -82,7 +82,7 @@ def popen_check():
# Load dll, will trigger system library registration
ctypes.CDLL(path_dso)
# Load the system wide library
dev = tvm.cuda()
dev = tvm.maca()
a_np = np.random.uniform(size=12).astype("float32")
a_nd = tvm.runtime.tensor(a_np, dev)
b_nd = tvm.runtime.tensor(a_np, dev)
Expand Down
2 changes: 1 addition & 1 deletion tests/python/codegen/test_target_codegen_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


@pytest.mark.gpu
@pytest.mark.parametrize("target", ["llvm", "cuda", "rocm", "vulkan", "metal", "opencl"])
@pytest.mark.parametrize("target", ["llvm", "cuda", "rocm", "vulkan", "metal", "opencl", "maca"])
def test_cmp_load_store(target):
if not tvm.testing.device_enabled(target):
pytest.skip(f"{target} not enabled")
Expand Down
Loading
Loading