diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/CMakeLists.txt | 64 | ||||
-rw-r--r-- | python/StandaloneExtension.cpp | 31 | ||||
-rw-r--r-- | python/mlir_standalone/dialects/StandaloneOps.td | 15 | ||||
-rw-r--r-- | python/mlir_standalone/dialects/standalone.py | 6 |
4 files changed, 116 insertions, 0 deletions
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt new file mode 100644 index 0000000..a8c4382 --- /dev/null +++ b/python/CMakeLists.txt @@ -0,0 +1,64 @@ +include(AddMLIRPython) + +# Specifies that all MLIR packages are co-located under the `mlir_standalone` +# top level package (the API has been embedded in a relocatable way). +# TODO: Add an upstream cmake param for this vs having a global here. +add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=mlir_standalone.") + + +################################################################################ +# Sources +################################################################################ + +declare_mlir_python_sources(StandalonePythonSources) + +declare_mlir_dialect_python_bindings( + ADD_TO_PARENT StandalonePythonSources + ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir_standalone" + TD_FILE dialects/StandaloneOps.td + SOURCES + dialects/standalone.py + DIALECT_NAME standalone) + +declare_mlir_python_extension(StandalonePythonSources.Extension + MODULE_NAME _standaloneDialects + ADD_TO_PARENT StandalonePythonSources + SOURCES + StandaloneExtension.cpp + EMBED_CAPI_LINK_LIBS + StandaloneCAPI +) + +################################################################################ +# Common CAPI +################################################################################ + +add_mlir_python_common_capi_library(StandalonePythonCAPI + INSTALL_COMPONENT StandalonePythonModules + INSTALL_DESTINATION python_packages/standalone/mlir_standalone/_mlir_libs + OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone/_mlir_libs" + RELATIVE_INSTALL_ROOT "../../../.." + DECLARED_SOURCES + StandalonePythonSources + # TODO: Remove this in favor of showing fine grained registration once + # available. + MLIRPythonExtension.RegisterEverything + MLIRPythonSources.Core +) + +################################################################################ +# Instantiation of all Python modules +################################################################################ + +add_mlir_python_modules(StandalonePythonModules + ROOT_PREFIX "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone" + INSTALL_PREFIX "python_packages/standalone/mlir_standalone" + DECLARED_SOURCES + StandalonePythonSources + # TODO: Remove this in favor of showing fine grained registration once + # available. + MLIRPythonExtension.RegisterEverything + MLIRPythonSources + COMMON_CAPI_LINK_LIBS + StandalonePythonCAPI + ) diff --git a/python/StandaloneExtension.cpp b/python/StandaloneExtension.cpp new file mode 100644 index 0000000..4c2043a --- /dev/null +++ b/python/StandaloneExtension.cpp @@ -0,0 +1,31 @@ +//===- StandaloneExtension.cpp - Extension module -------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "Standalone-c/Dialects.h" +#include "mlir/Bindings/Python/PybindAdaptors.h" + +namespace py = pybind11; +using namespace mlir::python::adaptors; + +PYBIND11_MODULE(_standaloneDialects, m) { + //===--------------------------------------------------------------------===// + // standalone dialect + //===--------------------------------------------------------------------===// + auto standalone_m = m.def_submodule("standalone"); + + standalone_m.def( + "register_dialect", + [](MlirContext context, bool load) { + MlirDialectHandle handle = mlirGetDialectHandle__standalone__(); + mlirDialectHandleRegisterDialect(handle, context); + if (load) { + mlirDialectHandleLoadDialect(handle, context); + } + }, + py::arg("context") = py::none(), py::arg("load") = true); +} diff --git a/python/mlir_standalone/dialects/StandaloneOps.td b/python/mlir_standalone/dialects/StandaloneOps.td new file mode 100644 index 0000000..6cfa6b7 --- /dev/null +++ b/python/mlir_standalone/dialects/StandaloneOps.td @@ -0,0 +1,15 @@ +//===-- StandaloneOps.td - Python bindings for standalone --*- tablegen -*-===// +// +// 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 +// +//===---------------------------------------------------------------------===// + +#ifndef PYTHON_BINDINGS_STANDALONE_OPS +#define PYTHON_BINDINGS_STANDALONE_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "Standalone/StandaloneOps.td" + +#endif diff --git a/python/mlir_standalone/dialects/standalone.py b/python/mlir_standalone/dialects/standalone.py new file mode 100644 index 0000000..c958b2a --- /dev/null +++ b/python/mlir_standalone/dialects/standalone.py @@ -0,0 +1,6 @@ +# 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 ._standalone_ops_gen import * +from .._mlir_libs._standaloneDialects.standalone import * |