blob: b091a83c2bc248bdc012edad2e80d85c5a7011f5 [file] [log] [blame]
#!/bin/bash
# Copyright 2021 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Test the cross-compiled RISCV 64-bit Linux targets.
set -xeuo pipefail
# Print the UTC time when set -x is on
export PS4='[$(date -u "+%T %Z")] '
ROOT_DIR="${ROOT_DIR:-$(git rev-parse --show-toplevel)}"
IREE_IMPORT_TFLITE_BIN="${IREE_IMPORT_TFLITE_BIN:-iree-import-tflite}"
LLVM_BIN_DIR="${LLVM_BIN_DIR}"
# Environment variable used by the emulator and iree-compile for the
# llvm-cpu bytecode codegen.
export RISCV_TOOLCHAIN_ROOT="${RISCV_RV64_LINUX_TOOLCHAIN_ROOT}"
function generate_llvm_cpu_vmfb {
local target="${1}"; shift
local compile_args=(
--iree-hal-target-backends=llvm-cpu
--iree-llvm-embedded-linker-path="${IREE_HOST_BINARY_ROOT}/bin/lld"
--iree-llvm-target-triple=riscv64
--iree-llvm-target-cpu=generic-rv64
--iree-llvm-target-abi=lp64d
)
if [[ "${target}" == "mhlo" ]]; then
compile_args+=(
--iree-input-type=mhlo
--iree-llvm-target-cpu-features="+m,+a,+f,+d,+c"
)
elif [[ "${target}" == "tosa" ]]; then
local input_file="${1}"; shift
"${IREE_IMPORT_TFLITE_BIN}" -o "${BUILD_RISCV_DIR}/tosa.mlir" "${input_file}"
compile_args+=(
--iree-input-type=tosa
--iree-llvm-target-cpu-features="+m,+a,+f,+d,+c"
"${BUILD_RISCV_DIR}/tosa.mlir"
)
elif [[ "${target}" == "tosa-rvv" ]]; then
local input_file="${1}"; shift
"${IREE_IMPORT_TFLITE_BIN}" -o "${BUILD_RISCV_DIR}/tosa.mlir" "${input_file}"
compile_args+=(
--iree-input-type=tosa
--iree-llvm-target-cpu-features="+m,+a,+f,+d,+c,+v"
--riscv-v-fixed-length-vector-lmul-max=8
--riscv-v-vector-bits-min=512
"${BUILD_RISCV_DIR}/tosa.mlir"
)
fi
"${IREE_HOST_BINARY_ROOT}/bin/iree-compile" "${compile_args[@]}" "$@"
}
generate_llvm_cpu_vmfb mhlo \
"${ROOT_DIR}/tools/test/iree-run-module.mlir" \
-o "${BUILD_RISCV_DIR}/iree-run-module-llvm_cpu.vmfb"
wget -P "${BUILD_RISCV_DIR}/" "https://storage.googleapis.com/iree-model-artifacts/person_detect.tflite"
generate_llvm_cpu_vmfb tosa \
"${BUILD_RISCV_DIR}/person_detect.tflite" \
-o "${BUILD_RISCV_DIR}/person_detect.vmfb"
generate_llvm_cpu_vmfb tosa-rvv \
"${BUILD_RISCV_DIR}/person_detect.tflite" \
-o "${BUILD_RISCV_DIR}/person_detect_rvv.vmfb"
${PYTHON_BIN} "${ROOT_DIR}/third_party/llvm-project/llvm/utils/lit/lit.py" \
-v --path "${LLVM_BIN_DIR}" "${ROOT_DIR}/tests/riscv64"
# Test runtime unit tests
ctest --test-dir ${BUILD_RISCV_DIR}/runtime/ --timeout 900 --output-on-failure \
--no-tests=error --label-exclude \
'(^nokokoro$|^driver=vulkan$|^driver=cuda$|^vulkan_uses_vk_khr_shader_float16_int8$|^requires-filesystem$|^requires-dtz$)'
# Test e2e models. Excluding mobilebert, fp16, and lowering_config regression
# tests for now.
# TODO(#10462): Investigate the lowering_config test issue.
ctest --test-dir ${BUILD_RISCV_DIR}/tests/e2e --timeout 900 --output-on-failure \
--no-tests=error --label-exclude \
'(^nokokoro$|^driver=vulkan$|^driver=cuda$|^vulkan_uses_vk_khr_shader_float16_int8$)' \
-E '(bert|fp16|regression_llvm-cpu_lowering_config)'