|
| 1 | +#!/bin/bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | +# |
| 8 | +# Build the Cadence Xtensa op-level gtest tests for the configured backend and |
| 9 | +# run them on the Instruction Set Simulator (xt-run). |
| 10 | +# |
| 11 | +# Requires the Xtensa toolchain env to already be set (run |
| 12 | +# .ci/scripts/setup-xtensa-tools.sh <backend> first): XTENSA_TOOLCHAIN, |
| 13 | +# TOOLCHAIN_VER, XTENSA_CORE, CADENCE_OPT_FLAG, and xt-clang/xt-run on PATH. |
| 14 | +# |
| 15 | +# Unlike build-cadence-xtensa.sh (the runner, built -fno-exceptions -fno-rtti), |
| 16 | +# the gtest tests need exceptions + RTTI, so those flags are NOT set here. |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +: "${XTENSA_TOOLCHAIN:?run setup-xtensa-tools.sh first}" |
| 21 | +: "${TOOLCHAIN_VER:?run setup-xtensa-tools.sh first}" |
| 22 | +: "${XTENSA_CORE:?run setup-xtensa-tools.sh first}" |
| 23 | +: "${CADENCE_OPT_FLAG:?run setup-xtensa-tools.sh first}" |
| 24 | + |
| 25 | +# Map the optimized-kernel flag to the backend dir + gtest target name. |
| 26 | +case "${CADENCE_OPT_FLAG}" in |
| 27 | + EXECUTORCH_NNLIB_OPT) TARGET_DIR=hifi ;; |
| 28 | + EXECUTORCH_VISION_OPT) TARGET_DIR=vision ;; |
| 29 | + EXECUTORCH_FUSION_G3_OPT) TARGET_DIR=fusion_g3 ;; |
| 30 | + *) |
| 31 | + echo "ERROR: unknown CADENCE_OPT_FLAG='${CADENCE_OPT_FLAG}'" >&2 |
| 32 | + exit 1 |
| 33 | + ;; |
| 34 | +esac |
| 35 | +TEST_TARGET="cadence_${TARGET_DIR}_op_tests" |
| 36 | +TEST_ELF="cmake-out/backends/cadence/${TARGET_DIR}/operators/tests/${TEST_TARGET}" |
| 37 | + |
| 38 | +NPROC=$(nproc) |
| 39 | +echo "=== building ${TEST_TARGET} for ${XTENSA_CORE} (${CADENCE_OPT_FLAG}) ===" |
| 40 | +xt-clang --version | head -1 |
| 41 | + |
| 42 | +rm -rf cmake-out |
| 43 | +cmake \ |
| 44 | + -DCMAKE_TOOLCHAIN_FILE=./backends/cadence/cadence.cmake \ |
| 45 | + -DCMAKE_INSTALL_PREFIX=cmake-out \ |
| 46 | + -DCMAKE_BUILD_TYPE=Release \ |
| 47 | + -DEXECUTORCH_BUILD_CADENCE=ON \ |
| 48 | + "-D${CADENCE_OPT_FLAG}=ON" \ |
| 49 | + -DEXECUTORCH_BUILD_PORTABLE_OPS=ON \ |
| 50 | + -DEXECUTORCH_BUILD_CADENCE_OP_TESTS=ON \ |
| 51 | + -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ |
| 52 | + -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON \ |
| 53 | + -DEXECUTORCH_ENABLE_LOGGING=ON \ |
| 54 | + -DEXECUTORCH_BUILD_PTHREADPOOL=OFF \ |
| 55 | + -DEXECUTORCH_BUILD_CPUINFO=OFF \ |
| 56 | + -DEXECUTORCH_USE_DL=OFF \ |
| 57 | + -DEXECUTORCH_BUILD_KERNELS_LLM=OFF \ |
| 58 | + -DEXECUTORCH_BUILD_DEVTOOLS=OFF \ |
| 59 | + -DHAVE_FNMATCH_H=OFF \ |
| 60 | + -DFLATCC_ALLOW_WERROR=OFF \ |
| 61 | + -DPYTHON_EXECUTABLE="$(which python3)" \ |
| 62 | + -Bcmake-out . |
| 63 | + |
| 64 | +cmake --build cmake-out --target "${TEST_TARGET}" -j"${NPROC}" |
| 65 | + |
| 66 | +if [[ ! -f "${TEST_ELF}" ]]; then |
| 67 | + echo "ERROR: ${TEST_ELF} was not produced" >&2 |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +echo "=== running ${TEST_TARGET} on xt-run ===" |
| 72 | +LOG=$(mktemp) |
| 73 | +# --exit_with_target_code propagates gtest_main's exit code, so a failing test |
| 74 | +# fails this step; also assert on the gtest summary lines as a backstop. |
| 75 | +xt-run --turbo --exit_with_target_code "${TEST_ELF}" 2>&1 | tee "${LOG}" |
| 76 | +if grep -q "\[ FAILED \]" "${LOG}"; then |
| 77 | + echo "ERROR: gtest reported failures for ${TEST_TARGET}" >&2 |
| 78 | + exit 1 |
| 79 | +fi |
| 80 | +if ! grep -q "\[ PASSED \]" "${LOG}"; then |
| 81 | + echo "ERROR: ${TEST_TARGET} did not report a gtest PASSED summary" >&2 |
| 82 | + exit 1 |
| 83 | +fi |
| 84 | +echo "Cadence ${TARGET_DIR} op tests passed on ${XTENSA_CORE}." |
0 commit comments