From 4fc2e87a4212f5300543833e57737146c2f9c403 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Thu, 3 Jun 2021 10:25:38 -0700 Subject: [PATCH] Add mhlo python binding generator target This just invokes the generator backend & creates a filegroup. PiperOrigin-RevId: 377318653 --- BUILD | 40 ++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 1 + python/CMakeLists.txt | 9 +++++++++ python/MhloOps.td | 24 ++++++++++++++++++++++++ python/mhlo.py | 18 ++++++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 python/CMakeLists.txt create mode 100644 python/MhloOps.td create mode 100644 python/mhlo.py diff --git a/BUILD b/BUILD index 64498fe..8af4602 100644 --- a/BUILD +++ b/BUILD @@ -1250,3 +1250,43 @@ cc_binary( "@llvm-project//mlir:Support", ], ) + +# Python library. + +td_library( + name = "MhloOpsPyTdFiles", + srcs = [ + "@llvm-project//mlir:include/mlir/Bindings/Python/Attributes.td", + ], + includes = ["include"], + deps = [ + ":hlo_ops_td_files", + "@llvm-project//mlir:OpBaseTdFiles", + ], +) + +gentbl_filegroup( + name = "MhloOpsPyGen", + tbl_outs = [ + ( + [ + "-gen-python-op-bindings", + "-bind-dialect=mhlo", + ], + "python/_mhlo_ops_gen.py", + ), + ], + tblgen = "@llvm-project//mlir:mlir-tblgen", + td_file = "python/MhloOps.td", + deps = [ + ":MhloOpsPyTdFiles", + ], +) + +filegroup( + name = "MhloOpsPyFiles", + srcs = [ + "python/mhlo.py", + ":MhloOpsPyGen", + ], +) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8bfc0d2..b6eba93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,5 +85,6 @@ add_custom_target(check-mlir-hlo) add_subdirectory(include/mlir-hlo) add_subdirectory(lib) +add_subdirectory(python) add_subdirectory(tools) add_subdirectory(tests) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt new file mode 100644 index 0000000..91b783e --- /dev/null +++ b/python/CMakeLists.txt @@ -0,0 +1,9 @@ +include(AddMLIRPython) + +################################################################################ +# Generate dialect-specific bindings. +################################################################################ + +add_mlir_dialect_python_bindings(MLIRBindingsPythonMhloOps + TD_FILE MhloOps.td + DIALECT_NAME mhlo_dialect) diff --git a/python/MhloOps.td b/python/MhloOps.td new file mode 100644 index 0000000..eb9d1c5 --- /dev/null +++ b/python/MhloOps.td @@ -0,0 +1,24 @@ +/* Copyright 2021 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// Entry point for MHLO ops bind. + +#ifndef PYTHON_BINDINGS_MHLO_OPS +#define PYTHON_BINDINGS_MHLO_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "mlir-hlo/Dialect/mhlo/IR/hlo_ops.td" + +#endif diff --git a/python/mhlo.py b/python/mhlo.py new file mode 100644 index 0000000..cc8288a --- /dev/null +++ b/python/mhlo.py @@ -0,0 +1,18 @@ +# Copyright 2020 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +# pylint: disable=wildcard-import,relative-beyond-top-level +from ._mhlo_ops_gen import * +# pylint: enable=wildcard-import,relative-beyond-top-level