This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Modify Partial op conversion mode to optionally track all non-legalizable operations.
ClosedPublic

Authored by lucyrfox on Apr 23 2020, 9:39 PM.

Details

Summary

There are three op conversion modes: Partial, Full, and Analysis. This change modifies the Partial mode to optionally take a set of non-legalizable ops. If this parameter is specified, all ops that are not legalizable (i.e. would cause full conversion to fail) are tracked throughout the partial legalization.

Diff Detail

Event Timeline

lucyrfox created this revision.Apr 23 2020, 9:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2020, 9:39 PM

Took a first pass at this, but I'm open to different ways of approaching this change. At I've written it now, the basic idea of the Analysis conversion is "we're performing a partial conversion and emitting warnings along the way for any ops that would fail to legalize in a full conversion". Success is returned as long as the partial conversion succeeds. I did it this way because returning failure outright means that the partially converted IR doesn't get emitted, which is useful for debugging.

However, an implication of this is that if the legalization did fully succeed, we don't know that based on the Analysis conversion. As a result, I foresee a lot of users running an Analysis conversion immediately followed by a Full conversion, thus incurring an unnecessary pass over the IR. So ideally, this would return success/failure for the full conversion while still outputting the partially converted IR in the failure case.

What do you think?

lucyrfox updated this revision to Diff 259926.Apr 24 2020, 10:35 AM

Minor formatting change.

Took a first pass at this, but I'm open to different ways of approaching this change. At I've written it now, the basic idea of the Analysis conversion is "we're performing a partial conversion and emitting warnings along the way for any ops that would fail to legalize in a full conversion". Success is returned as long as the partial conversion succeeds. I did it this way because returning failure outright means that the partially converted IR doesn't get emitted, which is useful for debugging.

Before answering, please note that we do not base these decisions based on debugging. What the result is depends on what the user intends to do with the result.

However, an implication of this is that if the legalization did fully succeed, we don't know that based on the Analysis conversion. As a result, I foresee a lot of users running an Analysis conversion immediately followed by a Full conversion, thus incurring an unnecessary pass over the IR. So ideally, this would return success/failure for the full conversion while still outputting the partially converted IR in the failure case.

Seems like the user can easily tell if the conversion was completely successful by checking if the set of unlegalized operations is empty?

What do you think?

We can change analysis conversion to whatever we want, but the main question is what are you doing with the information? What happens after the analysis conversion and what do you want to convey? We may end up with different types of analysis conversions based on the answer to that question. For example, the original envisioning for this was that a user would performs analysis conversions targeting different backends to detail which parts of the subgraph were really supported for a specific target. In that type of mode you don't want to do any conversions, because you want to splice the original graph based on the analysis. It seems that the use case you are targeting is different. For your use case, what is the pipeline that you are envisioning and how does an analysis conversion fit into it?

mlir/lib/Transforms/DialectConversion.cpp
1575

I'm not sure we always want warnings here, seems like more of a DEBUG log. If a user is relying on an analysis conversion to help slice code that is supported by different backends, they may not care that certain operations weren't converted.

mehdi_amini added inline comments.Apr 27 2020, 12:04 PM
mlir/lib/Transforms/DialectConversion.cpp
1568

Isn't the mode necessarily Partial/Analysis here?

1577

Isn't this something we'd want to track even in "Partial" mode?

It seems like the difference between Partial and Analysis overall is about whether the conversion is performed or not. Anything else should be uniform.
Partial vs Full is that the latter is aborting early and so does not need to accumulate the unlegalizableOps.

1579

Do we need to warn here?
Can we let signaling up to the client since we populate unlegalizableOps?

lucyrfox marked 2 inline comments as done.Apr 28 2020, 4:40 PM

[Note: I haven't made code changes in this iteration because I want to settle on an approach before refactoring this. For the same reason I'm leaving some comments unresolved for now.]

Took a first pass at this, but I'm open to different ways of approaching this change. At I've written it now, the basic idea of the Analysis conversion is "we're performing a partial conversion and emitting warnings along the way for any ops that would fail to legalize in a full conversion". Success is returned as long as the partial conversion succeeds. I did it this way because returning failure outright means that the partially converted IR doesn't get emitted, which is useful for debugging.

Before answering, please note that we do not base these decisions based on debugging. What the result is depends on what the user intends to do with the result.

However, an implication of this is that if the legalization did fully succeed, we don't know that based on the Analysis conversion. As a result, I foresee a lot of users running an Analysis conversion immediately followed by a Full conversion, thus incurring an unnecessary pass over the IR. So ideally, this would return success/failure for the full conversion while still outputting the partially converted IR in the failure case.

Seems like the user can easily tell if the conversion was completely successful by checking if the set of unlegalized operations is empty?

Good point, don't know why I didn't think of this :)

What do you think?

We can change analysis conversion to whatever we want, but the main question is what are you doing with the information? What happens after the analysis conversion and what do you want to convey? We may end up with different types of analysis conversions based on the answer to that question. For example, the original envisioning for this was that a user would performs analysis conversions targeting different backends to detail which parts of the subgraph were really supported for a specific target. In that type of mode you don't want to do any conversions, because you want to splice the original graph based on the analysis. It seems that the use case you are targeting is different. For your use case, what is the pipeline that you are envisioning and how does an analysis conversion fit into it?

Thanks for raising these points; this helps me better understand the current design of the analysis conversion mode.

My use case (for the TF XLA bridge) is the following: we want to perform a full conversion and for the result to be fully legalized (in that sense, the same as full legalization today). However, in the case that it fails, we want to (a) know all of the ops that failed to legalize and (b) have a partially legalized graph output. I suppose in that sense, this conversion mode I'm envisioning would act like full legalization in the success case but like partial legalization in the failure case.

After considering the comments here, I see a couple of possibilities (both of which would involve leaving the existing Analysis conversion mode as it is today):

(1) Modify the partial conversion mode to take an (optional?) unlegalizedOps set as input and populate it with all ops that fail to legalize.
-In our use case, this would mean always using the Partial conversion mode, and if what we really want is a Full conversion, checking whether that set of ops is empty. That's totally fine from the TF XLA perspective, but is that a level of indirection that ought to be in Core?
-Cons: API instability if the unlegalizedOps set is not optional.

(2) Add a new (2nd type of analysis) conversion mode that aligns with this use case.

I lean toward option (1), but I want to solicit some more thoughts before making the code change.

mlir/lib/Transforms/DialectConversion.cpp
1577

Isn't this something we'd want to track even in "Partial" mode?

I think this is a good idea and aligns with option (1) I describe in the larger comment on this reply.

It seems like the difference between Partial and Analysis overall is about whether the conversion is performed or not. Anything else should be uniform.

This is true with Analysis mode as it is today, but this patch (in its current state) makes it such that both Partial and Analysis mode perform the conversion. The key difference is whether or not the unlegalizable ops are collected in that set.

Partial vs Full is that the latter is aborting early and so does not need to accumulate the unlegalizableOps.

This is the difference between Analysis and Full. Presently, Partial doesn't accumulate the unlegalizableOps, either.

I lean toward option (1), but I want to solicit some more thoughts before making the code change.

(1) seems like a fine option to add.

lucyrfox updated this revision to Diff 261123.Apr 29 2020, 9:33 PM
lucyrfox marked 6 inline comments as done.

Modify Partial conversion mode (instead of Analysis mode) to take an optional parameter to store non-legalizable ops.

lucyrfox added inline comments.Apr 29 2020, 9:34 PM
mlir/lib/Transforms/DialectConversion.cpp
1575

Removed these warnings.

1579

Agreed. Changed.

mehdi_amini accepted this revision.Apr 29 2020, 11:45 PM
mehdi_amini added inline comments.
mlir/include/mlir/Transforms/DialectConversion.h
669 ↗(On Diff #261123)

Just a nit, but I believe that if you use backticks ` to refer to arguments then doxygen link these.

This revision is now accepted and ready to land.Apr 29 2020, 11:45 PM
rriddle accepted this revision.Apr 30 2020, 12:02 AM
lucyrfox retitled this revision from [MLIR] Modify Analysis op conversion mode to emit errors for all unlegalizable operations. to [MLIR] Modify Partial op conversion mode to optionally track all non-legalizable operations..Apr 30 2020, 8:46 AM
lucyrfox edited the summary of this revision. (Show Details)
lucyrfox updated this revision to Diff 261269.Apr 30 2020, 9:47 AM
lucyrfox marked an inline comment as done.

Small formatting fix.

This revision was automatically updated to reflect the committed changes.