From 7558bbcf3ab4bfedc9eda6fb22e7a1e8cbb9ba73 Mon Sep 17 00:00:00 2001 From: Jakub Kuderski Date: Wed, 14 Jun 2023 13:18:44 -0400 Subject: [PATCH] [StableHLO] Use stablehlo submodule (#14094) Use the stablehlo submodule to provide stablehlo, since we do not need the 'mhlo' part or mlir-hlo anymore. Fixes: https://github.com/openxla/iree/issues/12678 --------- Co-authored-by: Scott Todd --- .gitmodules | 6 ++-- CMakeLists.txt | 4 +-- build_tools/bazel/workspace.bzl | 4 +-- .../bazel_to_cmake/bazel_to_cmake_targets.py | 6 ++-- build_tools/scripts/integrate/README.md | 24 +++++++-------- build_tools/scripts/integrate/iree_modules.py | 16 +++++----- build_tools/scripts/integrate/patch_module.py | 2 +- .../third_party/mlir-hlo/CMakeLists.txt | 29 ------------------- .../third_party/stablehlo/CMakeLists.txt | 12 ++++++++ compiler/bindings/python/CMakeLists.txt | 4 +-- compiler/setup.py | 2 +- .../InputConversion/Common/BUILD.bazel | 2 +- .../InputConversion/StableHLO/BUILD.bazel | 10 +++---- .../InputConversion/StableHLO/CMakeLists.txt | 2 +- .../StableHLO/Preprocessing/BUILD.bazel | 6 ++-- .../StableHLO/Preprocessing/CMakeLists.txt | 2 +- compiler/src/iree/compiler/Tools/BUILD.bazel | 4 +-- third_party/mlir-hlo | 1 - third_party/stablehlo | 1 + 19 files changed, 60 insertions(+), 77 deletions(-) delete mode 100644 build_tools/third_party/mlir-hlo/CMakeLists.txt create mode 100644 build_tools/third_party/stablehlo/CMakeLists.txt delete mode 160000 third_party/mlir-hlo create mode 160000 third_party/stablehlo diff --git a/.gitmodules b/.gitmodules index 10187acb1a7c0..7c6eb3f6c4abc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -32,9 +32,6 @@ [submodule "third_party/cpuinfo"] path = third_party/cpuinfo url = https://github.com/pytorch/cpuinfo.git -[submodule "third_party/mlir-hlo"] - path = third_party/mlir-hlo - url = https://github.com/iree-org/iree-mhlo-fork.git [submodule "third_party/libyaml"] path = third_party/libyaml url = https://github.com/yaml/libyaml.git @@ -44,6 +41,9 @@ [submodule "third_party/musl"] path = third_party/musl url = https://github.com/powderluv/musl.git +[submodule "third_party/stablehlo"] + path = third_party/stablehlo + url = https://github.com/iree-org/stablehlo.git [submodule "third_party/tpp-mlir"] path = third_party/tpp-mlir url = https://github.com/plaidml/tpp-mlir diff --git a/CMakeLists.txt b/CMakeLists.txt index c79f3c906aad8..f52bf46883849 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -816,7 +816,7 @@ else() # Add default external projects. iree_llvm_add_external_project(mlir-iree-dialects ${CMAKE_CURRENT_SOURCE_DIR}/llvm-external-projects/iree-dialects) - iree_llvm_add_external_project(mlir-hlo ${CMAKE_CURRENT_SOURCE_DIR}/third_party/mlir-hlo) + iree_llvm_add_external_project(stablehlo ${CMAKE_CURRENT_SOURCE_DIR}/third_party/stablehlo) if(IREE_INPUT_TORCH) iree_llvm_add_external_project(torch-mlir-dialects ${CMAKE_CURRENT_SOURCE_DIR}/third_party/torch-mlir-dialects) endif() @@ -876,7 +876,7 @@ if(IREE_HAL_DRIVER_VULKAN) endif() if(IREE_BUILD_COMPILER) - add_subdirectory(build_tools/third_party/mlir-hlo EXCLUDE_FROM_ALL) + add_subdirectory(build_tools/third_party/stablehlo EXCLUDE_FROM_ALL) endif() if(IREE_BUILD_TESTS) diff --git a/build_tools/bazel/workspace.bzl b/build_tools/bazel/workspace.bzl index f54c920179f3f..10ff1464174e0 100644 --- a/build_tools/bazel/workspace.bzl +++ b/build_tools/bazel/workspace.bzl @@ -129,8 +129,8 @@ def configure_iree_submodule_deps(iree_repo_alias = "@", iree_path = "./"): maybe( native.local_repository, - name = "mlir-hlo", - path = paths.join(iree_path, "third_party/mlir-hlo"), + name = "stablehlo", + path = paths.join(iree_path, "third_party/stablehlo"), ) maybe( diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py b/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py index 7c70e30d32910..9d95d23f2ea3c 100644 --- a/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py +++ b/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py @@ -78,9 +78,9 @@ def __init__(self, repo_map: Dict[str, str]): "@llvm-project//mlir:VectorOps": ["MLIRVector"], # StableHLO. - "@mlir-hlo//stablehlo:chlo_ops": ["ChloOps",], - "@mlir-hlo//stablehlo:stablehlo_ops": ["StablehloOps",], - "@mlir-hlo//stablehlo:broadcast_utils": ["StablehloBroadcastUtils",], + "@stablehlo//:chlo_ops": ["ChloOps",], + "@stablehlo//:stablehlo_ops": ["StablehloOps",], + "@stablehlo//:broadcast_utils": ["StablehloBroadcastUtils",], # NCCL "@nccl//:headers": ["nccl::headers",], diff --git a/build_tools/scripts/integrate/README.md b/build_tools/scripts/integrate/README.md index 059fa63479683..bc9e882c59f08 100644 --- a/build_tools/scripts/integrate/README.md +++ b/build_tools/scripts/integrate/README.md @@ -4,7 +4,7 @@ This directory contains scripts for managing some of our more storied third party dependencies (which are submodules in the project): * llvm-project -* mlir-hlo +* stablehlo Depending on your activity, please refer to the appropriate script, which has comments at the top on how to use it: @@ -87,11 +87,11 @@ In this guide, we reference this directory as `$SCRIPTS`. ### Advancing the mainline branch in forks -The IREE team maintains fork repositories for both llvm-project and mlir-hlo, +The IREE team maintains fork repositories for both llvm-project and stablehlo, allowing them to be patched out of band. These repositories are: * https://github.com/iree-org/iree-llvm-fork (`main` branch) -* https://github.com/iree-org/iree-mhlo-fork (`master` branch) +* https://github.com/iree-org/stablehlo (`main` branch) * https://github.com/iree-org/iree-tf-fork (`master` branch) Iree repository has an @@ -106,9 +106,9 @@ it manually. #### Strategy 1: Bump third_party/llvm-project in isolation It is very common to only bump llvm-project and not sync to new versions of -mlir-hlo and tensorflow. However, as we need to periodically integrate those +stablehlo and tensorflow. However, as we need to periodically integrate those as well, if the Google repositories are up to date and you have the option -to integrate to a common LLVM commit, bringing mlir-hlo and tensorflow up +to integrate to a common LLVM commit, bringing stablehlo and tensorflow up to date as well, it can save some cycles overall. In order to bump to the current ToT commit, simply run: @@ -152,20 +152,20 @@ the CI and fix it directly. But if dealing with some large/breaking changes, be prepared to settle in for a bit and play a triage role, working to get things minimally to a point that you can shard failures to others. -Note that if not bumping mlir-hlo, then it is likely that you will hit a -compiler error in mlir-hlo at some point and will need to fix it. Advancing +Note that if not bumping stablehlo, then it is likely that you will hit a +compiler error in stablehlo at some point and will need to fix it. Advancing it to HEAD is always an option, if that contains the fix, but this dependency is unstable and should be maintained version locked with the integrations directory. It is possible to advance it, but only if integrations tests pass, and even then there is the chance for untested compatibility issues. -Typically, for the parts of mlir-hlo that we use, changes can be trivial (a +Typically, for the parts of stablehlo that we use, changes can be trivial (a few lines, likely that you have already patched something similar in IREE). Just make the changes in your submodule, commit them and push to a patch branch with: ``` -$SCRIPTS/patch_module.py --module_name=mlir-hlo +$SCRIPTS/patch_module.py --module_name=stablehlo ``` You can just do this in your integrate branch and incorporate the changes. @@ -196,7 +196,7 @@ Please add the integrator to reviewers in the cherry-pick PR, so the integrator won't miss the commits when bumping submodules. If you don't know who is the integrator, you can reach out to @hanchung on discord or add hanhanW as a reviewer. -We support cherry-picking specific commits in to both llvm-project and mlir-hlo. +We support cherry-picking specific commits in to both llvm-project and stablehlo. This should only ever be done to incorporate patches that enable further development and which will resolve automatically as part of a future integrate of the respective module: make sure that you are only cherry-picking @@ -205,12 +205,12 @@ experimental changes, feel free to push a personal branch to the fork repo with such changes, which will let you use the CI -- but please do not commit experimental, non-upstream committed commits to the main project. -The process for cherry-picking into llvm-project or mlir-hlo uses the same +The process for cherry-picking into llvm-project or stablehlo uses the same script. The first step is to prepare a patch branch and reset your local submodule to track it: ``` -$SCRIPTS/patch_module.py --module={llvm-project|mlir-hlo} +$SCRIPTS/patch_module.py --module={llvm-project|stablehlo} ``` If successful, this will allocate a new branch in the fork repo with a name diff --git a/build_tools/scripts/integrate/iree_modules.py b/build_tools/scripts/integrate/iree_modules.py index 3d9cf046e6362..39ac4fd8b8bc5 100644 --- a/build_tools/scripts/integrate/iree_modules.py +++ b/build_tools/scripts/integrate/iree_modules.py @@ -30,14 +30,14 @@ def __init__(self, *, name: str, path: str, branch_pin_file: str, fork_repository_pull="https://github.com/iree-org/iree-llvm-fork.git", branch_prefix="patched-llvm-project-", ), - "mlir-hlo": + "stablehlo": ModuleInfo( - name="mlir-hlo", - path="third_party/mlir-hlo", - branch_pin_file="third_party/mlir-hlo.branch-pin", - default_repository_url="https://github.com/iree-org/iree-mhlo-fork.git", - fork_repository_push="git@github.com:iree-org/iree-mhlo-fork.git", - fork_repository_pull="https://github.com/iree-org/iree-mhlo-fork.git", - branch_prefix="patched-mlir-hlo-", + name="stablehlo", + path="third_party/stablehlo", + branch_pin_file="third_party/stablehlo.branch-pin", + default_repository_url="https://github.com/iree-org/stablehlo.git", + fork_repository_push="git@github.com:iree-org/stablehlo.git", + fork_repository_pull="https://github.com/iree-org/stablehlo.git", + branch_prefix="patched-stablehlo-", ) } diff --git a/build_tools/scripts/integrate/patch_module.py b/build_tools/scripts/integrate/patch_module.py index 7b77a75e13483..6068ceed2bd5a 100755 --- a/build_tools/scripts/integrate/patch_module.py +++ b/build_tools/scripts/integrate/patch_module.py @@ -16,7 +16,7 @@ # git cherry-pick # 3. Run this script from the main IREE repository (one of the following): # patch_module.py --module=llvm-project -# patch_module.py --module=mlir-hlo +# patch_module.py --module=stablehlo # 4. Send a PR on the main IREE repo to bump the submodule. Be sure to include # the name of the patch branch for posterity. diff --git a/build_tools/third_party/mlir-hlo/CMakeLists.txt b/build_tools/third_party/mlir-hlo/CMakeLists.txt deleted file mode 100644 index a68af7ebb35fe..0000000000000 --- a/build_tools/third_party/mlir-hlo/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2020 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 - -set(TF_MLIR_HLO_SOURCE_DIR - "${IREE_SOURCE_DIR}/third_party/mlir-hlo/" -) -set(TF_MLIR_HLO_BINARY_DIR - "${IREE_BINARY_DIR}/llvm-external-projects/mlir-hlo" -) - -external_cc_library( - PACKAGE - tensorflow - NAME - external_mhlo_includes - ROOT - ${TF_MLIR_HLO_SOURCE_DIR} - INCLUDES - "${TF_MLIR_HLO_SOURCE_DIR}" - "${TF_MLIR_HLO_SOURCE_DIR}/include/" - "${TF_MLIR_HLO_SOURCE_DIR}/stablehlo/" - "${TF_MLIR_HLO_BINARY_DIR}" - "${TF_MLIR_HLO_BINARY_DIR}/include/" - "${TF_MLIR_HLO_BINARY_DIR}/stablehlo/" - PUBLIC -) diff --git a/build_tools/third_party/stablehlo/CMakeLists.txt b/build_tools/third_party/stablehlo/CMakeLists.txt new file mode 100644 index 0000000000000..568e47ab4043a --- /dev/null +++ b/build_tools/third_party/stablehlo/CMakeLists.txt @@ -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 + +set(STABLEHLO_SOURCE_DIR + "${IREE_SOURCE_DIR}/third_party/stablehlo/" +) +set(STABLEHLO_BINARY_DIR + "${IREE_BINARY_DIR}/llvm-external-projects/stablehlo" +) diff --git a/compiler/bindings/python/CMakeLists.txt b/compiler/bindings/python/CMakeLists.txt index 0c034469c582d..38c420c2157e5 100644 --- a/compiler/bindings/python/CMakeLists.txt +++ b/compiler/bindings/python/CMakeLists.txt @@ -34,8 +34,8 @@ include_directories( "${IREE_SOURCE_DIR}/compiler/bindings/c" "${IREE_SOURCE_DIR}/llvm-external-projects/iree-dialects/include" "${IREE_SOURCE_DIR}/third_party/llvm-project/mlir/include" - "${IREE_SOURCE_DIR}/third_party/mlir-hlo/include" - "${IREE_SOURCE_DIR}/third_party/mlir-hlo" + "${IREE_SOURCE_DIR}/third_party/stablehlo/include" + "${IREE_SOURCE_DIR}/third_party/stablehlo" ) # On Unixes, disable the creation of versioned/symlinked `.so` files. With diff --git a/compiler/setup.py b/compiler/setup.py index df9e1e9fea6fa..562d194f0aab0 100644 --- a/compiler/setup.py +++ b/compiler/setup.py @@ -355,7 +355,7 @@ def find_git_versions(): print(f"ERROR: Could not get IREE revision: {e}", file=sys.stderr) revisions["LLVM_PROJECT"] = find_git_submodule_revision( "third_party/llvm-project") - revisions["MLIR_HLO"] = find_git_submodule_revision("third_party/mlir-hlo") + revisions["STABLEHLO"] = find_git_submodule_revision("third_party/stablehlo") return revisions diff --git a/compiler/src/iree/compiler/InputConversion/Common/BUILD.bazel b/compiler/src/iree/compiler/InputConversion/Common/BUILD.bazel index 3f944a582667a..a3d7e7b2bfbec 100644 --- a/compiler/src/iree/compiler/InputConversion/Common/BUILD.bazel +++ b/compiler/src/iree/compiler/InputConversion/Common/BUILD.bazel @@ -105,7 +105,7 @@ iree_compiler_cc_library( "@llvm-project//mlir:Pass", "@llvm-project//mlir:TosaDialect", "@llvm-project//mlir:Transforms", - "@mlir-hlo//stablehlo:stablehlo_ops", + "@stablehlo//:stablehlo_ops", "@torch-mlir-dialects//:TorchMLIRTMTensorDialect", ], ) diff --git a/compiler/src/iree/compiler/InputConversion/StableHLO/BUILD.bazel b/compiler/src/iree/compiler/InputConversion/StableHLO/BUILD.bazel index ff0e92c1c4070..4a457e97b1c25 100644 --- a/compiler/src/iree/compiler/InputConversion/StableHLO/BUILD.bazel +++ b/compiler/src/iree/compiler/InputConversion/StableHLO/BUILD.bazel @@ -53,8 +53,8 @@ iree_gentbl_cc_library( tblgen = "@llvm-project//mlir:mlir-tblgen", td_file = "CHLODecompositionPatterns.td", deps = [ - "@mlir-hlo//stablehlo:chlo_ops_td_files", - "@mlir-hlo//stablehlo:stablehlo_ops_td_files", + "@stablehlo//:chlo_ops_td_files", + "@stablehlo//:stablehlo_ops_td_files", ], ) @@ -115,9 +115,9 @@ iree_compiler_cc_library( "@llvm-project//mlir:TensorUtils", "@llvm-project//mlir:Transforms", "@llvm-project//mlir:VectorDialect", - "@mlir-hlo//stablehlo:broadcast_utils", - "@mlir-hlo//stablehlo:chlo_ops", - "@mlir-hlo//stablehlo:stablehlo_ops", + "@stablehlo//:broadcast_utils", + "@stablehlo//:chlo_ops", + "@stablehlo//:stablehlo_ops", ], ) diff --git a/compiler/src/iree/compiler/InputConversion/StableHLO/CMakeLists.txt b/compiler/src/iree/compiler/InputConversion/StableHLO/CMakeLists.txt index f23c246c4c646..4674e8a7fe300 100644 --- a/compiler/src/iree/compiler/InputConversion/StableHLO/CMakeLists.txt +++ b/compiler/src/iree/compiler/InputConversion/StableHLO/CMakeLists.txt @@ -1,5 +1,5 @@ # Add this tablegen include to support CHLO rewrites with DRR. -list(APPEND IREE_COMPILER_TABLEGEN_INCLUDE_DIRS "${IREE_SOURCE_DIR}/third_party/mlir-hlo/stablehlo") +list(APPEND IREE_COMPILER_TABLEGEN_INCLUDE_DIRS "${IREE_SOURCE_DIR}/third_party/stablehlo") ### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_ABOVE_THIS_LINE ### ################################################################################ diff --git a/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/BUILD.bazel b/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/BUILD.bazel index 5979832a29c5a..165ce95e3bd50 100644 --- a/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/BUILD.bazel +++ b/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/BUILD.bazel @@ -53,7 +53,7 @@ iree_gentbl_cc_library( td_file = "ComplexLoweringPatterns.td", deps = [ "@llvm-project//mlir:FuncTdFiles", - "@mlir-hlo//stablehlo:stablehlo_ops_td_files", + "@stablehlo//:stablehlo_ops_td_files", ], ) @@ -90,7 +90,7 @@ iree_compiler_cc_library( "@llvm-project//mlir:Support", "@llvm-project//mlir:TensorDialect", "@llvm-project//mlir:Transforms", - "@mlir-hlo//stablehlo:chlo_ops", - "@mlir-hlo//stablehlo:stablehlo_ops", + "@stablehlo//:chlo_ops", + "@stablehlo//:stablehlo_ops", ], ) diff --git a/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/CMakeLists.txt b/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/CMakeLists.txt index 5aefb3afabed9..8fccaefa92f58 100644 --- a/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/CMakeLists.txt +++ b/compiler/src/iree/compiler/InputConversion/StableHLO/Preprocessing/CMakeLists.txt @@ -1,5 +1,5 @@ # Add this tablegen include to support stablehlo rewrites with DRR. -list(APPEND IREE_COMPILER_TABLEGEN_INCLUDE_DIRS "${IREE_SOURCE_DIR}/third_party/mlir-hlo/stablehlo") +list(APPEND IREE_COMPILER_TABLEGEN_INCLUDE_DIRS "${IREE_SOURCE_DIR}/third_party/stablehlo") ### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_ABOVE_THIS_LINE ### ################################################################################ diff --git a/compiler/src/iree/compiler/Tools/BUILD.bazel b/compiler/src/iree/compiler/Tools/BUILD.bazel index 799372ed115b8..1bd4185282f7d 100644 --- a/compiler/src/iree/compiler/Tools/BUILD.bazel +++ b/compiler/src/iree/compiler/Tools/BUILD.bazel @@ -43,8 +43,8 @@ iree_compiler_cc_library( "@llvm-project//mlir:ConversionPasses", "@llvm-project//mlir:IR", "@llvm-project//mlir:TosaDialect", - "@mlir-hlo//stablehlo:chlo_ops", - "@mlir-hlo//stablehlo:stablehlo_ops", + "@stablehlo//:chlo_ops", + "@stablehlo//:stablehlo_ops", "@torch-mlir-dialects//:TorchMLIRTMTensorDialect", ], ) diff --git a/third_party/mlir-hlo b/third_party/mlir-hlo deleted file mode 160000 index 63a907f9839f0..0000000000000 --- a/third_party/mlir-hlo +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 63a907f9839f06863a64d7f47d059624f7e035bf diff --git a/third_party/stablehlo b/third_party/stablehlo new file mode 160000 index 0000000000000..52de2c0b4b744 --- /dev/null +++ b/third_party/stablehlo @@ -0,0 +1 @@ +Subproject commit 52de2c0b4b7446a56e8985a4de6d50c1d8b47c3b