Skip to content

Commit

Permalink
[StableHLO] Use stablehlo submodule (#14094)
Browse files Browse the repository at this point in the history
Use the stablehlo submodule to provide stablehlo, since we do not need
the 'mhlo' part or mlir-hlo anymore.

Fixes: #12678

---------

Co-authored-by: Scott Todd <scotttodd@google.com>
  • Loading branch information
kuhar and ScottTodd committed Jun 14, 2023
1 parent a219cb5 commit 3546f2a
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 77 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,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()
Expand Down Expand Up @@ -865,7 +865,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)
Expand Down
4 changes: 2 additions & 2 deletions build_tools/bazel/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",],
Expand Down
24 changes: 12 additions & 12 deletions build_tools/scripts/integrate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions build_tools/scripts/integrate/iree_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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-",
)
}
2 changes: 1 addition & 1 deletion build_tools/scripts/integrate/patch_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# git cherry-pick <some commit>
# 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.

Expand Down
29 changes: 0 additions & 29 deletions build_tools/third_party/mlir-hlo/CMakeLists.txt

This file was deleted.

12 changes: 12 additions & 0 deletions build_tools/third_party/stablehlo/CMakeLists.txt
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

set(STABLEHLO_SOURCE_DIR
"${IREE_SOURCE_DIR}/third_party/stablehlo/"
)
set(STABLEHLO_BINARY_DIR
"${IREE_BINARY_DIR}/llvm-external-projects/stablehlo"
)
4 changes: 2 additions & 2 deletions compiler/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
10 changes: 5 additions & 5 deletions compiler/src/iree/compiler/InputConversion/StableHLO/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down Expand Up @@ -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",
],
)

Expand Down
Original file line number Diff line number Diff line change
@@ -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 ###
################################################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down Expand Up @@ -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",
],
)
Original file line number Diff line number Diff line change
@@ -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 ###
################################################################################
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/iree/compiler/Tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down
1 change: 0 additions & 1 deletion third_party/mlir-hlo
Submodule mlir-hlo deleted from 63a907
1 change: 1 addition & 0 deletions third_party/stablehlo
Submodule stablehlo added at 52de2c

0 comments on commit 3546f2a

Please sign in to comment.