mirror of
https://github.com/tile-ai/tilelang.git
synced 2026-10-22 06:50:25 +08:00
* [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>
36 lines
1.1 KiB
Python
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()
|