Skip to content

Commit

Permalink
Recurse on stride when inlining (inducer#733)
Browse files Browse the repository at this point in the history
* Recurse on stride when inlining

* Add issue link to test_inline_stride

Co-authored-by: Andreas Klöckner <[email protected]>
  • Loading branch information
isuruf and inducer committed Jan 14, 2023
1 parent b1a0973 commit a7432a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion loopy/transform/callable.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def map_subscript(self, expr, expn_state):
flatten_index += idx*caller_arg.dim_tags[i].stride

flatten_index += sum(
idx * tag.stride
idx * self.rec(tag.stride, expn_state)
for idx, tag in zip(self.rec(expr.index_tuple, expn_state),
callee_arg.dim_tags))

Expand Down
26 changes: 26 additions & 0 deletions test/test_callables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,32 @@ def test_inline_deps(ctx_factory):
assert np.array_equal(a_dev.get(), np.arange(4))


def test_inline_stride():
# https://github.com/inducer/loopy/issues/728
child_knl = lp.make_function(
[],
"""
g[0] = 2*e[0] + 3*f[0] {id=a}
g[1] = 2*e[1] + 3*f[1] {dep=a}
""", name="linear_combo")
parent_knl = lp.make_kernel(
["{[j]:0<=j<n}", "{[i]:0<=i<n}"],
"""
[i]: z[i, j] = linear_combo([i]: x[i, j], [i]: y[i,j])
""",
kernel_data=[
lp.GlobalArg(
name="x, y, z",
dtype=np.float64,
shape=("n", "n")),
...],
assumptions="n>=1",
)
knl = lp.merge([parent_knl, child_knl])
knl = lp.inline_callable_kernel(knl, "linear_combo")
lp.generate_code_v2(knl).device_code()


if __name__ == "__main__":
if len(sys.argv) > 1:
exec(sys.argv[1])
Expand Down

0 comments on commit a7432a0

Please sign in to comment.