This is an automated email from the ASF dual-hosted git repository.
tlopex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-tirx.git
The following commit(s) were added to refs/heads/main by this push:
new deab26e8f [FIX] Default ROCm thread_warp_size to 32 on RDNA and limit
MFMA detection to CDNA (#263)
deab26e8f is described below
commit deab26e8f621a3c9be11c06badb8dcb22e64eec4
Author: Ravi Gupta <[email protected]>
AuthorDate: Thu Nov 26 22:03:08 2026 -0800
[FIX] Default ROCm thread_warp_size to 32 on RDNA and limit MFMA detection
to CDNA (#263)
RDNA GPUs (gfx10xx, gfx11xx, gfx12xx) execute wave32, but the rocm
target kind defaulted
thread_warp_size to 64 for every arch. Kernels scheduled for warp 64
then ran with the
wrong lane count on RDNA: cross-lane reductions gave wrong results, and
one such run hung the GPU.
have_matrixcore() also returned True for any compute version >= 9, so
MFMA schedules and
tests ran on RDNA, which has WMMA rather than MFMA, and crashed there.
- target_kind.cc: thread_warp_size has no static default any more.
UpdateROCmAttrs sets
32 for gfx10/11/12 and 64 otherwise. An explicit thread_warp_size is
always kept.
This resolves the existing RDNA TODO.
- support/rocm.py: have_matrixcore() is True only for the MFMA archs
(gfx908, gfx90a,
gfx94x, gfx950). Add have_rdna_wmma() for gfx11/gfx12.
- tests/python/target/test_target.py: device-independent tests for the
warp-size default
per arch, an explicit override, and MFMA/WMMA detection.
Tested on gfx1151 (Radeon 8060S, ROCm 7.2): the new tests pass, MFMA
numeric tests skip
instead of crashing, and dlight GPU schedules are correct with warp 32.
---
python/tvm_tirx/support/rocm.py | 33 +++++++++++++++++++++------
src/backend/rocm/codegen/target_kind.cc | 13 ++++++++---
tests/python/target/test_target.py | 40 +++++++++++++++++++++++++++++++++
3 files changed, 76 insertions(+), 10 deletions(-)
diff --git a/python/tvm_tirx/support/rocm.py b/python/tvm_tirx/support/rocm.py
index 545ea96b0..41b92f922 100644
--- a/python/tvm_tirx/support/rocm.py
+++ b/python/tvm_tirx/support/rocm.py
@@ -202,18 +202,24 @@ def parse_compute_version(compute_version):
raise RuntimeError("Compute version parsing error: " + str(err))
+MFMA_ARCHS = ("gfx908", "gfx90a", "gfx940", "gfx941", "gfx942", "gfx950")
+
+
def have_matrixcore(compute_version=None):
- """Either MatrixCore support is provided in the compute capability or not
+ """Whether the GPU has MFMA matrix cores (CDNA: gfx908, gfx90a, gfx94x,
gfx950).
+
+ RDNA GPUs (compute version 10.x-12.x) have WMMA instead of MFMA (see
`have_rdna_wmma`), and
+ MFMA code must not be run on them.
Parameters
----------
compute_version : str, optional
- compute capability of a GPU (e.g. "7.0").
+ compute capability of a GPU (e.g. "9.4").
Returns
-------
have_matrixcore : bool
- True if MatrixCore support is provided, False otherwise
+ True if MFMA matrix cores are available, False otherwise
"""
if compute_version is None:
if tvm_tirx.rocm(0).exist:
@@ -221,11 +227,24 @@ def have_matrixcore(compute_version=None):
else:
raise RuntimeError("No ROCm runtime found")
major, _ = parse_compute_version(compute_version)
- # matrix core first introduced in 8.0
- if major >= 8:
- return True
+ if major != 9:
+ return False # GCN <= 8.x: no matrix cores; RDNA 10.x-12.x: WMMA, not
MFMA
+ try:
+ arch = get_rocm_arch()
+ except Exception: # pylint: disable=broad-except
+ return True # cannot query the arch: keep the previous (permissive)
behaviour for 9.x
+ return arch in MFMA_ARCHS
+
- return False
+def have_rdna_wmma(compute_version=None):
+ """Whether the GPU has RDNA WMMA (gfx11xx / gfx12xx, wave32)."""
+ if compute_version is None:
+ if tvm_tirx.rocm(0).exist:
+ compute_version = tvm_tirx.rocm(0).compute_version
+ else:
+ raise RuntimeError("No ROCm runtime found")
+ major, _ = parse_compute_version(compute_version)
+ return major in (11, 12)
@tvm_ffi.register_global_func("tvm_callback_rocm_get_arch")
diff --git a/src/backend/rocm/codegen/target_kind.cc
b/src/backend/rocm/codegen/target_kind.cc
index dae3d8e78..0eb24b9bb 100644
--- a/src/backend/rocm/codegen/target_kind.cc
+++ b/src/backend/rocm/codegen/target_kind.cc
@@ -89,6 +89,14 @@ ffi::Map<ffi::String, ffi::Any>
UpdateROCmAttrs(ffi::Map<ffi::String, ffi::Any>
target.Set("mcpu", ffi::String(arch));
}
+ // RDNA (gfx10xx, gfx11xx, gfx12xx) executes wave32; GCN/CDNA (gfx9xx)
wave64. Respect an
+ // explicit thread_warp_size.
+ if (!target.count("thread_warp_size")) {
+ std::string ver = arch.rfind("gfx", 0) == 0 ? arch.substr(3) : arch;
+ bool rdna = ver.rfind("10", 0) == 0 || ver.rfind("11", 0) == 0 ||
ver.rfind("12", 0) == 0;
+ target.Set("thread_warp_size", static_cast<int64_t>(rdna ? 32 : 64));
+ }
+
ffi::Any val;
int version;
if (!DetectDeviceFlag({kDLROCM, 0}, "api_version", &val)) {
@@ -123,12 +131,11 @@ TVM_FFI_STATIC_INIT_BLOCK() {
.def_option<ffi::String>("mcpu")
.def_option<ffi::String>("mtriple")
.def_option<ffi::Array<ffi::String>>("mattr")
- // TODO(masahi): Support querying from a target device
- // On RDNA cards, thread_warp_size should be 32
.def_option<int64_t>("max_num_threads", refl::DefaultValue(256))
.def_option<int64_t>("max_threads_per_block", refl::DefaultValue(256))
.def_option<int64_t>("max_shared_memory_per_block",
refl::DefaultValue(65536))
- .def_option<int64_t>("thread_warp_size", refl::DefaultValue(64))
+ // Set by UpdateROCmAttrs from mcpu when not given: 32 on RDNA
(gfx10/11/12), else 64.
+ .def_option<int64_t>("thread_warp_size")
.set_default_keys({"rocm", "gpu"})
.set_target_canonicalizer(UpdateROCmAttrs);
}
diff --git a/tests/python/target/test_target.py
b/tests/python/target/test_target.py
index 2a01e14d3..0b603cc44 100644
--- a/tests/python/target/test_target.py
+++ b/tests/python/target/test_target.py
@@ -496,5 +496,45 @@ def test_webgpu_target_subgroup_attrs():
Target(config)
[email protected](
+ "mcpu, expected",
+ [
+ ("gfx1030", 32),
+ ("gfx1100", 32),
+ ("gfx1151", 32),
+ ("gfx1201", 32),
+ ("gfx90a", 64),
+ ("gfx942", 64),
+ ],
+)
+def test_rocm_thread_warp_size_default(mcpu, expected):
+ """RDNA (gfx10/11/12) executes wave32; GCN/CDNA (gfx9) wave64."""
+ target = Target({"kind": "rocm", "mcpu": mcpu})
+ assert int(target.attrs["thread_warp_size"]) == expected
+
+
+def test_rocm_thread_warp_size_explicit():
+ target = Target({"kind": "rocm", "mcpu": "gfx1100", "thread_warp_size":
64})
+ assert int(target.attrs["thread_warp_size"]) == 64
+
+
[email protected](
+ "compute_version, mfma, wmma",
+ [
+ ("8.0", False, False),
+ ("10.3", False, False),
+ ("11.0", False, True),
+ ("11.5", False, True),
+ ("12.0", False, True),
+ ],
+)
+def test_rocm_matrix_core_detection(compute_version, mfma, wmma):
+ """RDNA GPUs have WMMA, not MFMA: MFMA code (and tests) must not run
there."""
+ from tvm_tirx.support import rocm # pylint:
disable=import-outside-toplevel
+
+ assert rocm.have_matrixcore(compute_version) == mfma
+ assert rocm.have_rdna_wmma(compute_version) == wmma
+
+
if __name__ == "__main__":
tvm_tirx.testing.main()