forked from zhuxy-USTC/HCCL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
154 lines (131 loc) · 3.78 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
# This file is a part of the CANN Open Software.
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
# Please refer to the License for details. You may not use this file except in compliance with the License.
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
# See LICENSE in the root of the software repository for the full text of the License.
# ======================================================================================================================
set -e
CURRENT_DIR=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
BUILD_DIR=${CURRENT_DIR}/build
OUTPUT_DIR=${CURRENT_DIR}/output
USER_ID=$(id -u)
CPU_NUM=$(($(cat /proc/cpuinfo | grep "^processor" | wc -l)*2))
JOB_NUM="-j${CPU_NUM}"
ASAN="false"
COV="false"
CUSTOM_OPTION="-DCMAKE_INSTALL_PREFIX=${OUTPUT_DIR}"
if [ "${USER_ID}" != "0" ]; then
DEFAULT_TOOLKIT_INSTALL_DIR="${HOME}/Ascend/ascend-toolkit/latest"
DEFAULT_INSTALL_DIR="${HOME}/Ascend/latest"
else
DEFAULT_TOOLKIT_INSTALL_DIR="/usr/local/Ascend/ascend-toolkit/latest"
DEFAULT_INSTALL_DIR="/usr/local/Ascend/latest"
fi
function log() {
local current_time=`date +"%Y-%m-%d %H:%M:%S"`
echo "[$current_time] "$1
}
function set_env()
{
source $ASCEND_CANN_PACKAGE_PATH/bin/setenv.bash || echo "0"
}
function clean()
{
if [ -n "${BUILD_DIR}" ];then
rm -rf ${BUILD_DIR}
fi
if [ -z "${TEST}" ];then
if [ -n "${OUTPUT_DIR}" ];then
rm -rf ${OUTPUT_DIR}
fi
fi
mkdir -p ${BUILD_DIR} ${OUTPUT_DIR}
}
function cmake_config()
{
local extra_option="$1"
log "Info: cmake config ${CUSTOM_OPTION} ${extra_option} ."
cmake .. ${CUSTOM_OPTION} ${extra_option}
}
function build()
{
local target="$1"
cmake --build . --target ${target} ${JOB_NUM} --verbose
}
function build_package(){
cmake_config
build package
}
function build_test() {
cmake_config
build all
}
while [[ $# -gt 0 ]]; do
case $1 in
--ccache)
CCACHE_PROGRAM="$2"
shift 2
;;
-p|--package-path)
ascend_package_path="$2"
shift 2
;;
--nlohmann_path)
third_party_nlohmann_path="$2"
shift 2
;;
-t|--test)
TEST="all"
shift
;;
--asan)
ASAN="true"
shift
;;
--cov)
COV="true"
shift
;;
*)
break
;;
esac
done
if [ -n "${TEST}" ];then
CUSTOM_OPTION="${CUSTOM_OPTION} -DENABLE_TEST=ON"
fi
if [ "${ASAN}" == "true" ];then
CUSTOM_OPTION="${CUSTOM_OPTION} -DENABLE_ASAN=true"
fi
if [ "${COV}" == "true" ];then
CUSTOM_OPTION="${CUSTOM_OPTION} -DENABLE_GCOV=true"
fi
if [ -n "${ascend_package_path}" ];then
ASCEND_CANN_PACKAGE_PATH=${ascend_package_path}
elif [ -n "${ASCEND_HOME_PATH}" ];then
ASCEND_CANN_PACKAGE_PATH=${ASCEND_HOME_PATH}
elif [ -n "${ASCEND_OPP_PATH}" ];then
ASCEND_CANN_PACKAGE_PATH=$(dirname ${ASCEND_OPP_PATH})
elif [ -d "${DEFAULT_TOOLKIT_INSTALL_DIR}" ];then
ASCEND_CANN_PACKAGE_PATH=${DEFAULT_TOOLKIT_INSTALL_DIR}
elif [ -d "${DEFAULT_INSTALL_DIR}" ];then
ASCEND_CANN_PACKAGE_PATH=${DEFAULT_INSTALL_DIR}
else
log "Error: Please set the toolkit package installation directory through parameter -p|--package-path."
exit 1
fi
if [ -n "${third_party_nlohmann_path}" ];then
CUSTOM_OPTION="${CUSTOM_OPTION} -DTHIRD_PARTY_NLOHMANN_PATH=${third_party_nlohmann_path}"
fi
CUSTOM_OPTION="${CUSTOM_OPTION} -DCUSTOM_ASCEND_CANN_PACKAGE_PATH=${ASCEND_CANN_PACKAGE_PATH}"
set_env
clean
cd ${BUILD_DIR}
if [ -n "${TEST}" ];then
build_test
else
build_package
fi