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

Recurse on stride when inlining #733

Merged
merged 2 commits into from
Jan 12, 2023
Merged
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
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