Skip to content

Commit 8873d39

Browse files
abadamsclaude
andauthored
Fix internal error sliding through a compute_with-fused loop (#9149)
AddLoopMinOrig referred to a Variable("<loop>.loop_min") for the value of its .loop_min.orig let. For loops renamed by compute_with's substitute_fused_bounds, no .loop_min let exists under the fused name, so sliding window emitted references to a non-existent symbol and codegen failed with "Symbol not found: ...fused...loop_min". Use the loop's min expression directly instead. Also fix a pre-existing oversight in apps/harris/Makefile where \$(GENERATOR_OUTPUTS) was not passed to the generator. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3bb5d0c commit 8873d39

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

apps/harris/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ $(GENERATOR_BIN)/harris.generator: harris_generator.cpp $(GENERATOR_DEPS)
1010

1111
$(BIN)/%/harris.a: $(GENERATOR_BIN)/harris.generator
1212
@mkdir -p $(@D)
13-
$< -g harris -f harris -o $(BIN)/$* target=$*-no_runtime
13+
$< -g harris -f harris -e $(GENERATOR_OUTPUTS) -o $(BIN)/$* target=$*-no_runtime
1414

1515
$(BIN)/%/harris_auto_schedule.a: $(GENERATOR_BIN)/harris.generator
1616
@mkdir -p $(@D)
17-
$< -g harris -f harris_auto_schedule -o $(BIN)/$* target=$*-no_runtime autoscheduler=Mullapudi2016
17+
$< -g harris -f harris_auto_schedule -e $(GENERATOR_OUTPUTS) -o $(BIN)/$* target=$*-no_runtime autoscheduler=Mullapudi2016
1818

1919
$(BIN)/%/runtime.a: $(GENERATOR_BIN)/harris.generator
2020
@mkdir -p $(@D)

src/SlidingWindow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ class SlidingWindow : public IRMutator {
901901
};
902902

903903
// It is convenient to be able to assume that loops have a .loop_min.orig
904-
// let in addition to .loop_min. Most of these will get simplified away.
904+
// let giving the original loop min. Most of these will get simplified away.
905905
class AddLoopMinOrig : public IRMutator {
906906
using IRMutator::visit;
907907

@@ -916,7 +916,7 @@ class AddLoopMinOrig : public IRMutator {
916916
} else {
917917
result = For::make(op->name, min, max, op->for_type, op->partition_policy, op->device_api, body);
918918
}
919-
return LetStmt::make(op->name + ".loop_min.orig", Variable::make(Int(32), op->name + ".loop_min"), result);
919+
return LetStmt::make(op->name + ".loop_min.orig", op->min, result);
920920
}
921921
};
922922

test/correctness/sliding_window.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,28 @@ int main(int argc, char **argv) {
393393
}
394394
}
395395

396+
{
397+
// Sliding a producer along the outer loop of a pair of outputs fused
398+
// together with compute_with. Previously triggered an internal compiler
399+
// error referencing a missing .loop_min symbol on the fused loop.
400+
count = 0;
401+
Func f, g1, g2;
402+
f(x, y) = call_counter(x, y);
403+
g1(x, y) = f(x, y - 1) + f(x, y + 1);
404+
g2(x, y) = f(x, y - 1) - f(x, y + 1);
405+
406+
f.store_root().compute_at(g1, y);
407+
g2.compute_with(g1, x);
408+
409+
Pipeline({g1, g2}).realize({10, 10});
410+
411+
// f spans y in [-1, 10], so 12 rows of 10 = 120 calls when slid.
412+
if (count != 120) {
413+
printf("f was called %d times instead of %d times\n", count, 120);
414+
return 1;
415+
}
416+
}
417+
396418
printf("Success!\n");
397419
return 0;
398420
}

0 commit comments

Comments
 (0)