CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 3 | # Copyright 2021 The IREE Authors |
CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 4 | # |
Geoffrey Martin-Noble | 552d3f8 | 2021-05-25 17:56:09 -0700 | [diff] [blame] | 5 | # Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 6 | # See https://llvm.org/LICENSE.txt for license information. |
| 7 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 8 | |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 9 | # Cross-compile the runtime using CMake targeting RISC-V |
CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 10 | # |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame] | 11 | # The required IREE_HOST_BIN_DIR environment variable indicates the location |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 12 | # of the precompiled IREE binaries. The BUILD_PRESET environment variable |
| 13 | # indicates how the project should be configured: "test", "benchmark", |
| 14 | # "benchmark-with-tracing", or "benchmark-suite-test". Defaults to "test". |
Jerry Wu | 2b22644 | 2022-09-01 09:13:24 -0700 | [diff] [blame] | 15 | # |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 16 | # The desired build directory can be passed as the first argument. Otherwise, it |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 17 | # uses the environment variable IREE_TARGET_BUILD_DIR, defaulting to |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 18 | # "build-riscv". Designed for CI, but can be run manually. It reuses the build |
| 19 | # directory if it already exists. Expects to be run from the root of the IREE |
| 20 | # repository. |
CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 21 | |
Geoffrey Martin-Noble | 53f31d1 | 2022-07-20 15:53:34 -0700 | [diff] [blame] | 22 | set -xeuo pipefail |
CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 23 | |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 24 | BUILD_DIR="${1:-${IREE_TARGET_BUILD_DIR:-build-riscv}}" |
Diego Caballero | 431ef02 | 2023-02-17 09:54:11 -0800 | [diff] [blame] | 25 | BUILD_TYPE="${IREE_BUILD_TYPE:-RelWithDebInfo}" |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 26 | RISCV_PLATFORM="${IREE_TARGET_PLATFORM:-linux}" |
| 27 | RISCV_ARCH="${IREE_TARGET_ARCH:-riscv_64}" |
Cindy Liu | 49b844a | 2022-06-16 13:56:19 -0700 | [diff] [blame] | 28 | RISCV_COMPILER_FLAGS="${RISCV_COMPILER_FLAGS:--O3}" |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame] | 29 | IREE_HOST_BIN_DIR="$(realpath ${IREE_HOST_BIN_DIR})" |
Jerry Wu | 9484142 | 2022-12-01 21:14:50 +0000 | [diff] [blame] | 30 | E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR:-build-e2e-test-artifacts/e2e_test_artifacts}" |
Jerry Wu | 2b22644 | 2022-09-01 09:13:24 -0700 | [diff] [blame] | 31 | BUILD_PRESET="${BUILD_PRESET:-test}" |
CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 32 | |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 33 | source build_tools/cmake/setup_build.sh |
CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 34 | |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 35 | RISCV_PLATFORM_ARCH="${RISCV_PLATFORM}-${RISCV_ARCH}" |
| 36 | echo "Build riscv target with the config of ${RISCV_PLATFORM_ARCH}" |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 37 | TOOLCHAIN_FILE="$(realpath build_tools/cmake/riscv.toolchain.cmake)" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 38 | declare -a args |
| 39 | args=( |
| 40 | "-G" "Ninja" |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 41 | "-B" "${BUILD_DIR}" |
Diego Caballero | 431ef02 | 2023-02-17 09:54:11 -0800 | [diff] [blame] | 42 | "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" |
Jerry Wu | 56d65bf | 2023-01-04 20:44:09 -0500 | [diff] [blame] | 43 | "-DPython3_EXECUTABLE=${IREE_PYTHON3_EXECUTABLE}" |
| 44 | "-DPYTHON_EXECUTABLE=${IREE_PYTHON3_EXECUTABLE}" |
| 45 | "-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE}" |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame] | 46 | "-DIREE_HOST_BIN_DIR=${IREE_HOST_BIN_DIR}" |
Jerry Wu | 56d65bf | 2023-01-04 20:44:09 -0500 | [diff] [blame] | 47 | "-DRISCV_CPU=${RISCV_PLATFORM_ARCH}" |
| 48 | "-DRISCV_COMPILER_FLAGS=${RISCV_COMPILER_FLAGS}" |
| 49 | "-DIREE_BUILD_COMPILER=OFF" |
Geoffrey Martin-Noble | e384187 | 2022-08-01 19:19:02 -0700 | [diff] [blame] | 50 | # CPU info doesn't work on RISCV |
Jerry Wu | 56d65bf | 2023-01-04 20:44:09 -0500 | [diff] [blame] | 51 | "-DIREE_ENABLE_CPUINFO=OFF" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 52 | ) |
| 53 | |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 54 | if [[ "${RISCV_PLATFORM}" == "linux" ]]; then |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 55 | args+=( |
Geoffrey Martin-Noble | 53f31d1 | 2022-07-20 15:53:34 -0700 | [diff] [blame] | 56 | -DRISCV_TOOLCHAIN_ROOT="${RISCV_RV64_LINUX_TOOLCHAIN_ROOT}" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 57 | ) |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 58 | elif [[ "${RISCV_PLATFORM_ARCH}" == "generic-riscv_32" ]]; then |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 59 | args+=( |
Scott Todd | f57ab75 | 2022-05-23 10:36:44 -0700 | [diff] [blame] | 60 | # TODO(#6353): Off until tools/ are refactored to support threadless config. |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 61 | -DIREE_BUILD_TESTS=OFF |
Geoffrey Martin-Noble | 53f31d1 | 2022-07-20 15:53:34 -0700 | [diff] [blame] | 62 | -DRISCV_TOOLCHAIN_ROOT="${RISCV_RV32_NEWLIB_TOOLCHAIN_ROOT}" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 63 | ) |
| 64 | else |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 65 | echo "riscv config for ${RISCV_PLATFORM_ARCH} not supported yet" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 66 | return -1 |
| 67 | fi |
| 68 | |
Jerry Wu | 2b22644 | 2022-09-01 09:13:24 -0700 | [diff] [blame] | 69 | case "${BUILD_PRESET}" in |
| 70 | test) |
| 71 | args+=( |
| 72 | -DIREE_ENABLE_ASSERTIONS=ON |
| 73 | -DIREE_BUILD_SAMPLES=ON |
| 74 | ) |
| 75 | ;; |
| 76 | benchmark) |
| 77 | args+=( |
| 78 | -DIREE_ENABLE_ASSERTIONS=OFF |
| 79 | -DIREE_BUILD_SAMPLES=OFF |
| 80 | -DIREE_BUILD_TESTS=OFF |
| 81 | ) |
| 82 | ;; |
| 83 | benchmark-with-tracing) |
| 84 | args+=( |
| 85 | -DIREE_ENABLE_ASSERTIONS=OFF |
| 86 | -DIREE_BUILD_SAMPLES=OFF |
| 87 | -DIREE_BUILD_TESTS=OFF |
| 88 | -DIREE_ENABLE_RUNTIME_TRACING=ON |
| 89 | ) |
| 90 | ;; |
CindyLiu | 3e100f7 | 2022-10-06 09:24:49 -0700 | [diff] [blame] | 91 | benchmark-suite-test) |
Jerry Wu | 9484142 | 2022-12-01 21:14:50 +0000 | [diff] [blame] | 92 | E2E_TEST_ARTIFACTS_DIR="$(realpath ${E2E_TEST_ARTIFACTS_DIR})" |
CindyLiu | 3e100f7 | 2022-10-06 09:24:49 -0700 | [diff] [blame] | 93 | args+=( |
Jerry Wu | 9484142 | 2022-12-01 21:14:50 +0000 | [diff] [blame] | 94 | -DIREE_E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR}" |
CindyLiu | 3e100f7 | 2022-10-06 09:24:49 -0700 | [diff] [blame] | 95 | ) |
| 96 | ;; |
Jerry Wu | 2b22644 | 2022-09-01 09:13:24 -0700 | [diff] [blame] | 97 | *) |
| 98 | echo "Unknown build preset: ${BUILD_PRESET}" |
| 99 | exit 1 |
| 100 | ;; |
| 101 | esac |
| 102 | |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 103 | "${CMAKE_BIN}" "${args[@]}" |
CindyLiu | d3d4ed0 | 2022-09-08 10:32:18 -0700 | [diff] [blame] | 104 | |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 105 | if [[ "${BUILD_PRESET}" == "benchmark-suite-test" ]]; then |
| 106 | if [[ "${RISCV_PLATFORM}" == "linux" ]]; then |
| 107 | echo "Building iree-run-module and run-module-test deps for RISC-V" |
| 108 | echo "------------------------------------------------------------" |
| 109 | "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-run-module \ |
| 110 | iree-run-module-test-deps -- -k 0 |
| 111 | else |
| 112 | echo "benchmark-suite-test on ${RISCV_PLATFORM_ARCH} not supported yet" |
| 113 | return -1 |
| 114 | fi |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 115 | else |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 116 | "${CMAKE_BIN}" --build "${BUILD_DIR}" -- -k 0 |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 117 | if [[ "${RISCV_PLATFORM}" == "linux" ]]; then |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 118 | echo "Building test deps for RISC-V" |
| 119 | echo "-----------------------------" |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 120 | "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-test-deps -- -k 0 |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 121 | fi |
CindyLiu | d3d4ed0 | 2022-09-08 10:32:18 -0700 | [diff] [blame] | 122 | fi |