-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Halide cross-compilation #7073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hmm, is there no way to import host-built LLVM tools, but target-built binaries? |
Yes. That is how |
@alexreinking, I tried LLVM and Halide both with RISC-V toolchain in this scenario. So am I right that it's not necessary to cross-compile LLVM but use host version and cross-compile only Halide? |
|
Oh, you're absoultely right. I just had to specify |
|
Glad it's working. 🙂 In the future, please open an issue with at least an error message (but ideally a reproducer) first so we can evaluate whether a proposed fix is the best one. |
|
@alexreinking, actually, I think I got stuck again 😅. I tried two approaches:
x86 LLVM + RISC-V HalideBuild LLVMgit clone --depth 1 --branch llvmorg-15.0.2 https://github.com/llvm/llvm-project.git
cmake -DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra" \
-DLLVM_TARGETS_TO_BUILD="X86;RISCV" \
-DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_BUILD_32_BITS=OFF \
-S llvm-project/llvm -B llvm-build
cmake --build llvm-build -j$(nproc --all)
cmake --install llvm-build --prefix llvm-installInstall
|
|
Sorry, still cannot cross-compile LLVM+Halide without these changes. Used set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR riscv64)
set(CMAKE_C_COMPILER riscv64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER riscv64-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
find_program(QEMU_RISCV64 qemu-riscv64-static)
if (QEMU_RISCV64)
set(CMAKE_CROSSCOMPILING_EMULATOR ${QEMU_RISCV64})
endif ()LLVM: cmake -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=$(realpath riscv64.toolchain.cmake) \
-DLLVM_ENABLE_PROJECTS="clang;lld;clang-tools-extra" \
-DLLVM_TARGETS_TO_BUILD="X86;RISCV" \
-DLLVM_TARGET_ARCH="riscv64" \
-DLLVM_HOST_TRIPLE="riscv64-unknown-linux-gnu" \
-DLLVM_DEFAULT_TARGET_TRIPLE="riscv64-unknown-linux-gnu" \
-DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_BUILD_32_BITS=OFF \
-S llvm-project/llvm -B llvm-build-riscv64
cmake --build llvm-build-riscv64/ -j4
cmake --install llvm-build-riscv64 --prefix llvm-install-riscv64 Halide: cmake -DLLVM_DIR=$(realpath llvm-install-riscv64/lib/cmake/llvm) \
-DClang_DIR=$(realpath llvm-install-riscv64/lib/cmake/clang) \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=$(realpath riscv64.toolchain.cmake) \
-DWITH_TESTS=OFF \
-DWITH_TUTORIALS=OFF \
-DWITH_PYTHON_BINDINGS=OFF \
-S Halide -B halide-build-riscv64
cmake --build halide-build-riscv64 -j4OK with this PR and |
|
Please review |
Use CMAKE_CROSSCOMPILING_EMULATOR for llvm-as and clang imported targets
Hi! I tried cross-compile Halide with LLVM for RISC-V host and found that imported targets
llvm-asandclangignoreCMAKE_CROSSCOMPILING_EMULATOR. So need to use it manually in the command.Please let me know if you're interested in the complete cross-compilation guide.