[Mlir-commits] [mlir] 53c866c - Enable python bindings for tensor, shape and linalg dialects.

Stella Laurenzo llvmlistbot at llvm.org
Mon Jan 11 12:36:41 PST 2021


Author: Stella Laurenzo
Date: 2021-01-11T12:35:49-08:00
New Revision: 53c866c286a7ca52bd09c7661d4c532ce5c0def8

URL: https://github.com/llvm/llvm-project/commit/53c866c286a7ca52bd09c7661d4c532ce5c0def8
DIFF: https://github.com/llvm/llvm-project/commit/53c866c286a7ca52bd09c7661d4c532ce5c0def8.diff

LOG: Enable python bindings for tensor, shape and linalg dialects.

* We've got significant missing features in order to use most of these effectively (i.e. custom builders, region-based builders).
* We presently also lack a mechanism for actually registering these dialects but they can be use with contexts that allow unregistered dialects for further prototyping.

Differential Revision: https://reviews.llvm.org/D94368

Added: 
    mlir/lib/Bindings/Python/LinalgOps.td
    mlir/lib/Bindings/Python/ShapeOps.td
    mlir/lib/Bindings/Python/TensorOps.td

Modified: 
    mlir/cmake/modules/AddMLIRPythonExtension.cmake
    mlir/lib/Bindings/Python/CMakeLists.txt
    mlir/test/Bindings/Python/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/mlir/cmake/modules/AddMLIRPythonExtension.cmake b/mlir/cmake/modules/AddMLIRPythonExtension.cmake
index 290b4a23aa31..dbbe71e22b13 100644
--- a/mlir/cmake/modules/AddMLIRPythonExtension.cmake
+++ b/mlir/cmake/modules/AddMLIRPythonExtension.cmake
@@ -136,17 +136,27 @@ function(add_mlir_python_extension libname extname)
 
 endfunction()
 
-function(add_mlir_dialect_python_bindings tblgen_target filename dialectname)
-  set(LLVM_TARGET_DEFINITIONS ${filename})
-  mlir_tablegen("${dialectname}.py" -gen-python-op-bindings
-                -bind-dialect=${dialectname})
-  add_public_tablegen_target(${tblgen_target})
+function(add_mlir_dialect_python_bindings tblgen_target)
+  cmake_parse_arguments(ARG
+    ""
+    "TD_FILE;DIALECT_NAME"
+    "DEPENDS"
+    ${ARGN})
+
+  set(LLVM_TARGET_DEFINITIONS ${ARG_TD_FILE})
+  mlir_tablegen("${ARG_DIALECT_NAME}.py" -gen-python-op-bindings
+                -bind-dialect=${ARG_DIALECT_NAME})
+  add_public_tablegen_target(
+    ${tblgen_target})
+  if(ARG_DEPENDS)
+    add_dependencies(${tblgen_target} ${ARG_DEPENDS})
+  endif()
 
   add_custom_command(
     TARGET ${tblgen_target} POST_BUILD
-    COMMENT "Copying generated python source \"dialects/${dialectname}.py\""
+    COMMENT "Copying generated python source \"dialects/${ARG_DIALECT_NAME}.py\""
     COMMAND "${CMAKE_COMMAND}" -E copy_if_
diff erent
-      "${CMAKE_CURRENT_BINARY_DIR}/${dialectname}.py"
-      "${PROJECT_BINARY_DIR}/python/mlir/dialects/${dialectname}.py")
+      "${CMAKE_CURRENT_BINARY_DIR}/${ARG_DIALECT_NAME}.py"
+      "${PROJECT_BINARY_DIR}/python/mlir/dialects/${ARG_DIALECT_NAME}.py")
 endfunction()
 

diff  --git a/mlir/lib/Bindings/Python/CMakeLists.txt b/mlir/lib/Bindings/Python/CMakeLists.txt
index 0c34f5b55415..827348913744 100644
--- a/mlir/lib/Bindings/Python/CMakeLists.txt
+++ b/mlir/lib/Bindings/Python/CMakeLists.txt
@@ -35,11 +35,27 @@ endforeach()
 # Generate dialect-specific bindings.
 ################################################################################
 
+add_mlir_dialect_python_bindings(MLIRBindingsPythonLinalgOps
+  TD_FILE LinalgOps.td
+  DIALECT_NAME linalg
+  DEPENDS LinalgOdsGen)
+add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonLinalgOps)
+
+add_mlir_dialect_python_bindings(MLIRBindingsPythonShapeOps
+  TD_FILE ShapeOps.td
+  DIALECT_NAME shape)
+add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonShapeOps)
+
 add_mlir_dialect_python_bindings(MLIRBindingsPythonStandardOps
-  StandardOps.td
-  std)
+  TD_FILE StandardOps.td
+  DIALECT_NAME std)
 add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonStandardOps)
 
+add_mlir_dialect_python_bindings(MLIRBindingsPythonTensorOps
+  TD_FILE TensorOps.td
+  DIALECT_NAME tensor)
+add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonTensorOps)
+
 ################################################################################
 # Build core python extension
 ################################################################################

diff  --git a/mlir/lib/Bindings/Python/LinalgOps.td b/mlir/lib/Bindings/Python/LinalgOps.td
new file mode 100644
index 000000000000..7650e954d59e
--- /dev/null
+++ b/mlir/lib/Bindings/Python/LinalgOps.td
@@ -0,0 +1,16 @@
+//===-- LinalgOps.td - Entry point for linalg bind ---------*- 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_LINALG_OPS
+#define PYTHON_BINDINGS_LINALG_OPS
+
+include "mlir/Bindings/Python/Attributes.td"
+include "mlir/Dialect/Linalg/IR/LinalgOps.td"
+include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.td"
+
+#endif

diff  --git a/mlir/lib/Bindings/Python/ShapeOps.td b/mlir/lib/Bindings/Python/ShapeOps.td
new file mode 100644
index 000000000000..c469a586bb27
--- /dev/null
+++ b/mlir/lib/Bindings/Python/ShapeOps.td
@@ -0,0 +1,15 @@
+//===-- ShapeOps.td - Entry point for TensorOps bind -------*- 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_SHAPE_OPS
+#define PYTHON_BINDINGS_SHAPE_OPS
+
+include "mlir/Bindings/Python/Attributes.td"
+include "mlir/Dialect/Shape/IR/ShapeOps.td"
+
+#endif

diff  --git a/mlir/lib/Bindings/Python/TensorOps.td b/mlir/lib/Bindings/Python/TensorOps.td
new file mode 100644
index 000000000000..40ecea7bfe8a
--- /dev/null
+++ b/mlir/lib/Bindings/Python/TensorOps.td
@@ -0,0 +1,15 @@
+//===-- TensorOps.td - Entry point for TensorOps bind ------*- 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_TENSOR_OPS
+#define PYTHON_BINDINGS_TENSOR_OPS
+
+include "mlir/Bindings/Python/Attributes.td"
+include "mlir/Dialect/Tensor/IR/TensorOps.td"
+
+#endif

diff  --git a/mlir/test/Bindings/Python/CMakeLists.txt b/mlir/test/Bindings/Python/CMakeLists.txt
index 619f4e317c96..666bd9fd1cec 100644
--- a/mlir/test/Bindings/Python/CMakeLists.txt
+++ b/mlir/test/Bindings/Python/CMakeLists.txt
@@ -1,4 +1,4 @@
 include(AddMLIRPythonExtension)
 add_mlir_dialect_python_bindings(MLIRBindingsPythonTestOps
-  python_test_ops.td
-  python_test)
+  TD_FILE python_test_ops.td
+  DIALECT_NAME python_test)


        


More information about the Mlir-commits mailing list