Possibility to align a split. - #9371
Conversation
Co-authored-by: Andrew Adams <andrew.b.adams@gmail.com>
… conceptual stmt'
…alled/deadlocked several times but couldn't debug it.
|
Could you provide an example where the starting loop is not already aligned in absolute coordinates? In your example before case it's aligned to zero. Also, how do aligned splits interact with rfactor? It has to enact any relevant splits eagerly. Hopefully rfactor tolerates this as-is, but some adding some rfactor test cases that use aligned splits is probably a good idea. |
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: Gemini Pro 3.1 <gemini@aistudio.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
… those blend operations in case of aligned splits. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Fix old copy-paste bug in simplifier rules. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The starting loop is aligned in absolute coordinates. The problem is that the split() always rebases the inner and outer loop to zero. So your original loop was aligned (before rebase loops to zero lowering pass), but the initial scheduling rewrites the aligned loop by a split into two non-aligned loops. That happens here (notice Line 29 in 5c21c82 and Lines 176 to 181 in 5c21c82 |
Opening PR to show off, and gather feedback and enter discussion.
Instead of splitting a loop where the rewritten inner and outer loop always start at 0, like this:
It's now possible to align the first iteration of the inner loop, like so:
This allows you to then unroll or vectorize the inner loop with a known alignment (modulo).
This comes up when demosaicing Bayer images where the offset of the filter pattern (CFA) is not known up front. Instead of compiling 4 different specializations of this pipeline with all for possible offsets, you can now pass in the CFA-offset as a runtime
Param<int>:Alternative considered
After a very lengthy discussion with @abadams I attempted to implement a
.guard_with_if()directive that would combine orthogonally with.align_bounds(). However, align bounds changes the bounds during bounds inference phase. The initial idea of "fixing" the widend bounds was to protect it with an if (henceguard_with_if()). However, what the if is supposed to do is to guard against out-of-bounds accesses, butalign_bounds()actually changes the bounds, so there is nothing to protect against. For more details, see #9357.While implementing this, the number of things that broke, missing simplifier rules to make it work, new behavior required in BoundsInference, BoundConstantExtentLoops, SlidingWindow was not pretty. While I think I got all of this working correctly in
mcourteaux/guard-with-if, it is fundamentally backwards-incompatible because.align_bounds()is meant to change the size of the bounds (and impose constraints on it): it extends the computed region. Combining it with aShiftInwards, orguard_with_if()again shrinks the computed region. There were several tests depending on the widening behavior ofalign_bounds().Breaking changes
None, it's a new feature that isn't used anywhere.
If we can agree this is a good idea, I'll keep working on this to get it with the necessary documentation, tutorial, serialization, python bindings.
Checklist
As I said, checklist to be completed if others greenlight this.