Track whether or not let expressions failed to solve in solver by abadams · Pull Request #7982 · halide/Halide · GitHub
Skip to content

Track whether or not let expressions failed to solve in solver#7982

Merged
abadams merged 14 commits into
mainfrom
abadams/track_failedness_through_solver_lets
Jan 26, 2024
Merged

Track whether or not let expressions failed to solve in solver#7982
abadams merged 14 commits into
mainfrom
abadams/track_failedness_through_solver_lets

Conversation

@abadams

@abadams abadams commented Dec 6, 2023

Copy link
Copy Markdown
Member

After mutating an expression, the solver needs to know two things:

  1. Did the expression contain the variable we're solving for
  2. Was the expression successfully "solved" for the variable. I.e. the variable only appears once in the leftmost position. We need to know this to know property 1 of any subexpressions (e.g. does the right child of the expression contain the variable). This drives what transformations we do in ways that are guaranteed to terminate and not take exponential time.

We were tracking property 1 through lets but not property 2, and this meant we were doing unhelpful transformations in some cases. I found a case in the wild where this made a pipeline take > 1 hour to compile (I killed it after an hour). It may have been in an infinite transformation loop, or it might have just been exponential. Not sure.

As a drive-by while trying to figure out why it was taking so long I also made remainder checking cheaper in the common case of division by a constant, by avoiding a call to can_prove.

After mutating an expression, the solver needs to know two things:

1) Did the expression contain the variable we're solving for
2) Was the expression successfully "solved" for the variable. I.e. the
variable only appears once in the leftmost position. We need to know
this to know property 1 of any subexpressions (i.e. does the right child
of the expression contain the variable). This drives what
transformations we do in ways that are guaranteed to terminate and not
take exponential time.

We were tracking property 1 through lets but not property 2, and this
meant we were doing unhelpful transformations in some cases. I found a
case in the wild where this made a pipeline take > 1 hour to compile (I
killed it after an hour). It may have been in an infinite transformation
loop, or it might have just been exponential. Not sure.
Comment thread src/Solve.cpp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I sure which C++ had a terse way to express this pattern (that wasn't an RIAA class)...

@steven-johnson

Copy link
Copy Markdown
Contributor

Does this need new test(s)?

@abadams

abadams commented Dec 6, 2023

Copy link
Copy Markdown
Member Author

It's a failure to scale gracefully with large inputs. For the correctness of it, the existing solver tests are fine.

@abadams

abadams commented Dec 6, 2023

Copy link
Copy Markdown
Member Author

Looks like there are some real failures to investigate

@steven-johnson

Copy link
Copy Markdown
Contributor

I assume this is still in-progress?

@abadams

abadams commented Jan 16, 2024

Copy link
Copy Markdown
Member Author

Yes

@abadams

abadams commented Jan 22, 2024

Copy link
Copy Markdown
Member Author

The test failure was caused by use of an uninitialized value because I didn't check a return value. I added the must use result macro to reduce_expr_modulo to prevent this problem in future.

@abadams

abadams commented Jan 26, 2024

Copy link
Copy Markdown
Member Author

Failure unrelated. Just needs an approval

Comment thread src/ModulusRemainder.h

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"must use result" should really be the default in the language, with the current behavior opt-in :-/

@abadams abadams merged commit 45d7850 into main Jan 26, 2024
steven-johnson pushed a commit that referenced this pull request Feb 1, 2024
* Track whether or not let expressions failed to solve in solver

After mutating an expression, the solver needs to know two things:

1) Did the expression contain the variable we're solving for
2) Was the expression successfully "solved" for the variable. I.e. the
variable only appears once in the leftmost position. We need to know
this to know property 1 of any subexpressions (i.e. does the right child
of the expression contain the variable). This drives what
transformations we do in ways that are guaranteed to terminate and not
take exponential time.

We were tracking property 1 through lets but not property 2, and this
meant we were doing unhelpful transformations in some cases. I found a
case in the wild where this made a pipeline take > 1 hour to compile (I
killed it after an hour). It may have been in an infinite transformation
loop, or it might have just been exponential. Not sure.

* Remove surplus comma

* Fix use of uninitialized value that could cause bad transformation
ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
…e#7982)

* Track whether or not let expressions failed to solve in solver

After mutating an expression, the solver needs to know two things:

1) Did the expression contain the variable we're solving for
2) Was the expression successfully "solved" for the variable. I.e. the
variable only appears once in the leftmost position. We need to know
this to know property 1 of any subexpressions (i.e. does the right child
of the expression contain the variable). This drives what
transformations we do in ways that are guaranteed to terminate and not
take exponential time.

We were tracking property 1 through lets but not property 2, and this
meant we were doing unhelpful transformations in some cases. I found a
case in the wild where this made a pipeline take > 1 hour to compile (I
killed it after an hour). It may have been in an infinite transformation
loop, or it might have just been exponential. Not sure.

* Remove surplus comma

* Fix use of uninitialized value that could cause bad transformation
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.

2 participants