-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add change_type() directive with reduction-aware overflow checks #9257
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
Merged
+2,364
−47
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8754a09
Add change_type() directive with reduction-aware overflow checks
alexreinking db74af9
Add tests for change_type() directive
alexreinking 953d72e
Fix change_type soundness checks
alexreinking f9a24ff
Refactor get_associative_identity
alexreinking 02ff163
Appease clang-tidy
alexreinking 054bdda
Add narrow-blocks test
alexreinking 437e957
Drop stale TODO
alexreinking fc5af09
Serialize type-change checks
alexreinking 10a47a0
Address review: check float change_type() targets for exactness
alexreinking f72bf43
Add follow_global_wrappers arguments
alexreinking 8a3b4f7
Address review: thread FuncValueBounds through lossless_cast/constant…
alexreinking c2da8c6
Implement covering_constant_interval with constant_integer_bounds
alexreinking 232c410
Improve comment on int-to-float cast-stripping
alexreinking 46279db
Make retype_value not-recursive, clarify comment.
alexreinking e5e7aa7
Drop impossible uint case for RVar extent
alexreinking eff2cef
Use Op::make rather than Op's operator overload
alexreinking 7c1854e
Clarify comment for nonempty_dense_update_precondition
alexreinking 9aff833
Add TODO for saturating_add/sub
alexreinking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include "AddTypeChangeChecks.h" | ||
| #include "Function.h" | ||
| #include "IR.h" | ||
| #include "IROperator.h" | ||
| #include "Schedule.h" | ||
| #include "Simplify.h" | ||
|
|
||
| namespace Halide { | ||
| namespace Internal { | ||
|
|
||
| Stmt add_type_change_checks(const Stmt &s, const std::map<std::string, Function> &env) { | ||
| std::vector<Stmt> stmts; | ||
|
|
||
| for (const auto &p : env) { | ||
| const Function &f = p.second; | ||
| for (const auto &[condition, message] : f.schedule().type_change_checks()) { | ||
| if (!condition.defined()) { | ||
| continue; | ||
| } | ||
| Expr proven = simplify(condition); | ||
| if (is_const_one(proven)) { | ||
| // Statically proven; no runtime check needed. | ||
| continue; | ||
| } | ||
| Expr error = requirement_failed_error(condition, {Expr(message)}); | ||
| stmts.push_back(AssertStmt::make(condition, error)); | ||
| } | ||
| } | ||
|
|
||
| stmts.push_back(s); | ||
| return Block::make(stmts); | ||
| } | ||
|
|
||
| } // namespace Internal | ||
| } // namespace Halide |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #ifndef HALIDE_ADD_TYPE_CHANGE_CHECKS_H | ||
| #define HALIDE_ADD_TYPE_CHANGE_CHECKS_H | ||
|
|
||
| /** \file | ||
| * Defines the lowering pass that injects the overflow-safety preconditions | ||
| * recorded by Func::change_type() into the pipeline's assertion block. | ||
| */ | ||
|
|
||
| #include <map> | ||
| #include <string> | ||
|
|
||
| #include "Expr.h" | ||
|
|
||
| namespace Halide { | ||
| namespace Internal { | ||
|
|
||
| class Function; | ||
|
|
||
| /** Prepend assertions for any static preconditions that Func::change_type() | ||
| * recorded on the funcs in `env` (that it could not discharge at schedule time, | ||
| * e.g. because a reduction extent was symbolic). Statically-true conditions are | ||
| * dropped. Like the other check passes, the resulting asserts are removed later | ||
| * when the no_asserts target feature is set. */ | ||
| Stmt add_type_change_checks(const Stmt &s, const std::map<std::string, Function> &env); | ||
|
|
||
| } // namespace Internal | ||
| } // namespace Halide | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.