Skip to content

Commit

Permalink
Add python bindings for IREE internal dialects.
Browse files Browse the repository at this point in the history
I've been running into these recently when wanting to create helper scripts. Also some of these will be helpful for Turbine.
  • Loading branch information
stellaraccident committed Aug 22, 2023
1 parent 3e31d4c commit dfe89c0
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 0 deletions.
46 changes: 46 additions & 0 deletions compiler/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,51 @@ set(CMAKE_PLATFORM_NO_VERSIONED_SONAME 1)
# Sources
################################################################################

declare_mlir_python_sources(IREEPythonSources)
declare_mlir_python_sources(IREEPythonSources.Dialects
ADD_TO_PARENT IREEPythonSources
)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT IREEPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/iree/compiler"
TD_FILE dialects/FlowBinding.td
SOURCES dialects/flow.py
DIALECT_NAME flow
)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT IREEPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/iree/compiler"
TD_FILE dialects/HALBinding.td
SOURCES dialects/hal.py
DIALECT_NAME hal
)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT IREEPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/iree/compiler"
TD_FILE dialects/StreamBinding.td
SOURCES dialects/stream.py
DIALECT_NAME stream
)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT IREEPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/iree/compiler"
TD_FILE dialects/UtilBinding.td
SOURCES dialects/util.py
DIALECT_NAME util
)

declare_mlir_dialect_python_bindings(
ADD_TO_PARENT IREEPythonSources.Dialects
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/iree/compiler"
TD_FILE dialects/VMBinding.td
SOURCES dialects/vm.py
DIALECT_NAME vm
)

declare_mlir_python_sources(IREECompilerAPIPythonTools
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/iree/compiler"
SOURCES
Expand Down Expand Up @@ -88,6 +133,7 @@ set(_SOURCE_COMPONENTS
# Local sources.
IREECompilerAPIPythonTools
IREECompilerPythonExtensions
IREEPythonSources

MLIRPythonSources.Core

Expand Down
12 changes: 12 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/FlowBinding.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2023 The IREE Authors
//
// Licensed 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_FLOW_OPS
#define PYTHON_BINDINGS_FLOW_OPS

include "iree/compiler/Dialect/Flow/IR/FlowOps.td"

#endif // PYTHON_BINDINGS_FLOW_OPS
12 changes: 12 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/HALBinding.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2023 The IREE Authors
//
// Licensed 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_HAL_OPS
#define PYTHON_BINDINGS_HAL_OPS

include "iree/compiler/Dialect/HAL/IR/HALOps.td"

#endif // PYTHON_BINDINGS_HAL_OPS
12 changes: 12 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/StreamBinding.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2023 The IREE Authors
//
// Licensed 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_STREAM_OPS
#define PYTHON_BINDINGS_STREAM_OPS

include "iree/compiler/Dialect/Stream/IR/StreamOps.td"

#endif // PYTHON_BINDINGS_STREAM_OPS
12 changes: 12 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/UtilBinding.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2023 The IREE Authors
//
// Licensed 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_UTIL_OPS
#define PYTHON_BINDINGS_UTIL_OPS

include "iree/compiler/Dialect/Util/IR/UtilOps.td"

#endif // PYTHON_BINDINGS_UTIL_OPS
12 changes: 12 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/VMBinding.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2023 The IREE Authors
//
// Licensed 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_VM_OPS
#define PYTHON_BINDINGS_VM_OPS

include "iree/compiler/Dialect/VM/IR/VMOps.td"

#endif // PYTHON_BINDINGS_VM_OPS
7 changes: 7 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2023 The IREE Authors
#
# Licensed 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 ._flow_ops_gen import *
7 changes: 7 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/hal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2023 The IREE Authors
#
# Licensed 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 ._hal_ops_gen import *
7 changes: 7 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2023 The IREE Authors
#
# Licensed 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 ._stream_ops_gen import *
7 changes: 7 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2023 The IREE Authors
#
# Licensed 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 ._util_ops_gen import *
7 changes: 7 additions & 0 deletions compiler/bindings/python/iree/compiler/dialects/vm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2023 The IREE Authors
#
# Licensed 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 ._vm_ops_gen import *
6 changes: 6 additions & 0 deletions compiler/bindings/python/test/ir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ iree_py_test(
"registration_test.py"
)

iree_py_test(
NAME
dialects_test
SRCS
"dialects_test.py"
)
16 changes: 16 additions & 0 deletions compiler/bindings/python/test/ir/dialects_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 The IREE Authors
#
# Licensed 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 iree.compiler import ir

# Make sure that our dialects import.
from iree.compiler.dialects import (
flow,
hal,
stream,
vm,
util,
)

0 comments on commit dfe89c0

Please sign in to comment.