Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check that PredicateLoads must be used in the outermost split of a dimension #7788

Merged
merged 9 commits into from
Sep 5, 2023

Conversation

TH3CHARLie
Copy link
Contributor

Fixes #7764

From the above issue, we found out that using PredicateLoads in inner splits will write zeros to the tail region of the middle loop, but these tail regions overlap the valid region of the next outer loop iteration, so valid data may be overwritten with zeros.

We can't prove the safety of using PredicateLoads in these cases, so in this PR we introduce a check that disallows such behavior. PredicateLoads must be in the outermost split of a dimension.

This could potentially be a big change since it makes the valid scheduling space smaller and may impact existing Halide programs ("valid" -> invalid). so cc @steven-johnson @abadams @derek-gerstmann

@steven-johnson steven-johnson added the release_notes For changes that may warrant a note in README for official releases. label Aug 21, 2023
@steven-johnson
Copy link
Contributor

may impact existing Halide programs ("valid" -> invalid)

...except that the ones that would be affected weren't actually ever valid in the first place, since they may be subject to data overwriting. Breaking existing code in the name of fixing safety/correctness issue is always on the table, IMHO (and in this case, probably unavoidable).

(Tagging with release_notes since this is clearly something to note for next release)

@steven-johnson
Copy link
Contributor

(I'm going to go ahead and test this inside google)

@TH3CHARLie
Copy link
Contributor Author

...except that the ones that would be affected weren't actually ever valid in the first place, since they may be subject to data overwriting. Breaking existing code in the name of fixing safety/correctness issue is always on the table, IMHO (and in this case, probably unavoidable).

That's why I double quoted "valid" : D

src/Func.cpp Outdated Show resolved Hide resolved
@steven-johnson
Copy link
Contributor

Failures are unrelated, ready to land

@steven-johnson steven-johnson requested a review from abadams August 24, 2023 22:17
@TH3CHARLie
Copy link
Contributor Author

how does this affect the code inside Google? (if allowed to share at all lol)

@steven-johnson
Copy link
Contributor

Not sure yet, need to run a test to find out :-)

@steven-johnson
Copy link
Contributor

Testing in google looks good so far, stand by

@steven-johnson
Copy link
Contributor

Testing in google showed zero failures, good to land

@@ -1090,6 +1090,36 @@ void Stage::split(const string &old, const string &outer, const string &inner, c
<< "Use TailStrategy::GuardWithIf instead.";
}

bool predicate_loads_ok = !exact;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think PredicateLoads might actually be legal when exact is true. Let's discuss offline.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, exact is when you're splitting an rvar, which may scatter, so it's not legal to use PredicateLoads because it may scatter garbage values.

Copy link
Contributor Author

@TH3CHARLie TH3CHARLie Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which means we keep this line and the check?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends which error message we want to trigger first. I guess we want the second one to trigger, because the first one says "you can't use PredicateLoads on this Var in this way", and the second says "you can't use PredicateLoads on this Var at all". So keep this line and the check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reflected, I think the PR is now ready to land

src/Func.cpp Show resolved Hide resolved
@TH3CHARLie
Copy link
Contributor Author

Failures seem unrelated, ready to land?

@abadams abadams merged commit 02865e2 into halide:main Sep 5, 2023
@TH3CHARLie TH3CHARLie deleted the xuanda/fix-7764 branch September 5, 2023 21:02
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
…f a dimension (halide#7788)

* add a check that PredicateLoads must be used in the outermost split of a dimension

* newline

* use the repro example

* fix

* avoid check for every other tail strategy

* update error message to point out what's not allowed

---------

Co-authored-by: Steven Johnson <srj@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_notes For changes that may warrant a note in README for official releases.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PredicateLoads produces wrong results when inner split is larger than the outer split factor
3 participants