Skip to content

Commit

Permalink
Additional cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fzakaria committed Mar 22, 2024
1 parent 8215898 commit 245a3f3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 139 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ if(STABLEHLO_EXTERNAL_PROJECT_BUILD)
list(APPEND CMAKE_MODULE_PATH "${MLIR_MAIN_SRC_DIR}/cmake/modules")
elseif(NOT STABLEHLO_BUILD_EMBEDDED)
message(STATUS "Building StableHLO with an installed MLIR")

# These defaults are moderately important to us, but the user *can*
# override them (enabling some of these brings in deps that will conflict,
# so ymmv).
Expand All @@ -112,9 +112,11 @@ elseif(NOT STABLEHLO_BUILD_EMBEDDED)
# Unconditionally enable mlir.
list(APPEND LLVM_ENABLE_PROJECTS mlir)

set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)

# Setup LLVM lib and bin directories.
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/llvm-project/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/llvm-project/lib)
set(LLVM_TOOLS_BINARY_DIR ${CMAKE_BINARY_DIR}/llvm-project/bin)

list(APPEND CMAKE_MESSAGE_INDENT " ")
set(_BUNDLED_LLVM_CMAKE_SOURCE_SUBDIR "llvm-project/llvm")
add_subdirectory("${_BUNDLED_LLVM_CMAKE_SOURCE_SUBDIR}" "llvm-project" EXCLUDE_FROM_ALL)
Expand Down
7 changes: 5 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@
"LLVM_ENABLE_ASSERTIONS": "ON",
"LLVM_ENABLE_LLD": "ON",
"STABLEHLO_ENABLE_BINDINGS_PYTHON" : "OFF",
"STABLEHLO_ENABLE_SPLIT_DWARF": "ON",
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_C_COMPILER_LAUNCHER": "ccache",
"CMAKE_C_COMPILER": "clang",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
"MLIR_DIR": "${sourceDir}/llvm-build/lib/cmake/mlir"
"CMAKE_PLATFORM_NO_VERSIONED_SONAME": "ON",
"LLVM_VERSION_SUFFIX": "",
"LLVM_USE_SPLIT_DWARF": "ON",
"STABLEHLO_ENABLE_SPLIT_DWARF": "ON"
}
},
{
"name": "debug-python",
"displayName": "Debug w/ python bindings",
"inherits": "debug",
"cacheVariables": {
"MLIR_ENABLE_BINDINGS_PYTHON": "ON",
"STABLEHLO_ENABLE_BINDINGS_PYTHON" : "ON",
"STABLEHLO_ENABLE_SANITIZER": "OFF"
}
Expand Down
76 changes: 12 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,13 @@ Here's how to build the StableHLO repo on Linux or macOS:

```sh
# On Linux
sudo apt install cmake ninja-build lld
sudo apt install cmake ninja-build lld ccache

# On macOS
brew install cmake ninja
brew install cmake ninja ccache
```

2. Set the `LLVM_ENABLE_LLD` shell variable depending on your preferences. We
recommend setting it to `ON` on Linux and to `OFF` on macOS.

```sh
[[ "$(uname)" != "Darwin" ]] && LLVM_ENABLE_LLD="ON" || LLVM_ENABLE_LLD="OFF"
```

3. Clone the StableHLO repo and the LLVM repository:
2. Clone the StableHLO repo and the LLVM repository:

```sh
git clone https://github.com/openxla/stablehlo
Expand All @@ -57,78 +50,33 @@ Here's how to build the StableHLO repo on Linux or macOS:

Cloning the LLVM repository may take a few minutes.

4. Make sure you check out the correct commit in the LLVM repository:
3. Make sure you check out the correct commit in the LLVM repository:

```sh
(cd llvm-project && git fetch && git checkout $(cat ../build_tools/llvm_version.txt))
```

You need to do this every time `llvm_version.txt` changes.

5. Configure and build MLIR:
4. Build StableHLO as a standalone library:

```sh
MLIR_ENABLE_BINDINGS_PYTHON=OFF build_tools/build_mlir.sh ${PWD}/llvm-project/ ${PWD}/llvm-build
cmake --build --preset debug
```

This will take a considerable amount of time. For example, on a MacBook Pro
with an M1 Pro chip, building MLIR took around 10 minutes at the moment
of writing.

Again, you need to do this every time `llvm_version.txt` changes.

6. Build StableHLO as a standalone library:
5. Now you can make sure it works by running some tests:

```sh
mkdir -p build && cd build
cmake .. -GNinja \
-DLLVM_ENABLE_LLD="$LLVM_ENABLE_LLD" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DSTABLEHLO_ENABLE_BINDINGS_PYTHON=OFF \
-DMLIR_DIR=${PWD}/../llvm-build/lib/cmake/mlir
cmake --build .
```

If you are actively developing StableHLO, you may want the following additional
CMake settings:

```sh
cmake .. -GNinja \
-DSTABLEHLO_ENABLE_LLD=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DSTABLEHLO_ENABLE_BINDINGS_PYTHON=OFF \
-DSTABLEHLO_ENABLE_SPLIT_DWARF=ON \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DSTABLEHLO_ENABLE_SANITIZER=address \
-DMLIR_DIR=${PWD}/../llvm-build/lib/cmake/mlir
cmake --build .
```

This will enable debug symbols and ccache, which can speed up incremental
builds. It also creates a GDB index file in the binary to speed up
debugging.

If you build MLIR using the script above it should also set by default
`LLVM_USE_SPLIT_DWARF` which does the majority of the size saving for
the binary and should also be set.

7. Now you can make sure it works by running some tests:

```sh
ninja check-stablehlo-tests
cmake --build --preset debug --target check-stablehlo-tests
```

You should see results like this:

```txt
Testing Time: 5.99s
Passed: 47
Testing Time: 4.13s
Total Discovered Tests: 137
Passed: 137 (100.00%)
```

This runs all the tests in `stablehlo/tests/`.
Expand Down
69 changes: 0 additions & 69 deletions build_tools/build_mlir.sh

This file was deleted.

0 comments on commit 245a3f3

Please sign in to comment.