This is an archive of the discontinued LLVM Phabricator instance.

[mlir][PassRegistry] Allow pipelines to be registered multiple times
AbandonedPublic

Authored by maxbartel on Aug 16 2023, 8:12 AM.

Details

Summary

Right now we only allow passes to be registered multiple times, as long
as they have the same TypeId. For PassPipelines this was simply not
allowed. This creates problems when you have a pipeline that is specific
to a dialect and load them both at the same time in the python bindings.
If you have a python file with multiple tests each having its own
context and want to load your dialect, you will hit this assert.

On a side-note: We are handling the dialect registry with the
MLIRContext. There is nothing similar for
passes, they are managed by a ManagedStatic StringMap. Is there a
specific reason for that?

Diff Detail

Event Timeline

maxbartel created this revision.Aug 16 2023, 8:12 AM
Herald added a project: Restricted Project. · View Herald Transcript
maxbartel requested review of this revision.Aug 16 2023, 8:12 AM
mehdi_amini requested changes to this revision.EditedAug 29 2023, 2:13 AM

I don't understand the use-case here, but that seems fishy and unsafe, I would question the setup that leads there instead.

This revision now requires changes to proceed.Aug 29 2023, 2:13 AM
maxbartel added a comment.EditedAug 29 2023, 5:41 AM

I don't understand the use-case here, but that seems fishy and unsafe, I would question the setup that leads there instead.

It is quite easy to reproduce. When you have two python tests that should run independent from each other and you register the pass pipeline. Something like this:

def test1():
    register_custom_pass_pipeline()

def test2():
    register_custom_pass_pipeline()

This would work for passes, but will trigger the assert with pipelines.

To be clear, I don't think just allowing them is a nice solution, but at least it would then be aligned with the normal passes. Hence my question regarding the MLIRContext. I would also be happy to implement something else, but that would probably need an RFC. WDYT @mehdi_amini ?

This doesn't really provide you with the independence testing side, but rather hides that there is global state being mutated. Given tests can run in any order, Python side you probably need to do this registration at file scope.

What about letting MLIRContext also handle the pass registry? Is there something obvious going against that?

You are probably right about doing that at the file scope, but I kind of feel that this is also a workaround.

At some point, register_custom_pass_pipeline() will get into some C++, where you can make it idempotent by relying on a static variable.

The MLIRContext has to do with the IR entities, the pass management is fully decoupled: the IR library does not depend on the pass infra library.

Got it, thank you! I will close this then.

maxbartel abandoned this revision.Aug 30 2023, 12:17 AM