Files
tilelang/testing/python/language/test_tilelang_language_kernel_threads.py
T
禾可 207f3a75f2 [BugFix] Reject non-positive thread extents in T.Kernel (#2653)
* [BugFix] Reject non-positive thread extents in T.Kernel

`_normalize_threads` passed its argument straight through, so a non-positive
extent such as `T.Kernel(1, threads=-1)` compiled and launched cleanly while
writing nothing. Validate the normalized extents and raise instead.

Concrete integer extents only, so symbolic extents keep working.

Fixes #2633.

Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>

* [BugFix] Document _normalize_threads contract

Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>

---------

Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>
2026-07-13 17:29:01 +08:00

36 lines
1.1 KiB
Python

"""Tests for T.Kernel thread-extent validation."""
import pytest
import tilelang
import tilelang.testing
from tilelang.language.kernel import _normalize_threads
# ===========================================================================
# Validation tests (do not require GPU)
# ===========================================================================
@pytest.mark.parametrize("threads", [-1, 0, [-1], [128, 0], (128, 1, -2)])
def test_normalize_threads_rejects_non_positive(threads):
"""A non-positive extent must be rejected instead of launching an empty block."""
with pytest.raises(ValueError, match="threads must be positive"):
_normalize_threads(threads)
@pytest.mark.parametrize(
"threads, expected",
[
(None, [128, 1, 1]),
(256, [256, 1, 1]),
([32, 4], [32, 4, 1]),
((32, 2, 2), [32, 2, 2]),
],
)
def test_normalize_threads_accepts_positive(threads, expected):
"""Valid extents are still normalized to a 3-D thread block."""
assert _normalize_threads(threads) == expected
if __name__ == "__main__":
tilelang.testing.main()