Skip to content

Commit ee3b6b8

Browse files
author
Farid Zakaria
committed
Additional cleanup
1 parent 368938e commit ee3b6b8

File tree

4 files changed

+23
-139
lines changed

4 files changed

+23
-139
lines changed

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ if(STABLEHLO_EXTERNAL_PROJECT_BUILD)
8989
list(APPEND CMAKE_MODULE_PATH "${MLIR_MAIN_SRC_DIR}/cmake/modules")
9090
elseif(NOT STABLEHLO_BUILD_EMBEDDED)
9191
message(STATUS "Building StableHLO with an installed MLIR")
92-
92+
9393
# These defaults are moderately important to us, but the user *can*
9494
# override them (enabling some of these brings in deps that will conflict,
9595
# so ymmv).
@@ -112,9 +112,11 @@ elseif(NOT STABLEHLO_BUILD_EMBEDDED)
112112
# Unconditionally enable mlir.
113113
list(APPEND LLVM_ENABLE_PROJECTS mlir)
114114

115-
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/bin)
116-
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/lib)
117-
115+
# Setup LLVM lib and bin directories.
116+
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/llvm-project/bin)
117+
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/llvm-project/lib)
118+
set(LLVM_TOOLS_BINARY_DIR ${CMAKE_BINARY_DIR}/llvm-project/bin)
119+
118120
list(APPEND CMAKE_MESSAGE_INDENT " ")
119121
set(_BUNDLED_LLVM_CMAKE_SOURCE_SUBDIR "llvm-project/llvm")
120122
add_subdirectory("${_BUNDLED_LLVM_CMAKE_SOURCE_SUBDIR}" "llvm-project" EXCLUDE_FROM_ALL)

CMakePresets.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,23 @@
1111
"LLVM_ENABLE_ASSERTIONS": "ON",
1212
"LLVM_ENABLE_LLD": "ON",
1313
"STABLEHLO_ENABLE_BINDINGS_PYTHON" : "OFF",
14-
"STABLEHLO_ENABLE_SPLIT_DWARF": "ON",
1514
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache",
1615
"CMAKE_CXX_COMPILER": "clang++",
1716
"CMAKE_C_COMPILER_LAUNCHER": "ccache",
1817
"CMAKE_C_COMPILER": "clang",
1918
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
20-
"MLIR_DIR": "${sourceDir}/llvm-build/lib/cmake/mlir"
19+
"CMAKE_PLATFORM_NO_VERSIONED_SONAME": "ON",
20+
"LLVM_VERSION_SUFFIX": "",
21+
"LLVM_USE_SPLIT_DWARF": "ON",
22+
"STABLEHLO_ENABLE_SPLIT_DWARF": "ON"
2123
}
2224
},
2325
{
2426
"name": "debug-python",
2527
"displayName": "Debug w/ python bindings",
2628
"inherits": "debug",
2729
"cacheVariables": {
30+
"MLIR_ENABLE_BINDINGS_PYTHON": "ON",
2831
"STABLEHLO_ENABLE_BINDINGS_PYTHON" : "ON",
2932
"STABLEHLO_ENABLE_SANITIZER": "OFF"
3033
}

README.md

Lines changed: 12 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,13 @@ Here's how to build the StableHLO repo on Linux or macOS:
3232

3333
```sh
3434
# On Linux
35-
sudo apt install cmake ninja-build lld
35+
sudo apt install cmake ninja-build lld ccache
3636

3737
# On macOS
38-
brew install cmake ninja
38+
brew install cmake ninja ccache
3939
```
4040

41-
2. Set the `LLVM_ENABLE_LLD` shell variable depending on your preferences. We
42-
recommend setting it to `ON` on Linux and to `OFF` on macOS.
43-
44-
```sh
45-
[[ "$(uname)" != "Darwin" ]] && LLVM_ENABLE_LLD="ON" || LLVM_ENABLE_LLD="OFF"
46-
```
47-
48-
3. Clone the StableHLO repo and the LLVM repository:
41+
2. Clone the StableHLO repo and the LLVM repository:
4942

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

5851
Cloning the LLVM repository may take a few minutes.
5952

60-
4. Make sure you check out the correct commit in the LLVM repository:
53+
3. Make sure you check out the correct commit in the LLVM repository:
6154

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

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

68-
5. Configure and build MLIR:
61+
4. Build StableHLO as a standalone library:
6962

7063
```sh
71-
MLIR_ENABLE_BINDINGS_PYTHON=OFF build_tools/build_mlir.sh ${PWD}/llvm-project/ ${PWD}/llvm-build
64+
cmake --build --preset debug
7265
```
7366

74-
This will take a considerable amount of time. For example, on a MacBook Pro
75-
with an M1 Pro chip, building MLIR took around 10 minutes at the moment
76-
of writing.
77-
78-
Again, you need to do this every time `llvm_version.txt` changes.
79-
80-
6. Build StableHLO as a standalone library:
67+
5. Now you can make sure it works by running some tests:
8168

8269
```sh
83-
mkdir -p build && cd build
84-
85-
cmake .. -GNinja \
86-
-DLLVM_ENABLE_LLD="$LLVM_ENABLE_LLD" \
87-
-DCMAKE_BUILD_TYPE=Release \
88-
-DLLVM_ENABLE_ASSERTIONS=ON \
89-
-DSTABLEHLO_ENABLE_BINDINGS_PYTHON=OFF \
90-
-DMLIR_DIR=${PWD}/../llvm-build/lib/cmake/mlir
91-
92-
cmake --build .
93-
```
94-
95-
If you are actively developing StableHLO, you may want the following additional
96-
CMake settings:
97-
98-
```sh
99-
cmake .. -GNinja \
100-
-DSTABLEHLO_ENABLE_LLD=ON \
101-
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
102-
-DLLVM_ENABLE_ASSERTIONS=ON \
103-
-DSTABLEHLO_ENABLE_BINDINGS_PYTHON=OFF \
104-
-DSTABLEHLO_ENABLE_SPLIT_DWARF=ON \
105-
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
106-
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
107-
-DSTABLEHLO_ENABLE_SANITIZER=address \
108-
-DMLIR_DIR=${PWD}/../llvm-build/lib/cmake/mlir
109-
110-
cmake --build .
111-
```
112-
113-
This will enable debug symbols and ccache, which can speed up incremental
114-
builds. It also creates a GDB index file in the binary to speed up
115-
debugging.
116-
117-
If you build MLIR using the script above it should also set by default
118-
`LLVM_USE_SPLIT_DWARF` which does the majority of the size saving for
119-
the binary and should also be set.
120-
121-
7. Now you can make sure it works by running some tests:
122-
123-
```sh
124-
ninja check-stablehlo-tests
70+
cmake --build --preset debug --target check-stablehlo-tests
12571
```
12672

12773
You should see results like this:
12874

12975
```txt
130-
Testing Time: 5.99s
131-
Passed: 47
76+
Testing Time: 4.13s
77+
78+
Total Discovered Tests: 137
79+
Passed: 137 (100.00%)
13280
```
13381

13482
This runs all the tests in `stablehlo/tests/`.

build_tools/build_mlir.sh

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)