From cd90cbf92fbf82627d6a3a069960d4695bcf31eb Mon Sep 17 00:00:00 2001 From: Jakub Kuderski Date: Tue, 13 Jun 2023 11:44:29 -0400 Subject: [PATCH] [StableHLO] Use stablehlo submodule Use the stablehlo submodule to provide stablehlo, since we do not need the 'mhlo' part or mlir-hlo anymore. --- .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/llvm-project | 2 +- third_party/mlir-hlo | 1 - third_party/stablehlo | 1 + 20 files changed, 61 insertions(+), 78 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 384ac8fa3650..22e0981b9054 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,3 +41,6 @@ [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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e37d2a81f79..48ac9d834e1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -807,7 +807,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() @@ -860,7 +860,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 f54c920179f3..10ff1464174e 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 7c70e30d3291..9d95d23f2ea3 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 059fa6347968..bc9e882c59f0 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 3d9cf046e636..d829355ac5ff 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/iree-stablehlo-fork.git", + fork_repository_push="git@github.com:iree-org/iree-stablehlo-fork.git", + fork_repository_pull="https://github.com/iree-org/iree-stablehlo-fork.git", + branch_prefix="patched-stablehlo-", ) } diff --git a/build_tools/scripts/integrate/patch_module.py b/build_tools/scripts/integrate/patch_module.py index 7b77a75e1348..6068ceed2bd5 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 a68af7ebb35f..000000000000 --- 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 000000000000..568e47ab4043 --- /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 0c034469c582..38c420c2157e 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 df9e1e9fea6f..562d194f0aab 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 3f944a582667..a3d7e7b2bfbe 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 ff0e92c1c407..4a457e97b1c2 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 f23c246c4c64..4674e8a7fe30 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 5979832a29c5..165ce95e3bd5 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 5aefb3afabed..8fccaefa92f5 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 799372ed115b..1bd4185282f7 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/llvm-project b/third_party/llvm-project index 0258a53521cf..faae4d5d8127 160000 --- a/third_party/llvm-project +++ b/third_party/llvm-project @@ -1 +1 @@ -Subproject commit 0258a53521cfedf5cb80c2b1d4a66c942615de74 +Subproject commit faae4d5d8127b999a0cd8d00cae6237aba407c06 diff --git a/third_party/mlir-hlo b/third_party/mlir-hlo deleted file mode 160000 index 63a907f9839f..000000000000 --- 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 000000000000..52de2c0b4b74 --- /dev/null +++ b/third_party/stablehlo @@ -0,0 +1 @@ +Subproject commit 52de2c0b4b7446a56e8985a4de6d50c1d8b47c3b