File tree Expand file tree Collapse file tree 5 files changed +28
-8
lines changed
python/mlir/_mlir_libs/_mlir Expand file tree Collapse file tree 5 files changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,12 @@ PYBIND11_MODULE(_mlir, m) {
36
36
self.getDialectSearchPrefixes ().push_back (std::move (moduleName));
37
37
},
38
38
" module_name" _a)
39
+ .def (
40
+ " _check_dialect_module_loaded" ,
41
+ [](PyGlobals &self, const std::string &dialectNamespace) {
42
+ return self.loadDialectModule (dialectNamespace);
43
+ },
44
+ " dialect_namespace" _a)
39
45
.def (" _register_dialect_impl" , &PyGlobals::registerDialectImpl,
40
46
" dialect_namespace" _a, " dialect_class" _a,
41
47
" Testing hook for directly registering a dialect" )
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ class _Globals:
7
7
def _register_dialect_impl (self , dialect_namespace : str , dialect_class : type ) -> None : ...
8
8
def _register_operation_impl (self , operation_name : str , operation_class : type ) -> None : ...
9
9
def append_dialect_search_prefix (self , module_name : str ) -> None : ...
10
+ def _check_dialect_module_loaded (self , dialect_namespace : str ) -> bool : ...
10
11
11
12
def register_dialect (dialect_class : type ) -> object : ...
12
13
def register_operation (dialect_class : type ) -> object : ...
Original file line number Diff line number Diff line change
1
+ # The purpose of this empty dialect module is to enable successfully loading the "custom" dialect.
2
+ # Without this file here (and a corresponding _cext.globals.append_dialect_search_prefix("custom_dialect")),
3
+ # PyGlobals::loadDialectModule would search and fail to find the "custom" dialect for each Operation.create("custom.op")
4
+ # (amongst other things).
Original file line number Diff line number Diff line change 1
1
# RUN: %PYTHON %s | FileCheck %s
2
2
3
3
import gc
4
+ import sys
4
5
from mlir .ir import *
6
+ from mlir .dialects ._ods_common import _cext
5
7
6
8
7
9
def run (f ):
@@ -104,3 +106,18 @@ def testIsRegisteredOperation():
104
106
print (f"cf.cond_br: { ctx .is_registered_operation ('cf.cond_br' )} " )
105
107
# CHECK: func.not_existing: False
106
108
print (f"func.not_existing: { ctx .is_registered_operation ('func.not_existing' )} " )
109
+
110
+
111
+ # CHECK-LABEL: TEST: testAppendPrefixSearchPath
112
+ @run
113
+ def testAppendPrefixSearchPath ():
114
+ ctx = Context ()
115
+ ctx .allow_unregistered_dialects = True
116
+ with Location .unknown (ctx ):
117
+ assert not _cext .globals ._check_dialect_module_loaded ("custom" )
118
+ Operation .create ("custom.op" )
119
+ assert not _cext .globals ._check_dialect_module_loaded ("custom" )
120
+
121
+ sys .path .append ("." )
122
+ _cext .globals .append_dialect_search_prefix ("custom_dialect" )
123
+ assert _cext .globals ._check_dialect_module_loaded ("custom" )
Original file line number Diff line number Diff line change 1
1
# RUN: %PYTHON %s | FileCheck %s
2
2
3
3
import gc
4
- import io
5
- import itertools
6
- import sys
7
-
8
4
from mlir .ir import *
9
- from mlir .dialects ._ods_common import _cext
10
-
11
- sys .path .append ("." )
12
- _cext .globals .append_dialect_search_prefix ("custom_dialect" )
13
5
14
6
15
7
def run (f ):
You can’t perform that action at this time.
0 commit comments