You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.sh 30 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. #!/bin/bash
  2. # Copyright 2019 Huawei Technologies Co., Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # ============================================================================
  16. set -e
  17. BASEPATH=$(cd "$(dirname $0)"; pwd)
  18. CUDA_PATH=""
  19. CUDNN_PATH=""
  20. export BUILD_PATH="${BASEPATH}/build/"
  21. # print usage message
  22. usage()
  23. {
  24. echo "Usage:"
  25. echo "bash build.sh [-d] [-r] [-v] [-c on|off] [-t on|off] [-g on|off] [-h] [-b ge] [-m infer|train] \\"
  26. echo " [-a on|off] [-Q on|off] [-p on|off] [-i] [-L] [-R] [-D on|off] [-j[n]] [-e gpu|d|cpu] \\"
  27. echo " [-P on|off] [-z [on|off]] [-M on|off] [-V 9.2|10.1] [-I arm64|arm32|x86_64] [-K] \\"
  28. echo " [-B on|off] [-w on|off] [-E] [-l on|off] [-n]"
  29. echo ""
  30. echo "Options:"
  31. echo " -d Debug mode"
  32. echo " -r Release mode, default mode"
  33. echo " -v Display build command"
  34. echo " -c Enable code coverage, default off"
  35. echo " -t Run testcases, default on"
  36. echo " -g Use glog to output log, default on"
  37. echo " -h Print usage"
  38. echo " -b Select other backend, available: \\"
  39. echo " ge:graph engine"
  40. echo " -m Select graph engine backend mode, available: infer, train, default is infer"
  41. echo " -a Enable ASAN, default off"
  42. echo " -p Enable pipeline profile, print to stdout, default off"
  43. echo " -R Enable pipeline profile, record to json, default off"
  44. echo " -i Enable increment building, default off"
  45. echo " -L Enable load ANF-IR as input of 'infer', default off"
  46. echo " -j[n] Set the threads when building (Default: -j8)"
  47. echo " -e Use gpu, d or cpu"
  48. echo " -P Enable dump anf graph to file in ProtoBuffer format, default on"
  49. echo " -Q Enable dump memory, default off"
  50. echo " -D Enable dumping of function graph ir, default on"
  51. echo " -z Compile dataset & mindrecord, default on"
  52. echo " -n Compile minddata lite"
  53. echo " -M Enable MPI and NCCL for GPU training, gpu default on"
  54. echo " -V Specify the minimum required cuda version, default CUDA 10.1"
  55. echo " -I Compile lite"
  56. echo " -K Compile with AKG, default on"
  57. echo " -s Enable serving module, default off"
  58. echo " -w Enable acl module, default off"
  59. echo " -B Enable debugger, default off"
  60. echo " -E Enable IBVERBS for parameter server, default off"
  61. echo " -l Compile with python dependency, default on"
  62. }
  63. # check value of input is 'on' or 'off'
  64. # usage: check_on_off arg_value arg_name
  65. check_on_off()
  66. {
  67. if [[ "X$1" != "Xon" && "X$1" != "Xoff" ]]; then
  68. echo "Invalid value $1 for option -$2"
  69. usage
  70. exit 1
  71. fi
  72. }
  73. # check and set options
  74. checkopts()
  75. {
  76. # Init default values of build options
  77. THREAD_NUM=8
  78. DEBUG_MODE="off"
  79. VERBOSE=""
  80. ENABLE_COVERAGE="off"
  81. RUN_TESTCASES="off"
  82. ENABLE_BACKEND=""
  83. TRAIN_MODE="INFER"
  84. ENABLE_ASAN="off"
  85. ENABLE_PROFILE="off"
  86. INC_BUILD="off"
  87. ENABLE_LOAD_IR="off"
  88. ENABLE_TIMELINE="off"
  89. ENABLE_DUMP2PROTO="on"
  90. ENABLE_DUMPE2E="off"
  91. ENABLE_DUMP_IR="on"
  92. COMPILE_MINDDATA="on"
  93. COMPILE_MINDDATA_LITE="off"
  94. ENABLE_MPI="off"
  95. CUDA_VERSION="10.1"
  96. COMPILE_LITE="off"
  97. LITE_PLATFORM=""
  98. SUPPORT_TRAIN="off"
  99. USE_GLOG="on"
  100. ENABLE_AKG="on"
  101. ENABLE_SERVING="off"
  102. ENABLE_ACL="off"
  103. ENABLE_DEBUGGER="off"
  104. ENABLE_IBVERBS="off"
  105. ENABLE_PYTHON="on"
  106. ENABLE_GPU="off"
  107. # Process the options
  108. while getopts 'drvj:c:t:hsb:a:g:p:ie:m:l:I:LRP:Q:D:zM:V:K:swB:EnT:' opt
  109. do
  110. OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]')
  111. case "${opt}" in
  112. d)
  113. DEBUG_MODE="on"
  114. ;;
  115. n)
  116. COMPILE_MINDDATA_LITE="on"
  117. ;;
  118. r)
  119. DEBUG_MODE="off"
  120. ;;
  121. v)
  122. VERBOSE="VERBOSE=1"
  123. ;;
  124. j)
  125. THREAD_NUM=$OPTARG
  126. ;;
  127. c)
  128. check_on_off $OPTARG c
  129. ENABLE_COVERAGE="$OPTARG"
  130. ;;
  131. t)
  132. check_on_off $OPTARG t
  133. RUN_TESTCASES="$OPTARG"
  134. ;;
  135. g)
  136. check_on_off $OPTARG g
  137. USE_GLOG="$OPTARG"
  138. ;;
  139. h)
  140. usage
  141. exit 0
  142. ;;
  143. b)
  144. if [[ "X$OPTARG" != "Xge" && "X$OPTARG" != "Xcpu" ]]; then
  145. echo "Invalid value ${OPTARG} for option -b"
  146. usage
  147. exit 1
  148. fi
  149. ENABLE_BACKEND=$(echo "$OPTARG" | tr '[a-z]' '[A-Z]')
  150. if [[ "X$ENABLE_BACKEND" != "XCPU" ]]; then
  151. ENABLE_CPU="on"
  152. fi
  153. ;;
  154. a)
  155. check_on_off $OPTARG a
  156. ENABLE_ASAN="$OPTARG"
  157. ;;
  158. p)
  159. check_on_off $OPTARG p
  160. ENABLE_PROFILE="$OPTARG"
  161. ;;
  162. l)
  163. check_on_off $OPTARG l
  164. ENABLE_PYTHON="$OPTARG"
  165. ;;
  166. i)
  167. INC_BUILD="on"
  168. ;;
  169. m)
  170. if [[ "X$OPTARG" != "Xinfer" && "X$OPTARG" != "Xtrain" ]]; then
  171. echo "Invalid value ${OPTARG} for option -m"
  172. usage
  173. exit 1
  174. fi
  175. TRAIN_MODE=$(echo "$OPTARG" | tr '[a-z]' '[A-Z]')
  176. ;;
  177. L)
  178. ENABLE_LOAD_IR="on"
  179. echo "build with enable load anf ir"
  180. ;;
  181. R)
  182. ENABLE_TIMELINE="on"
  183. echo "enable time_line record"
  184. ;;
  185. e)
  186. if [[ "X$OPTARG" == "Xgpu" ]]; then
  187. ENABLE_GPU="on"
  188. ENABLE_CPU="on"
  189. ENABLE_MPI="on"
  190. elif [[ "X$OPTARG" == "Xd" || "X$OPTARG" == "Xascend" ]]; then
  191. ENABLE_D="on"
  192. ENABLE_CPU="on"
  193. ENABLE_SERVING="on"
  194. elif [[ "X$OPTARG" == "Xcpu" ]]; then
  195. ENABLE_CPU="on"
  196. else
  197. echo "Invalid value ${OPTARG} for option -e"
  198. usage
  199. exit 1
  200. fi
  201. ;;
  202. M)
  203. check_on_off $OPTARG M
  204. ENABLE_MPI="$OPTARG"
  205. ;;
  206. V)
  207. if [[ "X$OPTARG" != "X9.2" && "X$OPTARG" != "X10.1" ]]; then
  208. echo "Invalid value ${OPTARG} for option -V"
  209. usage
  210. exit 1
  211. fi
  212. if [[ "X$OPTARG" == "X9.2" ]]; then
  213. echo "Unsupported CUDA version 9.2"
  214. exit 1
  215. fi
  216. CUDA_VERSION="$OPTARG"
  217. ;;
  218. P)
  219. check_on_off $OPTARG p
  220. ENABLE_DUMP2PROTO="$OPTARG"
  221. echo "enable dump anf graph to proto file"
  222. ;;
  223. Q)
  224. check_on_off $OPTARG Q
  225. ENABLE_DUMPE2E="$OPTARG"
  226. echo "enable dump end to end"
  227. ;;
  228. D)
  229. check_on_off $OPTARG D
  230. ENABLE_DUMP_IR="$OPTARG"
  231. echo "enable dump function graph ir"
  232. ;;
  233. z)
  234. eval ARG=\$\{$OPTIND\}
  235. if [[ -n $ARG && $ARG != -* ]]; then
  236. OPTARG=$ARG
  237. check_on_off $OPTARG z
  238. OPTIND=$((OPTIND + 1))
  239. else
  240. OPTARG=""
  241. fi
  242. if [[ "X$OPTARG" == "Xoff" ]]; then
  243. COMPILE_MINDDATA="off"
  244. fi
  245. ;;
  246. I)
  247. COMPILE_LITE="on"
  248. if [[ "$OPTARG" == "arm64" ]]; then
  249. LITE_PLATFORM="arm64"
  250. elif [[ "$OPTARG" == "arm32" ]]; then
  251. LITE_PLATFORM="arm32"
  252. elif [[ "$OPTARG" == "x86_64" ]]; then
  253. ENABLE_CONVERTER="on"
  254. LITE_PLATFORM="x86_64"
  255. else
  256. echo "-I parameter must be arm64、arm32 or x86_64"
  257. exit 1
  258. fi
  259. ;;
  260. K)
  261. ENABLE_AKG="on"
  262. echo "enable compile with akg"
  263. ;;
  264. s)
  265. ENABLE_SERVING="on"
  266. echo "enable serving"
  267. ;;
  268. w)
  269. ENABLE_ACL="on"
  270. echo "enable acl"
  271. ;;
  272. B)
  273. check_on_off $OPTARG B
  274. ENABLE_DEBUGGER="on"
  275. echo "enable debugger"
  276. ;;
  277. E)
  278. ENABLE_IBVERBS="on"
  279. echo "enable IBVERBS for parameter server"
  280. ;;
  281. T)
  282. check_on_off $OPTARG T
  283. SUPPORT_TRAIN=$OPTARG
  284. echo "support train on device "
  285. ;;
  286. *)
  287. echo "Unknown option ${opt}!"
  288. usage
  289. exit 1
  290. esac
  291. done
  292. }
  293. checkopts "$@"
  294. if [[ "X$ENABLE_GPU" = "Xon" ]] && [[ "X$ENABLE_DUMPE2E" = "Xon" ]]; then
  295. ENABLE_DEBUGGER="on"
  296. fi
  297. echo "---------------- MindSpore: build start ----------------"
  298. mkdir -pv "${BUILD_PATH}/package/mindspore/lib"
  299. git submodule update --init graphengine
  300. if [[ "X$ENABLE_AKG" = "Xon" ]] && [[ "X$ENABLE_D" = "Xon" || "X$ENABLE_GPU" = "Xon" ]]; then
  301. git submodule update --init --recursive akg
  302. fi
  303. build_exit()
  304. {
  305. echo "$@" >&2
  306. stty echo
  307. exit 1
  308. }
  309. # Create building path
  310. build_mindspore()
  311. {
  312. echo "start build mindspore project."
  313. mkdir -pv "${BUILD_PATH}/mindspore"
  314. cd "${BUILD_PATH}/mindspore"
  315. CMAKE_ARGS="-DDEBUG_MODE=$DEBUG_MODE -DBUILD_PATH=$BUILD_PATH"
  316. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_LOAD_ANF_IR=$ENABLE_LOAD_IR"
  317. if [[ "X$ENABLE_COVERAGE" = "Xon" ]]; then
  318. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_COVERAGE=ON"
  319. fi
  320. if [[ "X$RUN_TESTCASES" = "Xon" ]]; then
  321. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_TESTCASES=ON"
  322. fi
  323. if [[ -n "$ENABLE_BACKEND" ]]; then
  324. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_${ENABLE_BACKEND}=ON"
  325. fi
  326. if [[ -n "$TRAIN_MODE" ]]; then
  327. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_${TRAIN_MODE}=ON"
  328. fi
  329. if [[ "X$ENABLE_ASAN" = "Xon" ]]; then
  330. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_ASAN=ON"
  331. fi
  332. if [[ "X$ENABLE_PROFILE" = "Xon" ]]; then
  333. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_PROFILE=ON"
  334. fi
  335. if [[ "X$ENABLE_TIMELINE" = "Xon" ]]; then
  336. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_TIMELINE=ON"
  337. fi
  338. if [[ "X$ENABLE_DUMP2PROTO" = "Xon" ]]; then
  339. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_DUMP_PROTO=ON"
  340. fi
  341. if [[ "X$ENABLE_DUMPE2E" = "Xon" ]]; then
  342. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_DUMP_E2E=ON"
  343. fi
  344. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_DUMP_IR=${ENABLE_DUMP_IR}"
  345. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_PYTHON=${ENABLE_PYTHON}"
  346. if [[ "X$ENABLE_MPI" = "Xon" ]]; then
  347. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_MPI=ON"
  348. fi
  349. if [[ "X$ENABLE_D" = "Xon" ]]; then
  350. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_D=ON"
  351. fi
  352. if [[ "X$ENABLE_GPU" = "Xon" ]]; then
  353. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GPU=ON -DUSE_CUDA=ON -DCUDA_PATH=$CUDA_PATH -DCUDNN_PATH=$CUDNN_PATH -DMS_REQUIRE_CUDA_VERSION=${CUDA_VERSION}"
  354. fi
  355. if [[ "X$ENABLE_CPU" = "Xon" ]]; then
  356. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_CPU=ON"
  357. fi
  358. if [[ "X$COMPILE_MINDDATA" = "Xon" ]]; then
  359. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_MINDDATA=ON"
  360. fi
  361. if [[ "X$USE_GLOG" = "Xon" ]]; then
  362. CMAKE_ARGS="${CMAKE_ARGS} -DUSE_GLOG=ON"
  363. fi
  364. if [[ "X$ENABLE_AKG" = "Xon" ]] && [[ "X$ENABLE_D" = "Xon" || "X$ENABLE_GPU" = "Xon" ]]; then
  365. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_AKG=ON"
  366. fi
  367. if [[ "X$ENABLE_SERVING" = "Xon" ]]; then
  368. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_SERVING=ON"
  369. fi
  370. if [[ "X$ENABLE_ACL" = "Xon" ]]; then
  371. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_ACL=ON"
  372. fi
  373. if [[ "X$ENABLE_DEBUGGER" = "Xon" ]]; then
  374. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_DEBUGGER=ON"
  375. fi
  376. if [[ "X$ENABLE_IBVERBS" = "Xon" ]]; then
  377. CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_IBVERBS=ON"
  378. fi
  379. echo "${CMAKE_ARGS}"
  380. if [[ "X$INC_BUILD" = "Xoff" ]]; then
  381. cmake ${CMAKE_ARGS} ../..
  382. fi
  383. if [[ -n "$VERBOSE" ]]; then
  384. CMAKE_VERBOSE="--verbose"
  385. fi
  386. if [[ "X$ENABLE_ACL" = "Xon" ]]; then
  387. cmake --build . ${CMAKE_VERBOSE} -j$THREAD_NUM
  388. else
  389. cmake --build . --target package ${CMAKE_VERBOSE} -j$THREAD_NUM
  390. fi
  391. echo "success to build mindspore project!"
  392. }
  393. checkndk() {
  394. if [ "${ANDROID_NDK}" ]; then
  395. echo -e "\e[31mANDROID_NDK_PATH=$ANDROID_NDK \e[0m"
  396. else
  397. echo -e "\e[31mplease set ANDROID_NDK in environment variable for example: export ANDROID_NDK=/root/usr/android-ndk-r20b/ \e[0m"
  398. exit 1
  399. fi
  400. }
  401. gene_flatbuffer() {
  402. FLAT_DIR="${BASEPATH}/mindspore/lite/schema"
  403. cd ${FLAT_DIR} && rm -rf "${FLAT_DIR}/inner" && mkdir -p "${FLAT_DIR}/inner"
  404. find . -name "*.fbs" -print0 | xargs -0 "${FLATC}" -c -b
  405. find . -name "*.fbs" -print0 | xargs -0 "${FLATC}" -c -b --reflect-types --gen-mutable --reflect-names --gen-object-api -o "${FLAT_DIR}/inner"
  406. FLAT_DIR="${BASEPATH}/mindspore/lite/tools/converter/parser/tflite"
  407. cd ${FLAT_DIR}
  408. find . -name "*.fbs" -print0 | xargs -0 "${FLATC}" -c -b --reflect-types --gen-mutable --reflect-names --gen-object-api -o "${FLAT_DIR}/"
  409. }
  410. build_flatbuffer() {
  411. cd ${BASEPATH}
  412. FLATC="${BASEPATH}"/third_party/flatbuffers/build/flatc
  413. if [[ ! -f "${FLATC}" ]]; then
  414. git submodule update --init --recursive third_party/flatbuffers
  415. cd ${BASEPATH}/third_party/flatbuffers
  416. rm -rf build && mkdir -pv build && cd build && cmake .. && make -j$THREAD_NUM
  417. gene_flatbuffer
  418. fi
  419. if [[ "${INC_BUILD}" == "off" ]]; then
  420. gene_flatbuffer
  421. fi
  422. }
  423. gene_protobuf() {
  424. PROTO_SRC_DIR="${BASEPATH}/mindspore/lite/tools/converter/parser/caffe"
  425. find ${PROTO_SRC_DIR} -name "*.proto" -print0 | xargs -0 "${PROTOC}" -I"${PROTO_SRC_DIR}" --cpp_out="${PROTO_SRC_DIR}"
  426. PROTO_SRC_DIR="${BASEPATH}/mindspore/lite/tools/converter/parser/onnx"
  427. find ${PROTO_SRC_DIR} -name "*.proto" -print0 | xargs -0 "${PROTOC}" -I"${PROTO_SRC_DIR}" --cpp_out="${PROTO_SRC_DIR}"
  428. }
  429. build_protobuf() {
  430. cd ${BASEPATH}
  431. PROTOC="${BASEPATH}"/third_party/protobuf/build/bin/protoc
  432. if [[ ! -f "${PROTOC}" ]]; then
  433. git submodule update --init --recursive third_party/protobuf
  434. cd ${BASEPATH}/third_party/protobuf
  435. rm -rf build && mkdir -pv build && ./autogen.sh
  436. ./configure --prefix=${BASEPATH}/third_party/protobuf/build
  437. make clean && make -j$THREAD_NUM && make install
  438. gene_protobuf
  439. fi
  440. if [[ "${INC_BUILD}" == "off" ]]; then
  441. gene_protobuf
  442. fi
  443. }
  444. build_gtest() {
  445. cd ${BASEPATH}
  446. git submodule update --init --recursive third_party/googletest
  447. }
  448. gene_clhpp() {
  449. CL_SRC_DIR="${BASEPATH}/mindspore/lite/src/runtime/kernel/opencl/cl"
  450. for sub_dir in "${CL_SRC_DIR}"/*
  451. do
  452. data_type="$(basename ${sub_dir})"
  453. if [ ! -d ${CL_SRC_DIR}/${data_type} ]; then
  454. continue
  455. fi
  456. cd ${CL_SRC_DIR}/${data_type}
  457. rm -rf *.inc
  458. echo "$(cd "$(dirname $0)"; pwd)"
  459. for file_path in "${CL_SRC_DIR}/${data_type}"/*
  460. do
  461. file="$(basename ${file_path})"
  462. inc_file=`echo ${CL_SRC_DIR}/${data_type}/${file} | sed 's/$/.inc/'`
  463. sed 's/^/\"/;s/$/ \\n\" \\/' ${CL_SRC_DIR}/${data_type}/${file} > ${inc_file}
  464. kernel_name=`echo ${file} | sed s'/.\{3\}$//'`
  465. sed -i "1i\static const char *${kernel_name}_source_${data_type} =\"\\n\" \\" ${inc_file}
  466. sed -i '$a\;' ${inc_file}
  467. done
  468. done
  469. }
  470. gene_ocl_program() {
  471. CL_SRC_DIR="${BASEPATH}/mindspore/lite/src/runtime/kernel/opencl/cl"
  472. SPIRV_DIR=build/spirv
  473. rm -rf ${SPIRV_DIR}
  474. mkdir -pv ${SPIRV_DIR}
  475. for sub_dir in "${CL_SRC_DIR}"/*
  476. do
  477. data_type="$(basename ${sub_dir})"
  478. if [ ! -d ${CL_SRC_DIR}/${data_type} ]; then
  479. continue
  480. fi
  481. #echo $(cd "$(dirname $0)"; pwd)
  482. for file_path in "${CL_SRC_DIR}/${data_type}"/*
  483. do
  484. file="$(basename ${file_path})"
  485. if [ "${file##*.}" != "cl" ]; then
  486. continue
  487. fi
  488. clang -Xclang -finclude-default-header -cl-std=CL2.0 --target=spir64-unknown-unknown -emit-llvm \
  489. -c -O0 -o ${SPIRV_DIR}/${file%.*}.bc ${CL_SRC_DIR}/${data_type}/${file}
  490. done
  491. done
  492. bcs=`ls ${SPIRV_DIR}/*.bc`
  493. llvm-link ${bcs} -o ${SPIRV_DIR}/program.bc
  494. llvm-spirv -o ${SPIRV_DIR}/program.spv ${SPIRV_DIR}/program.bc
  495. CL_PROGRAM_PATH="${BASEPATH}/mindspore/lite/src/runtime/kernel/opencl/cl/program.inc"
  496. echo "#include <vector>" > ${CL_PROGRAM_PATH}
  497. echo "std::vector<unsigned char> g_program_binary = {" >> ${CL_PROGRAM_PATH}
  498. #hexdump -v -e '16/1 "0x%02x, " "\n"' ${SPIRV_DIR}/program.spv >> ${CL_PROGRAM_PATH}
  499. hexdump -v -e '1/1 "0x%02x, "' ${SPIRV_DIR}/program.spv >> ${CL_PROGRAM_PATH}
  500. echo "};" >> ${CL_PROGRAM_PATH}
  501. echo "Compile SPIRV done"
  502. }
  503. build_opencl() {
  504. cd ${BASEPATH}
  505. git submodule update --init third_party/OpenCL-Headers
  506. git submodule update --init third_party/OpenCL-CLHPP
  507. if [[ "${OPENCL_OFFLINE_COMPILE}" == "on" ]]; then
  508. gene_ocl_program
  509. else
  510. gene_clhpp
  511. fi
  512. }
  513. build_opencv() {
  514. cd ${BASEPATH}
  515. if [[ "${INC_BUILD}" == "off" ]]; then
  516. git submodule update --init --recursive third_party/opencv
  517. cd ${BASEPATH}/third_party/opencv
  518. rm -rf build && mkdir -p build && cd build && cmake ${CMAKE_MINDDATA_ARGS} -DBUILD_SHARED_LIBS=ON -DBUILD_ANDROID_PROJECTS=OFF \
  519. -DBUILD_LIST=core,imgcodecs,imgproc -DBUILD_ZLIB=ON .. && make -j$THREAD_NUM
  520. fi
  521. }
  522. build_jpeg_turbo() {
  523. cd ${BASEPATH}
  524. if [[ "${INC_BUILD}" == "off" ]]; then
  525. git submodule update --init --recursive third_party/libjpeg-turbo
  526. cd ${BASEPATH}/third_party/libjpeg-turbo
  527. rm -rf build && mkdir -p build && cd build && cmake ${CMAKE_MINDDATA_ARGS} -DCMAKE_BUILD_TYPE=Release \
  528. -DCMAKE_INSTALL_PREFIX="${BASEPATH}/third_party/libjpeg-turbo" .. && make -j$THREAD_NUM && make install
  529. fi
  530. }
  531. build_eigen() {
  532. cd ${BASEPATH}
  533. git submodule update --init --recursive third_party/eigen
  534. }
  535. build_minddata_lite_deps()
  536. {
  537. echo "start build minddata lite project"
  538. if [[ "${LITE_PLATFORM}" == "arm64" ]]; then
  539. CMAKE_MINDDATA_ARGS="-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=19 \
  540. -DANDROID_NDK=${ANDROID_NDK} -DANDROID_ABI=arm64-v8a -DANDROID_TOOLCHAIN_NAME=aarch64-linux-android-clang \
  541. -DANDROID_STL=c++_shared -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
  542. elif [[ "${LITE_PLATFORM}" == "arm32" ]]; then
  543. CMAKE_MINDDATA_ARGS="-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=19 \
  544. -DANDROID_NDK=${ANDROID_NDK} -DANDROID_ABI=armeabi-v7a -DANDROID_TOOLCHAIN_NAME=clang \
  545. -DANDROID_STL=c++_shared -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
  546. else
  547. CMAKE_MINDDATA_ARGS="-DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
  548. fi
  549. build_opencv
  550. build_eigen
  551. build_jpeg_turbo
  552. }
  553. prepare_md_lite() {
  554. if [ "${COMPILE_MINDDATA_LITE}" == "on" ]; then
  555. echo "packaging minddata"
  556. cp ${BASEPATH}/mindspore/ccsrc/minddata/dataset/include/*h ${OUTPUT_DIR}/include/
  557. cp ${BASEPATH}/mindspore/lite/build/minddata/libminddata-lite.so ${OUTPUT_DIR}/lib/
  558. if [[ "$LITE_PLATFORM" == "x86_64" ]]; then
  559. mkdir -p ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib
  560. cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libjpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/
  561. cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libturbojpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/
  562. mkdir -p ${OUTPUT_DIR}/third_party/opencv/lib/
  563. cp -r ${BASEPATH}/third_party/opencv/build/lib/libopencv_core.so ${OUTPUT_DIR}/third_party/opencv/lib/
  564. cp -r ${BASEPATH}/third_party/opencv/build/lib/libopencv_imgcodecs.so ${OUTPUT_DIR}/third_party/opencv/lib/
  565. cp -r ${BASEPATH}/third_party/opencv/build/lib/libopencv_imgproc.so ${OUTPUT_DIR}/third_party/opencv/lib/
  566. elif [[ "$LITE_PLATFORM" == "arm64" ]]; then
  567. mkdir -p ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib
  568. cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libjpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/
  569. cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libturbojpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/
  570. mkdir -p ${OUTPUT_DIR}/third_party/opencv/lib/arm64-v8a/
  571. cp -r ${BASEPATH}/third_party/opencv/build/lib/arm64-v8a/libopencv_core.so ${OUTPUT_DIR}/third_party/opencv/lib/arm64-v8a/
  572. cp -r ${BASEPATH}/third_party/opencv/build/lib/arm64-v8a/libopencv_imgcodecs.so ${OUTPUT_DIR}/third_party/opencv/lib/arm64-v8a/
  573. cp -r ${BASEPATH}/third_party/opencv/build/lib/arm64-v8a/libopencv_imgproc.so ${OUTPUT_DIR}/third_party/opencv/lib/arm64-v8a/
  574. elif [[ "$LITE_PLATFORM" == "arm32" ]]; then
  575. mkdir -p ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib
  576. cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libjpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/
  577. cp -r ${BASEPATH}/third_party/libjpeg-turbo/lib/libturbojpeg.so ${OUTPUT_DIR}/third_party/libjpeg-turbo/lib/
  578. mkdir -p ${OUTPUT_DIR}/third_party/opencv/lib/armeabi-v7a/
  579. cp -r ${BASEPATH}/third_party/opencv/build/lib/armeabi-v7a/libopencv_core.so ${OUTPUT_DIR}/third_party/opencv/lib/armeabi-v7a/
  580. cp -r ${BASEPATH}/third_party/opencv/build/lib/armeabi-v7a/libopencv_imgcodecs.so ${OUTPUT_DIR}/third_party/opencv/lib/armeabi-v7a/
  581. cp -r ${BASEPATH}/third_party/opencv/build/lib/armeabi-v7a/libopencv_imgproc.so ${OUTPUT_DIR}/third_party/opencv/lib/armeabi-v7a/
  582. fi
  583. fi
  584. }
  585. build_lite()
  586. {
  587. echo "start build mindspore lite project"
  588. if [ "${ENABLE_GPU}" == "on" ] && [ "${LITE_PLATFORM}" == "arm64" ]; then
  589. echo "start build opencl"
  590. build_opencl
  591. fi
  592. if [[ "${LITE_PLATFORM}" == "x86_64" ]]; then
  593. build_protobuf
  594. fi
  595. build_flatbuffer
  596. build_gtest
  597. if [ "${COMPILE_MINDDATA_LITE}" == "on" ]; then
  598. build_minddata_lite_deps
  599. fi
  600. cd "${BASEPATH}/mindspore/lite"
  601. if [[ "${INC_BUILD}" == "off" ]]; then
  602. rm -rf build
  603. fi
  604. mkdir -pv build
  605. cd build
  606. BUILD_TYPE="Release"
  607. if [[ "${DEBUG_MODE}" == "on" ]]; then
  608. BUILD_TYPE="Debug"
  609. fi
  610. if [[ "${LITE_PLATFORM}" == "arm64" ]]; then
  611. checkndk
  612. cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \
  613. -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="arm64-v8a" -DANDROID_TOOLCHAIN_NAME="aarch64-linux-android-clang" \
  614. -DANDROID_STL="c++_shared" -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \
  615. -DBUILD_DEVICE=on -DPLATFORM_ARM64=on -DBUILD_CONVERTER=off -DENABLE_NEON=on -DENABLE_FP16="off" \
  616. -DSUPPORT_GPU=${ENABLE_GPU} -DOFFLINE_COMPILE=${OPENCL_OFFLINE_COMPILE} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \
  617. "${BASEPATH}/mindspore/lite"
  618. elif [[ "${LITE_PLATFORM}" == "arm32" ]]; then
  619. checkndk
  620. cmake -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" -DANDROID_NATIVE_API_LEVEL="19" \
  621. -DANDROID_NDK="${ANDROID_NDK}" -DANDROID_ABI="armeabi-v7a" -DANDROID_TOOLCHAIN_NAME="clang" \
  622. -DANDROID_STL="c++_shared" -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
  623. -DBUILD_DEVICE=on -DPLATFORM_ARM32=on -DENABLE_NEON=on -DSUPPORT_TRAIN=${SUPPORT_TRAIN} -DBUILD_CONVERTER=off \
  624. -DSUPPORT_GPU=${ENABLE_GPU} -DOFFLINE_COMPILE=${OPENCL_OFFLINE_COMPILE} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \
  625. "${BASEPATH}/mindspore/lite"
  626. else
  627. cmake -DBUILD_DEVICE=on -DPLATFORM_ARM64=off -DBUILD_CONVERTER=${ENABLE_CONVERTER} -DSUPPORT_TRAIN=${SUPPORT_TRAIN} \
  628. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DSUPPORT_GPU=${ENABLE_GPU} -DBUILD_MINDDATA=${COMPILE_MINDDATA_LITE} \
  629. -DOFFLINE_COMPILE=${OPENCL_OFFLINE_COMPILE} "${BASEPATH}/mindspore/lite"
  630. fi
  631. VERBOSE=2 make -j$THREAD_NUM
  632. COMPILE_RET=$?
  633. if [[ "${COMPILE_RET}" -ne 0 ]]; then
  634. echo "---------------- mindspore lite: build failed ----------------"
  635. else
  636. mkdir -pv ${BASEPATH}/mindspore/lite/output/
  637. if [[ "$LITE_PLATFORM" == "x86_64" ]]; then
  638. OUTPUT_DIR=${BASEPATH}/output/MSLite-0.6.0-linux_x86_64
  639. rm -rf ${OUTPUT_DIR} && mkdir -p ${OUTPUT_DIR} && cd ${OUTPUT_DIR}
  640. mkdir -p ${OUTPUT_DIR}/converter && mkdir -p ${OUTPUT_DIR}/time_profile
  641. mkdir -p ${OUTPUT_DIR}/benchmark && mkdir -p ${OUTPUT_DIR}/include && mkdir -p ${OUTPUT_DIR}/lib
  642. mkdir -p ${OUTPUT_DIR}/third_party
  643. prepare_md_lite
  644. cp ${BASEPATH}/mindspore/lite/build/tools/converter/converter_lite ${OUTPUT_DIR}/converter/
  645. cp ${BASEPATH}/mindspore/lite/build/tools/benchmark/benchmark ${OUTPUT_DIR}/benchmark/
  646. cp ${BASEPATH}/mindspore/lite/build/tools/time_profile/timeprofile ${OUTPUT_DIR}/time_profile/
  647. cp ${BASEPATH}/mindspore/lite/include/*.h ${OUTPUT_DIR}/include/
  648. mkdir -p ${OUTPUT_DIR}/include/ir/dtype/
  649. cp ${BASEPATH}/mindspore/core/ir/dtype/type_id.h ${OUTPUT_DIR}/include/ir/dtype/
  650. mkdir -p ${OUTPUT_DIR}/include/schema/
  651. cp ${BASEPATH}/mindspore/lite/schema/*.h ${OUTPUT_DIR}/include/schema/
  652. cp ${BASEPATH}/mindspore/lite/build/src/libmindspore-lite.so ${OUTPUT_DIR}/lib/
  653. mkdir -p ${OUTPUT_DIR}/third_party/protobuf/lib
  654. cp -r ${BASEPATH}/third_party/protobuf/build/include/ ${OUTPUT_DIR}/third_party/protobuf/
  655. cp -r ${BASEPATH}/third_party/protobuf/build/lib/libprotobuf.so.19 ${OUTPUT_DIR}/third_party/protobuf/lib/
  656. cp -r ${BASEPATH}/third_party/protobuf/build/lib/libprotobuf.so.19.0.0 ${OUTPUT_DIR}/third_party/protobuf/lib/
  657. mkdir -p ${OUTPUT_DIR}/third_party/flatbuffers
  658. cp -r ${BASEPATH}/third_party/flatbuffers/include/ ${OUTPUT_DIR}/third_party/flatbuffers/
  659. cd ..
  660. tar -czf MSLite-0.6.0-linux_x86_64.tar.gz MSLite-0.6.0-linux_x86_64/ --warning=no-file-changed
  661. sha256sum MSLite-0.6.0-linux_x86_64.tar.gz > MSLite-0.6.0-linux_x86_64.tar.gz.sha256
  662. rm -rf MSLite-0.6.0-linux_x86_64/
  663. elif [[ "$LITE_PLATFORM" == "arm64" ]]; then
  664. OUTPUT_DIR=${BASEPATH}/output/MSLite-0.6.0-linux_arm64
  665. rm -rf ${OUTPUT_DIR} && mkdir -p ${OUTPUT_DIR} && cd ${OUTPUT_DIR}
  666. mkdir -p ${OUTPUT_DIR}/time_profile && mkdir -p ${OUTPUT_DIR}/benchmark
  667. mkdir -p ${OUTPUT_DIR}/include && mkdir -p ${OUTPUT_DIR}/lib
  668. mkdir -p ${OUTPUT_DIR}/third_party
  669. prepare_md_lite
  670. cp ${BASEPATH}/mindspore/lite/build/tools/benchmark/benchmark ${OUTPUT_DIR}/benchmark/
  671. cp ${BASEPATH}/mindspore/lite/build/tools/time_profile/timeprofile ${OUTPUT_DIR}/time_profile/
  672. cp ${BASEPATH}/mindspore/lite/include/*.h ${OUTPUT_DIR}/include/
  673. mkdir -p ${OUTPUT_DIR}/include/ir/dtype/
  674. cp ${BASEPATH}/mindspore/core/ir/dtype/type_id.h ${OUTPUT_DIR}/include/ir/dtype/
  675. mkdir -p ${OUTPUT_DIR}/include/schema/
  676. cp ${BASEPATH}/mindspore/lite/schema/*.h ${OUTPUT_DIR}/include/schema/
  677. cp ${BASEPATH}/mindspore/lite/build/src/libmindspore-lite.so ${OUTPUT_DIR}/lib/
  678. mkdir -p ${OUTPUT_DIR}/third_party/flatbuffers
  679. cp -r ${BASEPATH}/third_party/flatbuffers/include/ ${OUTPUT_DIR}/third_party/flatbuffers/
  680. cd ..
  681. tar -czf MSLite-0.6.0-linux_arm64.tar.gz MSLite-0.6.0-linux_arm64/ --warning=no-file-changed
  682. sha256sum MSLite-0.6.0-linux_arm64.tar.gz > MSLite-0.6.0-linux_arm64.tar.gz.sha256
  683. rm -rf MSLite-0.6.0-linux_arm64/
  684. elif [[ "$LITE_PLATFORM" == "arm32" ]]; then
  685. OUTPUT_DIR=${BASEPATH}/output/MSLite-0.6.0-linux_arm32
  686. rm -rf ${OUTPUT_DIR} && mkdir -p ${OUTPUT_DIR} && cd ${OUTPUT_DIR}
  687. mkdir -p ${OUTPUT_DIR}/time_profile && mkdir -p ${OUTPUT_DIR}/benchmark
  688. mkdir -p ${OUTPUT_DIR}/include && mkdir -p ${OUTPUT_DIR}/lib
  689. mkdir -p ${OUTPUT_DIR}/third_party
  690. prepare_md_lite
  691. cp ${BASEPATH}/mindspore/lite/build/tools/benchmark/benchmark ${OUTPUT_DIR}/benchmark/
  692. cp ${BASEPATH}/mindspore/lite/build/tools/time_profile/timeprofile ${OUTPUT_DIR}/time_profile/
  693. cp ${BASEPATH}/mindspore/lite/include/*.h ${OUTPUT_DIR}/include/
  694. mkdir -p ${OUTPUT_DIR}/include/ir/dtype/
  695. cp ${BASEPATH}/mindspore/core/ir/dtype/type_id.h ${OUTPUT_DIR}/include/ir/dtype/
  696. mkdir -p ${OUTPUT_DIR}/include/schema/
  697. cp ${BASEPATH}/mindspore/lite/schema/*.h ${OUTPUT_DIR}/include/schema/
  698. cp ${BASEPATH}/mindspore/lite/build/src/libmindspore-lite.so ${OUTPUT_DIR}/lib/
  699. mkdir -p ${OUTPUT_DIR}/third_party/flatbuffers
  700. cp -r ${BASEPATH}/third_party/flatbuffers/include/ ${OUTPUT_DIR}/third_party/flatbuffers/
  701. cd ..
  702. tar -czf MSLite-0.6.0-linux_arm32.tar.gz MSLite-0.6.0-linux_arm32/ --warning=no-file-changed
  703. sha256sum MSLite-0.6.0-linux_arm32.tar.gz > MSLite-0.6.0-linux_arm32.tar.gz.sha256
  704. rm -rf MSLite-0.6.0-linux_arm32/
  705. fi
  706. echo "---------------- mindspore lite: build success ----------------"
  707. fi
  708. }
  709. if [[ "X$COMPILE_LITE" = "Xon" ]]; then
  710. build_lite
  711. exit
  712. else
  713. build_mindspore
  714. fi
  715. cp -rf ${BUILD_PATH}/package/mindspore/lib ${BUILD_PATH}/../mindspore
  716. cp -rf ${BUILD_PATH}/package/mindspore/*.so ${BUILD_PATH}/../mindspore
  717. echo "---------------- mindspore: build end ----------------"