Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright 2022 The IREE Authors |
| 4 | # |
| 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 |
| 8 | |
| 9 | # Build e2e test artifacts using a host tools directory. |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +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 |
Jerry Wu | a4fef93 | 2023-05-24 00:13:15 +0000 | [diff] [blame] | 12 | # of the precompiled IREE binaries. The IREE_BENCHMARK_PRESETS environment |
| 13 | # variable can be set to build required artifacts for the comma-separated |
| 14 | # benchmark presets. By default `iree-benchmark-suites` is built for sanity |
| 15 | # check and e2e model testing. It can be disabled with the environment variable |
| 16 | # `IREE_BUILD_DEFAULT_BENCHMARK_SUITES=0`. |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 17 | # |
| 18 | # Designed for CI, but can be run locally. The desired build directory can be |
| 19 | # passed as the first argument. Otherwise, it uses the environment variable |
| 20 | # IREE_BUILD_E2E_TEST_ARTIFACTS_DIR, defaulting to "build-e2e-test-artifacts". |
| 21 | # It reuses the build directory if it already exists. Expects to be run from the |
| 22 | # root of the IREE repository. |
| 23 | |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 24 | |
| 25 | set -xeuo pipefail |
| 26 | |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 27 | BUILD_DIR="${1:-${IREE_BUILD_E2E_TEST_ARTIFACTS_DIR:-build-e2e-test-artifacts}}" |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame] | 28 | IREE_HOST_BIN_DIR="$(realpath ${IREE_HOST_BIN_DIR})" |
Jerry Wu | a4fef93 | 2023-05-24 00:13:15 +0000 | [diff] [blame] | 29 | BENCHMARK_PRESETS="${IREE_BENCHMARK_PRESETS:-}" |
| 30 | BUILD_DEFAULT_BENCHMARK_SUITES="${IREE_BUILD_DEFAULT_BENCHMARK_SUITES:-1}" |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +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 |
Jerry Wu | 035bfc5 | 2023-04-12 23:08:12 +0000 | [diff] [blame] | 33 | source build_tools/cmake/setup_tf_python.sh |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 34 | |
Jerry Wu | a4fef93 | 2023-05-24 00:13:15 +0000 | [diff] [blame] | 35 | declare -a BUILD_TARGETS |
| 36 | |
| 37 | if (( "${BUILD_DEFAULT_BENCHMARK_SUITES}" == 1 )); then |
| 38 | BUILD_TARGETS+=("iree-benchmark-suites") |
| 39 | fi |
| 40 | |
| 41 | # Separate the presets into the execution and compilation benchmark presets to |
| 42 | # export different configs with export_benchmark_config.py. |
| 43 | COMPILATION_PRESETS="" |
| 44 | EXECUTION_PRESETS="" |
| 45 | if [[ -n "${BENCHMARK_PRESETS}" ]]; then |
| 46 | IFS=, read -r -a PRESET_ARRAY <<< "${BENCHMARK_PRESETS}" |
| 47 | for PRESET in "${PRESET_ARRAY[@]}"; do |
| 48 | case "${PRESET}" in |
| 49 | comp-stats) |
| 50 | BUILD_TARGETS+=(iree-e2e-compile-stats-suites) |
| 51 | COMPILATION_PRESETS="${COMPILATION_PRESETS},${PRESET}" |
| 52 | ;; |
Jerry Wu | 2544efe | 2023-06-05 13:31:38 -0700 | [diff] [blame] | 53 | comp-stats-large) |
| 54 | BUILD_TARGETS+=(iree-e2e-compile-stats-suites-large) |
Jerry Wu | a4fef93 | 2023-05-24 00:13:15 +0000 | [diff] [blame] | 55 | COMPILATION_PRESETS="${COMPILATION_PRESETS},${PRESET}" |
| 56 | ;; |
Jerry Wu | 2544efe | 2023-06-05 13:31:38 -0700 | [diff] [blame] | 57 | *-large) |
| 58 | BUILD_TARGETS+=(iree-benchmark-suites-large) |
Jerry Wu | a4fef93 | 2023-05-24 00:13:15 +0000 | [diff] [blame] | 59 | EXECUTION_PRESETS="${EXECUTION_PRESETS},${PRESET}" |
| 60 | ;; |
| 61 | *) |
| 62 | # Build target of the default preset has been added above. |
| 63 | EXECUTION_PRESETS="${EXECUTION_PRESETS},${PRESET}" |
| 64 | ;; |
| 65 | esac |
| 66 | done |
| 67 | COMPILATION_PRESETS="${COMPILATION_PRESETS#,}" |
| 68 | EXECUTION_PRESETS="${EXECUTION_PRESETS#,}" |
| 69 | fi |
| 70 | |
| 71 | if (( "${#BUILD_TARGETS[@]}" == 0 )); then |
| 72 | echo "No target to build." |
| 73 | exit 1 |
| 74 | fi |
| 75 | |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 76 | echo "Configuring to build e2e test artifacts" |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 77 | "${CMAKE_BIN}" -B "${BUILD_DIR}" \ |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 78 | -G Ninja \ |
Jerry Wu | 56d65bf | 2023-01-04 20:44:09 -0500 | [diff] [blame] | 79 | -DPython3_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE}" \ |
| 80 | -DPYTHON_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE}" \ |
Scott Todd | a92999e | 2023-01-13 10:13:12 -0800 | [diff] [blame] | 81 | -DIREE_HOST_BIN_DIR="${IREE_HOST_BIN_DIR}" \ |
Jerry Wu | 5740497 | 2023-03-02 22:16:11 +0000 | [diff] [blame] | 82 | -DIREE_BUILD_E2E_TEST_ARTIFACTS=ON \ |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 83 | -DIREE_BUILD_COMPILER=OFF \ |
| 84 | -DIREE_BUILD_SAMPLES=OFF \ |
Jerry Wu | 035bfc5 | 2023-04-12 23:08:12 +0000 | [diff] [blame] | 85 | -DIREE_BUILD_TESTS=OFF |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 86 | |
| 87 | echo "Building e2e test artifacts" |
| 88 | "${CMAKE_BIN}" \ |
Geoffrey Martin-Noble | 971cd4b | 2022-11-29 14:02:31 -0800 | [diff] [blame] | 89 | --build "${BUILD_DIR}" \ |
Jerry Wu | a4fef93 | 2023-05-24 00:13:15 +0000 | [diff] [blame] | 90 | --target "${BUILD_TARGETS[@]}" \ |
Jerry Wu | d41d073 | 2022-11-23 01:43:55 +0000 | [diff] [blame] | 91 | -- -k 0 |
Jerry Wu | a4fef93 | 2023-05-24 00:13:15 +0000 | [diff] [blame] | 92 | |
| 93 | E2E_TEST_ARTIFACTS_DIR="${BUILD_DIR}/e2e_test_artifacts" |
| 94 | COMPILATION_CONFIG="${E2E_TEST_ARTIFACTS_DIR}/compilation-benchmark-config.json" |
| 95 | EXECUTION_CONFIG="${E2E_TEST_ARTIFACTS_DIR}/execution-benchmark-config.json" |
| 96 | FLAG_DUMP="${E2E_TEST_ARTIFACTS_DIR}/benchmark-flag-dump.txt" |
| 97 | ./build_tools/benchmarks/export_benchmark_config.py \ |
| 98 | compilation \ |
| 99 | --benchmark_presets="${COMPILATION_PRESETS}" \ |
| 100 | --output="${COMPILATION_CONFIG}" |
| 101 | ./build_tools/benchmarks/export_benchmark_config.py \ |
| 102 | execution \ |
| 103 | --benchmark_presets="${EXECUTION_PRESETS}" \ |
| 104 | --output="${EXECUTION_CONFIG}" |
| 105 | ./build_tools/benchmarks/benchmark_helper.py dump-cmds \ |
| 106 | --execution_benchmark_config="${EXECUTION_CONFIG}" \ |
| 107 | --compilation_benchmark_config="${COMPILATION_CONFIG}" \ |
| 108 | > "${FLAG_DUMP}" |