-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathtest_fission.py
More file actions
145 lines (97 loc) · 4.23 KB
/
test_fission.py
File metadata and controls
145 lines (97 loc) · 4.23 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import numpy as np
from conftest import assert_structure
from devito import (Eq, Inc, Grid, Function, TimeFunction, SubDimension, SubDomain,
Operator, VectorTimeFunction, Buffer, curl, solve)
def test_issue_1725():
class ToyPMLLeft(SubDomain):
name = 'toypmlleft'
def define(self, dimensions):
x, y = dimensions
return {x: x, y: ('left', 2)}
class ToyPMLRight(SubDomain):
name = 'toypmlright'
def define(self, dimensions):
x, y = dimensions
return {x: x, y: ('right', 2)}
subdomains = [ToyPMLLeft(), ToyPMLRight()]
grid = Grid(shape=(20, 20), subdomains=subdomains)
u = TimeFunction(name='u', grid=grid, time_order=2, space_order=2)
eqns = [Eq(u.forward, solve(u.dt2 - u.laplace, u.forward), subdomain=sd)
for sd in subdomains]
op = Operator(eqns, opt='fission')
# Note the `x` loop is fissioned, so now both loop nests can be collapsed
# for maximum parallelism
assert_structure(op, ['t,x,y', 't,x,y'], 't,x,y,x,y')
def test_nofission_as_unprofitable():
"""
Test there's no fission if no increase in number of collapsable loops.
"""
grid = Grid(shape=(20, 20))
x, y = grid.dimensions
t = grid.stepping_dim
yl = SubDimension.left(name='yl', parent=y, thickness=4)
yr = SubDimension.right(name='yr', parent=y, thickness=4)
u = TimeFunction(name='u', grid=grid)
eqns = [Eq(u.forward, u[t + 1, x, y + 1] + 1.).subs(y, yl),
Eq(u.forward, u[t + 1, x, y - 1] + 1.).subs(y, yr)]
op = Operator(eqns, opt='fission')
assert_structure(op, ['t,x,y', 't,x,y'], 't,x,y,y')
def test_nofission_as_illegal():
"""
Test there's no fission if dependencies would break.
"""
grid = Grid(shape=(20, 20))
x, y = grid.dimensions
f = Function(name='f', grid=grid, dimensions=(y,), shape=(20,))
u = TimeFunction(name='u', grid=grid)
v = TimeFunction(name='v', grid=grid)
eqns = [Inc(f, v + 1.),
Eq(u.forward, f[y + 1] + 1.)]
op = Operator(eqns, opt='fission')
assert_structure(op, ['t,x,y', 't,x,y'], 't,x,y,y')
def test_fission_partial():
"""
Test there's no fission if no increase in number of collapsable loops.
"""
grid = Grid(shape=(20, 20))
x, y = grid.dimensions
t = grid.stepping_dim
yl = SubDimension.left(name='yl', parent=y, thickness=4)
yr = SubDimension.right(name='yr', parent=y, thickness=4)
u = TimeFunction(name='u', grid=grid)
eqns = [Eq(u.forward, u[t + 1, x, y + 1] + 1.).subs(y, yl),
Eq(u.forward, u[t + 1, x, y - 1] + 1.).subs(y, yr),
Eq(u.forward, u[t + 1, x, y] + 1.)]
op = Operator(eqns, opt='fission')
assert_structure(op, ['t,x,y', 't,x,y', 't,x,y'], 't,x,y,y,x,y')
def test_issue_1921():
space_order = 4
grid = Grid(shape=(8, 8), dtype=np.int32)
f = Function(name='f', grid=grid, space_order=space_order)
g = TimeFunction(name='g', grid=grid, space_order=space_order)
g1 = TimeFunction(name='g', grid=grid, space_order=space_order)
f.data[:] = np.arange(8*8).reshape((8, 8))
t, x, y = g.dimensions
ymin = y.symbolic_min
eqns = []
eqns.append(Eq(g.forward, f + g))
for i in range(space_order//2):
eqns.append(Eq(g[t+t.spacing, x, ymin-i], g[t+t.spacing, x, ymin+i]))
op0 = Operator(eqns)
op1 = Operator(eqns, opt='fission')
assert_structure(op1, ['t,x,y', 't,x'], 't,x,y,x')
op0.apply(time_m=1, time_M=5)
op1.apply(time_m=1, time_M=5, g=g1)
assert np.all(g.data == g1.data)
def test_fission_largest_cluster():
grid = Grid(shape=(10, 10, 10))
x, y, z = grid.dimensions
A = VectorTimeFunction(name='A', grid=grid, save=Buffer(1), space_order=2,
time_order=1, staggered=(x, y, z))
B = VectorTimeFunction(name='B', grid=grid, save=Buffer(1), space_order=2,
time_order=1, staggered=((y, z), (x, z), (x, y)))
f = Function(name='f', grid=grid, space_order=2)
eqs = [Eq(B.forward, solve(Eq(curl(A), -B.dt), B.forward)),
Eq(A.forward, solve(Eq(curl(B.forward), f*A.dt), A.forward))]
op = Operator(eqs, opt='fission')
assert_structure(op, ['t,x,y,z', 't,x,y,z'], 't,x,y,z,x,y,z')