blob: bdd9a0dec73e6cb8da136baeb3e0c6e727646f84 [file] [log] [blame]
Jerry Wud41d0732022-11-23 01:43:55 +00001#!/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 Wud41d0732022-11-23 01:43:55 +000010#
Scott Todda92999e2023-01-13 10:13:12 -080011# The required IREE_HOST_BIN_DIR environment variable indicates the location
Jerry Wua4fef932023-05-24 00:13:15 +000012# 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-Noble971cd4b2022-11-29 14:02:31 -080017#
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 Wud41d0732022-11-23 01:43:55 +000024
25set -xeuo pipefail
26
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080027BUILD_DIR="${1:-${IREE_BUILD_E2E_TEST_ARTIFACTS_DIR:-build-e2e-test-artifacts}}"
Scott Todda92999e2023-01-13 10:13:12 -080028IREE_HOST_BIN_DIR="$(realpath ${IREE_HOST_BIN_DIR})"
Jerry Wua4fef932023-05-24 00:13:15 +000029BENCHMARK_PRESETS="${IREE_BENCHMARK_PRESETS:-}"
30BUILD_DEFAULT_BENCHMARK_SUITES="${IREE_BUILD_DEFAULT_BENCHMARK_SUITES:-1}"
Jerry Wud41d0732022-11-23 01:43:55 +000031
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080032source build_tools/cmake/setup_build.sh
Jerry Wu035bfc52023-04-12 23:08:12 +000033source build_tools/cmake/setup_tf_python.sh
Jerry Wud41d0732022-11-23 01:43:55 +000034
Jerry Wua4fef932023-05-24 00:13:15 +000035declare -a BUILD_TARGETS
36
37if (( "${BUILD_DEFAULT_BENCHMARK_SUITES}" == 1 )); then
38 BUILD_TARGETS+=("iree-benchmark-suites")
39fi
40
41# Separate the presets into the execution and compilation benchmark presets to
42# export different configs with export_benchmark_config.py.
43COMPILATION_PRESETS=""
44EXECUTION_PRESETS=""
45if [[ -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 Wu2544efe2023-06-05 13:31:38 -070053 comp-stats-large)
54 BUILD_TARGETS+=(iree-e2e-compile-stats-suites-large)
Jerry Wua4fef932023-05-24 00:13:15 +000055 COMPILATION_PRESETS="${COMPILATION_PRESETS},${PRESET}"
56 ;;
Jerry Wu2544efe2023-06-05 13:31:38 -070057 *-large)
58 BUILD_TARGETS+=(iree-benchmark-suites-large)
Jerry Wua4fef932023-05-24 00:13:15 +000059 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#,}"
69fi
70
71if (( "${#BUILD_TARGETS[@]}" == 0 )); then
72 echo "No target to build."
73 exit 1
74fi
75
Jerry Wud41d0732022-11-23 01:43:55 +000076echo "Configuring to build e2e test artifacts"
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080077"${CMAKE_BIN}" -B "${BUILD_DIR}" \
Jerry Wud41d0732022-11-23 01:43:55 +000078 -G Ninja \
Jerry Wu56d65bf2023-01-04 20:44:09 -050079 -DPython3_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE}" \
80 -DPYTHON_EXECUTABLE="${IREE_PYTHON3_EXECUTABLE}" \
Scott Todda92999e2023-01-13 10:13:12 -080081 -DIREE_HOST_BIN_DIR="${IREE_HOST_BIN_DIR}" \
Jerry Wu57404972023-03-02 22:16:11 +000082 -DIREE_BUILD_E2E_TEST_ARTIFACTS=ON \
Jerry Wud41d0732022-11-23 01:43:55 +000083 -DIREE_BUILD_COMPILER=OFF \
84 -DIREE_BUILD_SAMPLES=OFF \
Jerry Wu035bfc52023-04-12 23:08:12 +000085 -DIREE_BUILD_TESTS=OFF
Jerry Wud41d0732022-11-23 01:43:55 +000086
87echo "Building e2e test artifacts"
88"${CMAKE_BIN}" \
Geoffrey Martin-Noble971cd4b2022-11-29 14:02:31 -080089 --build "${BUILD_DIR}" \
Jerry Wua4fef932023-05-24 00:13:15 +000090 --target "${BUILD_TARGETS[@]}" \
Jerry Wud41d0732022-11-23 01:43:55 +000091 -- -k 0
Jerry Wua4fef932023-05-24 00:13:15 +000092
93E2E_TEST_ARTIFACTS_DIR="${BUILD_DIR}/e2e_test_artifacts"
94COMPILATION_CONFIG="${E2E_TEST_ARTIFACTS_DIR}/compilation-benchmark-config.json"
95EXECUTION_CONFIG="${E2E_TEST_ARTIFACTS_DIR}/execution-benchmark-config.json"
96FLAG_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}"