diff --git a/mindspore/lite/test/codegen/run_benchmark_codegen.sh b/mindspore/lite/test/codegen/run_benchmark_codegen.sh deleted file mode 100644 index 81c7c30da7..0000000000 --- a/mindspore/lite/test/codegen/run_benchmark_codegen.sh +++ /dev/null @@ -1,201 +0,0 @@ -#!/bin/bash -# Copyright 2019 Huawei Technologies Co., Ltd -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================ - -function Run_Converter() { - cd ${x86_path} || exit 1 - tar -zxf mindspore-lite-${version}-inference-linux-x64.tar.gz || exit 1 - cd ${x86_path}/mindspore-lite-${version}-inference-linux-x64/ || exit 1 - - cp tools/converter/converter/converter_lite ./ || exit 1 - export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:./tools/converter/lib/:./tools/converter/third_party/glog/lib - - rm -rf ${ms_models_path} - mkdir -p ${ms_models_path} - - # Convert tflite models: - while read line; do - model_name=${line} - if [[ $model_name == \#* ]]; then - continue - fi - echo ${model_name} >> "${run_converter_log_file}" - echo './converter_lite --fmk=TFLITE --modelFile='${models_path}'/'${model_name}' --outputFile='${ms_models_path}'/'${model_name}'' >> "${run_converter_log_file}" - ./converter_lite --fmk=TFLITE --modelFile=$models_path/${model_name} --outputFile=${ms_models_path}/${model_name} - if [ $? = 0 ]; then - converter_result='converter tflite '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} - else - converter_result='converter tflite '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 - fi - done < ${models_tflite_config} -} - -function Run_x86() { - local CODEGEN_PATH=${x86_path}/mindspore-lite-${version}-inference-linux-x64/tools/codegen - - rm -rf ${build_path} - mkdir -p ${build_path} - - while read line; do - model_name=${line} - if [[ $model_name == \#* ]]; then - continue - fi - echo ${model_name} >> "${run_x86_log_file}" - ${CODEGEN_PATH}/codegen --codePath=${build_path} --modelPath=${ms_models_path}/${model_name}.ms >> ${run_x86_log_file} - # 1. build benchmark - mkdir -p ${build_path}/${model_name}/build && cd ${build_path}/${model_name}/build || exit 1 - cmake -DPKG_PATH=${x86_path}/mindspore-lite-${version}-inference-linux-x64 ${build_path}/${model_name} >> ${run_x86_log_file} - make >> ${run_x86_log_file} - # 2. run benchmark - echo "net file: ${build_path}/${model_name}/src/net.bin" >> ${run_x86_log_file} - echo "./benchmark ${models_path}/input_output/input/${model_name}.ms.bin ${build_path}/${model_name}/src/net.bin 1 ${models_path}/input_output/output/${model_name}.ms.out" >> ${run_x86_log_file} - ./benchmark ${models_path}/input_output/input/${model_name}.ms.bin ${build_path}/${model_name}/src/net.bin 1 ${models_path}/input_output/output/${model_name}.ms.out >> ${run_x86_log_file} - if [ $? = 0 ]; then - run_result='x86: '${model_name}' pass'; echo ${run_result} >> ${run_benchmark_result_file} - else - run_result='x86: '${model_name}' failed'; echo ${run_result} >> ${run_benchmark_result_file}; return 1 - fi - done < ${models_tflite_config} - - rm -rf ${build_path} -} - -# Print start msg before run testcase -function MS_PRINT_TESTCASE_START_MSG() { - echo "" - echo -e "-----------------------------------------------------------------------------------------------------------------------------------" - echo -e "env Testcase Result " - echo -e "--- -------- ------ " -} - -# Print start msg after run testcase -function MS_PRINT_TESTCASE_END_MSG() { - echo -e "-----------------------------------------------------------------------------------------------------------------------------------" -} - -function Print_Converter_Result() { - MS_PRINT_TESTCASE_END_MSG - while read line; do - arr=("${line}") - printf "%-15s %-20s %-90s %-7s\n" ${arr[0]} ${arr[1]} ${arr[2]} ${arr[3]} - done < ${run_converter_result_file} - MS_PRINT_TESTCASE_END_MSG -} - -function Print_Benchmark_Result() { - MS_PRINT_TESTCASE_START_MSG - while read line; do - arr=("${line}") - printf "%-20s %-100s %-7s\n" ${arr[0]} ${arr[1]} ${arr[2]} - done < ${run_benchmark_result_file} - MS_PRINT_TESTCASE_END_MSG -} - -basepath=$(pwd) -echo ${basepath} - -# Example:sh run_benchmark_nets.sh -r /home/temp_test -m /home/temp_test/models -d "8KE5T19620002408" -while getopts "r:m:e:" opt; do - case ${opt} in - r) - release_path=${OPTARG} - echo "release_path is ${OPTARG}" - ;; - m) - models_path=${OPTARG} - echo "models_path is ${OPTARG}" - ;; - e) - backend=${OPTARG} - echo "backend is ${OPTARG}" - ;; - ?) - echo "unknown para" - exit 1;; - esac -done - -x86_path=${release_path}/ubuntu_x86 -file_name=$(ls ${x86_path}/*inference-linux-x64.tar.gz) -IFS="-" read -r -a file_name_array <<< "$file_name" -version=${file_name_array[2]} - -ms_models_path=${basepath}/ms_models -build_path=${basepath}/build -models_tflite_config=${basepath}/models_tflite.cfg - -# Write converter result to temp file -run_converter_log_file=${basepath}/run_converter_log.txt -echo ' ' > ${run_converter_log_file} - -run_converter_result_file=${basepath}/run_converter_result.txt -echo ' ' > ${run_converter_result_file} - -run_x86_log_file=${basepath}/run_x86_log.txt -echo 'run x86 logs: ' > ${run_x86_log_file} - -# Run converter -echo "start Run converter ..." -Run_Converter -Run_converter_PID=$! -sleep 1 - -wait ${Run_converter_PID} -Run_converter_status=$? - -# Check converter result and return value -if [[ ${Run_converter_status} = 0 ]];then - echo "Run converter success" - Print_Converter_Result -else - echo "Run converter failed" - cat ${run_converter_log_file} - Print_Converter_Result - exit 1 -fi - -# Write benchmark result to temp file -run_benchmark_result_file=${basepath}/run_benchmark_result.txt -echo ' ' > ${run_benchmark_result_file} - -backend=${backend:-"all"} -isFailed=0 -if [[ $backend == "all" || $backend == "x86-all" || $backend == "x86" ]]; then - # Run on x86 - echo "start Run x86 ..." - Run_x86 & - Run_x86_PID=$! - sleep 1 -fi - -if [[ $backend == "all" || $backend == "x86-all" || $backend == "x86" ]]; then - wait ${Run_x86_PID} - Run_x86_status=$? - - # Check benchmark result and return value - if [[ ${Run_x86_status} != 0 ]];then - echo "Run_x86 failed" - cat ${run_x86_log_file} - isFailed=1 - fi -fi - -echo "Run_x86 is ended" -Print_Benchmark_Result -if [[ $isFailed == 1 ]]; then - exit 1 -fi -exit 0 diff --git a/mindspore/lite/test/run_benchmark_nets.sh b/mindspore/lite/test/run_benchmark_nets.sh index ceae5a4e4e..f597d17c49 100644 --- a/mindspore/lite/test/run_benchmark_nets.sh +++ b/mindspore/lite/test/run_benchmark_nets.sh @@ -1291,6 +1291,94 @@ function Run_x86_avx() { done < ${models_for_process_only_config} } +function Run_arm64_codegen() { + echo "ANDROID_NDK: ${ANDROID_NDK}" >> ${run_arm64_fp32_codegen_log_file} + cd ${arm64_path} || exit 1 + tar -zxf mindspore-lite-${version}-inference-android-aarch64.tar.gz || exit 1 + local PKG_PATH=${arm64_path}/mindspore-lite-${version}-inference-android-aarch64 + local CODEGEN_PATH=${x86_path}/mindspore-lite-${version}-inference-linux-x64/tools/codegen + + rm -rf ${build_path} + mkdir -p ${build_path} + + # Run tflite converted models: + while read line; do + model_name=${line} + if [[ $model_name == \#* ]]; then + continue + fi + + { + echo ${model_name} + echo "${CODEGEN_PATH}/codegen --codePath=${build_path} --modelPath=${ms_models_path}/${model_name}.ms --target=ARM64" + ${CODEGEN_PATH}/codegen --codePath=${build_path} --modelPath=${ms_models_path}/${model_name}.ms --target=ARM64 + } >> ${run_arm64_fp32_codegen_log_file} + + rm -rf ${build_path}/benchmark + mkdir -p ${build_path}/benchmark && cd ${build_path}/benchmark || exit 1 + + { + echo "cmake -DCMAKE_BUILD_TYPE=Release + -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake + -DANDROID_ABI=arm64-v8a + -DANDROID_TOOLCHAIN_NAME=aarch64-linux-android-clang + -DANDROID_NATIVE_API_LEVEL=19 + -DPLATFORM_ARM64=ON + -DPKG_PATH=${PKG_PATH} ${build_path}/${model_name}" + + cmake -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \ + -DANDROID_ABI="arm64-v8a" \ + -DANDROID_TOOLCHAIN_NAME="aarch64-linux-android-clang" \ + -DANDROID_NATIVE_API_LEVEL="19" \ + -DPLATFORM_ARM64=ON \ + -DPKG_PATH=${PKG_PATH} ${build_path}/${model_name} + + make -j4 + } >> ${run_arm64_fp32_codegen_log_file} + + rm -rf ${build_path}/codegen_test + mkdir ${build_path}/codegen_test && cd ${build_path}/codegen_test || exit 1 + cp -a ${build_path}/benchmark/benchmark ${build_path}/codegen_test/benchmark || exit 1 + cp -a ${build_path}/${model_name}/src/net.bin ${build_path}/codegen_test/net.bin || exit 1 + + { + echo 'ls ${build_path}/codegen_test' + ls ${build_path}/codegen_test + } >> ${run_arm64_fp32_codegen_log_file} + + # adb push all needed files to the phone + adb -s ${device_id} push ${build_path}/codegen_test /data/local/tmp/ > adb_push_log.txt + + { + echo 'cd /data/local/tmp/codegen_test' + echo 'chmod 777 benchmark' + echo 'chmod 777 net.bin' + echo 'ls' + echo './benchmark /data/local/tmp/input_output/input/'${model_name}'.ms.bin ./net.bin 1 /data/local/tmp/input_output/output/'${model_name}'.ms.out' + echo 'cd .. && rm -rf codegen_test' + } >> ${run_arm64_fp32_codegen_log_file} + + { + echo 'cd /data/local/tmp/codegen_test' + echo 'chmod 777 benchmark' + echo 'chmod 777 net.bin' + echo 'ls' + echo './benchmark /data/local/tmp/input_output/input/'${model_name}'.ms.bin ./net.bin 1 /data/local/tmp/input_output/output/'${model_name}'.ms.out' + echo 'cd .. && rm -rf codegen_test' + } > adb_run_cmd.txt + + adb -s ${device_id} shell < adb_run_cmd.txt >> ${run_arm64_fp32_codegen_log_file} + if [ $? = 0 ]; then + run_result='arm64_codegen: '${model_name}' pass'; echo ${run_result} >> ${run_benchmark_result_file} + else + run_result='arm64_codegen: '${model_name}' failed'; echo ${run_result} >> ${run_benchmark_result_file}; return 1 + fi + done < ${models_codegen_config} + + rm -rf ${build_path} +} + # Run on arm64 platform: function Run_arm64() { cd ${arm64_path} || exit 1 @@ -2542,6 +2630,9 @@ echo 'run x86 codegen logs: ' > ${run_x86_codegen_log_file} run_arm64_fp32_log_file=${basepath}/run_arm64_fp32_log.txt echo 'run arm64_fp32 logs: ' > ${run_arm64_fp32_log_file} +run_arm64_fp32_codegen_log_file=${basepath}/run_arm64_fp32_codegen_log.txt +echo 'run arm64_codegen logs: ' > ${run_arm64_fp32_codegen_log_file} + run_arm64_fp16_log_file=${basepath}/run_arm64_fp16_log.txt echo 'run arm64_fp16 logs: ' > ${run_arm64_fp16_log_file} @@ -2608,6 +2699,19 @@ if [[ $backend == "all" || $backend == "x86-all" || $backend == "x86-codegen" ]] sleep 1 fi +if [[ $backend == "all" || $backend == "arm_cpu" || $backend == "arm64_codegen" ]]; then + # Run on arm64 + arm64_path=${release_path}/android_aarch64 + file_name=$(ls ${arm64_path}/*inference-android-aarch64.tar.gz) + IFS="-" read -r -a file_name_array <<< "$file_name" + version=${file_name_array[2]} + + echo "start Run arm64 codegen ..." + Run_arm64_codegen + Run_arm64_codegen_status=$? + sleep 1 +fi + if [[ $backend == "all" || $backend == "arm_cpu" || $backend == "arm32_fp16" ]]; then # Run on armv82-a32-fp16 armv82_path=${release_path}/android_aarch32 @@ -2763,6 +2867,13 @@ if [[ $backend == "all" || $backend == "arm_cpu" || $backend == "arm64_fp32" ]]; isFailed=1 fi fi +if [[ $backend == "all" || $backend == "arm_cpu" || $backend == "arm64_codegen" ]]; then + if [[ ${Run_arm64_codegen_status} != 0 ]];then + echo "Run_arm64_fp32 failed" + cat ${run_arm64_fp32_log_file} + isFailed=1 + fi +fi if [[ $backend == "all" || $backend == "arm_cpu" || $backend == "arm64_fp16" ]]; then if [[ ${Run_arm64_fp16_status} != 0 ]];then echo "Run_arm64_fp16 failed"