Skip to content

Commit 56aa0d8

Browse files
Fix dtype validation for conditional SM targets
Refreshed onto current upstream. Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
1 parent ced90c9 commit 56aa0d8

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

‎src/cuda/tile/_passes/check_dtype_support.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ def _check_dtype(dtype: DType, sm_arch: str | None, sm_number: int | None,
138138
def check_dtype_support(root_block: Block, sm_arch: str | None,
139139
version: BytecodeVersion) -> None:
140140
# Skip arch check by setting sm_number to None when sm_arch is not provided
141-
sm_number = int(sm_arch.removeprefix("sm_")) if sm_arch is not None else None
141+
sm_number = None
142+
if sm_arch is not None:
143+
arch_number = sm_arch.removeprefix("sm_")
144+
if arch_number.endswith(("a", "f")):
145+
arch_number = arch_number[:-1]
146+
sm_number = int(arch_number)
142147
for op in root_block.traverse():
143148
if isinstance(op, TypedConst):
144149
_check_const_value(op)

‎test/test_conditional_arch.py‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# SPDX-FileCopyrightText: Copyright (c) <2026> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
from io import BytesIO
6+
7+
import pytest
8+
9+
import cuda.tile as ct
10+
from cuda.tile._cext import CallingConvention
11+
from cuda.tile._exception import TileUnsupportedFeatureError
12+
13+
14+
def compile_bytecode(pyfunc, arch, version):
15+
kernel = ct.kernel(pyfunc)
16+
sig = ct.compilation.KernelSignature(
17+
[], CallingConvention.cutile_python_v1(), symbol="kernel")
18+
output = BytesIO()
19+
ct.compilation.export_kernel(kernel, [sig], output_file=output, gpu_code=arch,
20+
output_format="tileir_bytecode", bytecode_version=version)
21+
assert output.getvalue()
22+
23+
24+
@pytest.mark.parametrize("arch", ["sm_90", "sm_90a", "sm_100a", "sm_100f", "sm_120a", "sm_121a"])
25+
def test_conditional_arch_dtype_check(arch):
26+
def kernel():
27+
t = ct.full((2,), 1.5, dtype=ct.float32)
28+
ct.printf("%f", t)
29+
30+
compile_bytecode(kernel, arch, "13.2")
31+
32+
33+
@pytest.mark.parametrize("arch", ["sm_90a", "sm_100f"])
34+
def test_conditional_arch_preserves_dtype_limits(arch):
35+
def kernel():
36+
t = ct.full((2,), 1.5, dtype=ct.float8_e5m3fnu)
37+
ct.printf("%f", t)
38+
39+
with pytest.raises(TileUnsupportedFeatureError, match=f"is not supported on {arch}"):
40+
compile_bytecode(kernel, arch, "13.4")
41+
42+
43+
@pytest.mark.parametrize("arch", ["sm_100a", "sm_100f"])
44+
def test_conditional_arch_preserves_bytecode_limits(arch):
45+
def kernel():
46+
t = ct.full((2,), 1.5, dtype=ct.float4_e2m1fn)
47+
ct.printf("%f", t)
48+
49+
with pytest.raises(TileUnsupportedFeatureError,
50+
match=r"float4_e2m1fn requires tileiras 13\.3"):
51+
compile_bytecode(kernel, arch, "13.2")
52+
53+
54+
@pytest.mark.parametrize("arch", ["sm_100aa", "sm_100af", "sm_100ff", "sm_100x"])
55+
def test_conditional_arch_rejects_invalid_suffix(arch):
56+
def kernel():
57+
ct.printf("%d", ct.bid(0))
58+
59+
with pytest.raises(ValueError, match="invalid literal for int"):
60+
compile_bytecode(kernel, arch, "13.2")

0 commit comments

Comments
 (0)