-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathtest_unpacking.py
More file actions
42 lines (34 loc) · 1.14 KB
/
test_unpacking.py
File metadata and controls
42 lines (34 loc) · 1.14 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
# SPDX-FileCopyrightText: Copyright (c) <2026> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
import pytest
import torch.cuda
import cuda.tile as ct
from cuda.tile import TileValueError
def test_too_few_values_to_unpack():
@ct.kernel
def kernel():
t = 1, 2
a, b, c = t
with pytest.raises(TileValueError, match="Too few values to unpack"):
ct.launch(torch.cuda.current_stream(), (1,), kernel, ())
def test_too_many_values_to_unpack():
@ct.kernel
def kernel():
t = 1, 2, 3
a, b = t
with pytest.raises(TileValueError, match="Too many values to unpack"):
ct.launch(torch.cuda.current_stream(), (1,), kernel, ())
def test_unpack_nested_tuple():
@ct.kernel
def kernel(x):
t = (1, (2, 3, 4)), 5
[(a, [b, c, d]), e] = t
ct.scatter(x, 0, a)
ct.scatter(x, 1, b)
ct.scatter(x, 2, c)
ct.scatter(x, 3, d)
ct.scatter(x, 4, e)
x = torch.zeros((5,), dtype=torch.int32, device="cuda")
ct.launch(torch.cuda.current_stream(), (1,), kernel, (x,))
assert x.tolist() == [1, 2, 3, 4, 5]