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

[TVM][BUGFIX] Fix missing reduction init predicates #2495

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions src/op/compute_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,11 @@ ComputeLoopNest ComputeLoopNest::make(
ret.init_vmap[iv] = ret.main_vmap.at(iv);
}
ret.num_common_loop = begin_loop;
// skip loops that does not relates to axis.
// skip loops that are related to reduction axes.
std::unordered_set<IterVar> skip_iter;
for (auto kv : update_state) {
int flag = kv.second;
if ((flag & 1) == 0) skip_iter.insert(kv.first);
if ((flag & 2) != 0) skip_iter.insert(kv.first);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why not flag == 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, this actually should be flag == 2. Added a test case for this.

ret.init_nest = op::MakeLoopNest(
stage, dom_map, begin_loop, true,
Expand Down
4 changes: 2 additions & 2 deletions src/op/tensor_compute_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ ComputeLoopNest MakeLoopNest(
ret.init_vmap[iv] = ret.main_vmap.at(iv);
}
ret.num_common_loop = begin_loop;
// skip loops that does not relates to axis.
// skip loops that are related to reduction axes.
std::unordered_set<IterVar> skip_iter;
for (auto kv : update_state) {
int flag = kv.second;
if ((flag & 1) == 0) skip_iter.insert(kv.first);
if ((flag & 2) != 0) skip_iter.insert(kv.first);
}
ret.init_nest = op::MakeLoopNest(
stage, dom_map, begin_loop, true,
Expand Down
16 changes: 15 additions & 1 deletion tests/python/unittest/test_schedule_schedule_ops.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tvm

import numpy as np

def test_schedule0():
m = tvm.var('m')
Expand Down Expand Up @@ -432,6 +432,19 @@ def f(n):
s.cache_write(Y, 'local')
f = tvm.build(s, [X, Y])

def test_reduction_and_dummy_fuse_split():
n = 10
X = tvm.placeholder(shape=(10,), dtype='int32', name="X")
k = tvm.reduce_axis((0, n))
Y = tvm.compute((), lambda: tvm.sum(X[k], k), name="Y")
s = tvm.create_schedule([Y.op])
ax = s[Y.op].fuse(*Y.op.axis)
axo, axi = s[Y.op].split(ax, nparts=20)
f = tvm.build(s, [Y, X])

args = [tvm.nd.empty((), 'int32')] + [tvm.ndarray.array(np.ones((n,), dtype='int32'))]
f(*args)
assert args[0].asnumpy() == n

if __name__ == "__main__":
test_loop_dep_reduce()
Expand All @@ -456,3 +469,4 @@ def f(n):
test_schedule_tensor_compute1()
test_schedule_tensor_compute2()
test_schedule_tensor_compute3()
test_reduction_and_dummy_fuse_split()