Skip to content

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

Open
abadams wants to merge 1 commit into
abadams/sliding_window_rewritefrom
abadams/slide_directive
Open

abadams wants to merge 1 commit 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 86.54709% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.10%. Comparing base (76a9d57) to head (75ca864).

Files with missing lines Patch % Lines
src/StorageFolding.cpp 75.00% 13 Missing and 12 partials ⚠️
src/SlidingWindow.cpp 91.30% 4 Missing and 14 partials ⚠️
src/ScheduleFunctions.cpp 85.34% 10 Missing and 7 partials ⚠️
Additional details and impacted files
@@                        Coverage Diff                         @@
##           abadams/sliding_window_rewrite    #9633      +/-   ##
==================================================================
+ Coverage                           72.84%   73.10%   +0.25%     
==================================================================
  Files                                 266      266              
  Lines                               83414    83762     +348     
  Branches                            20496    20585      +89     
==================================================================
+ Hits                                60765    61232     +467     
+ Misses                              16175    16149      -26     
+ Partials                             6474     6381      -93     

☔ 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

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