Skip to content

[transform_ext] Useful Python-defined TransformOpInterface ops#68

Merged
rolfmorel merged 7 commits intomainfrom
users/rolfmorel/transform-ops
Mar 19, 2026
Merged

[transform_ext] Useful Python-defined TransformOpInterface ops#68
rolfmorel merged 7 commits intomainfrom
users/rolfmorel/transform-ops

Conversation

@rolfmorel
Copy link
Contributor

No description provided.

Copy link
Member

@adam-smnk adam-smnk left a comment

Choose a reason for hiding this comment

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

Great utility 👍
It'll be particularly helpful with support transform like IR traversal etc.
And a good staging ground toward testing new ideas before upstreaming.

from mlir.dialects.transform import DiagnosedSilenceableFailure


def register_and_load(**kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Nothing to do with PR itself but an random idea.
I wonder if this could be done automatically on module import.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The upstream bindings do something like that, though they only register the dialect and operation classes. Because we use DynamicDialects under the hood, for the Python-defined dialects the _load_ing of the dialect needs to happen when we are under an ir.Context. Generally you import the module at file scope and hence not when there's an active context.

I think there might be a way to make this a bit more magic, but currently we don't have support. Will think about how to make this possible though!

Copy link
Member

Choose a reason for hiding this comment

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

Right, missed the need for ir.Context to be active.
Then an explicit call might be better.

Perhaps, we could just provide a lighthouse context decorator that performs more initialization steps.

Copy link
Member

@rengolin rengolin left a comment

Choose a reason for hiding this comment

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

this is pretty cool

__all__ = ["register_and_load", "transform_ext"]


def register_and_load(**kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

Can you just us from dialects import register_and_load?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing from lighthouse.dialects import register_and_load in other files indeed works.

Personally I prefer from lighthouse import dialects as lh_dialects so that when it's time to call lh_dialects.register_and_load() I have a clue about what's being registered and loaded.

@rolfmorel rolfmorel merged commit e72ec96 into main Mar 19, 2026
4 checks passed
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.

3 participants