Since stableHLO Release does not provide prebuilt binaries, you need to build StableHLO yourself in order to use stablehlo-opt.
Therefore, a prebuilt binary is uploaded here in advance. As you can see below, please note that this is a minimal version that only supports basic functionality.
Clone this repository into a directory named build under your stablehlo directory, as shown in the image below.
cd /path/to/stablehlo
sudo apt update
sudo apt install -y git-lfs
git lfs install
git clone https://github.com/joon363/StableHLO-compiler-pre-built-binary.git build
Now you can use stablehlo-opt!
cd /workspace
git clone --depth=1 --single-branch https://github.com/openxla/stablehlo- StableHLO 1.0 must use LLVM 22.1.0, because in https://github.com/llvm/llvm-project/commit/906295b8a31c8dac5aa845864c0bca9f02f86184 the command was changed from
buildtocreate. With the current LLVM 17 used in PyTorchSim, this is not possible. - Download https://github.com/llvm/llvm-project/releases/tag/llvmorg-22.1.0-rc1.
- In principle, LLVM should be built directly from source using Bazel, but if you follow step 2 below, you can avoid doing that.
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-22.1.0-rc1/LLVM-22.1.0-rc1-Linux-X64.tar.xz
tar -xJf LLVM-22.1.0-rc1-Linux-X64.tar.xz- The downloaded LLVM binary does not include
FileCheckandnot. These binaries are only generated when building llvm-project directly with-D LLVM_INSTALL_UTILS=ON. - However, these tools are used only for the test suite, so they are not required for development.
- If you have an environment where you can build LLVM yourself, you can skip this step. In my case, the build took more than 4 hours, so I abandoned it.
/workspace/stablehlo/stablehlo/CMakeLists.txt
# add_subdirectory(api)
add_subdirectory(conversions)
add_subdirectory(dialect)
# add_subdirectory(integrations)
add_subdirectory(reference)
add_subdirectory(tests)
# add_subdirectory(testdata)
add_subdirectory(tools)
add_subdirectory(transforms)/workspace/stablehlo/stablehlo/conversions/linalg/CMakeLists.txt
# add_subdirectory(tests)/workspace/stablehlo/stablehlo/conversions/tosa/CMakeLists.txt
# add_subdirectory(tests)/workspace/stablehlo/stablehlo/tools/CMakeLists.txt
# add_dependencies(check-stablehlo-quick stablehlo-lsp-server)/workspace/stablehlo/stablehlo/tests/CMakeLists.txt
# add_lit_testsuite(check-stablehlo-tests "Running the tests/ suite"
# ${CMAKE_CURRENT_BINARY_DIR}
# DEPENDS
# FileCheck not
# stablehlo-opt
# stablehlo-translate
# )
# add_dependencies(check-stablehlo-quick check-stablehlo-tests)rm -rf build
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=/LLVM-22.1.0-rc1-Linux-X64/lib/cmake/mlir # Path where the LLVM binary was extracted earlier
ninja -j 8 # Set to the desired number of jobs