|
| 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