test_gufunc_scheduling.py 2.62 KB
Newer Older
dugupeiwen's avatar
dugupeiwen committed
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
90
91
92
93
94
95
from numba.np.ufunc.deviceufunc import GUFuncEngine
import unittest


def template(signature, shapes, expects):
    gufb = GUFuncEngine.from_signature(signature)
    sch = gufb.schedule(shapes)
    for k, v in expects.items():
        got = getattr(sch, k)
        if got != v:
            fmt = 'error for %s: got=%s but expect=%s'
            raise AssertionError(fmt % (k, got, v))


class TestGUFuncScheduling(unittest.TestCase):
    def test_signature_1(self):
        signature = '(m, n), (n, p) -> (m, p)'
        shapes = (100, 4, 5), (1, 5, 7)
        expects = dict(
            ishapes=[(4, 5), (5, 7)],
            oshapes=[(4, 7)],
            loopdims=(100,),
            pinned=[False, True]
        )
        template(signature, shapes, expects)

    def test_signature_2(self):
        signature = '(m, n), (n, p) -> (m, p)'
        shapes = (100, 4, 5), (100, 5, 7)
        expects = dict(
            ishapes=[(4, 5), (5, 7)],
            oshapes=[(4, 7)],
            loopdims=(100,),
            pinned=[False, False]
        )
        template(signature, shapes, expects)

    def test_signature_3(self):
        signature = '(m, n), (n, p) -> (m, p)'
        shapes = (12, 34, 4, 5), (12, 34, 5, 7)
        expects = dict(
            ishapes=[(4, 5), (5, 7)],
            oshapes=[(4, 7)],
            loopdims=(12, 34),
            pinned=[False, False]
        )
        template(signature, shapes, expects)

    def test_signature_4(self):
        signature = '(m, n), (n, p) -> (m, p)'
        shapes = (4, 5), (5, 7)
        expects = dict(
            ishapes=[(4, 5), (5, 7)],
            oshapes=[(4, 7)],
            loopdims=(),
            pinned=[False, False]
        )
        template(signature, shapes, expects)

    def test_signature_5(self):
        signature = '(a), (a) -> (a)'
        shapes = (5,), (5,)
        expects = dict(
            ishapes=[(5,), (5,)],
            oshapes=[(5,)],
            loopdims=(),
            pinned=[False, False]
        )
        template(signature, shapes, expects)

    def test_signature_6(self):
        signature = '(), () -> ()'
        shapes = (5,), (5,)
        expects = dict(
            ishapes=[(), ()],
            oshapes=[()],
            loopdims=(5,),
            pinned=[False, False]
        )
        template(signature, shapes, expects)

    def test_signature_7(self):
        signature = '(), () -> ()'
        shapes = (5,), ()
        expects = dict(
            ishapes=[(), ()],
            oshapes=[()],
            loopdims=(5,),
            pinned=[False, True]
        )
        template(signature, shapes, expects)


if __name__ == '__main__':
    unittest.main()