Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler: Fix data dependency issue on dimension-wide WAR #2200

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion devito/ir/support/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,20 @@ def distance(self, other):
else:
v = i - j
if v.is_Number and v.is_finite:
return Vector(S.ImaginaryUnit)
if i.is_Number and j.is_Number:
return Vector(S.ImaginaryUnit)
else:
# For example:
georgebisbas marked this conversation as resolved.
Show resolved Hide resolved
# self=W<u,[0,y]> and other=R<u,[0,y+1]>
ret.append(v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to append Infinite here, otherwise I think we would have never ended up in this place, because we would have never left the first big loop at the top of the method over the iteration intervals

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The equation pair

eq0 = Eq(u[0,y], 1)
eq1 = Eq(u[1,1], u[0, y+1])

would resulting in the execution ending up at line 435

Also I'm confused to why adding an Infinite here would help with never reaching this part of the code


# Writing (reading) over an entire dimension, reading (writing)
# from one point

# For example:
# self=R<u,[1,2]> and other=W<u,[1, y+1]>
elif (not i.is_Number or not j.is_Number):
ret.append(S.Infinity)

return Vector(*ret)

Expand Down
52 changes: 52 additions & 0 deletions tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,6 +1934,58 @@ def test_topofuse_w_numeric_dim(self):

assert_structure(op, ['r,i', 'r'], 'r,i')

@pytest.mark.parametrize('eqns, expected, exp_trees, exp_iters', [
(['Eq(u[0, x], 1)',
'Eq(u[1, x], u[0, x + h_x] + u[0, x - h_x] - 2*u[0, x])'],
np.array([[1., 1., 1.], [-1., 0., -1.]]),
['x', 'x'], 'x,x')
])
def test_2194(self, eqns, expected, exp_trees, exp_iters):
grid = Grid(shape=(3, ))
u = TimeFunction(name='u', grid=grid)
x = grid.dimensions[0]
h_x = x.spacing # noqa: F841

for i, e in enumerate(list(eqns)):
eqns[i] = eval(e)

op = Operator(eqns)
assert_structure(op, exp_trees, exp_iters)

op.apply()
assert(np.all(u.data[:] == expected[:]))

@pytest.mark.parametrize('eqns, expected, exp_trees, exp_iters', [
(['Eq(u[0, y], 1)', 'Eq(u[1, y], u[0, y + 1])'],
np.array([[1., 1.], [1., 0.]]),
['y', 'y'], 'y,y'),
(['Eq(u[0, y], 1)', 'Eq(u[1, y], u[0, 2])'],
np.array([[1., 1.], [0., 0.]]),
['y', 'y'], 'y,y'),
(['Eq(u[0, y], 1)', 'Eq(u[1, y], u[0, 1])'],
np.array([[1., 1.], [1., 1.]]),
['y', 'y'], 'y,y'),
(['Eq(u[0, y], 1)', 'Eq(u[1, y], u[0, y + 1])'],
np.array([[1., 1.], [1., 0.]]),
['y', 'y'], 'y,y'),
(['Eq(u[0, 1], 1)', 'Eq(u[x, y], u[0, y])'],
np.array([[0., 1.], [0., 1.]]),
['xy'], 'x,y')
])
def test_2194_v2(self, eqns, expected, exp_trees, exp_iters):
grid = Grid(shape=(2, 2))
u = Function(name='u', grid=grid)
x, y = grid.dimensions

for i, e in enumerate(list(eqns)):
eqns[i] = eval(e)

op = Operator(eqns)
assert_structure(op, exp_trees, exp_iters)

op.apply()
assert(np.all(u.data[:] == expected[:]))


class TestInternals(object):

Expand Down