[Mlir-commits] [mlir] e82a30b - [mlir] enable Python bindings for the MemRef dialect
Alex Zinenko
llvmlistbot at llvm.org
Mon Mar 15 06:07:57 PDT 2021
Author: Alex Zinenko
Date: 2021-03-15T14:07:51+01:00
New Revision: e82a30bdce6955f7f5fe84ccacc92b8078e66f37
URL: https://github.com/llvm/llvm-project/commit/e82a30bdce6955f7f5fe84ccacc92b8078e66f37
DIFF: https://github.com/llvm/llvm-project/commit/e82a30bdce6955f7f5fe84ccacc92b8078e66f37.diff
LOG: [mlir] enable Python bindings for the MemRef dialect
A previous commit moved multiple ops from Standard to MemRef dialect.
Some of these ops are exercised in Python bindings. Enable bindings for
the newly created MemRef dialect and update a test accordingly.
Added:
mlir/lib/Bindings/Python/MemRefOps.td
mlir/lib/Bindings/Python/mlir/dialects/memref.py
mlir/test/Bindings/Python/dialects/memref.py
Modified:
mlir/lib/Bindings/Python/CMakeLists.txt
Removed:
mlir/test/Bindings/Python/dialects/std.py
################################################################################
diff --git a/mlir/lib/Bindings/Python/CMakeLists.txt b/mlir/lib/Bindings/Python/CMakeLists.txt
index c444ddcc4fc1..5f042ec57c29 100644
--- a/mlir/lib/Bindings/Python/CMakeLists.txt
+++ b/mlir/lib/Bindings/Python/CMakeLists.txt
@@ -42,6 +42,11 @@ add_mlir_dialect_python_bindings(MLIRBindingsPythonLinalgOps
DEPENDS LinalgOdsGen)
add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonLinalgOps)
+add_mlir_dialect_python_bindings(MLIRBindingsPythonMemRefOps
+ TD_FILE MemRefOps.td
+ DIALECT_NAME memref)
+add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonMemRefOps)
+
add_mlir_dialect_python_bindings(MLIRBindingsPythonShapeOps
TD_FILE ShapeOps.td
DIALECT_NAME shape)
diff --git a/mlir/lib/Bindings/Python/MemRefOps.td b/mlir/lib/Bindings/Python/MemRefOps.td
new file mode 100644
index 000000000000..8dd9764791ea
--- /dev/null
+++ b/mlir/lib/Bindings/Python/MemRefOps.td
@@ -0,0 +1,15 @@
+//===-- MemRefOps.td - Entry point for MemRefOps 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_MEMREF_OPS
+#define PYTHON_BINDINGS_MEMREF_OPS
+
+include "mlir/Bindings/Python/Attributes.td"
+include "mlir/Dialect/MemRef/IR/MemRefOps.td"
+
+#endif
diff --git a/mlir/lib/Bindings/Python/mlir/dialects/memref.py b/mlir/lib/Bindings/Python/mlir/dialects/memref.py
new file mode 100644
index 000000000000..3afb6a70cb9e
--- /dev/null
+++ b/mlir/lib/Bindings/Python/mlir/dialects/memref.py
@@ -0,0 +1,5 @@
+# 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 ._memref_ops_gen import *
diff --git a/mlir/test/Bindings/Python/dialects/std.py b/mlir/test/Bindings/Python/dialects/memref.py
similarity index 74%
rename from mlir/test/Bindings/Python/dialects/std.py
rename to mlir/test/Bindings/Python/dialects/memref.py
index 6f04e25727c0..8c3b95b07aee 100644
--- a/mlir/test/Bindings/Python/dialects/std.py
+++ b/mlir/test/Bindings/Python/dialects/memref.py
@@ -2,12 +2,13 @@
from mlir.ir import *
import mlir.dialects.std as std
+import mlir.dialects.memref as memref
def run(f):
print("\nTEST:", f.__name__)
f()
-# _HECK-LABEL: TEST: testSubViewAccessors
+# CHECK-LABEL: TEST: testSubViewAccessors
def testSubViewAccessors():
ctx = Context()
module = Module.parse(r"""
@@ -31,28 +32,22 @@ def testSubViewAccessors():
assert len(subview.strides) == 2
assert subview.result == subview.results[0]
- # _HECK: SubViewOp
+ # CHECK: SubViewOp
print(type(subview).__name__)
- # _HECK: constant 0
+ # CHECK: constant 0
print(subview.offsets[0])
- # _HECK: constant 1
+ # CHECK: constant 1
print(subview.offsets[1])
- # _HECK: constant 2
+ # CHECK: constant 2
print(subview.sizes[0])
- # _HECK: constant 3
+ # CHECK: constant 3
print(subview.sizes[1])
- # _HECK: constant 4
+ # CHECK: constant 4
print(subview.strides[0])
- # _HECK: constant 5
+ # CHECK: constant 5
print(subview.strides[1])
-# TODO: re-enable after moving the bindings from std to memref dialects
-# run(testSubViewAccessors)
+run(testSubViewAccessors)
-def forcePass():
- # CHECK: okay
- print("okay")
-
-run(forcePass)
More information about the Mlir-commits
mailing list