This is an archive of the discontinued LLVM Phabricator instance.

lowerParallel is also called on unit-size, one-sided reduction dims
ClosedPublic

Authored by Benoit on Jul 4 2022, 1:33 PM.

Details

Summary

This diff makes us not assert/crash on the testcase being added here.

This is the assert that this testcase is hitting.

This assertion is triggering because this function, lowerParallel, was expecting to be called on a parallel dimension, but its caller, ContractionOpLowering::matchAndRewrite, is actually calling it on dimensions that are not necessarily parallel.

Inspection of ContractionOpLowering::matchAndRewrite shows that it is calling lowerParallel on all dimensions except reductions dimensions that occur on both the LHS and the RHS. At first sight, that sounds equivalent to saying all dimensions except reduction dimensions, which in turns boils down to all parallel dimensions.

But the testcase has a unit-size reduction dimension occurring only on the LHS and not on the RHS. Even though it is a reduction dimension, because it does not occur on RHS, it is not seen by getContractingDimMap here and the logic below ends up calling lowerParallel on it here.

This testcase is "legitimate" in the sense that it is actually produced by the existing CastAwayContractionLeadingOneDim pattern applied on a more clearly legitimate testcase as explained in this gist:
https://gist.github.com/bjacob/d8be8ec7e70ed0be4b3a5794ced2a7e8

Diff Detail

Event Timeline

Benoit created this revision.Jul 4 2022, 1:33 PM
Herald added a project: Restricted Project. · View Herald Transcript
Benoit requested review of this revision.Jul 4 2022, 1:33 PM
Benoit updated this revision to Diff 442164.Jul 4 2022, 7:20 PM

full test, add comments and an assert message.

Benoit edited the summary of this revision. (Show Details)Jul 4 2022, 7:35 PM
Benoit edited the summary of this revision. (Show Details)

While you are touching this, it would be great to make lowerReduction and lowerParallel return a FailureOr and have the parent pattern lower gracefully with a failure rather than assert at all anywhere.

Benoit updated this revision to Diff 443256.Jul 8 2022, 8:26 AM

Changed to FailureOr<Value> (review comment)

While you are touching this, it would be great to make lowerReduction and lowerParallel return a FailureOr and have the parent pattern lower gracefully with a failure rather than assert at all anywhere.

PTAL

nicolasvasilache accepted this revision.Jul 13 2022, 7:33 AM

Thanks Benoit!
Could you please replace all emitError by rewriter.notifyMatchFailure ?
These are only emitted to the user when debugging pattern application (otherwise errors are expected to be very verbose and misleading in a successful flow).
Accepting conditioned on that change.

This revision is now accepted and ready to land.Jul 13 2022, 7:33 AM
Benoit updated this revision to Diff 444286.Jul 13 2022, 8:46 AM

review comment: emitError changed to notifyMatchFailure.

Thanks Benoit!
Could you please replace all emitError by rewriter.notifyMatchFailure ?
These are only emitted to the user when debugging pattern application (otherwise errors are expected to be very verbose and misleading in a successful flow).
Accepting conditioned on that change.

Thanks - Done.