Add mhlo python binding generator target

This just invokes the generator backend & creates a filegroup.

PiperOrigin-RevId: 377318653
This commit is contained in:
Jacques Pienaar 2021-06-03 10:25:38 -07:00 committed by TensorFlow MLIR Team
parent fe42a08fc9
commit 4fc2e87a42
5 changed files with 92 additions and 0 deletions

40
BUILD
View File

@ -1250,3 +1250,43 @@ cc_binary(
"@llvm-project//mlir:Support", "@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",
],
)

View File

@ -85,5 +85,6 @@ add_custom_target(check-mlir-hlo)
add_subdirectory(include/mlir-hlo) add_subdirectory(include/mlir-hlo)
add_subdirectory(lib) add_subdirectory(lib)
add_subdirectory(python)
add_subdirectory(tools) add_subdirectory(tools)
add_subdirectory(tests) add_subdirectory(tests)

9
python/CMakeLists.txt Normal file
View File

@ -0,0 +1,9 @@
include(AddMLIRPython)
################################################################################
# Generate dialect-specific bindings.
################################################################################
add_mlir_dialect_python_bindings(MLIRBindingsPythonMhloOps
TD_FILE MhloOps.td
DIALECT_NAME mhlo_dialect)

24
python/MhloOps.td Normal file
View File

@ -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

18
python/mhlo.py Normal file
View File

@ -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