Skip to content

Commit 53acfa0

Browse files
authored
Bump MLIR bindings (llvm#243)
Removes local changes to dynamic dialect loader. Reloading dialects is now handled in upstream dialect logic directly. Fixes llvm#229
1 parent 8e9ce62 commit 53acfa0

7 files changed

Lines changed: 8 additions & 53 deletions

File tree

‎lighthouse/dialects/dialect_base.py‎

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import weakref
2-
3-
from mlir import ir
41
from mlir.dialects import ext
52

63

@@ -26,35 +23,11 @@ def load(cls, *args, **kwargs):
2623
dialect stays loaded in every context it was loaded into.
2724
- Never loaded: perform a fresh load.
2825
"""
29-
# Per-subclass registry of the contexts this dialect is loaded in. A
30-
# single "last context" is insufficient: a dialect stays loaded in every
31-
# context it was loaded into, so interleaving contexts requires tracking
32-
# all of them. Contexts are held weakly so they remain garbage
33-
# collectable.
34-
#
35-
# FIXME: It is a workaround to simplify dialect loading.
36-
# Ideally, the `ext.Dialect` base class would handle this automatically.
37-
# See issue: #229
38-
loaded_contexts = cls.__dict__.get("_loaded_contexts")
39-
if loaded_contexts is None:
40-
loaded_contexts = weakref.WeakSet()
41-
cls._loaded_contexts = loaded_contexts
42-
43-
current = ir.Context.current
44-
if current in loaded_contexts:
45-
# Already present in this context; MLIR cannot load it again here.
26+
try:
27+
super().load(*args, **kwargs)
28+
except ext.DialectAlreadyLoadedError:
4629
return
4730

48-
# If the dialect was loaded before (in any context), its process-global,
49-
# context-independent registrations already exist and must be replaced
50-
# rather than added again.
51-
globals_registered = hasattr(cls, "_mlir_module")
52-
53-
# Registers the dialect and its op classes and loads them into the context.
54-
kwargs["reload"] = globals_registered
55-
super().load(*args, **kwargs)
56-
loaded_contexts.add(current)
57-
5831
# Attach interfaces to just registered/loaded operations.
5932
for op_cls in cls.operations:
6033
if hasattr(op_cls, "attach_interface_impls"):

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "lighthouse"
33
dynamic = ["version"]
44
requires-python = ">=3.10,<3.13" # Bounds are due to torch-mlir's packaging
55
dependencies = [
6-
"mlir-python-bindings==20260722+373df745f",
6+
"mlir-python-bindings==20260728+5e91f5d57",
77
"pyyaml>=6.0",
88
]
99

‎test/dialects/dialect_loading.py‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,5 @@ def load_fresh_context():
139139
print("reload after gc ok:", ctx_c.is_registered_operation(PROBE_OP), flush=True)
140140

141141

142-
# CHECK-LABEL: Test: test_explicit_reload_flag_is_safe
143-
@run
144-
def test_explicit_reload_flag_is_safe():
145-
"""Passing reload=True must never abort, even in an already-loaded context."""
146-
ctx = ir.Context()
147-
with ctx:
148-
lh_dialects.register_and_load()
149-
# Explicit reload in the same context cannot re-load into MLIR and must
150-
# be handled gracefully rather than asserting.
151-
lh_dialects.register_and_load(reload=True)
152-
# CHECK: explicit reload ok: True
153-
print("explicit reload ok:", ctx.is_registered_operation(PROBE_OP), flush=True)
154-
155-
156142
# CHECK: All dialect loading tests passed
157143
print("All dialect loading tests passed", flush=True)

‎test/dialects/transform_ext.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
def run(f):
1313
print("Test: ", f.__name__, flush=True)
1414
with ir.Context(), ir.Location.unknown():
15-
lh_dialects.register_and_load(
16-
reload=True
17-
) # reload across @run-s to ensure interfaces are registered for new contexts
15+
lh_dialects.register_and_load()
1816

1917
mod = ir.Module.create()
2018
mod.operation.attributes["transform.with_named_sequence"] = ir.UnitAttr.get()

‎test/dialects/transform_ext_subview.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ def run(payload_fn):
1313
def decorator(f):
1414
print("Test: ", f.__name__, flush=True)
1515
with ir.Context(), ir.Location.unknown():
16-
lh_dialects.register_and_load(
17-
reload=True
18-
) # reload across @run-s to ensure interfaces are registered for new contexts
16+
lh_dialects.register_and_load()
1917

2018
mod = ir.Module.create()
2119
mod.operation.attributes["transform.with_named_sequence"] = (

‎test/transform/test_pack_lowering.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def run(name, payload_str, make_schedule):
1414
print(f"Test: {name}", flush=True)
1515
with ir.Context(), ir.Location.unknown():
16-
lh_dialects.register_and_load(reload=True)
16+
lh_dialects.register_and_load()
1717
payload = ir.Module.parse(payload_str)
1818
# Keep the schedule module alive while it is applied.
1919
sched = make_schedule()

‎test/transform/test_tile_size_ops.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
def run(name, payload_str, build_schedule):
1616
print(f"Test: {name}", flush=True)
1717
with ir.Context(), ir.Location.unknown():
18-
lh_dialects.register_and_load(reload=True)
18+
lh_dialects.register_and_load()
1919
payload = ir.Module.parse(payload_str)
2020
sched = build_schedule()
2121
sched.body.operations[0].apply(payload.operation)

0 commit comments

Comments
 (0)