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 ClampUnsafeAccesses pass. #6294

Merged
merged 14 commits into from
Oct 8, 2021
Merged

Conversation

alexreinking
Copy link
Member

@alexreinking alexreinking commented Oct 7, 2021

Inject clamps around func calls h(...) when all the following conditions hold:

  1. The call is in an indexing context, such as: f(x) = g(h(x));
  2. The FuncValueBounds of h are smaller than those of its type

Fixes #6131

Inject clamps around func calls h(...) when all the following conditions hold:
  1. The call is in an indexing context, such as: f(x) = g(h(x));
  2. The schedule for f uses RoundUp or ShiftInwards
  3. h is not compute_at within f's produce node
  4. The FuncValueBounds of h are smaller than those of its type

Conditions (3) and (4) are not yet implemented.
@alexreinking alexreinking marked this pull request as ready for review October 7, 2021 00:40
src/ClampUnsafeAccesses.cpp Outdated Show resolved Hide resolved
src/ClampUnsafeAccesses.cpp Outdated Show resolved Hide resolved
src/ClampUnsafeAccesses.cpp Outdated Show resolved Hide resolved
if (is_inside_indexing) {
auto bounds = func_bounds.at({call->name, call->value_index});
if (bounds_smaller_than_type(bounds, call->type)) {
// TODO: check that the clamped function's allocation bounds might be wider than its compute bounds
Copy link
Member

Choose a reason for hiding this comment

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

Please open an issue or reuse the existing issue to track this, and add the issue ID to the comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I figured this PR was blocked on implementing this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Opened issue #6297 to track this.

Copy link
Member

Choose a reason for hiding this comment

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

It fixes a miscompilation. I think we can live with a few extra ops instead in the short term.

@alexreinking alexreinking merged commit 2bfa567 into master Oct 8, 2021
@alexreinking alexreinking deleted the nested_index_compute_bounds branch October 8, 2021 18:52
// TODO(#6297): check that the clamped function's allocation bounds might be wider than its compute bounds

auto [new_args, changed] = mutate_with_changes(call->args);
Expr new_call = changed ? call : Call::make(call->type, call->name, new_args, call->call_type, call->func, call->value_index, call->image, call->param);
Copy link
Contributor

Choose a reason for hiding this comment

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

(resurrecting a zombie PR...)

Uh, is this right? Shouldn't it be !changed ? call : ... ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeeeep, that looks like a typo. Want to try changing it to see if tests fail?

steven-johnson added a commit that referenced this pull request Mar 18, 2022
steven-johnson added a commit that referenced this pull request Mar 18, 2022
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.

Accesses inside indexing expressions should be in compute bounds
3 participants