Skip to content

[dialects] Idempotent dialect extension loader#228

Open
adam-smnk wants to merge 1 commit into
llvm:mainfrom
adam-smnk:idempotent-dialect-loading
Open

[dialects] Idempotent dialect extension loader#228
adam-smnk wants to merge 1 commit into
llvm:mainfrom
adam-smnk:idempotent-dialect-loading

Conversation

@adam-smnk

Copy link
Copy Markdown
Member

Extends dialect loading mechanism to automatically handle dialect management when switching MLIR contexts.

The new loader allows eager dialect registration without worrying about explicit reloading or double loading errors.

Assisted-by: Claude

Extends dialect loading mechanism to automatically handle dialect
management when switching MLIR contexts.

The new loader allows eager dialect registration without worrying
about explicit reloading or double loading errors.

Assisted-by: Claude
@adam-smnk adam-smnk requested review from rengolin and tkarna July 13, 2026 18:05
@adam-smnk

adam-smnk commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

Follow-up to #225 and another dialect loading solution.

Manual/caller-side dialect management has proven difficult for PyTorch backend as switching between different jitted torch models makes tracking active context difficult. Thus, a different strategy which should make loading dialects multiple times safe to perform.

This way different drivers etc. can safely ensure that dialects have been loaded or reloaded just before using them.
Note that the exact moment when dialects need to be reloaded might still need tweaking in case of more complex run behavior where multiple concurrent MLIR contexts switch a lot.

context are skipped, and extensions previously loaded in a different context
are automatically re-emitted for the current one (see
``DialectExtension.load``). Callers therefore do not need to reason about
whether a reload is required.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

then why do we still need the reload argument?

@classmethod
def load(cls, *args, **kwargs):
# Registers the dialect and its op classes and loads the dialect and ops into the context.
"""Register and load the dialect into the current MLIR context.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't this really be in the MLIR bindings instead of here?

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.

2 participants