1#!/bin/bash 2 3# Build x86 for nnie 4function Run_Build_x86() { 5 # decompress release_pkg 6 cd ${open_source_ms_path}/output/ || exit 1 7 file_name=$(ls ./*linux-x64.tar.gz) 8 IFS="-" read -r -a file_name_array <<< "$file_name" 9 version=${file_name_array[2]} 10 tar -xf mindspore-lite-${version}-linux-x64.tar.gz 11 12 # cp tools folder 13 cd ${open_source_ms_path}/output/mindspore-lite-${version}-linux-x64 || exit 1 14 rm -rf ${nnie_code_path}/mindspore/mindspore/lite/tools/converter/nnie/third_party/ms_lite/ 15 mkdir -p ${nnie_code_path}/mindspore/mindspore/lite/tools/converter/nnie/third_party/ms_lite/ || exit 1 16 cp -r ./tools/ ${nnie_code_path}/mindspore/mindspore/lite/tools/converter/nnie/third_party/ms_lite/ || exit 1 17 18 # compile nnie converter so 19 export MSLITE_ENABLE_NNIE=on 20 export MSLITE_ENABLE_CONVERTER=off 21 export MSLITE_ENABLE_TRAIN=off 22 export MSLITE_ENABLE_TOOLS=off 23 export MSLITE_ENABLE_TESTCASES=off 24 bash ${nnie_code_path}/mindspore/build.sh -I x86_64 -j ${thread_num} 25 if [ $? = 0 ]; then 26 echo "build x86 for nnie success" 27 hi3516d_release_path=${open_source_ms_path}/output/mindspore-lite-${version}-linux-x64/tools/converter/providers/Hi3516D 28 rm -rf ${hi3516d_release_path} 29 mkdir -p ${hi3516d_release_path}/third_party/opencv-4.2.0 30 mkdir -p ${hi3516d_release_path}/third_party/protobuf-3.9.0 31 cp ${nnie_code_path}/mindspore/mindspore/lite/tools/providers/NNIE/Hi3516D/opencv-4.2.0/lib/* ${hi3516d_release_path}/third_party/opencv-4.2.0/ 32 cp ${nnie_code_path}/mindspore/mindspore/lite/tools/providers/NNIE/Hi3516D/protobuf-3.9.0/lib/* ${hi3516d_release_path}/third_party/protobuf-3.9.0/ 33 cp ${nnie_code_path}/mindspore/mindspore/lite/tools/providers/NNIE/Hi3516D/libnnie_mapper.so ${hi3516d_release_path}/ 34 cp ${nnie_code_path}/mindspore/mindspore/lite/build/tools/converter/nnie/libmslite_nnie_converter.so ${hi3516d_release_path}/ || exit 1 35 cp ${nnie_code_path}/mindspore/mindspore/lite/build/tools/converter/nnie/data_process/libmslite_nnie_data_process.so ${hi3516d_release_path}/ || exit 1 36 ms_config_file=${hi3516d_release_path}/../../converter/converter.cfg 37 echo "[registry]" > ${ms_config_file} 38 echo 'plugin_path=../providers/Hi3516D/libmslite_nnie_converter.so' >> ${ms_config_file} 39 40 cd ${open_source_ms_path}/output/ || exit 1 41 # remove unused static library 42 echo "cp new nnie so to release pkg success" 43 rm ${open_source_ms_path}/output/mindspore-lite-${version}-linux-x64.tar.gz 44 tar -zcf ./mindspore-lite-${version}-linux-x64.tar.gz ./mindspore-lite-${version}-linux-x64/ 45 sha256sum ./mindspore-lite-${version}-linux-x64.tar.gz > ./mindspore-lite-${version}-linux-x64.tar.gz.sha256 46 else 47 echo "build x86 for nnie failed"; return 1 48 fi 49} 50 51# Build arm32 for nnie 52function Run_Build_arm32() { 53 # decompress release_pkg 54 cd ${open_source_ms_path}/output/ || exit 1 55 file_name=$(ls ./*linux-aarch32.tar.gz) 56 IFS="-" read -r -a file_name_array <<< "$file_name" 57 version=${file_name_array[2]} 58 tar -xf mindspore-lite-${version}-linux-aarch32.tar.gz 59 60 # cp runtime folder 61 cd ${open_source_ms_path}/output/mindspore-lite-${version}-linux-aarch32 || exit 1 62 rm -rf ${nnie_code_path}/mindspore/mindspore/lite/tools/benchmark/nnie/third_patry/runtime/ 63 mkdir -p ${nnie_code_path}/mindspore/mindspore/lite/tools/benchmark/nnie/third_patry/runtime/ || exit 1 64 rm -rf ${nnie_code_path}/mindspore/mindspore/lite/tools/benchmark/nnie_proposal/third_patry/runtime/ 65 mkdir -p ${nnie_code_path}/mindspore/mindspore/lite/tools/benchmark/nnie_proposal/third_patry/runtime/ || exit 1 66 cp -r ./runtime/ ${nnie_code_path}/mindspore/mindspore/lite/tools/benchmark/nnie/third_patry/ 67 cp -r ./runtime/ ${nnie_code_path}/mindspore/mindspore/lite/tools/benchmark/nnie_proposal/third_patry/ 68 69 # compile nnie runtime so 70 export TOOLCHAIN_FILE=${open_source_ms_path}/mindspore/lite/cmake/himix200.toolchain.cmake 71 export TOOLCHAIN_NAME=himix200 72 73 # disable gpu & npu & train 74 export MSLITE_GPU_BACKEND=off 75 export MSLITE_ENABLE_NPU=off 76 export MSLITE_ENABLE_TRAIN=off 77 export MSLITE_ENABLE_NNIE=on 78 79 bash ${nnie_code_path}/mindspore/build.sh -I arm32 -e cpu -j ${thread_num} 80 if [ $? = 0 ]; then 81 echo "build arm32 for nnie success" 82 hi3516d_release_path=${open_source_ms_path}/output/mindspore-lite-${version}-linux-aarch32/providers/Hi3516D/ 83 rm -rf ${hi3516d_release_path} 84 mkdir -p ${hi3516d_release_path} 85 cp ${nnie_code_path}/mindspore/mindspore/lite/build/tools/benchmark/benchmark ${open_source_ms_path}/output/mindspore-lite-${version}-linux-aarch32/tools/benchmark/ || exit 1 86 cp ${nnie_code_path}/mindspore/mindspore/lite/build/tools/benchmark/nnie/libmslite_nnie.so ${hi3516d_release_path}/ || exit 1 87 cp ${nnie_code_path}/mindspore/mindspore/lite/build/tools/benchmark/nnie_proposal/libmslite_proposal.so ${hi3516d_release_path}/ || exit 1 88 cp ${nnie_code_path}/mindspore/mindspore/lite/micro/example/hi3516d/libmicro_nnie.so ${hi3516d_release_path}/ || exit 1 89 echo "cp new nnie so to release pkg success" 90 cd ${open_source_ms_path}/output/ || exit 1 91 rm ${open_source_ms_path}/output/mindspore-lite-${version}-linux-aarch32.tar.gz 92 tar -zcf ./mindspore-lite-${version}-linux-aarch32.tar.gz ./mindspore-lite-${version}-linux-aarch32/ 93 sha256sum ./mindspore-lite-${version}-linux-aarch32.tar.gz > ./mindspore-lite-${version}-linux-aarch32.tar.gz.sha256 94 else 95 echo "build arm32 for nnie failed"; return 1 96 fi 97} 98 99# bashpath should be /home/jenkins/agent-working-dir/workspace/Compile_Lite_ARM32_3516D/ 100basepath=$(pwd) 101echo "basepath is ${basepath}" 102#set -e 103open_source_ms_path=${basepath}/mindspore 104 105# Example:sh compile_nnie.sh -I arm32 -b nnie_master 106while getopts "I:b:j:" opt; do 107 case ${opt} in 108 I) 109 task=${OPTARG} 110 echo "compile task is ${OPTARG}" 111 ;; 112 b) 113 branch_name=${OPTARG} 114 echo "branch name is ${OPTARG}" 115 ;; 116 j) 117 thread_num=${OPTARG} 118 echo "thread_num is ${OPTARG}" 119 ;; 120 ?) 121 echo "unknown para" 122 exit 1;; 123 esac 124done 125 126# download nnie repository 127nnie_code_path=${basepath}/nnie_code/ 128rm -rf ${nnie_code_path} 129mkdir -p ${nnie_code_path} 130cd ${nnie_code_path} || exit 1 131 132if [[ "${GITEE_CREDENTIAL_USR}" && "${GITEE_CREDENTIAL_PSW}" ]]; then 133 gitee_user_name=${GITEE_CREDENTIAL_USR} 134 gitee_user_pass=${GITEE_CREDENTIAL_PSW} 135else 136 echo "ERROR: ENV GITEE_CREDENTIAL_USR or GITEE_CREDENTIAL_PSW not found." 137 exit 1 138fi 139 140git clone https://${gitee_user_name}:${gitee_user_pass}@gitee.com/ms-incubator/mindspore.git -b ${branch_name} --single-branch 141if [[ $? -ne 0 ]]; then 142 echo "git clone https://gitee.com/ms-incubator/mindspore.git -b ${branch_name} failed." 143 exit 1 144fi 145 146if [ ${task} == "x86_64" ]; then 147 echo "start building x86 for nnie..." 148 Run_Build_x86 & 149 Run_build_x86_PID=$! 150 sleep 1 151elif [ ${task} == "arm32" ]; then 152 echo "start building arm32 for nnie..." 153 Run_Build_arm32 & 154 Run_build_arm32_PID=$! 155 sleep 1 156fi 157 158if [ ${task} == "x86_64" ]; then 159 wait ${Run_build_x86_PID} 160 Run_build_x86_status=$? 161 exit ${Run_build_x86_status} 162elif [ ${task} == "arm32" ]; then 163 wait ${Run_build_arm32_PID} 164 Run_build_arm32_status=$? 165 exit ${Run_build_arm32_status} 166fi 167