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
This commit is contained in:
parent
c1ae378205
commit
53c866c286
|
@ -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_different
|
||||
"${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()
|
||||
|
||||
|
|
|
@ -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
|
||||
################################################################################
|
||||
|
|
16
mlir/lib/Bindings/Python/LinalgOps.td
Normal file
16
mlir/lib/Bindings/Python/LinalgOps.td
Normal file
|
@ -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
|
15
mlir/lib/Bindings/Python/ShapeOps.td
Normal file
15
mlir/lib/Bindings/Python/ShapeOps.td
Normal file
|
@ -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
|
15
mlir/lib/Bindings/Python/TensorOps.td
Normal file
15
mlir/lib/Bindings/Python/TensorOps.td
Normal file
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue