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}}" |
| 25 | RISCV_PLATFORM="${IREE_TARGET_PLATFORM:-linux}" |
| 26 | RISCV_ARCH="${IREE_TARGET_ARCH:-riscv_64}" |
Cindy Liu | 49b844a | 2022-06-16 13:56:19 -0700 | [diff] [blame] | 27 | RISCV_COMPILER_FLAGS="${RISCV_COMPILER_FLAGS:--O3}" |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame^] | 28 | IREE_HOST_BIN_DIR="$(realpath ${IREE_HOST_BIN_DIR})" |
Jerry Wu | 9484142 | 2022-12-01 21:14:50 +0000 | [diff] [blame] | 29 | 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] | 30 | BUILD_PRESET="${BUILD_PRESET:-test}" |
CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 31 | |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 32 | source build_tools/cmake/setup_build.sh |
CindyLiu | d1384dc | 2021-05-07 03:53:23 +0000 | [diff] [blame] | 33 | |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 34 | RISCV_PLATFORM_ARCH="${RISCV_PLATFORM}-${RISCV_ARCH}" |
| 35 | echo "Build riscv target with the config of ${RISCV_PLATFORM_ARCH}" |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 36 | TOOLCHAIN_FILE="$(realpath build_tools/cmake/riscv.toolchain.cmake)" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 37 | declare -a args |
| 38 | args=( |
| 39 | "-G" "Ninja" |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 40 | "-B" "${BUILD_DIR}" |
Jerry Wu | 56d65bf | 2023-01-04 20:44:09 -0500 | [diff] [blame] | 41 | "-DPython3_EXECUTABLE=${IREE_PYTHON3_EXECUTABLE}" |
| 42 | "-DPYTHON_EXECUTABLE=${IREE_PYTHON3_EXECUTABLE}" |
| 43 | "-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE}" |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame^] | 44 | "-DIREE_HOST_BIN_DIR=${IREE_HOST_BIN_DIR}" |
Jerry Wu | 56d65bf | 2023-01-04 20:44:09 -0500 | [diff] [blame] | 45 | "-DRISCV_CPU=${RISCV_PLATFORM_ARCH}" |
| 46 | "-DRISCV_COMPILER_FLAGS=${RISCV_COMPILER_FLAGS}" |
| 47 | "-DIREE_BUILD_COMPILER=OFF" |
Geoffrey Martin-Noble | e384187 | 2022-08-01 19:19:02 -0700 | [diff] [blame] | 48 | # CPU info doesn't work on RISCV |
Jerry Wu | 56d65bf | 2023-01-04 20:44:09 -0500 | [diff] [blame] | 49 | "-DIREE_ENABLE_CPUINFO=OFF" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 50 | ) |
| 51 | |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 52 | if [[ "${RISCV_PLATFORM}" == "linux" ]]; then |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 53 | args+=( |
Geoffrey Martin-Noble | 53f31d1 | 2022-07-20 15:53:34 -0700 | [diff] [blame] | 54 | -DRISCV_TOOLCHAIN_ROOT="${RISCV_RV64_LINUX_TOOLCHAIN_ROOT}" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 55 | ) |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 56 | elif [[ "${RISCV_PLATFORM_ARCH}" == "generic-riscv_32" ]]; then |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 57 | args+=( |
Scott Todd | f57ab75 | 2022-05-23 10:36:44 -0700 | [diff] [blame] | 58 | # TODO(#6353): Off until tools/ are refactored to support threadless config. |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 59 | -DIREE_BUILD_TESTS=OFF |
Geoffrey Martin-Noble | 53f31d1 | 2022-07-20 15:53:34 -0700 | [diff] [blame] | 60 | -DRISCV_TOOLCHAIN_ROOT="${RISCV_RV32_NEWLIB_TOOLCHAIN_ROOT}" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 61 | ) |
| 62 | else |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 63 | echo "riscv config for ${RISCV_PLATFORM_ARCH} not supported yet" |
CindyLiu | 134edde | 2021-06-30 01:59:52 +0000 | [diff] [blame] | 64 | return -1 |
| 65 | fi |
| 66 | |
Jerry Wu | 2b22644 | 2022-09-01 09:13:24 -0700 | [diff] [blame] | 67 | case "${BUILD_PRESET}" in |
| 68 | test) |
| 69 | args+=( |
| 70 | -DIREE_ENABLE_ASSERTIONS=ON |
| 71 | -DIREE_BUILD_SAMPLES=ON |
| 72 | ) |
| 73 | ;; |
| 74 | benchmark) |
| 75 | args+=( |
| 76 | -DIREE_ENABLE_ASSERTIONS=OFF |
| 77 | -DIREE_BUILD_SAMPLES=OFF |
| 78 | -DIREE_BUILD_TESTS=OFF |
| 79 | ) |
| 80 | ;; |
| 81 | benchmark-with-tracing) |
| 82 | args+=( |
| 83 | -DIREE_ENABLE_ASSERTIONS=OFF |
| 84 | -DIREE_BUILD_SAMPLES=OFF |
| 85 | -DIREE_BUILD_TESTS=OFF |
| 86 | -DIREE_ENABLE_RUNTIME_TRACING=ON |
| 87 | ) |
| 88 | ;; |
CindyLiu | 3e100f7 | 2022-10-06 09:24:49 -0700 | [diff] [blame] | 89 | benchmark-suite-test) |
Jerry Wu | 9484142 | 2022-12-01 21:14:50 +0000 | [diff] [blame] | 90 | E2E_TEST_ARTIFACTS_DIR="$(realpath ${E2E_TEST_ARTIFACTS_DIR})" |
CindyLiu | 3e100f7 | 2022-10-06 09:24:49 -0700 | [diff] [blame] | 91 | args+=( |
Jerry Wu | 9484142 | 2022-12-01 21:14:50 +0000 | [diff] [blame] | 92 | -DIREE_E2E_TEST_ARTIFACTS_DIR="${E2E_TEST_ARTIFACTS_DIR}" |
CindyLiu | 3e100f7 | 2022-10-06 09:24:49 -0700 | [diff] [blame] | 93 | ) |
| 94 | ;; |
Jerry Wu | 2b22644 | 2022-09-01 09:13:24 -0700 | [diff] [blame] | 95 | *) |
| 96 | echo "Unknown build preset: ${BUILD_PRESET}" |
| 97 | exit 1 |
| 98 | ;; |
| 99 | esac |
| 100 | |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 101 | "${CMAKE_BIN}" "${args[@]}" |
CindyLiu | d3d4ed0 | 2022-09-08 10:32:18 -0700 | [diff] [blame] | 102 | |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 103 | if [[ "${BUILD_PRESET}" == "benchmark-suite-test" ]]; then |
| 104 | if [[ "${RISCV_PLATFORM}" == "linux" ]]; then |
| 105 | echo "Building iree-run-module and run-module-test deps for RISC-V" |
| 106 | echo "------------------------------------------------------------" |
| 107 | "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-run-module \ |
| 108 | iree-run-module-test-deps -- -k 0 |
| 109 | else |
| 110 | echo "benchmark-suite-test on ${RISCV_PLATFORM_ARCH} not supported yet" |
| 111 | return -1 |
| 112 | fi |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 113 | else |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 114 | "${CMAKE_BIN}" --build "${BUILD_DIR}" -- -k 0 |
Jerry Wu | 85ff57f | 2022-12-12 21:39:26 +0000 | [diff] [blame] | 115 | if [[ "${RISCV_PLATFORM}" == "linux" ]]; then |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 116 | echo "Building test deps for RISC-V" |
| 117 | echo "-----------------------------" |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 118 | "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-test-deps -- -k 0 |
Ben Vanik | b4bf5f7 | 2022-12-05 19:28:57 -0800 | [diff] [blame] | 119 | echo "Building sample deps for RISC-V" |
| 120 | echo "------------------" |
| 121 | "${CMAKE_BIN}" --build "${BUILD_DIR}" --target iree-sample-deps -- -k 0 |
CindyLiu | 99373e0 | 2022-10-12 09:22:24 -0700 | [diff] [blame] | 122 | fi |
CindyLiu | d3d4ed0 | 2022-09-08 10:32:18 -0700 | [diff] [blame] | 123 | fi |