diff --git a/mlir/cmake/modules/AddMLIRPythonExtension.cmake b/mlir/cmake/modules/AddMLIRPythonExtension.cmake --- a/mlir/cmake/modules/AddMLIRPythonExtension.cmake +++ b/mlir/cmake/modules/AddMLIRPythonExtension.cmake @@ -143,8 +143,9 @@ "DEPENDS" ${ARGN}) + set(dialect_filename "_${ARG_DIALECT_NAME}_ops_gen.py") set(LLVM_TARGET_DEFINITIONS ${ARG_TD_FILE}) - mlir_tablegen("${ARG_DIALECT_NAME}.py" -gen-python-op-bindings + mlir_tablegen("${dialect_filename}" -gen-python-op-bindings -bind-dialect=${ARG_DIALECT_NAME}) add_public_tablegen_target( ${tblgen_target}) @@ -154,9 +155,9 @@ add_custom_command( TARGET ${tblgen_target} POST_BUILD - COMMENT "Copying generated python source \"dialects/${ARG_DIALECT_NAME}.py\"" + COMMENT "Copying generated python source \"dialects/${dialect_filename}\"" COMMAND "${CMAKE_COMMAND}" -E copy_if_different - "${CMAKE_CURRENT_BINARY_DIR}/${ARG_DIALECT_NAME}.py" - "${PROJECT_BINARY_DIR}/python/mlir/dialects/${ARG_DIALECT_NAME}.py") + "${CMAKE_CURRENT_BINARY_DIR}/${dialect_filename}" + "${PROJECT_BINARY_DIR}/python/mlir/dialects/${dialect_filename}") endfunction() diff --git a/mlir/docs/Bindings/Python.md b/mlir/docs/Bindings/Python.md --- a/mlir/docs/Bindings/Python.md +++ b/mlir/docs/Bindings/Python.md @@ -122,18 +122,21 @@ LLVM/MLIR is a non-trivial python-native project that is likely to co-exist with other non-trivial native extensions. As such, the native extension (i.e. the `.so`/`.pyd`/`.dylib`) is exported as a notionally private top-level symbol -(`_mlir`), while a small set of Python code is provided in `mlir/__init__.py` -and siblings which loads and re-exports it. This split provides a place to stage -code that needs to prepare the environment *before* the shared library is loaded -into the Python runtime, and also provides a place that one-time initialization -code can be invoked apart from module constructors. - -To start with the `mlir/__init__.py` loader shim can be very simple and scale to -future need: - -```python -from _mlir import * -``` +(`_mlir`), while a small set of Python code is provided in +`mlir/_cext_loader.py` and siblings which loads and re-exports it. This +split provides a place to stage code that needs to prepare the environment +*before* the shared library is loaded into the Python runtime, and also +provides a place that one-time initialization code can be invoked apart from +module constructors. + +It is recommended to avoid using `__init__.py` files to the extent possible, +until reaching a leaf package that represents a discrete component. The rule +to keep in mind is that the presence of an `__init__.py` file prevents the +ability to split anything at that level or below in the namespace into +different directories, deployment packages, wheels, etc. + +See the documentation for more information and advice: +https://packaging.python.org/guides/packaging-namespace-packages/ ### Use the C-API @@ -361,13 +364,16 @@ been elided: refer to the build rules and python sources under `mlir.dialects` for the canonical way to use this facility. -### Generating `{DIALECT_NAMESPACE}.py` wrapper modules +Users are responsible for providing a `{DIALECT_NAMESPACE}.py` (or an +equivalent directory with `__init__.py` file) as the entrypoint. + +### Generating `_{DIALECT_NAMESPACE}_ops_gen.py` wrapper modules Each dialect with a mapping to python requires that an appropriate -`{DIALECT_NAMESPACE}.py` wrapper module is created. This is done by invoking -`mlir-tblgen` on a python-bindings specific tablegen wrapper that includes -the boilerplate and actual dialect specific `td` file. An example, for the -`StandardOps` (which is assigned the namespace `std` as a special case): +`_{DIALECT_NAMESPACE}_ops_gen.py` wrapper module is created. This is done by +invoking `mlir-tblgen` on a python-bindings specific tablegen wrapper that +includes the boilerplate and actual dialect specific `td` file. An example, for +the `StandardOps` (which is assigned the namespace `std` as a special case): ```tablegen #ifndef PYTHON_BINDINGS_STANDARD_OPS @@ -387,6 +393,13 @@ {PYTHON_BINDING_TD_FILE} ``` +The generates op classes must be included in the `{DIALECT_NAMESPACE}.py` file +in a similar way that generated headers are included for C++ generated code: + +```python +from ._my_dialect_ops_gen import * +``` + ### Extending the search path for wrapper modules When the python bindings need to locate a wrapper module, they consult the diff --git a/mlir/lib/Bindings/Python/mlir/__init__.py b/mlir/lib/Bindings/Python/mlir/_cext_loader.py rename from mlir/lib/Bindings/Python/mlir/__init__.py rename to mlir/lib/Bindings/Python/mlir/_cext_loader.py --- a/mlir/lib/Bindings/Python/mlir/__init__.py +++ b/mlir/lib/Bindings/Python/mlir/_cext_loader.py @@ -1,18 +1,7 @@ # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Note that the only function of this module is currently to load the -# native module and re-export its symbols. In the future, this file is -# reserved as a trampoline to handle environment specific loading needs -# and arbitrate any one-time initialization needed in various shared-library -# scenarios. - -__all__ = [ - "ir", - "execution_engine", - "passmanager", -] +"""Common module for looking up and manipulating C-Extensions.""" # Packaged installs have a top-level _mlir_libs package with symbols: # load_extension(name): Loads a named extension module @@ -36,19 +25,21 @@ _preload_dependency = _mlir_libs.preload_dependency _preload_dependency("MLIRPublicAPI") + # Expose the corresponding C-Extension module with a well-known name at this # top-level module. This allows relative imports like the following to # function: -# from .. import _cext +# from .._cext_loader import _cext # This reduces coupling, allowing embedding of the python sources into another # project that can just vary based on this top-level loader module. _cext = _load_extension("_mlir") + def _reexport_cext(cext_module_name, target_module_name): """Re-exports a named sub-module of the C-Extension into another module. Typically: - from . import _reexport_cext + from ._cext_loader import _reexport_cext _reexport_cext("ir", __name__) del _reexport_cext """ @@ -60,9 +51,5 @@ setattr(target_module, attr_name, getattr(source_module, attr_name)) -# Import sub-modules. Since these may import from here, this must come after -# any exported definitions. -from . import ir, execution_engine, passmanager - # Add our 'dialects' parent module to the search path for implementations. _cext.globals.append_dialect_search_prefix("mlir.dialects") diff --git a/mlir/lib/Bindings/Python/mlir/conversions/__init__.py b/mlir/lib/Bindings/Python/mlir/conversions/__init__.py --- a/mlir/lib/Bindings/Python/mlir/conversions/__init__.py +++ b/mlir/lib/Bindings/Python/mlir/conversions/__init__.py @@ -4,5 +4,5 @@ # Expose the corresponding C-Extension module with a well-known name at this # level. -from .. import _load_extension +from .._cext_loader import _load_extension _cextConversions = _load_extension("_mlirConversions") diff --git a/mlir/lib/Bindings/Python/mlir/dialects/_builtin.py b/mlir/lib/Bindings/Python/mlir/dialects/_builtin_ops_ext.py rename from mlir/lib/Bindings/Python/mlir/dialects/_builtin.py rename to mlir/lib/Bindings/Python/mlir/dialects/_builtin_ops_ext.py --- a/mlir/lib/Bindings/Python/mlir/dialects/_builtin.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/_builtin_ops_ext.py @@ -1,15 +1,15 @@ # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -from mlir.ir import * +from ..ir import * class ModuleOp: """Specialization for the module op class.""" def __init__(self, *, loc=None, ip=None): - super().__init__( - self.build_generic(results=[], operands=[], loc=loc, ip=ip)) + super().__init__(self.build_generic(results=[], operands=[], loc=loc, + ip=ip)) body = self.regions[0].blocks.append() with InsertionPoint(body): Operation.create("module_terminator") @@ -84,10 +84,11 @@ return self.regions[0].blocks[0] def add_entry_block(self): - ''' - Add an entry block to the function body using the function signature to infer block arguments + """ + Add an entry block to the function body using the function signature to + infer block arguments. Returns the newly created block - ''' + """ if not self.is_external: raise IndexError('The function already has an entry block!') self.body.blocks.append(*self.type.inputs) diff --git a/mlir/lib/Bindings/Python/mlir/dialects/_linalg.py b/mlir/lib/Bindings/Python/mlir/dialects/_linalg_ops_ext.py rename from mlir/lib/Bindings/Python/mlir/dialects/_linalg.py rename to mlir/lib/Bindings/Python/mlir/dialects/_linalg_ops_ext.py diff --git a/mlir/lib/Bindings/Python/mlir/dialects/__init__.py b/mlir/lib/Bindings/Python/mlir/dialects/_ods_common.py rename from mlir/lib/Bindings/Python/mlir/dialects/__init__.py rename to mlir/lib/Bindings/Python/mlir/dialects/_ods_common.py --- a/mlir/lib/Bindings/Python/mlir/dialects/__init__.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/_ods_common.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # Re-export the parent _cext so that every level of the API can get it locally. -from .. import _cext +from .._cext_loader import _cext __all__ = [ "equally_sized_accessor", diff --git a/mlir/lib/Bindings/Python/mlir/ir.py b/mlir/lib/Bindings/Python/mlir/dialects/builtin.py copy from mlir/lib/Bindings/Python/mlir/ir.py copy to mlir/lib/Bindings/Python/mlir/dialects/builtin.py --- a/mlir/lib/Bindings/Python/mlir/ir.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/builtin.py @@ -2,7 +2,4 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Simply a wrapper around the extension module of the same name. -from . import _reexport_cext -_reexport_cext("ir", __name__) -del _reexport_cext +from ._builtin_ops_gen import * diff --git a/mlir/lib/Bindings/Python/mlir/ir.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/__init__.py copy from mlir/lib/Bindings/Python/mlir/ir.py copy to mlir/lib/Bindings/Python/mlir/dialects/linalg/__init__.py --- a/mlir/lib/Bindings/Python/mlir/ir.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/linalg/__init__.py @@ -2,7 +2,4 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Simply a wrapper around the extension module of the same name. -from . import _reexport_cext -_reexport_cext("ir", __name__) -del _reexport_cext +from .._linalg_ops_gen import * diff --git a/mlir/lib/Bindings/Python/mlir/tools/__init__.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/__init__.py rename from mlir/lib/Bindings/Python/mlir/tools/__init__.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/__init__.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/dump_oplib.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/dump_oplib.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/dump_oplib.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/dump_oplib.py --- a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/dump_oplib.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/dump_oplib.py @@ -64,7 +64,8 @@ modules = [] for module_name in args.modules: modules.append( - importlib.import_module(module_name, package="mlir.tools.linalg_opdsl")) + importlib.import_module(module_name, + package="mlir.dialects.linalg.opdsl")) for i, file_path in enumerate(args.file or []): modules.append(load_module_from_file(f"_mlir_eval_oplib{i}", file_path)) for m in modules: diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/__init__.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/__init__.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/__init__.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/__init__.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/affine.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/affine.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/affine.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/affine.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/comprehension.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/comprehension.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/comprehension.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/comprehension.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/config.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/config.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/config.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/config.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/dsl.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/dsl.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/dsl.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/dsl.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/scalar_expr.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/scalar_expr.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/scalar_expr.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/scalar_expr.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/types.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/types.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/types.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/types.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/yaml_helper.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/yaml_helper.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/lang/yaml_helper.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/lang/yaml_helper.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/__init__.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/ops/__init__.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/__init__.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/ops/__init__.py diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/ops/core_named_ops.py b/mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py rename from mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/ops/core_named_ops.py rename to mlir/lib/Bindings/Python/mlir/dialects/linalg/opdsl/ops/core_named_ops.py diff --git a/mlir/lib/Bindings/Python/mlir/ir.py b/mlir/lib/Bindings/Python/mlir/dialects/python_test.py copy from mlir/lib/Bindings/Python/mlir/ir.py copy to mlir/lib/Bindings/Python/mlir/dialects/python_test.py --- a/mlir/lib/Bindings/Python/mlir/ir.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/python_test.py @@ -2,7 +2,4 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Simply a wrapper around the extension module of the same name. -from . import _reexport_cext -_reexport_cext("ir", __name__) -del _reexport_cext +from ._python_test_ops_gen import * diff --git a/mlir/lib/Bindings/Python/mlir/ir.py b/mlir/lib/Bindings/Python/mlir/dialects/shape.py copy from mlir/lib/Bindings/Python/mlir/ir.py copy to mlir/lib/Bindings/Python/mlir/dialects/shape.py --- a/mlir/lib/Bindings/Python/mlir/ir.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/shape.py @@ -2,7 +2,4 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Simply a wrapper around the extension module of the same name. -from . import _reexport_cext -_reexport_cext("ir", __name__) -del _reexport_cext +from ._shape_ops_gen import * diff --git a/mlir/lib/Bindings/Python/mlir/ir.py b/mlir/lib/Bindings/Python/mlir/dialects/std.py copy from mlir/lib/Bindings/Python/mlir/ir.py copy to mlir/lib/Bindings/Python/mlir/dialects/std.py --- a/mlir/lib/Bindings/Python/mlir/ir.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/std.py @@ -2,7 +2,4 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Simply a wrapper around the extension module of the same name. -from . import _reexport_cext -_reexport_cext("ir", __name__) -del _reexport_cext +from ._std_ops_gen import * diff --git a/mlir/lib/Bindings/Python/mlir/ir.py b/mlir/lib/Bindings/Python/mlir/dialects/tensor.py copy from mlir/lib/Bindings/Python/mlir/ir.py copy to mlir/lib/Bindings/Python/mlir/dialects/tensor.py --- a/mlir/lib/Bindings/Python/mlir/ir.py +++ b/mlir/lib/Bindings/Python/mlir/dialects/tensor.py @@ -2,7 +2,4 @@ # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Simply a wrapper around the extension module of the same name. -from . import _reexport_cext -_reexport_cext("ir", __name__) -del _reexport_cext +from ._tensor_ops_gen import * diff --git a/mlir/lib/Bindings/Python/mlir/execution_engine.py b/mlir/lib/Bindings/Python/mlir/execution_engine.py --- a/mlir/lib/Bindings/Python/mlir/execution_engine.py +++ b/mlir/lib/Bindings/Python/mlir/execution_engine.py @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # Simply a wrapper around the extension module of the same name. -from . import _cext +from ._cext_loader import _cext import ctypes class ExecutionEngine(_cext.execution_engine.ExecutionEngine): diff --git a/mlir/lib/Bindings/Python/mlir/ir.py b/mlir/lib/Bindings/Python/mlir/ir.py --- a/mlir/lib/Bindings/Python/mlir/ir.py +++ b/mlir/lib/Bindings/Python/mlir/ir.py @@ -3,6 +3,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # Simply a wrapper around the extension module of the same name. -from . import _reexport_cext +from ._cext_loader import _reexport_cext _reexport_cext("ir", __name__) del _reexport_cext diff --git a/mlir/lib/Bindings/Python/mlir/passmanager.py b/mlir/lib/Bindings/Python/mlir/passmanager.py --- a/mlir/lib/Bindings/Python/mlir/passmanager.py +++ b/mlir/lib/Bindings/Python/mlir/passmanager.py @@ -3,6 +3,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # Simply a wrapper around the extension module of the same name. -from . import _reexport_cext +from ._cext_loader import _reexport_cext _reexport_cext("passmanager", __name__) del _reexport_cext diff --git a/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/ops/__init__.py b/mlir/lib/Bindings/Python/mlir/tools/linalg_opdsl/ops/__init__.py deleted file mode 100644 diff --git a/mlir/lib/Bindings/Python/mlir/transforms/__init__.py b/mlir/lib/Bindings/Python/mlir/transforms/__init__.py --- a/mlir/lib/Bindings/Python/mlir/transforms/__init__.py +++ b/mlir/lib/Bindings/Python/mlir/transforms/__init__.py @@ -4,5 +4,5 @@ # Expose the corresponding C-Extension module with a well-known name at this # level. -from .. import _load_extension +from .._cext_loader import _load_extension _cextTransforms = _load_extension("_mlirTransforms") diff --git a/mlir/test/Bindings/Python/context_lifecycle.py b/mlir/test/Bindings/Python/context_lifecycle.py --- a/mlir/test/Bindings/Python/context_lifecycle.py +++ b/mlir/test/Bindings/Python/context_lifecycle.py @@ -1,7 +1,7 @@ # RUN: %PYTHON %s # Standalone sanity check of context life-cycle. import gc -import mlir +import mlir.ir assert mlir.ir.Context._get_live_count() == 0 diff --git a/mlir/test/Bindings/Python/dialects.py b/mlir/test/Bindings/Python/dialects.py --- a/mlir/test/Bindings/Python/dialects.py +++ b/mlir/test/Bindings/Python/dialects.py @@ -35,7 +35,7 @@ d = ctx.dialects.std # Note that the standard dialect namespace prints as ''. Others will print # as " + # CHECK: print(d) try: _ = ctx.dialects.not_existing @@ -46,7 +46,7 @@ # Access using index. d = ctx.dialects["std"] - # CHECK: + # CHECK: print(d) try: _ = ctx.dialects["not_existing"] @@ -57,7 +57,7 @@ # Using the 'd' alias. d = ctx.d["std"] - # CHECK: + # CHECK: print(d) run(testUserDialectClass) diff --git a/mlir/test/Bindings/Python/tools/linalg_opdsl/assignments.py b/mlir/test/Bindings/Python/dialects/linalg/opdsl/assignments.py rename from mlir/test/Bindings/Python/tools/linalg_opdsl/assignments.py rename to mlir/test/Bindings/Python/dialects/linalg/opdsl/assignments.py --- a/mlir/test/Bindings/Python/tools/linalg_opdsl/assignments.py +++ b/mlir/test/Bindings/Python/dialects/linalg/opdsl/assignments.py @@ -1,6 +1,6 @@ -# RUN: %PYTHON -m mlir.tools.linalg_opdsl.dump_oplib --file %s | FileCheck %s +# RUN: %PYTHON -m mlir.dialects.linalg.opdsl.dump_oplib --file %s | FileCheck %s -from mlir.tools.linalg_opdsl.lang import * +from mlir.dialects.linalg.opdsl.lang import * # CHECK: --- # CHECK-LABEL: matmul diff --git a/mlir/test/Bindings/Python/tools/linalg_opdsl/doctests.py b/mlir/test/Bindings/Python/dialects/linalg/opdsl/doctests.py rename from mlir/test/Bindings/Python/tools/linalg_opdsl/doctests.py rename to mlir/test/Bindings/Python/dialects/linalg/opdsl/doctests.py --- a/mlir/test/Bindings/Python/tools/linalg_opdsl/doctests.py +++ b/mlir/test/Bindings/Python/dialects/linalg/opdsl/doctests.py @@ -9,5 +9,5 @@ doctest.testmod(m, verbose=True, raise_on_error=True, report=True) -test_module("mlir.tools.linalg_opdsl.lang.affine") -test_module("mlir.tools.linalg_opdsl.lang.types") +test_module("mlir.dialects.linalg.opdsl.lang.affine") +test_module("mlir.dialects.linalg.opdsl.lang.types") diff --git a/mlir/test/Bindings/Python/tools/linalg_opdsl/interfaces.py b/mlir/test/Bindings/Python/dialects/linalg/opdsl/interfaces.py rename from mlir/test/Bindings/Python/tools/linalg_opdsl/interfaces.py rename to mlir/test/Bindings/Python/dialects/linalg/opdsl/interfaces.py --- a/mlir/test/Bindings/Python/tools/linalg_opdsl/interfaces.py +++ b/mlir/test/Bindings/Python/dialects/linalg/opdsl/interfaces.py @@ -1,6 +1,6 @@ -# RUN: %PYTHON -m mlir.tools.linalg_opdsl.dump_oplib --file %s | FileCheck %s +# RUN: %PYTHON -m mlir.dialects.linalg.opdsl.dump_oplib --file %s | FileCheck %s -from mlir.tools.linalg_opdsl.lang import * +from mlir.dialects.linalg.opdsl.lang import * # CHECK: --- # CHECK-LABEL: matmul diff --git a/mlir/test/Bindings/Python/tools/linalg_opdsl/lit.local.cfg b/mlir/test/Bindings/Python/dialects/linalg/opdsl/lit.local.cfg rename from mlir/test/Bindings/Python/tools/linalg_opdsl/lit.local.cfg rename to mlir/test/Bindings/Python/dialects/linalg/opdsl/lit.local.cfg diff --git a/mlir/test/Bindings/Python/tools/linalg_opdsl/shape_maps_iteration.py b/mlir/test/Bindings/Python/dialects/linalg/opdsl/shape_maps_iteration.py rename from mlir/test/Bindings/Python/tools/linalg_opdsl/shape_maps_iteration.py rename to mlir/test/Bindings/Python/dialects/linalg/opdsl/shape_maps_iteration.py --- a/mlir/test/Bindings/Python/tools/linalg_opdsl/shape_maps_iteration.py +++ b/mlir/test/Bindings/Python/dialects/linalg/opdsl/shape_maps_iteration.py @@ -1,6 +1,6 @@ -# RUN: %PYTHON -m mlir.tools.linalg_opdsl.dump_oplib --file %s | FileCheck %s +# RUN: %PYTHON -m mlir.dialects.linalg.opdsl.dump_oplib --file %s | FileCheck %s -from mlir.tools.linalg_opdsl.lang import * +from mlir.dialects.linalg.opdsl.lang import * # Verify that simple case with iteration order defined lexically and reduction diff --git a/mlir/test/Bindings/Python/dialects/linalg/opdsl/test_core_named_ops.py b/mlir/test/Bindings/Python/dialects/linalg/opdsl/test_core_named_ops.py new file mode 100644 --- /dev/null +++ b/mlir/test/Bindings/Python/dialects/linalg/opdsl/test_core_named_ops.py @@ -0,0 +1,4 @@ +# RUN: %PYTHON -m mlir.dialects.linalg.opdsl.dump_oplib .ops.core_named_ops | FileCheck %s + +# Just verify that at least one known op is generated. +# CHECK: name: matmul diff --git a/mlir/test/Bindings/Python/dialects/linalg.py b/mlir/test/Bindings/Python/dialects/linalg/ops.py rename from mlir/test/Bindings/Python/dialects/linalg.py rename to mlir/test/Bindings/Python/dialects/linalg/ops.py diff --git a/mlir/test/Bindings/Python/ir_operation.py b/mlir/test/Bindings/Python/ir_operation.py --- a/mlir/test/Bindings/Python/ir_operation.py +++ b/mlir/test/Bindings/Python/ir_operation.py @@ -492,7 +492,7 @@ # addf should map to a known OpView class in the std dialect. # We know the OpView for it defines an 'lhs' attribute. addf = module.body.operations[2] - # CHECK: