1 Star 0 Fork 227

钱泽洪 / tensorflow

forked from Ascend / tensorflow 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
build.sh 4.53 KB
一键复制 编辑 原始数据 按行查看 历史
huanruizhi 提交于 2021-05-31 10:42 . tfadapter ut
#!/bin/bash
# Copyright 2019-2020 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.
# ============================================================================
set -e
BASE_PATH=$(cd "$(dirname $0)"; pwd)
RELEASE_PATH="${BASE_PATH}/output"
export BUILD_PATH="${BASE_PATH}/build"
INSTALL_PATH="${BUILD_PATH}/install"
CMAKE_PATH="${BUILD_PATH}/tfadapter"
# print usage message
usage() {
echo "Usage:"
echo " bash build.sh [-h] [-j[n]] [-v] [-g] [-u]"
echo ""
echo "Options:"
echo " -h Print usage"
echo " -j[n] Set the number of threads used to build CANN, default is 8"
echo " -v Verbose"
echo " -g GCC compiler prefix, used to specify the compiler toolchain"
echo " -u TF_adapter utest"
echo "to be continued ..."
}
logging() {
echo "[INFO] $@"
}
# parse and set optionss
checkopts() {
VERBOSE=""
THREAD_NUM=8
GCC_PREFIX=""
ENABLE_TFADAPTER_UT="off"
# Process the options
while getopts 'hj:vug:' opt
do
case "${opt}" in
h) usage
exit 0 ;;
j) THREAD_NUM=$OPTARG ;;
v) VERBOSE="VERBOSE=1" ;;
g) GCC_PREFIX=$OPTARG ;;
u) ENABLE_TFADAPTER_UT="on" ;;
*) logging "Undefined option: ${opt}"
usage
exit 1 ;;
esac
done
}
# mkdir directory
mk_dir() {
local create_dir="$1"
mkdir -pv "${create_dir}"
logging "Created ${create_dir}"
}
# create build path
build_tfadapter() {
if [[ "X$ENABLE_TFADAPTER_UT" = "Xon" ]]; then
export OPEN_UT=1
fi
logging "Create build directory and build tfadapter"
cd "${BASE_PATH}" && ./configure
CMAKE_ARGS="-DENABLE_OPEN_SRC=True -DBUILD_PATH=$BUILD_PATH -DCMAKE_INSTALL_PREFIX=${RELEASE_PATH}"
if [[ "$GCC_PREFIX" != "" ]]; then
CMAKE_ARGS="$CMAKE_ARGS -DGCC_PREFIX=$GCC_PREFIX"
fi
if [[ "X$ENABLE_TFADAPTER_UT" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_TFADAPTER_UT=ON"
fi
logging "CMake Args: ${CMAKE_ARGS}"
mk_dir "${CMAKE_PATH}"
cd "${CMAKE_PATH}" && cmake ${CMAKE_ARGS} ../..
if [ 0 -ne $? ]
then
echo "execute command: cmake ${CMAKE_ARGS} .. failed."
return 1
fi
if [[ "X$ENABLE_TFADAPTER_UT" = "Xon" ]]; then
make tfadapter_utest ${VERBOSE} -j${THREAD_NUM}
logging "Build tfadapter utest success!"
else
make ${VERBOSE} -j${THREAD_NUM}
logging "tfadapter build success!"
chmod +x "${BASE_PATH}/tf_adapter_2.x/CI_Build"
sh "${BASE_PATH}/tf_adapter_2.x/CI_Build"
fi
}
release_tfadapter() {
logging "Create output directory"
RELEASE_TARGET="tfadapter.tar"
cd ${CMAKE_PATH}/dist/python/dist && mkdir -p tfplugin/bin && cp -r "${BASE_PATH}/script" tfplugin/ && mv npu_bridge-*.whl tfplugin/bin && mv "${BASE_PATH}/tf_adapter_2.x/build/dist/python/dist/npu_device-0.1-py3-none-any.whl" tfplugin/bin && tar cfz "${RELEASE_TARGET}" * && mv "${RELEASE_TARGET}" "${RELEASE_PATH}"
}
main() {
checkopts "$@"
# tfadapter build start
logging "---------------- tfadapter build start ----------------"
${GCC_PREFIX}g++ -v
mk_dir "${RELEASE_PATH}"
build_tfadapter
if [[ "X$ENABLE_TFADAPTER_UT" = "Xoff" ]]; then
release_tfadapter
fi
if [[ "X$ENABLE_TFADAPTER_UT" = "Xon" ]]; then
cd ${BASE_PATH}
export ASCEND_OPP_PATH=${BASE_PATH}/tf_adapter/tests/depends/support_json
export PRINT_MODEL=1
export LD_LIBRARY_PATH=${CMAKE_PATH}/tf_adapter/tests/depends/aoe/:$LD_LIBRARY_PATH
RUN_TEST_CASE=${CMAKE_PATH}/tf_adapter/tests/ut/tfadapter_utest && ${RUN_TEST_CASE}
if [[ "$?" -ne 0 ]]; then
echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
echo -e "\033[31m${RUN_TEST_CASE}\033[0m"
exit 1;
fi
logging "Generating coverage statistics, please wait..."
rm -rf ${BASE_PATH}/coverage
mkdir ${BASE_PATH}/coverage
lcov -c -d ${CMAKE_PATH}/tf_adapter/tests/ut/ -o coverage/tmp.info
lcov -r coverage/tmp.info '*/tests/*' '*/nlohmann_json-src/*' '*/tensorflow-src/*' \
'*/inc/*' '*/output/*' '*/usr/*' '*/Eigen/*' '*/absl/*' '*/google/*' '*/tensorflow/core/*' \
-o coverage/coverage.info
fi
logging "---------------- tfadapter build finished ----------------"
}
main "$@"
C++
1
https://gitee.com/tsien_z/tensorflow.git
git@gitee.com:tsien_z/tensorflow.git
tsien_z
tensorflow
tensorflow
master

搜索帮助