Skip to content

Add explicit slide directive and ability to slide over split loops - #9633

Draft
abadams wants to merge 14 commits into
abadams/sliding_window_rewritefrom
abadams/slide_directive
Draft

abadams wants to merge 14 commits into
abadams/sliding_window_rewritefrom
abadams/slide_directive

Conversation

@abadams

@abadams abadams commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Sliding window has numerous bugs relating to the interaction between the two kinds of sliding (loop unwinding vs adding selects). One known one was #8140 , but there were more. This PR adds a fuzzer for sliding window schedules and rewrites the sliding window pass to pass the fuzz tests. For review it's probably easier to just read the new version of the file, rather than looking at diffs. Several rounds of refactoring were done to try to make it easier to understand.

Separately, sliding window has long had an annoying limitation. When sliding and folding are combined, you get modulos due to the circular buffers. One might like to remove these modulos by unrolling the loop by the same factor, but if you do this you just get a different modulo, because sliding and folding can only slide over either the outer loop or the inner loop, not the loop you just split. This PR adds Func::slide, which lets you slide over a named Var, even if that Var has been split. For example, this is legal:

consumer.split(x, xo, xi, 8, TailStrategy::RoundUp).split(xo, xoo, xoi, 8, TailStrategy::RoundUp);
producer.store_root().compute_at(consumer, xi).slide(consumer, xo);

The producer can slide over xo, which is a transient loop that only existed in the middle of the chain of splits. It does this by jointly considering the loops it was split into - xoo and xoi. These loops must still appear in the schedule in order with no other loops in between. More commonly you would slide the producer over x - one of the original Vars. Using this directive lets you slide over x and also unroll the consumer's loop over x without changing the meaning of the slide.

This change is necessary for inductive Funcs (#8878) to be truly useful, because those rely critically on sliding window working well.

I can break this into two PRs if helpful. However Func::slide required a rewrite on top of the rewrite already done to fix the bugs, and I don't want to ask reviewers to review two rewrites of the same code. I would construct the stack by deleting the new feature from this branch, which might make some of the changes look pointless.

EDIT: Broken into multiple PRs. This one now just adds the slide directive and the ability to slide over spit loops. It is stacked on the rewrite and fuzzer.

@mcourteaux

Copy link
Copy Markdown
Contributor

Can this address #9375 ?

@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.81925% with 62 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.99%. Comparing base (def6072) to head (b314916).

Files with missing lines Patch % Lines
src/StorageFolding.cpp 75.23% 13 Missing and 13 partials ⚠️
src/ScheduleFunctions.cpp 87.79% 12 Missing and 9 partials ⚠️
src/SlidingWindow.cpp 92.82% 3 Missing and 12 partials ⚠️
Additional details and impacted files
@@                        Coverage Diff                         @@
##           abadams/sliding_window_rewrite    #9633      +/-   ##
==================================================================
+ Coverage                           72.92%   72.99%   +0.07%     
==================================================================
  Files                                 267      267              
  Lines                               83864    84273     +409     
  Branches                            20615    20720     +105     
==================================================================
+ Hits                                61156    61517     +361     
- Misses                              16256    16264       +8     
- Partials                             6452     6492      +40     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Func::slide(consumer, var) names a dimension of a consumer to slide
along, rather than leaving sliding window to pick a loop. The dimension
may have been split, in which case it has no loop of its own, only a
let built from the loops it was split into. Sliding and storage folding
both work over such a let as well as over a loop, warming up by
rewinding the outermost loop the dimension is built from.

Schedule validation checks that a slid dimension steps through its
values in order (serial, adjacent loops with constant split factors and
no tail except on the outermost), that the storage lives outside every
loop the dimension spans, and that the Func is computed inside them.

The sliding window fuzzer sometimes names y, which is split, or both x
and y.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@abadams
abadams changed the base branch from main to abadams/sliding_window_rewrite November 3, 2026 19:36
@abadams
abadams added this pull request to stack #9659 November 3, 2026 19:38
@abadams abadams changed the title Overhaul sliding window; add explicit slide directive Add explicit slide directive and ability to slide over split loops Nov 3, 2026
abadams and others added 9 commits November 4, 2026 11:59
DerivativeBounds only handled a Mul whose other operand was constant and
a Div by a constant. Use constant_integer_bounds on a var-independent
factor or denominator so that e.g. x / max(k, 1) is recognized as
monotonic increasing. This lets sliding window slide over such
footprints.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ctive

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A Func told to slide over a dimension silently computed its whole
region on every iteration if the window couldn't actually slide there.
Make that a user error that says why.

The fuzzer now only asks for slides that are possible: the region
required has to move with exactly the dimension named, every consumer
has to read more than one value along it, no update can scatter along
it, and no consumer stored outside the loops it is split into may slide
over those loops first. Its piecewise-affine coordinate with two slopes
is now written as a max, which bounds inference handles precisely.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ctive

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…irective

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ctive

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ctive

# Conflicts:
#	src/SlidingWindow.cpp
#	test/correctness/sliding_window.cpp
A slide over a dimension built from split loops, where the Func is
computed outside one of those loops, used to be silently ignored. It is
now a user error that suggests sliding over the outer loop instead, or
computing the Func at or inside the inner one. Lowering can now assume
that the producer is always inside every loop its dimension is built
from.

Also tests a named slide through a specialized consumer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Each schedule now aims to slide over y, over x and y, or in registers,
and the fuzzer checks that every slid producer stores no more than its
exact footprint plus the warm-up, so it catches slides that silently
fail to happen or that recompute.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@abadams
abadams marked this pull request as draft November 5, 2026 21:07

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants