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

Strip asserts right at the end of lowering #8094

Merged
merged 1 commit into from
Feb 15, 2024
Merged

Conversation

abadams
Copy link
Member

@abadams abadams commented Feb 13, 2024

The simplifier exploits asserts to make simplifications. When compiling with NoAsserts, certain assertions aren't ever introduced, which means that the simplifier can't exploit certain things that we know to be true. Mostly this has a negative effect on code size. E.g. tail cases get generated even though they are actually dead code.

This PR keeps all the assertions right until the end of lowering, when it strips them in a dedicated pass.

This reduces object file size for a large production blob of Halide code by ~10%, without measurably affecting runtime.

The simplifier exploits asserts to make simplification. When compiling
with NoAsserts, certain assertions aren't ever introduced, which means
that the simplifier can't exploit certain things that we know to be
true. Mostly this has a negative effect on code size. E.g. tail cases
get generated even though they are actually dead code.

This PR keeps all the assertions right until the end of lowering, when
it strips them in a dedicated pass.

This reduces object file size for a large production blob of Halide code
by ~10%, without measurably affecting runtime.
@zvookin
Copy link
Member

zvookin commented Feb 14, 2024

I expect we'll need to make sure this doesn't introduce any failures in our large codebase before it lands.

@steven-johnson
Copy link
Contributor

To be clear, this shouldn't affect code that isn't compiled with NoAsserts (ie. the vast majority of code), right?

Copy link
Contributor

@steven-johnson steven-johnson left a comment

Choose a reason for hiding this comment

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

LGTM but will test in google3 before we land

@@ -427,6 +428,12 @@ void lower_impl(const vector<Function> &output_funcs,
s = hoist_prefetches(s);
log("Lowering after hoisting prefetches:", s);

if (t.has_feature(Target::NoAsserts)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding comment from the PR about why we do this at the end

@abadams
Copy link
Member Author

abadams commented Feb 14, 2024

To be clear, this shouldn't affect code that isn't compiled with NoAsserts (ie. the vast majority of code), right?

That's correct. This should have no effect on regular assert-using Halide code.

@steven-johnson
Copy link
Contributor

No related failures yet, going to run an all-of-google test just to be sure

Copy link
Contributor

@steven-johnson steven-johnson left a comment

Choose a reason for hiding this comment

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

Ready to land.

@abadams abadams merged commit 2855ca3 into main Feb 15, 2024
19 checks passed
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.

3 participants