Skip to content

Commit

Permalink
Consider all dimensions before deciding to slide over a new dimension (
Browse files Browse the repository at this point in the history
…#7875)

* Don't deduce unreachability from predicated out of bounds stores

Fixes #7873

* Consider all dimensions before deciding to slide over a new dimension

Even ones we've already slid over. The previous version of this code
could try to slide over a loop where multiple dimensions depend on the
loop var, because it ignored dimensions that had already been slid over.
Moving a check resolves the issue.

Fixes #7872
  • Loading branch information
abadams authored Oct 5, 2023
1 parent 51ab364 commit 120e5fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/SlidingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,6 @@ class SlidingWindowOnFunctionAndLoop : public IRMutator {
string prefix = func.name() + ".s" + std::to_string(func.updates().size()) + ".";
const std::vector<string> func_args = func.args();
for (int i = 0; i < func.dimensions(); i++) {
if (slid_dimensions.count(i)) {
debug(3) << "Already slid over dimension " << i << ", so skipping it.\n";
continue;
}
// Look up the region required of this function's last stage
string var = prefix + func_args[i];
internal_assert(scope.contains(var + ".min") && scope.contains(var + ".max"));
Expand Down Expand Up @@ -304,6 +300,12 @@ class SlidingWindowOnFunctionAndLoop : public IRMutator {
}
}

if (!dim.empty() && slid_dimensions.count(dim_idx)) {
debug(1) << "Already slid over dimension " << dim_idx << ", so skipping it.\n";
dim = "";
min_required = Expr();
max_required = Expr();
}
if (!min_required.defined()) {
debug(3) << "Could not perform sliding window optimization of "
<< func.name() << " over " << loop_var << " because multiple "
Expand Down
22 changes: 22 additions & 0 deletions test/correctness/fuzz_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ int main(int argc, char **argv) {
check_blur_output(buf, correct);
}

// https://github.com/halide/Halide/issues/7872
{
Func input("input");
Func local_sum("local_sum");
Func blurry("blurry");
Var x("x"), y("y");
RVar yryf;
input(x, y) = 2 * x + 5 * y;
RDom r(-2, 5, -2, 5, "rdom_r");
local_sum(x, y) = 0;
local_sum(x, y) += input(x + r.x, y + r.y);
blurry(x, y) = cast<int32_t>(local_sum(x, y) / 25);
Var xo, xi;
blurry.split(x, xo, xi, 2, TailStrategy::GuardWithIf);
local_sum.store_at(blurry, y).compute_at(blurry, xi);
// local_sum.store_root();
blurry.bound(y, 0, 1);
Pipeline p({blurry});
Buffer<int> buf = p.realize({4, 1});
check_blur_output(buf, correct);
}

printf("Success!\n");

return 0;
Expand Down

0 comments on commit 120e5fd

Please sign in to comment.