Fix quadratic bounds blow-up at the source - #9448
Conversation
Bounds inference scales quadratically in the number of update definitions of a Func. This is because all stages are considered to depend on all earlier stages. This makes bgu's bounds inference stage very slow. The root cause is the quadratic loop over all (consumer, producer) pairs. This can't be made linear, because there could genuinely be a quadratic number of relationships between stages. But we can skip or neuter iterations of this loop to at least not send quadratic amounts of IR downstream. The general problem is cases where A depends on B, B depends on C, and A also directly depends on C, and the transitive dependence of A on C via B is equivalent to the direct dependence. This PR skips once instance of this. It skips the dependence of one update stage on earlier update stages along a particular axis if the very next update stage would have the same dependence on earlier update stages along that axis because the var is pure in both. I.e. this situation: f(x, y) = ... ... some number of update defs ... f(x, 0) += 3; // update def 37 f(x, 2) += 4; // update def 38 There's no need to consider update def 37's dependence on earlier stages, because it's going to be the same as update def 38's. This is more powerful than the existing optimization because it still kicks in if most but not all of the update defs are pure in x.
alexreinking
left a comment
There was a problem hiding this comment.
nit: debug prints could be better
| if (!b[k].is_bounded()) { | ||
| std::ostringstream err; | ||
| if (consumer.stage == 0) { | ||
| err << "The pure definition "; | ||
| } else { | ||
| err << "Update definition number " << (consumer.stage - 1); | ||
| } | ||
| err << " of Function " << consumer.name | ||
| << " calls function " << producer.name | ||
| << " in an unbounded way in dimension " << k << "\n"; | ||
| user_error << err.str(); | ||
| } |
There was a problem hiding this comment.
user_assert(b[k].is_bounded()) << [&] {
std::ostringstream err;
// ...
return err.str();
}();
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9448 +/- ##
==========================================
+ Coverage 70.02% 70.13% +0.10%
==========================================
Files 261 261
Lines 79761 79850 +89
Branches 19443 19459 +16
==========================================
+ Hits 55855 56003 +148
Misses 18004 18004
+ Partials 5902 5843 -59 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Merged main into this PR, and benchmarked it with 3 reps for every generator of the apps.
@abadams Somehow the impact on |
|
Failure is the MAX_PATH windows nonsense |


Alternative to #9442
Bounds inference scales quadratically in the number of update definitions of a Func. This is because all stages are considered to depend on all earlier stages. This makes bgu's bounds inference stage very slow.
The root cause is the quadratic loop over all (consumer, producer) pairs. This can't be made linear, because there could genuinely be a quadratic number of relationships between stages. But we can skip or neuter iterations of this loop to at least not send quadratic amounts of IR downstream.
The general problem is cases where A depends on B, B depends on C, and A also directly depends on C, and the transitive dependence of A on C via B is equivalent to the direct dependence.
This PR skips once instance of this. It skips the dependence of one update stage on earlier update stages along a particular axis if the very next update stage would have the same dependence on earlier update stages along that axis because the var is pure in both. I.e. this situation:
f(x, y) = ...
... some number of update defs ...
f(x, 0) += 3; // update def 37
f(x, 2) += 4; // update def 38
There's no need to consider update def 37's dependence on earlier stages, because it's going to be the same as update def 38's.
This is more powerful than the existing optimization because it still kicks in if most but not all of the update defs are pure in x.