-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[mlir][python] enable registering dialects with the default Context
#72488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,14 +56,24 @@ def get_include_dirs() -> Sequence[str]: | |
# | ||
# This facility allows downstreams to customize Context creation to their | ||
# needs. | ||
|
||
|
||
def get_registry(): | ||
if not hasattr(get_registry, "__registry"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember if this is still a thing, but didn't it used to be that double underscore prefixed attributes were lexically mangled? I've got it stuck in my "never do that" category, but may be a legacy lint check in my brain :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's true but that's only for class fields - here I'm doing something even "dirtier" and setting it on the function object so it doesn't get mangled. But just this morning was thinking I'd refactor this to be a module global behind There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, just move it up a level and use nonlocal. No need for dirty tricks that someone will need to grok later. I'm not sure it needs to be thread local. This is a really basic facility in the same vein as site_initialize, which is global-global. Also, I note that your branch is named "remove_site_initialize_2". I assume this is all in addition to the current approach, which is used and works just fine for what we need it for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
from ._mlir import ir | ||
|
||
get_registry.__registry = ir.DialectRegistry() | ||
|
||
return get_registry.__registry | ||
|
||
|
||
def _site_initialize(): | ||
import importlib | ||
import itertools | ||
import logging | ||
from ._mlir import ir | ||
|
||
logger = logging.getLogger(__name__) | ||
registry = ir.DialectRegistry() | ||
post_init_hooks = [] | ||
disable_multithreading = False | ||
|
||
|
@@ -84,7 +94,7 @@ def process_initializer_module(module_name): | |
logger.debug("Initializing MLIR with module: %s", module_name) | ||
if hasattr(m, "register_dialects"): | ||
logger.debug("Registering dialects from initializer %r", m) | ||
m.register_dialects(registry) | ||
m.register_dialects(get_registry()) | ||
if hasattr(m, "context_init_hook"): | ||
logger.debug("Adding context init hook from %r", m) | ||
post_init_hooks.append(m.context_init_hook) | ||
|
@@ -110,7 +120,7 @@ def process_initializer_module(module_name): | |
class Context(ir._BaseContext): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.append_dialect_registry(registry) | ||
self.append_dialect_registry(get_registry()) | ||
for hook in post_init_hooks: | ||
hook(self) | ||
if not disable_multithreading: | ||
|
Uh oh!
There was an error while loading. Please reload this page.