-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathtest_bytecode_version_compat.py
More file actions
89 lines (65 loc) · 2.93 KB
/
test_bytecode_version_compat.py
File metadata and controls
89 lines (65 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# SPDX-FileCopyrightText: Copyright (c) <2026> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
from io import BytesIO
import pytest
import torch
import cuda.tile as ct
from cuda.tile._compile import get_sm_arch
from cuda.tile._exception import TileUnsupportedFeatureError
from cuda.tile._numeric_semantics import RoundingMode
from cuda.tile.compilation import CallingConvention, KernelSignature
def compile_with_version(kernel, args, version: str):
cconv = CallingConvention.cutile_python_v1()
sig = KernelSignature.from_kernel_args(kernel, args, cconv)
ct.compilation.export_kernel(kernel, [sig], output_file=BytesIO(),
gpu_code=get_sm_arch(), output_format="cubin",
bytecode_version=version)
def tensor(dtype=torch.float32):
return torch.zeros(64, dtype=dtype, device='cuda')
def test_atan2_requires_13_2():
@ct.kernel
def kernel(x, y, z):
tx = ct.load(x, 0, shape=64)
ty = ct.load(y, 0, shape=64)
ct.store(z, 0, tile=ct.atan2(tx, ty))
with pytest.raises(TileUnsupportedFeatureError, match=r"atan2 requires tileiras 13\.2"):
compile_with_version(kernel, (tensor(), tensor(), tensor()), "13.1")
def test_tanh_rounding_mode_requires_13_2():
@ct.kernel
def kernel(x, y):
tx = ct.load(x, 0, shape=64)
ct.store(y, 0, tile=ct.tanh(tx, rounding_mode=RoundingMode.APPROX))
with pytest.raises(TileUnsupportedFeatureError,
match=r"tanh rounding_mode=approx requires tileiras 13\.2"):
compile_with_version(kernel, (tensor(), tensor()), "13.1")
def test_tanh_without_rounding_mode_works_on_13_1():
@ct.kernel
def kernel(x, y):
tx = ct.load(x, 0, shape=64)
ct.store(y, 0, tile=ct.tanh(tx))
# Should not raise version error
compile_with_version(kernel, (tensor(), tensor()), "13.1")
def test_exp_rounding_mode_requires_13_3():
@ct.kernel
def kernel(x, y):
tx = ct.load(x, 0, shape=64)
ct.store(y, 0, tile=ct.exp(tx, rounding_mode=RoundingMode.APPROX))
with pytest.raises(TileUnsupportedFeatureError,
match=r"exp rounding_mode=approx requires tileiras 13\.3"):
compile_with_version(kernel, (tensor(), tensor()), "13.2")
def test_exp_without_rounding_mode_works_on_13_1():
@ct.kernel
def kernel(x, y):
tx = ct.load(x, 0, shape=64)
ct.store(y, 0, tile=ct.exp(tx))
# Should not raise version error
compile_with_version(kernel, (tensor(), tensor()), "13.1")
def test_num_worker_warps_warns_below_13_3():
@ct.kernel(num_worker_warps=8)
def kernel(x, y):
tx = ct.load(x, 0, shape=64)
ct.store(y, 0, tile=tx)
match = r"num_worker_warps is ignored: requires tileiras 13\.3, but current version is 13\.1"
with pytest.warns(UserWarning, match=match):
compile_with_version(kernel, (tensor(), tensor()), "13.1")