forked from StrongSpoon/tvm.schedule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_inline.py
32 lines (25 loc) · 888 Bytes
/
compute_inline.py
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
import tvm
n = 1024
k = 3
pad = 2
A = tvm.placeholder((n, n), name='A')
W = tvm.placeholder((k, k), name='W')
m = (n - k + 2 * pad) + 1
Apad = tvm.compute((n + 2 * pad, n + 2 * pad),
lambda yy, xx: tvm.if_then_else(
tvm.all(yy >= pad, yy < pad + n, xx >= pad, xx < pad + n),
A[yy - pad, xx - pad], tvm.const(0., "float32")),
name='Apad')
ry = tvm.reduce_axis((0, k), name='ry')
rx = tvm.reduce_axis((0, k), name='rx')
B = tvm.compute((m, m),
lambda yy, xx:
tvm.sum(Apad[yy + ry, xx + rx] * W[ry, rx],
axis=[ry, rx]),
name='B')
s = tvm.create_schedule(B.op)
print(tvm.lower(s, [A, W, B], simple_mode=True))
print("---------cutting line---------")
s[Apad].compute_inline()
print(tvm.lower(s, [A, W, B], simple_mode=True))
exit(0)