已合并
refactor: 拆分build.sh为模块化脚本 #1204
liu-wei创建于 7月30日
refactor: 拆分build.sh为模块化脚本 #1204
已合并
共 9 个文件变更+1990-1886
| @@ -10,1892 +10,18 @@ | |||
| 10 | # ----------------------------------------------------------------------------------------------------------- | 10 | # ----------------------------------------------------------------------------------------------------------- |
| 11 | 11 | ||
| 12 | set -e | 12 | set -e |
| 13 | -RELEASE_TARGETS=("ophost" "opapi" "opgraph" "opkernel" "opkernel_aicpu" "onnxplugin") | ||
| 14 | -SUPPORTED_UT_TARGETS=("ophost_test" "opapi_test" "opgraph_test" "opkernel_test" "opkernel_aicpu_test") | ||
| 15 | -SUPPORT_COMPUTE_UNIT_SHORT=("ascend031" "ascend035" "ascend310b" "ascend310p" "ascend610lite" "ascend630" | ||
| 16 | - "ascend910_93" "ascend950" "ascend910b" "ascend910" "mc62" "kirinx90" "kirin9030") | ||
| 17 | 13 | ||
| 18 | -# 所有支持的短选项 | 14 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 19 | -SUPPORTED_SHORT_OPTS="hj:vO:uf:-:" | 15 | +export BASE_PATH="${SCRIPT_DIR}" |
| 20 | - | 16 | + |
| 21 | -# 所有支持的长选项 | 17 | +source "${SCRIPT_DIR}/scripts/build_conf.sh" |
| 22 | -SUPPORTED_LONG_OPTS=( | 18 | +source "${SCRIPT_DIR}/scripts/build_clean.sh" |
| 23 | - "help" "ops=" "soc=" "vendor_name=" "build-type=" "cov" "noexec" "aicpu" "noaicpu" "opkernel" "opkernel_aicpu" "jit" | 19 | +source "${SCRIPT_DIR}/scripts/build_options.sh" |
| 24 | - "pkg" "asan" "valgrind" "make_clean" "static" "simulator" | 20 | +source "${SCRIPT_DIR}/scripts/build_cmake.sh" |
| 25 | - "ophost" "opapi" "opgraph" "ophost_test" "opapi_test" "opgraph_test" "opkernel_test" "opkernel_aicpu_test" | 21 | +source "${SCRIPT_DIR}/scripts/build_lib.sh" |
| 26 | - "run_example" "genop=" "genop_aicpu=" "cann_3rd_lib_path" "experimental" "mssanitizer" "oom" "onnxplugin" "dump_cce" | 22 | +source "${SCRIPT_DIR}/scripts/build_ut.sh" |
| 27 | - "bisheng_flags=" "kernel_template_input=" "rule_launch=" "ccache=" "pkg-type=" | 23 | +source "${SCRIPT_DIR}/scripts/build_example.sh" |
| 28 | -) | 24 | +source "${SCRIPT_DIR}/scripts/build_genop.sh" |
| 29 | - | ||
| 30 | -in_array() { | ||
| 31 | - local needle="$1" | ||
| 32 | - shift | ||
| 33 | - local haystack=("$@") | ||
| 34 | - for item in "${haystack[@]}"; do | ||
| 35 | - if [[ "$item" == "$needle" ]]; then | ||
| 36 | - return 0 | ||
| 37 | - fi | ||
| 38 | - done | ||
| 39 | - return 1 | ||
| 40 | -} | ||
| 41 | - | ||
| 42 | -check_pkg_type() { | ||
| 43 | - local pkg_type="$1" | ||
| 44 | - if [[ "$pkg_type" != "run" && "$pkg_type" != "rpm" && "$pkg_type" != "deb" && "$pkg_type" != "all" ]]; then | ||
| 45 | - echo "[ERROR] --pkg-type only supports run/rpm/deb/all, got: $pkg_type" | ||
| 46 | - exit 1 | ||
| 47 | - fi | ||
| 48 | -} | ||
| 49 | - | ||
| 50 | -normalize_compute_unit() { | ||
| 51 | - local compute_unit="$1" | ||
| 52 | - local compute_unit_lower | ||
| 53 | - compute_unit_lower=$(echo "$compute_unit" | tr '[:upper:]' '[:lower:]') | ||
| 54 | - if [[ "$compute_unit_lower" =~ ^ascend950[0-9a-z_-]*$ ]]; then | ||
| 55 | - echo "ascend950" | ||
| 56 | - else | ||
| 57 | - echo "$compute_unit_lower" | ||
| 58 | - fi | ||
| 59 | -} | ||
| 60 | - | ||
| 61 | -check_option_validity() { | ||
| 62 | - local arg="$1" | ||
| 63 | - | ||
| 64 | - if [[ "$arg" =~ ^-[^-] ]]; then | ||
| 65 | - local opt_chars=${arg:1} | ||
| 66 | - | ||
| 67 | - local needs_arg_opts=$(echo "$SUPPORTED_SHORT_OPTS" | grep -o "[a-zA-Z]:" | tr -d ':') | ||
| 68 | - | ||
| 69 | - local i=0 | ||
| 70 | - while [ $i -lt ${#opt_chars} ]; do | ||
| 71 | - local char="${opt_chars:$i:1}" | ||
| 72 | - | ||
| 73 | - if [[ ! "$SUPPORTED_SHORT_OPTS" =~ "$char" ]]; then | ||
| 74 | - echo "[ERROR] Invalid short option: -$char" | ||
| 75 | - return 1 | ||
| 76 | - fi | ||
| 77 | - | ||
| 78 | - if [[ "$needs_arg_opts" =~ "$char" ]]; then | ||
| 79 | - while [ $i -lt ${#opt_chars} ] && [[ "${opt_chars:$i:1}" =~ [0-9a-zA-Z] ]]; do | ||
| 80 | - i=$((i + 1)) | ||
| 81 | - done | ||
| 82 | - else | ||
| 83 | - i=$((i + 1)) | ||
| 84 | - fi | ||
| 85 | - done | ||
| 86 | - return 0 | ||
| 87 | - fi | ||
| 88 | - | ||
| 89 | - if [[ "$arg" =~ ^-- ]]; then | ||
| 90 | - local long_opt="${arg:2}" | ||
| 91 | - local opt_name="${long_opt%%=*}" | ||
| 92 | - | ||
| 93 | - for supported_opt in "${SUPPORTED_LONG_OPTS[@]}"; do | ||
| 94 | - # with "=" in long options | ||
| 95 | - if [[ "$supported_opt" =~ =$ ]]; then | ||
| 96 | - local base_opt="${supported_opt%=}" | ||
| 97 | - if [[ "$opt_name" == "$base_opt" ]]; then | ||
| 98 | - return 0 | ||
| 99 | - fi | ||
| 100 | - else | ||
| 101 | - # without "=" in long options | ||
| 102 | - if [[ "$opt_name" == "$supported_opt" ]]; then | ||
| 103 | - return 0 | ||
| 104 | - fi | ||
| 105 | - fi | ||
| 106 | - done | ||
| 107 | - | ||
| 108 | - echo "[ERROR] Invalid long option: --$opt_name" | ||
| 109 | - return 1 | ||
| 110 | - fi | ||
| 111 | - | ||
| 112 | - return 0 | ||
| 113 | -} | ||
| 114 | - | ||
| 115 | -dotted_line="----------------------------------------------------------------" | ||
| 116 | -export BASE_PATH=$( | ||
| 117 | - cd "$(dirname $0)" | ||
| 118 | - pwd | ||
| 119 | -) | ||
| 120 | -export BUILD_PATH="${BASE_PATH}/build" | ||
| 121 | -export BUILD_OUT_PATH="${BASE_PATH}/build_out" | ||
| 122 | -REPOSITORY_NAME="cv" | ||
| 123 | - | ||
| 124 | -CORE_NUMS=$(cat /proc/cpuinfo | grep "processor" | wc -l) | ||
| 125 | -ARCH_INFO=$(uname -m) | ||
| 126 | -CANN_3RD_LIB_PATH="${BASE_PATH}/third_party" | ||
| 127 | - | ||
| 128 | -if [ -z "$ASCEND_INSTALL_PATH" ]; then | ||
| 129 | - if [ -n "$ASCEND_HOME_PATH" ]; then | ||
| 130 | - ASCEND_INSTALL_PATH="$ASCEND_HOME_PATH" | ||
| 131 | - else | ||
| 132 | - ASCEND_INSTALL_PATH="/usr/local/Ascend/cann" | ||
| 133 | - fi | ||
| 134 | -fi | ||
| 135 | - | ||
| 136 | -# Base paths | ||
| 137 | -export INCLUDE_PATH="${ASCEND_HOME_PATH}/include" | ||
| 138 | -export LIB_PATH="${ASCEND_HOME_PATH}/lib64" | ||
| 139 | - | ||
| 140 | -# Include paths | ||
| 141 | -export ACLNN_INCLUDE_PATH="${INCLUDE_PATH}/aclnn" | ||
| 142 | -export GRAPH_INCLUDE_PATH="${INCLUDE_PATH}/graph" | ||
| 143 | -export CP_GRAPH_INCLUDE_PATH="${INCLUDE_PATH}/graph" | ||
| 144 | -export GE_INCLUDE_PATH="${INCLUDE_PATH}/ge" | ||
| 145 | -export CP_GE_INCLUDE_PATH="${INCLUDE_PATH}/ge" | ||
| 146 | -export CP_GE_EXTERNAL_INCLUDE_PATH="${INCLUDE_PATH}/external" | ||
| 147 | -export INC_INCLUDE_PATH="${ASCEND_OPP_PATH}/built-in/op_proto/inc" | ||
| 148 | - | ||
| 149 | -# Library paths | ||
| 150 | -export EAGER_LIBRARY_PATH="${LIB_PATH}" | ||
| 151 | -export GRAPH_LIBRARY_PATH="${LIB_PATH}" | ||
| 152 | -export CP_GRAPH_LIBRARY_PATH="${LIB_PATH}" | ||
| 153 | -export CP_EXECUTOR_LIBRARY_PATH="${LIB_PATH}" | ||
| 154 | - | ||
| 155 | -# Stub paths | ||
| 156 | -export GRAPH_LIBRARY_STUB_PATH="${LIB_PATH}/stub" | ||
| 157 | -export CP_GRAPH_LIBRARY_STUB_PATH="${LIB_PATH}/stub" | ||
| 158 | - | ||
| 159 | -# print usage message | ||
| 160 | -usage() { | ||
| 161 | - local specific_help="$1" | ||
| 162 | - | ||
| 163 | - if [[ -n "$specific_help" ]]; then | ||
| 164 | - case "$specific_help" in | ||
| 165 | - package) | ||
| 166 | - echo "Package Build Options:" | ||
| 167 | - echo $dotted_line | ||
| 168 | - echo " --pkg Build run package with kernel bin" | ||
| 169 | - echo " --pkg-type=<TYPE> Specify package type(TYPE options: run/rpm/deb/all), Default: run" | ||
| 170 | - echo " --static Build static library package" | ||
| 171 | - echo " --jit Build run package without kernel bin" | ||
| 172 | - echo " --soc=soc_version Compile for specified Ascend SoC" | ||
| 173 | - echo " --vendor_name=name Specify custom operator package vendor name" | ||
| 174 | - echo " --ops=op1,op2,... Compile specified operators (comma-separated for multiple)" | ||
| 175 | - echo " -j[n] Compile thread nums, default is 8, eg: -j8" | ||
| 176 | - echo " -O[n] Compile optimization options, support [O0 O1 O2 O3], eg:-O3" | ||
| 177 | - echo " --asan Enable ASAN (Address Sanitizer) on the host side" | ||
| 178 | - echo " --ccache=<VALUE> Enable or disable ccache (VALUE: on/off/true/false/disable), Default: on" | ||
| 179 | - echo " --build-type=<TYPE>" | ||
| 180 | - echo " Specify build type(TYPE options: Release/Debug), Default:Release" | ||
| 181 | - echo " --experimental Build experimental version" | ||
| 182 | - echo " --cann_3rd_lib_path=<PATH>" | ||
| 183 | - echo " Set ascend third_party package install path, default ./third_party" | ||
| 184 | - echo " --mssanitizer Build with mssanitizer mode on the kernel side, with options: '-g --cce-enable-sanitizer'" | ||
| 185 | - echo " --oom Build with oom mode on the kernel side, with options: '-g --cce-enable-oom'" | ||
| 186 | - echo " --dump_cce Dump kernel precompiled files" | ||
| 187 | - echo " --bisheng_flags=flag1,flag2" | ||
| 188 | - echo " Specify bisheng compiler flags (comma-separated for multiple)" | ||
| 189 | - echo " --kernel_template_input=args0,args1" | ||
| 190 | - echo " Specify kernel template input arguments(comma-separated for multiple)" | ||
| 191 | - echo $dotted_line | ||
| 192 | - echo "Examples:" | ||
| 193 | - echo " bash build.sh --pkg --soc=ascend910b --vendor_name=customize -j16 -O3" | ||
| 194 | - echo " bash build.sh --pkg --pkg-type=deb --soc=ascend910b" | ||
| 195 | - echo " bash build.sh --pkg --pkg-type=rpm --soc=ascend910b" | ||
| 196 | - echo " bash build.sh --pkg --ops=add,sub --build-type=Debug" | ||
| 197 | - echo " bash build.sh --pkg --static --soc=ascend910b" | ||
| 198 | - echo " bash build.sh --pkg --ops=add,sub --debug" | ||
| 199 | - echo " bash build.sh --pkg --experimental --soc=ascend910b" | ||
| 200 | - echo " bash build.sh --pkg --experimental --soc=ascend910b --ops=add --mssanitizer" | ||
| 201 | - echo " bash build.sh --pkg --experimental --soc=ascend910b --ops=add --oom" | ||
| 202 | - echo " bash build.sh --pkg --experimental --soc=ascend910b --ops=add --dump_cce" | ||
| 203 | - echo " bash build.sh --pkg --experimental --soc=ascend910b --ops=add --bisheng_flags=ccec_g,oom" | ||
| 204 | - echo " bash build.sh --pkg --experimental --soc=ascend950 --ops=abs --kernel_template_input=0,1" | ||
| 205 | - return | ||
| 206 | - ;; | ||
| 207 | - opkernel) | ||
| 208 | - echo "Opkernel Build Options:" | ||
| 209 | - echo $dotted_line | ||
| 210 | - echo " --opkernel Build binary kernel" | ||
| 211 | - echo " --soc=soc_version Compile for specified Ascend SoC" | ||
| 212 | - echo " --ops=op1,op2,... Compile specified operators (comma-separated for multiple)" | ||
| 213 | - echo " --build-type=<Type> Specify build-type (Type options: Release/Debug), Default:Release" | ||
| 214 | - echo " --ccache=<VALUE> Enable or disable ccache (VALUE: on/off/true/false/disable), Default: on" | ||
| 215 | - echo " --mssanitizer Build with mssanitizer mode on the kernel side, with options: '-g --cce-enable-sanitizer'" | ||
| 216 | - echo " --oom Build with oom mode on the kernel side, with options: '-g --cce-enable-oom'" | ||
| 217 | - echo " --dump_cce Dump kernel precompiled files" | ||
| 218 | - echo " --bisheng_flags=flag1,flag2" | ||
| 219 | - echo " Specify bisheng compiler config (comma-separated for multiple)" | ||
| 220 | - echo " --kernel_template_input=args0,args1" | ||
| 221 | - echo " Specify kernel template input arguments(comma-separated for multiple)" | ||
| 222 | - echo $dotted_line | ||
| 223 | - echo "Examples:" | ||
| 224 | - echo " bash build.sh --opkernel --soc=ascend310p --ops=grid_sample" | ||
| 225 | - echo " bash build.sh --opkernel --soc=ascend310p --ops=grid_sample --build-type=Debug" | ||
| 226 | - echo " bash build.sh --opkernel --soc=ascend310p --ops=grid_sample --mssanitizer" | ||
| 227 | - echo " bash build.sh --opkernel --soc=ascend310p --ops=grid_sample --oom" | ||
| 228 | - echo " bash build.sh --opkernel --soc=ascend310p --ops=grid_sample --dump_cce" | ||
| 229 | - echo " bash build.sh --opkernel --soc=ascend310p --ops=grid_sample --bisheng_flags=ccec_g,oom" | ||
| 230 | - echo " bash build.sh --opkernel --soc=ascend950 --ops=abs --kernel_template_input=0,1" | ||
| 231 | - return | ||
| 232 | - ;; | ||
| 233 | - opkernel_aicpu) | ||
| 234 | - echo "AICPU Opkernel Build Options:" | ||
| 235 | - echo $dotted_line | ||
| 236 | - echo " --opkernel_aicpu Build AICPU kernel" | ||
| 237 | - echo " --soc=soc_version Compile for specified Ascend SoC" | ||
| 238 | - echo " --ops=op1,op2,... Compile specified operators (comma-separated for multiple)" | ||
| 239 | - echo " --build-type=<Type> Specify build-type (Type options: Release/Debug), Default:Release" | ||
| 240 | - echo " --ccache=<VALUE> Enable or disable ccache (VALUE: on/off/true/false/disable), Default: on" | ||
| 241 | - echo " --mssanitizer Build with mssanitizer mode on the kernel side, with options: '-g --cce-enable-sanitizer'" | ||
| 242 | - echo " --oom Build with oom mode on the kernel side, with options: '-g --cce-enable-oom'" | ||
| 243 | - echo " --dump_cce Dump kernel precompiled files" | ||
| 244 | - echo " --bisheng_flags=flag1,flag2" | ||
| 245 | - echo " Specify bisheng compiler flags (comma-separated for multiple)" | ||
| 246 | - echo " --kernel_template_input=args0,args1" | ||
| 247 | - echo " Specify kernel template input arguments(comma-separated for multiple)" | ||
| 248 | - echo $dotted_line | ||
| 249 | - echo "Examples:" | ||
| 250 | - echo " bash build.sh --opkernel_aicpu --soc=ascend910b --ops=crop_and_resize" | ||
| 251 | - echo " bash build.sh --opkernel_aicpu --soc=ascend910b --ops=crop_and_resize --build-type=Debug" | ||
| 252 | - echo " bash build.sh --opkernel_aicpu --soc=ascend910b --ops=crop_and_resize --mssanitizer" | ||
| 253 | - echo " bash build.sh --opkernel_aicpu --soc=ascend910b --ops=crop_and_resize --oom" | ||
| 254 | - echo " bash build.sh --opkernel_aicpu --soc=ascend910b --ops=crop_and_resize --dump_cce" | ||
| 255 | - echo " bash build.sh --opkernel_aicpu --soc=ascend910b --ops=crop_and_resize --bisheng_flags=ccec_g,oom" | ||
| 256 | - return | ||
| 257 | - ;; | ||
| 258 | - test) | ||
| 259 | - echo "Test Options:" | ||
| 260 | - echo $dotted_line | ||
| 261 | - echo " -u Build and run all unit tests" | ||
| 262 | - echo " --noexec Only compile ut, do not execute" | ||
| 263 | - echo " --cov Enable code coverage for unit tests" | ||
| 264 | - echo " --ccache=<VALUE> Enable or disable ccache (VALUE: on/off/true/false/disable), Default: on" | ||
| 265 | - echo " --soc=soc_version Run unit tests for specified Ascend SoC" | ||
| 266 | - echo " --ophost_test Build and run ophost unit tests" | ||
| 267 | - echo " --opapi_test Build and run opapi unit tests" | ||
| 268 | - echo " --opgraph_test Build and run opgraph unit tests" | ||
| 269 | - echo " --ophost -u Same as --ophost_test" | ||
| 270 | - echo " --opapi -u Same as --opapi_test" | ||
| 271 | - echo " --opgraph -u Same as --opgraph_test" | ||
| 272 | - echo $dotted_line | ||
| 273 | - echo "Examples:" | ||
| 274 | - echo " bash build.sh -u --noexec --cov" | ||
| 275 | - echo " bash build.sh -u --ophost --soc=ascend910b --ops=grid_sample" | ||
| 276 | - echo " bash build.sh --ophost_test --opapi_test --noexec" | ||
| 277 | - echo " bash build.sh --ophost --opapi --opgraph -u --cov" | ||
| 278 | - return | ||
| 279 | - ;; | ||
| 280 | - clean) | ||
| 281 | - echo "Clean Options:" | ||
| 282 | - echo $dotted_line | ||
| 283 | - echo " --make_clean Clean build artifacts" | ||
| 284 | - echo $dotted_line | ||
| 285 | - return | ||
| 286 | - ;; | ||
| 287 | - valgrind) | ||
| 288 | - echo "Valgrind Options:" | ||
| 289 | - echo $dotted_line | ||
| 290 | - echo " --valgrind Run unit tests with valgrind (disables ASAN and noexec)" | ||
| 291 | - echo $dotted_line | ||
| 292 | - return | ||
| 293 | - ;; | ||
| 294 | - ophost) | ||
| 295 | - echo "Ophost Build Options:" | ||
| 296 | - echo $dotted_line | ||
| 297 | - echo " --ophost Build ophost library" | ||
| 298 | - echo " -j[n] Compile thread nums, default is 8, eg: -j8" | ||
| 299 | - echo " -O[n] Compile optimization options, support [O0 O1 O2 O3], eg:-O3" | ||
| 300 | - echo " --build-type=<TYPE>" | ||
| 301 | - echo " Specify build type(TYPE options: Release/Debug), Default:Release" | ||
| 302 | - echo " --ccache=<VALUE> Enable or disable ccache (VALUE: on/off/true/false/disable), Default: on" | ||
| 303 | - echo $dotted_line | ||
| 304 | - echo "Examples:" | ||
| 305 | - echo " bash build.sh --ophost -j16 -O3" | ||
| 306 | - echo " bash build.sh --ophost --build-type=Debug" | ||
| 307 | - return | ||
| 308 | - ;; | ||
| 309 | - opapi) | ||
| 310 | - echo "Opapi Build Options:" | ||
| 311 | - echo $dotted_line | ||
| 312 | - echo " --opapi Build opapi library" | ||
| 313 | - echo " -j[n] Compile thread nums, default is 8, eg: -j8" | ||
| 314 | - echo " -O[n] Compile optimization options, support [O0 O1 O2 O3], eg:-O3" | ||
| 315 | - echo " --build-type=<TYPE>" | ||
| 316 | - echo " Specify build type(TYPE options: Release/Debug), Default:Release" | ||
| 317 | - echo " --ccache=<VALUE> Enable or disable ccache (VALUE: on/off/true/false/disable), Default: on" | ||
| 318 | - echo $dotted_line | ||
| 319 | - echo "Examples:" | ||
| 320 | - echo " bash build.sh --opapi -j16 -O3" | ||
| 321 | - echo " bash build.sh --opapi --build-type=Debug" | ||
| 322 | - return | ||
| 323 | - ;; | ||
| 324 | - opgraph) | ||
| 325 | - echo "Opgraph Build Options:" | ||
| 326 | - echo $dotted_line | ||
| 327 | - echo " --opgraph Build opgraph library" | ||
| 328 | - echo " -j[n] Compile thread nums, default is 8, eg: -j8" | ||
| 329 | - echo " -O[n] Compile optimization options, support [O0 O1 O2 O3], eg:-O3" | ||
| 330 | - echo " --build-type=<TYPE>" | ||
| 331 | - echo " Specify build type(TYPE options: Release/Debug), Default:Release" | ||
| 332 | - echo " --ccache=<VALUE> Enable or disable ccache (VALUE: on/off/true/false/disable), Default: on" | ||
| 333 | - echo $dotted_line | ||
| 334 | - echo "Examples:" | ||
| 335 | - echo " bash build.sh --opgraph -j16 -O3" | ||
| 336 | - echo " bash build.sh --opgraph --build-type=Debug" | ||
| 337 | - return | ||
| 338 | - ;; | ||
| 339 | - onnxplugin) | ||
| 340 | - echo "ONNXPlugin Build Options:" | ||
| 341 | - echo $dotted_line | ||
| 342 | - echo " --onnxplugin Build onnxplugin library" | ||
| 343 | - echo " -j[n] Compile thread nums, default is 8, eg: -j8" | ||
| 344 | - echo " -O[n] Compile optimization options, support [O0 O1 O2 O3], eg:-O3" | ||
| 345 | - echo " --debug Build with debug mode" | ||
| 346 | - echo " --ccache=<VALUE> Enable or disable ccache (VALUE: on/off/true/false/disable), Default: on" | ||
| 347 | - echo $dotted_line | ||
| 348 | - echo "Examples:" | ||
| 349 | - echo " bash build.sh --onnxplugin -j16 -O3" | ||
| 350 | - echo " bash build.sh --onnxplugin --debug" | ||
| 351 | - return | ||
| 352 | - ;; | ||
| 353 | - ophost_test) | ||
| 354 | - echo "Ophost Test Options:" | ||
| 355 | - echo $dotted_line | ||
| 356 | - echo " --ophost_test Build and run ophost unit tests" | ||
| 357 | - echo " --noexec Only compile ut, do not execute" | ||
| 358 | - echo " --cov Enable code coverage for unit tests" | ||
| 359 | - echo $dotted_line | ||
| 360 | - echo "Examples:" | ||
| 361 | - echo " bash build.sh --ophost_test --noexec --cov" | ||
| 362 | - return | ||
| 363 | - ;; | ||
| 364 | - opapi_test) | ||
| 365 | - echo "Opapi Test Options:" | ||
| 366 | - echo $dotted_line | ||
| 367 | - echo " --opapi_test Build and run opapi unit tests" | ||
| 368 | - echo " --noexec Only compile ut, do not execute" | ||
| 369 | - echo " --cov Enable code coverage for unit tests" | ||
| 370 | - echo $dotted_line | ||
| 371 | - echo "Examples:" | ||
| 372 | - echo " bash build.sh --opapi_test --noexec --cov" | ||
| 373 | - return | ||
| 374 | - ;; | ||
| 375 | - opgraph_test) | ||
| 376 | - echo "Opgraph Test Options:" | ||
| 377 | - echo $dotted_line | ||
| 378 | - echo " --opgraph_test Build and run opgraph unit tests" | ||
| 379 | - echo " --noexec Only compile ut, do not execute" | ||
| 380 | - echo " --cov Enable code coverage for unit tests" | ||
| 381 | - echo $dotted_line | ||
| 382 | - echo "Examples:" | ||
| 383 | - echo " bash build.sh --opgraph_test --noexec --cov" | ||
| 384 | - return | ||
| 385 | - ;; | ||
| 386 | - run_example) | ||
| 387 | - echo "Run examples Options:" | ||
| 388 | - echo $dotted_line | ||
| 389 | - echo " --run_example op_type mode[eager:graph] [pkg_mode --vendor_name=name] Compile and execute the test_aclnn_xxx.cpp/test_geir_xxx.cpp" | ||
| 390 | - echo " --simulator Enable simulator mode when running aclnn examples" | ||
| 391 | - echo $dotted_line | ||
| 392 | - echo "Examples:" | ||
| 393 | - echo " bash build.sh --run_example abs eager" | ||
| 394 | - echo " bash build.sh --run_example abs graph" | ||
| 395 | - echo " bash build.sh --run_example abs eager cust" | ||
| 396 | - echo " bash build.sh --run_example abs eager cust --vendor_name=custom" | ||
| 397 | - echo " bash build.sh --run_example abs eager --simulator --soc=ascend950" | ||
| 398 | - return | ||
| 399 | - ;; | ||
| 400 | - genop) | ||
| 401 | - echo "Gen Op Directory Options:" | ||
| 402 | - echo $dotted_line | ||
| 403 | - echo " --genop=op_class/op_name Create the initial directory for op_name undef op_class" | ||
| 404 | - echo $dotted_line | ||
| 405 | - echo "Examples:" | ||
| 406 | - echo " bash build.sh --genop=examples/add" | ||
| 407 | - return | ||
| 408 | - ;; | ||
| 409 | - genop_aicpu) | ||
| 410 | - echo "Gen Op Directory Options:" | ||
| 411 | - echo $dotted_line | ||
| 412 | - echo " --genop_aicpu=op_class/op_name Create the initial directory for op_name undef op_class" | ||
| 413 | - echo $dotted_line | ||
| 414 | - echo "Examples:" | ||
| 415 | - echo " bash build.sh --genop_aicpu=examples/add" | ||
| 416 | - return | ||
| 417 | - ;; | ||
| 418 | - esac | ||
| 419 | - fi | ||
| 420 | - | ||
| 421 | - echo "build script for ops-cv repository" | ||
| 422 | - echo "Usage:" | ||
| 423 | - echo " bash build.sh [-h] [-j[n]] [-v] [-O[n]] [-u] " | ||
| 424 | - echo "" | ||
| 425 | - echo "" | ||
| 426 | - echo "Options:" | ||
| 427 | - echo $dotted_line | ||
| 428 | - echo " Build parameters " | ||
| 429 | - echo $dotted_line | ||
| 430 | - echo " -h Print usage" | ||
| 431 | - echo " -j[n] Compile thread nums, default is 8, eg: -j8" | ||
| 432 | - echo " -v Cmake compile verbose" | ||
| 433 | - echo " -O[n] Compile optimization options, support [O0 O1 O2 O3], eg:-O3" | ||
| 434 | - echo " -u Compile all ut" | ||
| 435 | - echo $dotted_line | ||
| 436 | - echo " examples, Build ophost_test with O3 level compilation optimization and do not execute." | ||
| 437 | - echo " ./build.sh --ophost_test --noexec -O3" | ||
| 438 | - echo $dotted_line | ||
| 439 | - echo " The following are all supported arguments:" | ||
| 440 | - echo $dotted_line | ||
| 441 | - echo " --build-type Specify build type(TYPE options: Release/Debug), Default:Release" | ||
| 442 | - echo " --cov When building uTest locally, count the coverage." | ||
| 443 | - echo " --noexec Only compile ut, do not execute the compiled executable file" | ||
| 444 | - echo " --make_clean make clean" | ||
| 445 | - echo " --asan enable asan with pkg on the host side" | ||
| 446 | - echo " --valgrind run ut with valgrind. This option will disable asan, noexec and run utest by valgrind" | ||
| 447 | - echo " --ccache=<VALUE> Enable or disable ccache compilation acceleration" | ||
| 448 | - echo " VALUE options: on/off/true/false/disable, Default: on" | ||
| 449 | - echo " Example: --ccache=off to disable ccache" | ||
| 450 | - echo " --ops Compile specified operator, use snake name, like: --ops=grid_sample,iou_v2, use ',' to separate different operator" | ||
| 451 | - echo " --soc Compile binary with specified Ascend SoC, like: --soc=ascend910b" | ||
| 452 | - echo " --soc supported parameters must only in [ascend031 ascend035 ascend310b ascend310p ascend610lite ascend630 ascend910_93 ascend950 ascend910b ascend910 mc62 kirinx90 kirin9030], A3(--soc=ascend910_93)" | ||
| 453 | - echo " --vendor_name Specify the custom operator package vendor name, like: --vendor_name=customize, default to customize-cv" | ||
| 454 | - echo " --aicpu build aicpu task" | ||
| 455 | - echo " --opgraph build op_graph_cv.so" | ||
| 456 | - echo " --onnxplugin build oponnx_plugin_cv.so" | ||
| 457 | - echo " --opapi build opapi_cv.so" | ||
| 458 | - echo " --ophost build ophost_cv.so" | ||
| 459 | - echo " --opkernel build binary kernel" | ||
| 460 | - echo " --opkernel_aicpu build aicpu kernel" | ||
| 461 | - echo " --jit build run package without kernel bin" | ||
| 462 | - echo " --pkg build run package with kernel bin" | ||
| 463 | - echo " --pkg-type=<TYPE> Specify package type(TYPE options: run/rpm/deb/all), Default: run" | ||
| 464 | - echo " --static build static library package" | ||
| 465 | - echo " --experimental Build experimental version" | ||
| 466 | - echo " --opapi_test build and run opapi unit tests" | ||
| 467 | - echo " --ophost_test build and run ophost unit tests" | ||
| 468 | - echo " --opgraph_test build and run opgraph unit tests" | ||
| 469 | - echo " --opkernel_test build and run opkernel unit tests" | ||
| 470 | - echo " --opkernel_aicpu_test build and run aicpu opkernel unit tests" | ||
| 471 | - echo " --run_example Compile and execute the test_aclnn_xxx.cpp/test_geir_xxx.cpp" | ||
| 472 | - echo " --simulator Enable simulator mode for run_example (requires --soc parameter)" | ||
| 473 | - echo " --genop Create the initial directory for op" | ||
| 474 | - echo " --genop_aicpu Create the initial directory for AI CPU op" | ||
| 475 | - echo " --mssanitizer Build with mssanitizer mode on the kernel side, with options: '-g --cce-enable-sanitizer'" | ||
| 476 | - echo " --oom Build with oom mode on the kernel side, with options: '-g --cce-enable-oom'" | ||
| 477 | - echo " --dump_cce Dump kernel precompiled files" | ||
| 478 | - echo " --bisheng_flags Specify bisheng compiler config, like: --bisheng_flags=ccec_g,oom, use ',' to separate different compiler flags" | ||
| 479 | - echo " --kernel_template_input Specify kernel template input arguments, like: --kernel_template_input=0,1, use ',' to separate different kernel template args" | ||
| 480 | - echo "to be continued ..." | ||
| 481 | -} | ||
| 482 | - | ||
| 483 | -check_help_combinations() { | ||
| 484 | - local args=("$@") | ||
| 485 | - local has_u=false | ||
| 486 | - local has_test_command=false | ||
| 487 | - local has_build_command=false | ||
| 488 | - local has_package=false | ||
| 489 | - local has_opkernel=false | ||
| 490 | - local has_opkernel_aicpu=false | ||
| 491 | - | ||
| 492 | - for arg in "${args[@]}"; do | ||
| 493 | - case "$arg" in | ||
| 494 | - -u) has_u=true ;; | ||
| 495 | - --ophost_test | --opapi_test | --opgraph_test | --ophost | --opapi | --opgraph | --onnxplugin) | ||
| 496 | - has_test_command=true | ||
| 497 | - has_build_command=true | ||
| 498 | - ;; | ||
| 499 | - --pkg) has_package=true ;; | ||
| 500 | - --opkernel) has_opkernel=true ;; | ||
| 501 | - --opkernel_aicpu) has_opkernel_aicpu=true ;; | ||
| 502 | - --help | -h) ;; | ||
| 503 | - esac | ||
| 504 | - done | ||
| 505 | - | ||
| 506 | - # Check the invalid command combinations in help | ||
| 507 | - if [[ "$has_package" == "true" && ("$has_test_command" == "true" || "$has_u" == "true") ]]; then | ||
| 508 | - echo "[ERROR] --pkg cannot be used with test(-u, --ophost_test, etc.), --ophost, --opapi, or --opgraph" | ||
| 509 | - return 1 | ||
| 510 | - fi | ||
| 511 | - | ||
| 512 | - if [[ "$has_opkernel" == "true" && ("$has_test_command" == "true" || "$has_u" == "true") ]]; then | ||
| 513 | - echo "[ERROR] --opkernel cannot be used with test(-u, --ophost_test, etc.), --ophost, --opapi, or --opgraph" | ||
| 514 | - return 1 | ||
| 515 | - fi | ||
| 516 | - | ||
| 517 | - if [[ "$has_opkernel_aicpu" == "true" && ("$has_test_command" == "true" || "$has_u" == "true") ]]; then | ||
| 518 | - echo "[ERROR] --opkernel_aicpu cannot be used with test(-u, --ophost_test, etc.), --ophost, --opapi, or --opgraph" | ||
| 519 | - return 1 | ||
| 520 | - fi | ||
| 521 | - | ||
| 522 | - return 0 | ||
| 523 | -} | ||
| 524 | - | ||
| 525 | -check_param() { | ||
| 526 | - if [[ "$ENABLE_RUN_EXAMPLE" == "TRUE" ]]; then | ||
| 527 | - ENABLE_CUSTOM=FALSE | ||
| 528 | - fi | ||
| 529 | - # --ops不能与--ophost,--opapi,--opgraph同时存在,如果带U则可以 | ||
| 530 | - if [[ -n "$COMPILED_OPS" && "$ENABLE_TEST" == "FALSE" ]] && [[ "$OP_HOST" == "TRUE" || "$OP_API" == "TRUE" || "$OP_GRAPH" == "TRUE" ]]; then | ||
| 531 | - echo "[ERROR] --ops cannot be used with --ophost, --opapi, or --opgraph" | ||
| 532 | - exit 1 | ||
| 533 | - fi | ||
| 534 | - | ||
| 535 | - # -pkg不能与-u(UT模式,包含_test的参数)或者--ophost,--opapi,--opgraph同时存在 | ||
| 536 | - if [[ "$ENABLE_PACKAGE" == "TRUE" ]]; then | ||
| 537 | - if [[ "$ENABLE_TEST" == "TRUE" ]]; then | ||
| 538 | - echo "[ERROR] --pkg cannot be used with test(-u, --ophost_test, etc.)" | ||
| 539 | - exit 1 | ||
| 540 | - fi | ||
| 541 | - | ||
| 542 | - if [[ "$OP_HOST" == "TRUE" || "$OP_API" == "TRUE" || "$OP_GRAPH" == "TRUE" ]]; then | ||
| 543 | - echo "[ERROR] --pkg cannot be used with --ophost, --opapi, --opgraph" | ||
| 544 | - exit 1 | ||
| 545 | - fi | ||
| 546 | - | ||
| 547 | - if [[ "$ENABLE_GENOP" == "TRUE" ]]; then | ||
| 548 | - echo "[ERROR] --pkg cannot be used with --genop" | ||
| 549 | - exit 1 | ||
| 550 | - fi | ||
| 551 | - | ||
| 552 | - if [[ "$ENABLE_GENOP_AICPU" == "TRUE" ]]; then | ||
| 553 | - echo "[ERROR] --pkg cannot be used with --genop_aicpu" | ||
| 554 | - exit 1 | ||
| 555 | - fi | ||
| 556 | - | ||
| 557 | - if [[ -n "${BUILD_TYPE}" ]]; then | ||
| 558 | - if [[ "${BUILD_TYPE}" != "Release" && "${BUILD_TYPE}" != "Debug" ]]; then | ||
| 559 | - echo "[ERROR] --build-type only support Release/Debug Mode" | ||
| 560 | - exit 1 | ||
| 561 | - fi | ||
| 562 | - fi | ||
| 563 | - if [[ "${BUILD_TYPE}" == "Debug" ]]; then | ||
| 564 | - if [[ "$ENABLE_MSSANITIZER" == "TRUE" || "$ENABLE_OOM" == "TRUE" || "$ENABLE_DUMP_CCE" == "TRUE" ]]; then | ||
| 565 | - echo "[ERROR] --build-type=Debug cannot be used with --mssanitizer, --oom or --dump_cce" | ||
| 566 | - exit 1 | ||
| 567 | - fi | ||
| 568 | - fi | ||
| 569 | - | ||
| 570 | - if [[ "$ENABLE_MSSANITIZER" == "TRUE" && "$ENABLE_OOM" == "TRUE" ]]; then | ||
| 571 | - echo "[ERROR] --mssanitizer cannot be used with --oom" | ||
| 572 | - exit 1 | ||
| 573 | - fi | ||
| 574 | - | ||
| 575 | - if [ -n "$BISHENG_FLAGS" ]; then | ||
| 576 | - if [[ "$ENABLE_MSSANITIZER" == "TRUE" || "$ENABLE_OOM" == "TRUE" || "$ENABLE_DUMP_CCE" == "TRUE" ]]; then | ||
| 577 | - echo "[ERROR] --bisheng_flags= cannot be used with --mssanitizer, --oom, --dump_cce" | ||
| 578 | - exit 1 | ||
| 579 | - fi | ||
| 580 | - fi | ||
| 581 | - | ||
| 582 | - if [ -n "$KERNEL_TEMPLATE_INPUT" ]; then | ||
| 583 | - if [[ -z "${COMPILED_OPS}" || "$COMPILED_OPS" == *","* ]]; then | ||
| 584 | - echo "[ERROR] --kernel_template_input must be used with --ops= and can only specify a single operator" | ||
| 585 | - exit 1 | ||
| 586 | - fi | ||
| 587 | - fi | ||
| 588 | - fi | ||
| 589 | - | ||
| 590 | - if [[ "$PACKAGE_TYPE_SET" == "TRUE" && "$ENABLE_PACKAGE" != "TRUE" ]]; then | ||
| 591 | - echo "[ERROR] --pkg-type can only be used with --pkg" | ||
| 592 | - exit 1 | ||
| 593 | - fi | ||
| 594 | - | ||
| 595 | - if [[ "$PACKAGE_TYPE" != "run" ]]; then | ||
| 596 | - if [[ "$ENABLE_STATIC" == "TRUE" ]]; then | ||
| 597 | - echo "[ERROR] --pkg-type=${PACKAGE_TYPE} cannot be used with --static" | ||
| 598 | - exit 1 | ||
| 599 | - fi | ||
| 600 | - if [[ "$ENABLE_JIT" == "TRUE" ]]; then | ||
| 601 | - echo "[ERROR] --pkg-type=${PACKAGE_TYPE} cannot be used with --jit" | ||
| 602 | - exit 1 | ||
| 603 | - fi | ||
| 604 | - if [[ "$ENABLE_CUSTOM" == "TRUE" ]]; then | ||
| 605 | - echo "[ERROR] --pkg-type=${PACKAGE_TYPE} only supports built-in ops-cv packages; do not use --ops, --vendor_name, or --experimental" | ||
| 606 | - exit 1 | ||
| 607 | - fi | ||
| 608 | - fi | ||
| 609 | - | ||
| 610 | - if $(echo ${USE_CMD} | grep -wq "static") && [[ "$ENABLE_PACKAGE" != "TRUE" ]]; then | ||
| 611 | - echo "[ERROR] --static can only be used with --pkg" | ||
| 612 | - exit 1 | ||
| 613 | - fi | ||
| 614 | - | ||
| 615 | - if [[ "$ENABLE_STATIC" == "TRUE" && "$ENABLE_JIT" == "TRUE" && "$ENABLE_CUSTOM" == "TRUE" ]]; then | ||
| 616 | - echo "[ERROR] --static with --jit cannot be used with --ops, --vendor_name, or --experimental" | ||
| 617 | - exit 1 | ||
| 618 | - fi | ||
| 619 | - | ||
| 620 | - if $(echo ${USE_CMD} | grep -wq "opkernel") && $(echo ${USE_CMD} | grep -wq "jit"); then | ||
| 621 | - echo "[ERROR] --opkernel cannot be used with --jit" | ||
| 622 | - exit 1 | ||
| 623 | - fi | ||
| 624 | - | ||
| 625 | - if $(echo ${USE_CMD} | grep -wq "opkernel_aicpu") && $(echo ${USE_CMD} | grep -wq "jit"); then | ||
| 626 | - echo "[ERROR] --opkernel_aicpu cannot be used with --jit" | ||
| 627 | - exit 1 | ||
| 628 | - fi | ||
| 629 | - | ||
| 630 | - if [[ "$ENABLE_SIMULATOR" == "TRUE" && -z "$COMPUTE_UNIT" ]]; then | ||
| 631 | - echo "[ERROR] --simulator requires --soc parameter to be specified" | ||
| 632 | - exit 1 | ||
| 633 | - fi | ||
| 634 | - | ||
| 635 | - if [[ "$ENABLE_SIMULATOR" == "TRUE" && "$EXAMPLE_MODE" == "graph" ]]; then | ||
| 636 | - echo "[ERROR] --simulator does not support graph mode. Please use eager mode instead." | ||
| 637 | - exit 1 | ||
| 638 | - fi | ||
| 639 | -} | ||
| 640 | - | ||
| 641 | -set_create_libs() { | ||
| 642 | - if [[ "$ENABLE_TEST" == "TRUE" ]]; then | ||
| 643 | - return | ||
| 644 | - fi | ||
| 645 | - if [[ "$ENABLE_PACKAGE" == "TRUE" && "$ENABLE_CUSTOM" != "TRUE" ]]; then | ||
| 646 | - BUILD_LIBS=("ophost_${REPOSITORY_NAME}" "opapi_${REPOSITORY_NAME}" "opgraph_${REPOSITORY_NAME}" "oponnx_plugin_${REPOSITORY_NAME}") | ||
| 647 | - ENABLE_CREATE_LIB=TRUE | ||
| 648 | - else | ||
| 649 | - if [[ "$OP_HOST" == "TRUE" ]]; then | ||
| 650 | - BUILD_LIBS+=("ophost_${REPOSITORY_NAME}") | ||
| 651 | - ENABLE_CREATE_LIB=TRUE | ||
| 652 | - fi | ||
| 653 | - if [[ "$OP_API" == "TRUE" ]]; then | ||
| 654 | - BUILD_LIBS+=("opapi_${REPOSITORY_NAME}") | ||
| 655 | - ENABLE_CREATE_LIB=TRUE | ||
| 656 | - fi | ||
| 657 | - if [[ "$OP_GRAPH" == "TRUE" ]]; then | ||
| 658 | - BUILD_LIBS+=("opgraph_${REPOSITORY_NAME}") | ||
| 659 | - ENABLE_CREATE_LIB=TRUE | ||
| 660 | - fi | ||
| 661 | - if [[ "$ONNX_PLUGIN" == "TRUE" ]]; then | ||
| 662 | - BUILD_LIBS+=("oponnx_plugin_${REPOSITORY_NAME}") | ||
| 663 | - ENABLE_CREATE_LIB=TRUE | ||
| 664 | - fi | ||
| 665 | - if [[ "$OP_KERNEL" == "TRUE" ]]; then | ||
| 666 | - ENABLE_BINARY=TRUE | ||
| 667 | - fi | ||
| 668 | - fi | ||
| 669 | -} | ||
| 670 | - | ||
| 671 | -set_ut_mode() { | ||
| 672 | - if [[ "$ENABLE_TEST" != "TRUE" ]]; then | ||
| 673 | - return | ||
| 674 | - fi | ||
| 675 | - UT_TEST_ALL=TRUE | ||
| 676 | - if [[ "$OP_HOST" == "TRUE" ]]; then | ||
| 677 | - OP_HOST_UT=TRUE | ||
| 678 | - UT_TEST_ALL=FALSE | ||
| 679 | - fi | ||
| 680 | - if [[ "$OP_API" == "TRUE" ]]; then | ||
| 681 | - OP_API_UT=TRUE | ||
| 682 | - UT_TEST_ALL=FALSE | ||
| 683 | - fi | ||
| 684 | - if [[ "$OP_GRAPH" == "TRUE" ]]; then | ||
| 685 | - OP_GRAPH_UT=TRUE | ||
| 686 | - UT_TEST_ALL=FALSE | ||
| 687 | - fi | ||
| 688 | - if [[ "$OP_KERNEL" == "TRUE" ]]; then | ||
| 689 | - OP_KERNEL_UT=TRUE | ||
| 690 | - UT_TEST_ALL=FALSE | ||
| 691 | - fi | ||
| 692 | - if [[ "$OP_KERNEL_AICPU" == "TRUE" ]]; then | ||
| 693 | - OP_KERNEL_AICPU_UT=TRUE | ||
| 694 | - UT_TEST_ALL=FALSE | ||
| 695 | - fi | ||
| 696 | - | ||
| 697 | - # 检查测试项,至少有一个 | ||
| 698 | - if [[ "$UT_TEST_ALL" == "FALSE" && "$OP_HOST_UT" == "FALSE" && "$OP_API_UT" == "FALSE" && "$OP_GRAPH_UT" == "FALSE" && "$OP_KERNEL_UT" == "FALSE" && "$OP_KERNEL_AICPU_UT" == "FALSE" ]]; then | ||
| 699 | - echo "[ERROR] At least one test target must be specified (ophost_test, opapi_test, opgraph_test, opkernel_test, opkernel_aicpu_test)" | ||
| 700 | - usage | ||
| 701 | - exit 1 | ||
| 702 | - fi | ||
| 703 | - | ||
| 704 | - if [[ "$UT_TEST_ALL" == "TRUE" ]] || [[ "$OP_HOST_UT" == "TRUE" ]]; then | ||
| 705 | - UT_TARGETS+=("${REPOSITORY_NAME}_op_host_ut") | ||
| 706 | - fi | ||
| 707 | - if [[ "$UT_TEST_ALL" == "TRUE" ]] || [[ "$OP_API_UT" == "TRUE" ]]; then | ||
| 708 | - UT_TARGETS+=("${REPOSITORY_NAME}_op_api_ut") | ||
| 709 | - fi | ||
| 710 | - if [[ "$UT_TEST_ALL" == "TRUE" ]] || [[ "$OP_KERNEL_UT" == "TRUE" ]]; then | ||
| 711 | - UT_TARGETS+=("${REPOSITORY_NAME}_op_kernel_ut") | ||
| 712 | - fi | ||
| 713 | - if [[ "$UT_TEST_ALL" == "TRUE" ]] || [[ "$OP_KERNEL_AICPU_UT" == "TRUE" ]]; then | ||
| 714 | - UT_TARGETS+=("${REPOSITORY_NAME}_aicpu_op_kernel_ut") | ||
| 715 | - fi | ||
| 716 | -} | ||
| 717 | - | ||
| 718 | -print_error() { | ||
| 719 | - echo | ||
| 720 | - echo $dotted_line | ||
| 721 | - local msg="$1" | ||
| 722 | - echo -e "${COLOR_RED}[ERROR] ${msg}${COLOR_RESET}" | ||
| 723 | - echo $dotted_line | ||
| 724 | - echo | ||
| 725 | -} | ||
| 726 | - | ||
| 727 | -checkopts_run_example() { | ||
| 728 | - ENABLE_RUN_EXAMPLE=TRUE | ||
| 729 | - EXAMPLE_NAME="${!OPTIND}" | ||
| 730 | - ((OPTIND++)) | ||
| 731 | - if [[ $OPTIND -le $# ]] && [[ "${!OPTIND}" != --* ]]; then | ||
| 732 | - EXAMPLE_MODE="${!OPTIND}" | ||
| 733 | - ((OPTIND++)) | ||
| 734 | - fi | ||
| 735 | - | ||
| 736 | - if [[ $OPTIND -le $# ]] && [[ "${!OPTIND}" != --* ]]; then | ||
| 737 | - PKG_MODE="${!OPTIND}" | ||
| 738 | - ((OPTIND++)) | ||
| 739 | - if [[ $OPTIND -le $# ]] && [[ "${!OPTIND}" == --vendor_name* ]]; then | ||
| 740 | - VENDOR="${!OPTIND}" | ||
| 741 | - VENDOR="${VENDOR#*=}" | ||
| 742 | - ((OPTIND++)) | ||
| 743 | - else | ||
| 744 | - VENDOR="custom" | ||
| 745 | - fi | ||
| 746 | - fi | ||
| 747 | -} | ||
| 748 | - | ||
| 749 | -checkopts() { | ||
| 750 | - THREAD_NUM=${CORE_NUMS} | ||
| 751 | - THREAD_NUM=8 | ||
| 752 | - VERBOSE="" | ||
| 753 | - BUILD_MODE="" | ||
| 754 | - COMPILED_OPS="" | ||
| 755 | - UT_TEST_ALL=FALSE | ||
| 756 | - CHANGED_FILES="" | ||
| 757 | - CI_MODE=FALSE | ||
| 758 | - COMPUTE_UNIT="" | ||
| 759 | - VENDOR_NAME="" | ||
| 760 | - SHOW_HELP="" | ||
| 761 | - EXAMPLE_NAME="" | ||
| 762 | - EXAMPLE_MODE="" | ||
| 763 | - USE_CMD="$*" | ||
| 764 | - BISHENG_FLAGS="" | ||
| 765 | - KERNEL_TEMPLATE_INPUT="" | ||
| 766 | - | ||
| 767 | - BUILD_TYPE="Release" | ||
| 768 | - PACKAGE_TYPE="run" | ||
| 769 | - PACKAGE_TYPE_SET=FALSE | ||
| 770 | - ENABLE_MSSANITIZER=FALSE | ||
| 771 | - ENABLE_OOM=FALSE | ||
| 772 | - ENABLE_DUMP_CCE=FALSE | ||
| 773 | - ENABLE_COVERAGE=FALSE | ||
| 774 | - ENABLE_UT_EXEC=TRUE | ||
| 775 | - ENABLE_ASAN=FALSE | ||
| 776 | - ENABLE_VALGRIND=FALSE | ||
| 777 | - ENABLE_BINARY=FALSE | ||
| 778 | - ENABLE_CUSTOM=FALSE | ||
| 779 | - ENABLE_STATIC=FALSE | ||
| 780 | - ENABLE_SIMULATOR=FALSE | ||
| 781 | - ENABLE_PACKAGE=FALSE | ||
| 782 | - ENABLE_EXPERIMENTAL=FALSE | ||
| 783 | - ENABLE_TEST=FALSE | ||
| 784 | - ENABLE_JIT=FALSE | ||
| 785 | - AICPU_ONLY=FALSE | ||
| 786 | - DISABLE_AICPU=FALSE | ||
| 787 | - OP_API_UT=FALSE | ||
| 788 | - OP_HOST_UT=FALSE | ||
| 789 | - OP_GRAPH_UT=FALSE | ||
| 790 | - OP_KERNEL_UT=FALSE | ||
| 791 | - OP_KERNEL_AICPU_UT=FALSE | ||
| 792 | - OP_API=FALSE | ||
| 793 | - OP_HOST=FALSE | ||
| 794 | - OP_GRAPH=FALSE | ||
| 795 | - ONNX_PLUGIN=FALSE | ||
| 796 | - OP_KERNEL=FALSE | ||
| 797 | - OP_KERNEL_AICPU=FALSE | ||
| 798 | - ENABLE_CREATE_LIB=FALSE | ||
| 799 | - ENABLE_RUN_EXAMPLE=FALSE | ||
| 800 | - ENABLE_RULE_LAUNCH="" | ||
| 801 | - ENABLE_CCACHE=TRUE | ||
| 802 | - BUILD_LIBS=() | ||
| 803 | - UT_TARGETS=() | ||
| 804 | - | ||
| 805 | - ENABLE_GENOP=FALSE | ||
| 806 | - ENABLE_GENOP_AICPU=FALSE | ||
| 807 | - GENOP_TYPE="" | ||
| 808 | - GENOP_NAME="" | ||
| 809 | - GENOP_BASE=${BASE_PATH} | ||
| 810 | - | ||
| 811 | - # 首先检查所有参数是否合法 | ||
| 812 | - for arg in "$@"; do | ||
| 813 | - if [[ "$arg" =~ ^- ]]; then # 只检查以-开头的参数 | ||
| 814 | - if ! check_option_validity "$arg"; then | ||
| 815 | - echo "Use 'bash build.sh --help' for more information." | ||
| 816 | - exit 1 | ||
| 817 | - fi | ||
| 818 | - if [[ "$arg" == "--pkg-type" ]]; then | ||
| 819 | - echo "[ERROR] --pkg-type requires a value: run/rpm/deb/all" | ||
| 820 | - exit 1 | ||
| 821 | - fi | ||
| 822 | - if [[ "$arg" == --pkg-type=* ]]; then | ||
| 823 | - check_pkg_type "${arg#*=}" | ||
| 824 | - fi | ||
| 825 | - fi | ||
| 826 | - done | ||
| 827 | - | ||
| 828 | - # 检查并处理--help | ||
| 829 | - for arg in "$@"; do | ||
| 830 | - if [[ "$arg" == "--help" || "$arg" == "-h" ]]; then | ||
| 831 | - # 检查帮助信息中的组合参数 | ||
| 832 | - check_help_combinations "$@" | ||
| 833 | - local comb_result=$? | ||
| 834 | - if [ $comb_result -eq 1 ]; then | ||
| 835 | - exit 1 | ||
| 836 | - fi | ||
| 837 | - SHOW_HELP="general" | ||
| 838 | - | ||
| 839 | - # 检查 --help 前面的命令 | ||
| 840 | - for prev_arg in "$@"; do | ||
| 841 | - case "$prev_arg" in | ||
| 842 | - --pkg) SHOW_HELP="package" ;; | ||
| 843 | - --opkernel) SHOW_HELP="opkernel" ;; | ||
| 844 | - --opkernel_aicpu) SHOW_HELP="opkernel_aicpu" ;; | ||
| 845 | - -u) SHOW_HELP="test" ;; | ||
| 846 | - --make_clean) SHOW_HELP="clean" ;; | ||
| 847 | - --valgrind) SHOW_HELP="valgrind" ;; | ||
| 848 | - --ophost) SHOW_HELP="ophost" ;; | ||
| 849 | - --opapi) SHOW_HELP="opapi" ;; | ||
| 850 | - --opgraph) SHOW_HELP="opgraph" ;; | ||
| 851 | - --onnxplugin) SHOW_HELP="onnxplugin" ;; | ||
| 852 | - --ophost_test) SHOW_HELP="ophost_test" ;; | ||
| 853 | - --opapi_test) SHOW_HELP="opapi_test" ;; | ||
| 854 | - --opgraph_test) SHOW_HELP="opgraph_test" ;; | ||
| 855 | - --run_example) SHOW_HELP="run_example" ;; | ||
| 856 | - --genop) SHOW_HELP="genop" ;; | ||
| 857 | - --genop_aicpu) SHOW_HELP="genop_aicpu" ;; | ||
| 858 | - esac | ||
| 859 | - done | ||
| 860 | - | ||
| 861 | - usage "$SHOW_HELP" | ||
| 862 | - exit 0 | ||
| 863 | - fi | ||
| 864 | - done | ||
| 865 | - | ||
| 866 | - process_genop() { | ||
| 867 | - local opt_name=$1 | ||
| 868 | - local genop_value=$2 | ||
| 869 | - | ||
| 870 | - if [[ "$opt_name" == "genop" ]]; then | ||
| 871 | - ENABLE_GENOP=TRUE | ||
| 872 | - elif [[ "$opt_name" == "genop_aicpu" ]]; then | ||
| 873 | - ENABLE_GENOP_AICPU=TRUE | ||
| 874 | - else | ||
| 875 | - usage "genop" | ||
| 876 | - exit 1 | ||
| 877 | - fi | ||
| 878 | - | ||
| 879 | - if [[ "$genop_value" != *"/"* ]] || [[ "$genop_value" == *"/" ]]; then | ||
| 880 | - usage "$opt_name" | ||
| 881 | - exit 1 | ||
| 882 | - fi | ||
| 883 | - | ||
| 884 | - GENOP_NAME=${genop_value##*/} | ||
| 885 | - local remaining=${genop_value%/*} | ||
| 886 | - | ||
| 887 | - if [[ "$remaining" != *"/"* ]]; then | ||
| 888 | - GENOP_TYPE=$remaining | ||
| 889 | - GENOP_BASE=${BASE_PATH} | ||
| 890 | - else | ||
| 891 | - GENOP_TYPE=${remaining##*/} | ||
| 892 | - GENOP_BASE=${remaining%/*} | ||
| 893 | - if [[ ! "$GENOP_BASE" =~ ^/ && ! "$GENOP_BASE" =~ ^[a-zA-Z]: ]]; then | ||
| 894 | - GENOP_BASE="${BASE_PATH}/${GENOP_BASE}" | ||
| 895 | - fi | ||
| 896 | - fi | ||
| 897 | - } | ||
| 898 | - | ||
| 899 | - # Process the options | ||
| 900 | - while getopts $SUPPORTED_SHORT_OPTS opt; do | ||
| 901 | - case "${opt}" in | ||
| 902 | - h) | ||
| 903 | - usage | ||
| 904 | - exit 0 | ||
| 905 | - ;; | ||
| 906 | - j) THREAD_NUM=$OPTARG ;; | ||
| 907 | - v) VERBOSE="VERBOSE=1" ;; | ||
| 908 | - O) BUILD_MODE="-O$OPTARG" ;; | ||
| 909 | - u) ENABLE_TEST=TRUE ;; | ||
| 910 | - f) | ||
| 911 | - CHANGED_FILES=$OPTARG | ||
| 912 | - CI_MODE=TRUE | ||
| 913 | - ;; | ||
| 914 | - -) case $OPTARG in | ||
| 915 | - help) | ||
| 916 | - usage | ||
| 917 | - exit 0 | ||
| 918 | - ;; | ||
| 919 | - ops=*) | ||
| 920 | - COMPILED_OPS=${OPTARG#*=} | ||
| 921 | - ENABLE_CUSTOM=TRUE | ||
| 922 | - ;; | ||
| 923 | - genop=*) | ||
| 924 | - process_genop "genop" "${OPTARG#*=}" | ||
| 925 | - ;; | ||
| 926 | - genop_aicpu=*) | ||
| 927 | - process_genop "genop_aicpu" "${OPTARG#*=}" | ||
| 928 | - ;; | ||
| 929 | - soc=*) | ||
| 930 | - COMPUTE_UNIT=${OPTARG#*=} | ||
| 931 | - ;; | ||
| 932 | - vendor_name=*) | ||
| 933 | - VENDOR_NAME=${OPTARG#*=} | ||
| 934 | - ENABLE_CUSTOM=TRUE | ||
| 935 | - ;; | ||
| 936 | - build-type=*) | ||
| 937 | - BUILD_TYPE=${OPTARG#*=} | ||
| 938 | - ;; | ||
| 939 | - pkg-type=*) | ||
| 940 | - PACKAGE_TYPE=${OPTARG#*=} | ||
| 941 | - check_pkg_type "${PACKAGE_TYPE}" | ||
| 942 | - PACKAGE_TYPE_SET=TRUE | ||
| 943 | - ;; | ||
| 944 | - mssanitizer) ENABLE_MSSANITIZER=TRUE ;; | ||
| 945 | - oom) ENABLE_OOM=TRUE ;; | ||
| 946 | - dump_cce) ENABLE_DUMP_CCE=TRUE ;; | ||
| 947 | - bisheng_flags=*) | ||
| 948 | - BISHENG_FLAGS=${OPTARG#*=} | ||
| 949 | - ;; | ||
| 950 | - kernel_template_input=*) | ||
| 951 | - KERNEL_TEMPLATE_INPUT=${OPTARG#*=} | ||
| 952 | - ;; | ||
| 953 | - cov) ENABLE_COVERAGE=TRUE ;; | ||
| 954 | - noexec) ENABLE_UT_EXEC=FALSE ;; | ||
| 955 | - aicpu) AICPU_ONLY=TRUE ;; | ||
| 956 | - noaicpu) DISABLE_AICPU=TRUE ;; | ||
| 957 | - static) | ||
| 958 | - ENABLE_STATIC=TRUE | ||
| 959 | - ENABLE_BINARY=TRUE | ||
| 960 | - ;; | ||
| 961 | - pkg) | ||
| 962 | - ENABLE_BINARY=TRUE | ||
| 963 | - ENABLE_PACKAGE=TRUE | ||
| 964 | - ;; | ||
| 965 | - cann_3rd_lib_path=*) | ||
| 966 | - CANN_3RD_LIB_PATH="$(realpath ${OPTARG#*=})" | ||
| 967 | - ;; | ||
| 968 | - jit) | ||
| 969 | - ENABLE_BINARY=FALSE | ||
| 970 | - ENABLE_JIT=TRUE | ||
| 971 | - ;; | ||
| 972 | - asan) ENABLE_ASAN=TRUE ;; | ||
| 973 | - valgrind) | ||
| 974 | - ENABLE_VALGRIND=TRUE | ||
| 975 | - ENABLE_UT_EXEC=FALSE | ||
| 976 | - BUILD_TYPE="Debug" | ||
| 977 | - ;; | ||
| 978 | - simulator) ENABLE_SIMULATOR=TRUE ;; | ||
| 979 | - rule_launch=*) | ||
| 980 | - ENABLE_RULE_LAUNCH=${OPTARG#*=} | ||
| 981 | - ;; | ||
| 982 | - ccache=*) | ||
| 983 | - local ccache_val=${OPTARG#*=} | ||
| 984 | - if [[ "$ccache_val" == "off" || "$ccache_val" == "false" || "$ccache_val" == "disable" ]]; then | ||
| 985 | - ENABLE_CCACHE=FALSE | ||
| 986 | - fi | ||
| 987 | - ;; | ||
| 988 | - run_example) | ||
| 989 | - checkopts_run_example "$@" | ||
| 990 | - ;; | ||
| 991 | - experimental) | ||
| 992 | - ENABLE_EXPERIMENTAL=TRUE | ||
| 993 | - ENABLE_CUSTOM=TRUE | ||
| 994 | - ;; | ||
| 995 | - make_clean) | ||
| 996 | - clean_build | ||
| 997 | - clean_build_out | ||
| 998 | - exit 0 | ||
| 999 | - ;; | ||
| 1000 | - *) | ||
| 1001 | - ## 如果不在RELEASE_TARGETS 或者 UT_TARGETS,不做处理 | ||
| 1002 | - if ! in_array "$OPTARG" "${RELEASE_TARGETS[@]}" && ! in_array "$OPTARG" "${SUPPORTED_UT_TARGETS[@]}"; then | ||
| 1003 | - echo "[ERROR] Invalid option: --$OPTARG" | ||
| 1004 | - usage | ||
| 1005 | - exit 1 | ||
| 1006 | - fi | ||
| 1007 | - ## 如果_test形式的,那么获取正确的名,并强设UT_MODE为TRUE | ||
| 1008 | - if [[ "$OPTARG" == *"_test" ]]; then | ||
| 1009 | - OPTARG="${OPTARG%_test}" | ||
| 1010 | - ENABLE_TEST=TRUE | ||
| 1011 | - fi | ||
| 1012 | - | ||
| 1013 | - if [[ "$OPTARG" == "ophost" ]]; then | ||
| 1014 | - OP_HOST=TRUE | ||
| 1015 | - elif [[ "$OPTARG" == "opapi" ]]; then | ||
| 1016 | - OP_API=TRUE | ||
| 1017 | - elif [[ "$OPTARG" == "opgraph" ]]; then | ||
| 1018 | - OP_GRAPH=TRUE | ||
| 1019 | - elif [[ "$OPTARG" == "onnxplugin" ]]; then | ||
| 1020 | - ONNX_PLUGIN=TRUE | ||
| 1021 | - elif [[ "$OPTARG" == "opkernel" ]]; then | ||
| 1022 | - OP_KERNEL=TRUE | ||
| 1023 | - elif [[ "$OPTARG" == "opkernel_aicpu" ]]; then | ||
| 1024 | - OP_KERNEL_AICPU=TRUE | ||
| 1025 | - else | ||
| 1026 | - usage | ||
| 1027 | - exit 1 | ||
| 1028 | - fi | ||
| 1029 | - ;; | ||
| 1030 | - esac ;; | ||
| 1031 | - *) | ||
| 1032 | - echo "Undefined option: ${opt}" | ||
| 1033 | - usage | ||
| 1034 | - exit 1 | ||
| 1035 | - ;; | ||
| 1036 | - esac | ||
| 1037 | - done | ||
| 1038 | - | ||
| 1039 | - if [[ "$ENABLE_JIT" == "TRUE" ]]; then | ||
| 1040 | - ENABLE_BINARY=FALSE | ||
| 1041 | - fi | ||
| 1042 | - | ||
| 1043 | - check_param | ||
| 1044 | - set_create_libs | ||
| 1045 | - parse_changed_files | ||
| 1046 | - set_ut_mode | ||
| 1047 | -} | ||
| 1048 | - | ||
| 1049 | -parse_changed_files() { | ||
| 1050 | - if [[ -z "$CHANGED_FILES" ]]; then | ||
| 1051 | - return | ||
| 1052 | - fi | ||
| 1053 | - | ||
| 1054 | - if [[ "$CHANGED_FILES" != /* ]]; then | ||
| 1055 | - CHANGED_FILES=$PWD/$CHANGED_FILES | ||
| 1056 | - fi | ||
| 1057 | - | ||
| 1058 | - echo "changed files is $CHANGED_FILES" | ||
| 1059 | - echo "$dotted_line" | ||
| 1060 | - echo "changed lines:" | ||
| 1061 | - cat "$CHANGED_FILES" | ||
| 1062 | - echo "$dotted_line" | ||
| 1063 | - | ||
| 1064 | - COMPILED_OPS=$(python3 scripts/ci/parse_changed_ops.py "$CHANGED_FILES" "$ENABLE_EXPERIMENTAL") | ||
| 1065 | - echo "related ops $COMPILED_OPS" | ||
| 1066 | - | ||
| 1067 | - if [[ -z $COMPILED_OPS ]]; then | ||
| 1068 | - if [[ "$ENABLE_EXPERIMENTAL" == "TRUE" ]]; then | ||
| 1069 | - COMPILED_OPS='nms_with_mask' | ||
| 1070 | - else | ||
| 1071 | - COMPILED_OPS='grid_sample' | ||
| 1072 | - fi | ||
| 1073 | - echo "No ops changed found, set op $COMPILED_OPS as default." | ||
| 1074 | - fi | ||
| 1075 | - | ||
| 1076 | - if [[ "$ENABLE_PACKAGE" == "TRUE" ]]; then | ||
| 1077 | - return | ||
| 1078 | - fi | ||
| 1079 | - | ||
| 1080 | - local script_ret=$(python3 scripts/ci/parse_changed_files.py "$CHANGED_FILES" "$ENABLE_EXPERIMENTAL") | ||
| 1081 | - IFS='&&' read -r related_ut soc_info <<<"$script_ret" | ||
| 1082 | - echo "related ut $related_ut" | ||
| 1083 | - echo "related soc_info $soc_info" | ||
| 1084 | - | ||
| 1085 | - COMPUTE_UNIT=$soc_info | ||
| 1086 | - | ||
| 1087 | - if [[ "$related_ut" == "set()" ]]; then | ||
| 1088 | - ENABLE_TEST=FALSE | ||
| 1089 | - echo "no ut matched! no need to run!" | ||
| 1090 | - echo "---------------- CANN build finished ----------------" | ||
| 1091 | - return | ||
| 1092 | - else | ||
| 1093 | - ENABLE_TEST=TRUE | ||
| 1094 | - fi | ||
| 1095 | - | ||
| 1096 | - if [[ "$related_ut" =~ "ALL_UT" ]]; then | ||
| 1097 | - echo "ALL UT is triggered!" | ||
| 1098 | - return | ||
| 1099 | - fi | ||
| 1100 | - if [[ ("$related_ut" =~ "OP_HOST_UT" || "$related_ut" =~ "OP_GRAPH_UT") && "$OP_HOST" == "TRUE" ]]; then | ||
| 1101 | - echo "OP_HOST_UT is triggered!" | ||
| 1102 | - OP_HOST_UT=TRUE | ||
| 1103 | - OP_KERNEL_UT=TRUE | ||
| 1104 | - OP_KERNEL=TRUE | ||
| 1105 | - OP_GRAPH=TRUE | ||
| 1106 | - ENABLE_CUSTOM=TRUE | ||
| 1107 | - fi | ||
| 1108 | - if [[ "$related_ut" =~ "OP_API_UT" && "$OP_API" == "TRUE" ]]; then | ||
| 1109 | - echo "OP_API_UT is triggered!" | ||
| 1110 | - OP_API_UT=TRUE | ||
| 1111 | - ENABLE_CUSTOM=TRUE | ||
| 1112 | - fi | ||
| 1113 | - if [[ "$related_ut" =~ "OP_KERNEL_UT" && "$OP_KERNEL" == "TRUE" ]]; then | ||
| 1114 | - echo "OP_KERNEL_UT is triggered!" | ||
| 1115 | - OP_KERNEL_UT=TRUE | ||
| 1116 | - ENABLE_CUSTOM=TRUE | ||
| 1117 | - fi | ||
| 1118 | - if [[ "$related_ut" =~ "OP_KERNEL_AICPU_UT" && "$OP_KERNEL_AICPU" == "TRUE" ]]; then | ||
| 1119 | - echo "OP_KERNEL_AICPU_UT is triggered!" | ||
| 1120 | - OP_KERNEL_AICPU_UT=TRUE | ||
| 1121 | - ENABLE_CUSTOM=TRUE | ||
| 1122 | - fi | ||
| 1123 | -} | ||
| 1124 | - | ||
| 1125 | -custom_cmake_args() { | ||
| 1126 | - if [[ -n $COMPILED_OPS ]]; then | ||
| 1127 | - COMPILED_OPS="${COMPILED_OPS//,/;}" | ||
| 1128 | - CMAKE_ARGS="$CMAKE_ARGS -DASCEND_OP_NAME=$COMPILED_OPS" | ||
| 1129 | - fi | ||
| 1130 | - if [[ -n $VENDOR_NAME ]]; then | ||
| 1131 | - CMAKE_ARGS="$CMAKE_ARGS -DVENDOR_NAME=$VENDOR_NAME" | ||
| 1132 | - fi | ||
| 1133 | -} | ||
| 1134 | - | ||
| 1135 | -assemble_cmake_args() { | ||
| 1136 | - if [[ "$ENABLE_ASAN" == "TRUE" ]]; then | ||
| 1137 | - set +e | ||
| 1138 | - echo 'int main() {return 0;}' | gcc -x c -fsanitize=address - -o asan_test >/dev/null 2>&1 | ||
| 1139 | - if [ $? -ne 0 ]; then | ||
| 1140 | - echo "This environment does not have the ASAN library, no need enable ASAN" | ||
| 1141 | - ENABLE_ASAN=FALSE | ||
| 1142 | - else | ||
| 1143 | - $(rm -f asan_test) | ||
| 1144 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_ASAN=TRUE" | ||
| 1145 | - fi | ||
| 1146 | - set -e | ||
| 1147 | - fi | ||
| 1148 | - if [[ "$ENABLE_VALGRIND" == "TRUE" ]]; then | ||
| 1149 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_VALGRIND=TRUE" | ||
| 1150 | - fi | ||
| 1151 | - if [[ -n "$BUILD_TYPE" ]]; then | ||
| 1152 | - CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=${BUILD_TYPE}" | ||
| 1153 | - fi | ||
| 1154 | - if [[ "$ENABLE_MSSANITIZER" == "TRUE" ]]; then | ||
| 1155 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_MSSANITIZER=TRUE" | ||
| 1156 | - fi | ||
| 1157 | - if [[ "$ENABLE_OOM" == "TRUE" ]]; then | ||
| 1158 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_OOM=TRUE" | ||
| 1159 | - fi | ||
| 1160 | - if [[ "$DISABLE_AICPU" == "TRUE" ]]; then | ||
| 1161 | - CMAKE_ARGS="$CMAKE_ARGS -DDISABLE_AICPU=TRUE" | ||
| 1162 | - fi | ||
| 1163 | - if [[ "$ENABLE_DUMP_CCE" == "TRUE" ]]; then | ||
| 1164 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_DUMP_CCE=TRUE" | ||
| 1165 | - fi | ||
| 1166 | - if [[ "x$BISHENG_FLAGS" != "x" ]]; then | ||
| 1167 | - CMAKE_ARGS="$CMAKE_ARGS -DBISHENG_FLAGS=${BISHENG_FLAGS}" | ||
| 1168 | - fi | ||
| 1169 | - if [[ "$KERNEL_TEMPLATE_INPUT" != "" ]]; then | ||
| 1170 | - CMAKE_ARGS="$CMAKE_ARGS -DKERNEL_TEMPLATE_INPUT=$KERNEL_TEMPLATE_INPUT" | ||
| 1171 | - fi | ||
| 1172 | - if [[ "$ENABLE_TEST" == "TRUE" ]]; then | ||
| 1173 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_TEST=TRUE" | ||
| 1174 | - custom_cmake_args | ||
| 1175 | - fi | ||
| 1176 | - if [[ "$ENABLE_UT_EXEC" == "TRUE" ]]; then | ||
| 1177 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_UT_EXEC=TRUE" | ||
| 1178 | - fi | ||
| 1179 | - if [[ "$ENABLE_COVERAGE" == "TRUE" ]]; then | ||
| 1180 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_COVERAGE=TRUE" | ||
| 1181 | - fi | ||
| 1182 | - if [[ "$ENABLE_BINARY" == "TRUE" ]]; then | ||
| 1183 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_BINARY=TRUE" | ||
| 1184 | - fi | ||
| 1185 | - if [[ "$ENABLE_CUSTOM" == "TRUE" ]]; then | ||
| 1186 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_CUSTOM=TRUE -DENABLE_BINARY=TRUE" | ||
| 1187 | - custom_cmake_args | ||
| 1188 | - fi | ||
| 1189 | - if [[ "$ENABLE_PACKAGE" == "TRUE" ]]; then | ||
| 1190 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_PACKAGE=TRUE -DPACKAGE_TYPE=${PACKAGE_TYPE}" | ||
| 1191 | - fi | ||
| 1192 | - if [[ "$ENABLE_EXPERIMENTAL" == "TRUE" ]]; then | ||
| 1193 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_EXPERIMENTAL=TRUE" | ||
| 1194 | - fi | ||
| 1195 | - if [[ "$ENABLE_STATIC" == "TRUE" ]]; then | ||
| 1196 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_STATIC=${ENABLE_STATIC}" | ||
| 1197 | - fi | ||
| 1198 | - if [[ "x$BUILD_MODE" != "x" ]]; then | ||
| 1199 | - CMAKE_ARGS="$CMAKE_ARGS -DBUILD_MODE=${BUILD_MODE}" | ||
| 1200 | - fi | ||
| 1201 | - if [[ "$OP_HOST_UT" == "TRUE" ]]; then | ||
| 1202 | - CMAKE_ARGS="$CMAKE_ARGS -DOP_HOST_UT=TRUE" | ||
| 1203 | - fi | ||
| 1204 | - if [[ "$OP_API_UT" == "TRUE" ]]; then | ||
| 1205 | - CMAKE_ARGS="$CMAKE_ARGS -DOP_API_UT=TRUE" | ||
| 1206 | - fi | ||
| 1207 | - if [[ "$OP_GRAPH_UT" == "TRUE" ]]; then | ||
| 1208 | - CMAKE_ARGS="$CMAKE_ARGS -DOP_GRAPH_UT=TRUE" | ||
| 1209 | - fi | ||
| 1210 | - if [[ "$OP_KERNEL_UT" == "TRUE" ]]; then | ||
| 1211 | - CMAKE_ARGS="$CMAKE_ARGS -DOP_KERNEL_UT=TRUE" | ||
| 1212 | - fi | ||
| 1213 | - if [[ "$OP_KERNEL_AICPU_UT" == "TRUE" ]]; then | ||
| 1214 | - CMAKE_ARGS="$CMAKE_ARGS -DOP_KERNEL_AICPU_UT=TRUE" | ||
| 1215 | - fi | ||
| 1216 | - if [[ "$UT_TEST_ALL" == "TRUE" ]]; then | ||
| 1217 | - CMAKE_ARGS="$CMAKE_ARGS -DUT_TEST_ALL=TRUE" | ||
| 1218 | - fi | ||
| 1219 | - if [[ -n $COMPUTE_UNIT ]]; then | ||
| 1220 | - COMPUTE_UNIT=$(normalize_compute_unit "$COMPUTE_UNIT") | ||
| 1221 | - found=0 | ||
| 1222 | - for support_unit in "${SUPPORT_COMPUTE_UNIT_SHORT[@]}"; do | ||
| 1223 | - if [[ "$COMPUTE_UNIT" == "$support_unit" ]]; then | ||
| 1224 | - COMPUTE_UNIT_SHORT=$support_unit | ||
| 1225 | - found=1 | ||
| 1226 | - break | ||
| 1227 | - fi | ||
| 1228 | - done | ||
| 1229 | - if [[ $found -eq 0 ]]; then | ||
| 1230 | - echo "soc only support : ${SUPPORT_COMPUTE_UNIT_SHORT[@]}" | ||
| 1231 | - exit 1 | ||
| 1232 | - fi | ||
| 1233 | - echo "COMPUTE_UNIT: ${COMPUTE_UNIT}" | ||
| 1234 | - CMAKE_ARGS="$CMAKE_ARGS -DASCEND_COMPUTE_UNIT=$COMPUTE_UNIT" | ||
| 1235 | - fi | ||
| 1236 | - if [[ "x$ENABLE_RULE_LAUNCH" != "x" ]]; then | ||
| 1237 | - CMAKE_ARGS="$CMAKE_ARGS -DRULE_LAUNCH=${ENABLE_RULE_LAUNCH}" | ||
| 1238 | - fi | ||
| 1239 | - CMAKE_ARGS="$CMAKE_ARGS -DENABLE_CCACHE=${ENABLE_CCACHE}" | ||
| 1240 | - CMAKE_ARGS="$CMAKE_ARGS -DCANN_3RD_LIB_PATH=${CANN_3RD_LIB_PATH}" | ||
| 1241 | - CMAKE_ARGS="$CMAKE_ARGS -DASCEND_INSTALL_PATH=${ASCEND_INSTALL_PATH}" | ||
| 1242 | -} | ||
| 1243 | - | ||
| 1244 | -cmake_init() { | ||
| 1245 | - if [[ "$ENABLE_GENOP" == "TRUE" || "$ENABLE_GENOP_AICPU" == "TRUE" ]]; then | ||
| 1246 | - return | ||
| 1247 | - fi | ||
| 1248 | - if [ ! -d "${BUILD_PATH}" ]; then | ||
| 1249 | - mkdir -p "${BUILD_PATH}" | ||
| 1250 | - fi | ||
| 1251 | - if [ ! -d "${BUILD_OUT_PATH}" ]; then | ||
| 1252 | - mkdir -p "${BUILD_OUT_PATH}" | ||
| 1253 | - fi | ||
| 1254 | - | ||
| 1255 | - [ -f "${BUILD_PATH}/CMakeCache.txt" ] && rm -f "${BUILD_PATH}/CMakeCache.txt" | ||
| 1256 | - | ||
| 1257 | - cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} .. | ||
| 1258 | -} | ||
| 1259 | - | ||
| 1260 | -clean_build() { | ||
| 1261 | - if [ -d "${BUILD_PATH}" ]; then | ||
| 1262 | - rm -rf "${BUILD_PATH}"/* | ||
| 1263 | - fi | ||
| 1264 | -} | ||
| 1265 | - | ||
| 1266 | -clean_build_out() { | ||
| 1267 | - if [ -d "${BUILD_OUT_PATH}" ]; then | ||
| 1268 | - rm -rf "${BUILD_OUT_PATH}"/* | ||
| 1269 | - fi | ||
| 1270 | -} | ||
| 1271 | - | ||
| 1272 | -clean_build_binary() { | ||
| 1273 | - if [ -d "${BUILD_PATH}/tbe" ]; then | ||
| 1274 | - rm -rf "${BUILD_PATH}/tbe/" | ||
| 1275 | - fi | ||
| 1276 | - if [ -d "${BUILD_PATH}/autogen" ]; then | ||
| 1277 | - rm -rf "${BUILD_PATH}/autogen/" | ||
| 1278 | - fi | ||
| 1279 | - if [ -d "${BUILD_PATH}/binary" ]; then | ||
| 1280 | - rm -rf "${BUILD_PATH}/binary/" | ||
| 1281 | - fi | ||
| 1282 | - if [[ "$ENABLE_STATIC" == "TRUE" ]]; then | ||
| 1283 | - if [ -d "${BUILD_PATH}/static_library_files" ]; then | ||
| 1284 | - rm -rf "${BUILD_PATH}/static_library_files/" | ||
| 1285 | - fi | ||
| 1286 | - fi | ||
| 1287 | -} | ||
| 1288 | - | ||
| 1289 | -build_static_lib() { | ||
| 1290 | - echo $dotted_line | ||
| 1291 | - echo "Start to build static lib." | ||
| 1292 | - | ||
| 1293 | - cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} .. | ||
| 1294 | - local all_targets=$(cmake --build . --target help) | ||
| 1295 | - rm -fr "${BUILD_PATH}/bin_tmp" | ||
| 1296 | - mkdir -p "${BUILD_PATH}/bin_tmp" | ||
| 1297 | - if grep -wq "ophost_cv_static" <<< "${all_targets}"; then | ||
| 1298 | - cmake --build . --target ophost_cv_static -- ${VERBOSE} -j $THREAD_NUM | ||
| 1299 | - fi | ||
| 1300 | - | ||
| 1301 | - local UNITS=(${COMPUTE_UNIT_SHORT//;/ }) | ||
| 1302 | - if [[ ${#UNITS[@]} -eq 0 ]]; then | ||
| 1303 | - UNITS+=("ascend910b") | ||
| 1304 | - fi | ||
| 1305 | - if grep -wq "opapi_cv_static" <<< "${all_targets}"; then | ||
| 1306 | - cmake --build . --target opapi_cv_static -- ${VERBOSE} -j $THREAD_NUM | ||
| 1307 | - fi | ||
| 1308 | - local jit_command="" | ||
| 1309 | - if [[ "$ENABLE_JIT" == "TRUE" ]]; then | ||
| 1310 | - jit_command="-j" | ||
| 1311 | - fi | ||
| 1312 | - for unit in "${UNITS[@]}"; do | ||
| 1313 | - rm -fr "${BUILD_PATH}/bin_tmp/${unit}" | ||
| 1314 | - python3 "${BASE_PATH}/scripts/util/build_opp_kernel_static.py" GenStaticOpResourceIni -s ${unit} -b "${BUILD_PATH}" ${jit_command} | ||
| 1315 | - python3 "${BASE_PATH}/scripts/util/build_opp_kernel_static.py" StaticCompile -s ${unit} -b "${BUILD_PATH}" -n=0 -a=${ARCH_INFO} ${jit_command} | ||
| 1316 | - done | ||
| 1317 | - cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} .. | ||
| 1318 | - if grep -wq "cann_cv_static" <<< "${all_targets}"; then | ||
| 1319 | - cmake --build . --target cann_cv_static -- ${VERBOSE} -j $THREAD_NUM | ||
| 1320 | - fi | ||
| 1321 | - echo "Build static lib success!" | ||
| 1322 | -} | ||
| 1323 | - | ||
| 1324 | -build_lib() { | ||
| 1325 | - echo $dotted_line | ||
| 1326 | - echo "Start to build libs ${BUILD_LIBS[@]}" | ||
| 1327 | - | ||
| 1328 | - git submodule init && git submodule update | ||
| 1329 | - if [ ! -d "${BUILD_PATH}" ]; then | ||
| 1330 | - mkdir -p "${BUILD_PATH}" | ||
| 1331 | - fi | ||
| 1332 | - | ||
| 1333 | - cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} -UENABLE_STATIC .. | ||
| 1334 | - | ||
| 1335 | - for lib in "${BUILD_LIBS[@]}"; do | ||
| 1336 | - echo "Building target ${lib}" | ||
| 1337 | - cmake --build . --target ${lib} -- ${VERBOSE} -j $THREAD_NUM | ||
| 1338 | - done | ||
| 1339 | - | ||
| 1340 | - echo $dotted_line | ||
| 1341 | - echo "Build libs ${BUILD_LIBS[@]} success" | ||
| 1342 | - echo $dotted_line | ||
| 1343 | -} | ||
| 1344 | - | ||
| 1345 | -build_binary() { | ||
| 1346 | - if [[ "$ENABLE_TEST" == "TRUE" ]]; then | ||
| 1347 | - return | ||
| 1348 | - fi | ||
| 1349 | - | ||
| 1350 | - echo $dotted_line | ||
| 1351 | - echo "Start to build binary" | ||
| 1352 | - | ||
| 1353 | - if [ ! -d "${BUILD_PATH}" ]; then | ||
| 1354 | - mkdir -p "${BUILD_PATH}" | ||
| 1355 | - fi | ||
| 1356 | - | ||
| 1357 | - cd "${BUILD_PATH}" && cmake .. ${CMAKE_ARGS} | ||
| 1358 | - | ||
| 1359 | - echo "--------------- prepare build start ---------------" | ||
| 1360 | - local all_targets=$(cmake --build . --target help) | ||
| 1361 | - if echo "${all_targets}" | grep -wq "ascendc_impl_gen"; then | ||
| 1362 | - cmake --build . --target ascendc_impl_gen -- ${VERBOSE} -j $THREAD_NUM | ||
| 1363 | - if [ $? -ne 0 ]; then | ||
| 1364 | - echo "[ERROR] Failed to execute ascendc_impl_gen." | ||
| 1365 | - exit 1; | ||
| 1366 | - fi | ||
| 1367 | - else | ||
| 1368 | - echo "[WARNING] Build target 'ascendc_impl_gen' not found in cmake targets, available targets: ${all_targets}" | ||
| 1369 | - fi | ||
| 1370 | - | ||
| 1371 | - if echo "${all_targets}" | grep -wq "gen_bin_scripts"; then | ||
| 1372 | - cmake --build . --target gen_bin_scripts -- ${VERBOSE} -j $THREAD_NUM | ||
| 1373 | - if [ $? -ne 0 ]; then | ||
| 1374 | - echo "[ERROR] Failed to execute gen_bin_scripts." | ||
| 1375 | - exit 1; | ||
| 1376 | - fi | ||
| 1377 | - else | ||
| 1378 | - echo "[WARNING] Build target 'gen_bin_scripts' not found in cmake targets, available targets: ${all_targets}" | ||
| 1379 | - fi | ||
| 1380 | - echo "--------------- prepare build end ---------------" | ||
| 1381 | - | ||
| 1382 | - echo "--------------- binary build start ---------------" | ||
| 1383 | - local UNITS=(${COMPUTE_UNIT_SHORT//;/ }) | ||
| 1384 | - if [[ ${#UNITS[@]} -eq 0 ]]; then | ||
| 1385 | - UNITS+=("ascend910b") | ||
| 1386 | - fi | ||
| 1387 | - for unit in "${UNITS[@]}"; do | ||
| 1388 | - rm -rf "${BUILD_PATH}/binary/${unit}/bin/opc_cmd" | ||
| 1389 | - if grep -wq "prepare_binary_compile_${unit}" <<< "${all_targets}"; then | ||
| 1390 | - cmake --build . --target prepare_binary_compile_${unit} -- ${VERBOSE} -j 1 | ||
| 1391 | - if [ $? -ne 0 ]; then | ||
| 1392 | - print_error "opc gen failed!" && exit 1 | ||
| 1393 | - fi | ||
| 1394 | - fi | ||
| 1395 | - OPC_CMD_FILE="${BUILD_PATH}/binary/${unit}/bin/opc_cmd/opc_cmd.sh" | ||
| 1396 | - [[ -f "$OPC_CMD_FILE" ]] && opc_list_num=$(wc -l < "$OPC_CMD_FILE") || opc_list_num=0 | ||
| 1397 | - CMAKE_ARGS="${CMAKE_ARGS} -DOPC_NUM_${unit}=${opc_list_num}" | ||
| 1398 | - done | ||
| 1399 | - cd "$BUILD_PATH" && cmake .. ${CMAKE_ARGS} | ||
| 1400 | - | ||
| 1401 | - local cur_path=$(pwd) | ||
| 1402 | - mkdir -p "${cur_path}/op_impl/ai_core/tbe/op_tiling" | ||
| 1403 | - if [ ! -L op_impl/ai_core/tbe/op_tiling/liboptiling.so ]; then | ||
| 1404 | - if [ -e "${cur_path}/libophost_cv.so" ]; then | ||
| 1405 | - ln -s "${cur_path}/libophost_cv.so" op_impl/ai_core/tbe/op_tiling/liboptiling.so | ||
| 1406 | - else | ||
| 1407 | - cmake --build . --target ophost_cv -- ${VERBOSE} -j $THREAD_NUM | ||
| 1408 | - ln -s "${cur_path}/libophost_cv.so" op_impl/ai_core/tbe/op_tiling/liboptiling.so | ||
| 1409 | - fi | ||
| 1410 | - fi | ||
| 1411 | - export ASCEND_CUSTOM_OPP_PATH="${cur_path}" | ||
| 1412 | - if echo "${all_targets}" | grep -wq "binary"; then | ||
| 1413 | - cmake --build . --target binary -- ${VERBOSE} -j $THREAD_NUM | ||
| 1414 | - if [ $? -ne 0 ]; then | ||
| 1415 | - echo "[ERROR] Kernel compile failed!" && exit 1 | ||
| 1416 | - fi | ||
| 1417 | - else | ||
| 1418 | - echo "[WARNING] Compile kernel 'binary' failed! Build target 'binary' not found in cmake targets. Available targets: ${all_targets}" | ||
| 1419 | - fi | ||
| 1420 | - if echo "${all_targets}" | grep -wq "gen_bin_info_config"; then | ||
| 1421 | - cmake --build . --target gen_bin_info_config -- ${VERBOSE} -j $THREAD_NUM | ||
| 1422 | - if [ $? -ne 0 ]; then exit 1; fi | ||
| 1423 | - else | ||
| 1424 | - echo "[WARNING] Generate 'gen_bin_info_config' failed! Build target 'gen_bin_info_config' not found in cmake targets. Available targets: ${all_targets}" | ||
| 1425 | - fi | ||
| 1426 | - echo "--------------- binary build end ---------------" | ||
| 1427 | - | ||
| 1428 | - echo "Build binary success" | ||
| 1429 | - echo $dotted_line | ||
| 1430 | -} | ||
| 1431 | - | ||
| 1432 | -build_package() { | ||
| 1433 | - echo "--------------- build package start ---------------" | ||
| 1434 | - clean_build_out | ||
| 1435 | - | ||
| 1436 | - local all_targets=$(cmake --build . --target help) | ||
| 1437 | - if [[ "$ENABLE_BINARY" != "TRUE" && "$ENABLE_CUSTOM" != "TRUE" ]]; then | ||
| 1438 | - # gen impl python files | ||
| 1439 | - if echo "${all_targets}" | grep -wq "ascendc_impl_gen"; then | ||
| 1440 | - cmake --build . --target ascendc_impl_gen -- ${VERBOSE} -j $THREAD_NUM | ||
| 1441 | - if [ $? -ne 0 ]; then exit 1; fi | ||
| 1442 | - fi | ||
| 1443 | - fi | ||
| 1444 | - | ||
| 1445 | - cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} .. | ||
| 1446 | - if echo "${all_targets}" | grep -wq "build_es_cv"; then | ||
| 1447 | - cmake --build . --target build_es_cv -- ${VERBOSE} -j $THREAD_NUM | ||
| 1448 | - [ $? -ne 0 ] && echo "[ERROR] target:build_es_cv compile failed!" && exit 1 | ||
| 1449 | - fi | ||
| 1450 | - clean_rpm_deb_package | ||
| 1451 | - cmake --build . --target package -- ${VERBOSE} -j $THREAD_NUM | ||
| 1452 | - if [ $? -ne 0 ]; then | ||
| 1453 | - echo "[ERROR] target:package build failed!" | ||
| 1454 | - exit 1 | ||
| 1455 | - fi | ||
| 1456 | - collect_rpm_deb_package | ||
| 1457 | - echo "--------------- build package end ---------------" | ||
| 1458 | -} | ||
| 1459 | - | ||
| 1460 | -find_rpm_deb_package() { | ||
| 1461 | - if [[ "$PACKAGE_TYPE" == "run" ]]; then | ||
| 1462 | - return 0 | ||
| 1463 | - fi | ||
| 1464 | - | ||
| 1465 | - find "${BUILD_PATH}" -type f -name "cann-ops-cv*.${PACKAGE_TYPE}" | sort | ||
| 1466 | -} | ||
| 1467 | - | ||
| 1468 | -clean_rpm_deb_package() { | ||
| 1469 | - if [[ "$PACKAGE_TYPE" == "run" ]]; then | ||
| 1470 | - return 0 | ||
| 1471 | - fi | ||
| 1472 | - | ||
| 1473 | - local package_files=() | ||
| 1474 | - while IFS= read -r package_file; do | ||
| 1475 | - package_files+=("${package_file}") | ||
| 1476 | - done < <(find_rpm_deb_package) | ||
| 1477 | - | ||
| 1478 | - if [[ ${#package_files[@]} -eq 0 ]]; then | ||
| 1479 | - return 0 | ||
| 1480 | - fi | ||
| 1481 | - | ||
| 1482 | - for package_file in "${package_files[@]}"; do | ||
| 1483 | - rm -f "${package_file}" | ||
| 1484 | - echo "[INFO] Removed stale package artifact: ${package_file}" | ||
| 1485 | - done | ||
| 1486 | -} | ||
| 1487 | - | ||
| 1488 | -collect_rpm_deb_package() { | ||
| 1489 | - if [[ "$PACKAGE_TYPE" == "run" ]]; then | ||
| 1490 | - return 0 | ||
| 1491 | - fi | ||
| 1492 | - | ||
| 1493 | - local package_files=() | ||
| 1494 | - while IFS= read -r package_file; do | ||
| 1495 | - package_files+=("${package_file}") | ||
| 1496 | - done < <(find_rpm_deb_package) | ||
| 1497 | - | ||
| 1498 | - for package_file in "${package_files[@]}"; do | ||
| 1499 | - cp -f "${package_file}" "${BUILD_OUT_PATH}/" | ||
| 1500 | - echo "[INFO] Package artifact copied to ${BUILD_OUT_PATH}/$(basename "${package_file}")" | ||
| 1501 | - done | ||
| 1502 | -} | ||
| 1503 | - | ||
| 1504 | -build_ut() { | ||
| 1505 | - echo $dotted_line | ||
| 1506 | - echo "Start to build ut" | ||
| 1507 | - | ||
| 1508 | - git submodule init && git submodule update | ||
| 1509 | - if [ ! -d "${BUILD_PATH}" ]; then | ||
| 1510 | - mkdir -p "${BUILD_PATH}" | ||
| 1511 | - fi | ||
| 1512 | - | ||
| 1513 | - cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} .. | ||
| 1514 | - | ||
| 1515 | - for lib in "${UT_TARGETS[@]}"; do | ||
| 1516 | - `find . -name "${lib}*" -type f -delete` | ||
| 1517 | - cmake --build . --target ${lib} -- ${VERBOSE} -j $THREAD_NUM | ||
| 1518 | - done | ||
| 1519 | - | ||
| 1520 | - if [[ "$ENABLE_COVERAGE" =~ "TRUE" ]]; then | ||
| 1521 | - cmake --build . --target generate_ops_cpp_cov -- -j $THREAD_NUM | ||
| 1522 | - fi | ||
| 1523 | -} | ||
| 1524 | - | ||
| 1525 | -####################################### | ||
| 1526 | -# build_example entry | ||
| 1527 | -####################################### | ||
| 1528 | -build_example() { | ||
| 1529 | - echo $dotted_line | ||
| 1530 | - echo "Start to run examples,name:${EXAMPLE_NAME} mode:${EXAMPLE_MODE}" | ||
| 1531 | - | ||
| 1532 | - mkdir -p "${BUILD_PATH}" | ||
| 1533 | - cd "${BUILD_PATH}" || exit 1 | ||
| 1534 | - | ||
| 1535 | - if [[ "${EXAMPLE_MODE}" == "eager" ]]; then | ||
| 1536 | - build_example_eager | ||
| 1537 | - elif [[ "${EXAMPLE_MODE}" == "graph" ]]; then | ||
| 1538 | - build_example_graph | ||
| 1539 | - else | ||
| 1540 | - usage | ||
| 1541 | - exit 1 | ||
| 1542 | - fi | ||
| 1543 | -} | ||
| 1544 | - | ||
| 1545 | -####################################### | ||
| 1546 | -# eager mode | ||
| 1547 | -####################################### | ||
| 1548 | -build_example_eager() { | ||
| 1549 | - local file | ||
| 1550 | - local sim_lib_path | ||
| 1551 | - sim_lib_path=$(get_simulator_args) | ||
| 1552 | - local ret=$? | ||
| 1553 | - if [ $ret -ne 0 ]; then | ||
| 1554 | - exit 1 | ||
| 1555 | - fi | ||
| 1556 | - | ||
| 1557 | - if [[ "$ENABLE_EXPERIMENTAL" == "TRUE" ]]; then | ||
| 1558 | - file=$(find ../experimental -path "*/${EXAMPLE_NAME}/examples/*" -name test_aclnn_*.cpp) | ||
| 1559 | - else | ||
| 1560 | - file=$(find ../ -path "*/${EXAMPLE_NAME}/examples/*" -name test_aclnn_*.cpp -not -path "*/experimental/*") | ||
| 1561 | - if [[ "$COMPUTE_UNIT" == "ascend950" ]]; then | ||
| 1562 | - file+=($(find ../ -path "*/${EXAMPLE_NAME}/examples/arch35/*" -name test_aclnn_*.cpp)) | ||
| 1563 | - fi | ||
| 1564 | - fi | ||
| 1565 | - | ||
| 1566 | - if [ -z "$file" ]; then | ||
| 1567 | - echo "ERROR: ${EXAMPLE_NAME} do not have eager examples" | ||
| 1568 | - exit 1 | ||
| 1569 | - fi | ||
| 1570 | - | ||
| 1571 | - for f in $file; do | ||
| 1572 | - if [[ "${PKG_MODE}" == "cust" && "$f" == *add_example_aicpu* && "$f" == *opgen* ]]; then | ||
| 1573 | - continue | ||
| 1574 | - fi | ||
| 1575 | - | ||
| 1576 | - echo "Start compile and run examples file: $f" | ||
| 1577 | - | ||
| 1578 | - if [[ "${PKG_MODE}" == "" ]]; then | ||
| 1579 | - if [[ -n "$sim_lib_path" ]]; then | ||
| 1580 | - export LD_LIBRARY_PATH=${sim_lib_path}:${LD_LIBRARY_PATH} | ||
| 1581 | - ln -sf ${sim_lib_path}/libruntime_camodel.so ${sim_lib_path}/libruntime.so | ||
| 1582 | - ln -sf ${sim_lib_path}/libnpu_drv_camodel.so ${sim_lib_path}/libascend_hal.so | ||
| 1583 | - g++ ${f} \ | ||
| 1584 | - -I ${INCLUDE_PATH} \ | ||
| 1585 | - -I ${ACLNN_INCLUDE_PATH} \ | ||
| 1586 | - -L ${EAGER_LIBRARY_PATH} \ | ||
| 1587 | - -lopapi_cv -lascendcl -lnnopbase \ | ||
| 1588 | - -L ${sim_lib_path} \ | ||
| 1589 | - -lruntime_camodel -lnpu_drv_camodel \ | ||
| 1590 | - -o test_aclnn_${EXAMPLE_NAME} \ | ||
| 1591 | - -Wl,-rpath=${sim_lib_path} | ||
| 1592 | - else | ||
| 1593 | - g++ ${f} \ | ||
| 1594 | - -I ${INCLUDE_PATH} \ | ||
| 1595 | - -I ${ACLNN_INCLUDE_PATH} \ | ||
| 1596 | - -L ${EAGER_LIBRARY_PATH} \ | ||
| 1597 | - -lopapi_cv -lascendcl -lnnopbase \ | ||
| 1598 | - -o test_aclnn_${EXAMPLE_NAME} | ||
| 1599 | - fi | ||
| 1600 | - | ||
| 1601 | - elif [[ "${PKG_MODE}" == "cust" ]]; then | ||
| 1602 | - echo "pkg_mode:${PKG_MODE} vendor_name:${VENDOR}" | ||
| 1603 | - | ||
| 1604 | - local cust_include_flags="" | ||
| 1605 | - local cust_library_flags="" | ||
| 1606 | - local cust_rpath_flags="" | ||
| 1607 | - local cust_aclnnop_paths="" | ||
| 1608 | - | ||
| 1609 | - if [[ -n "${ASCEND_CUSTOM_OPP_PATH}" ]]; then | ||
| 1610 | - IFS=':' read -ra PATH_ARRAY <<< "${ASCEND_CUSTOM_OPP_PATH}" | ||
| 1611 | - for path in "${PATH_ARRAY[@]}"; do | ||
| 1612 | - cust_include_flags="${cust_include_flags} -I ${path}/op_api/include" | ||
| 1613 | - cust_library_flags="${cust_library_flags} -L ${path}/op_api/lib" | ||
| 1614 | - cust_rpath_flags="${cust_rpath_flags}:${path}/op_api/lib" | ||
| 1615 | - cust_aclnnop_paths="${cust_aclnnop_paths} ${path}/op_api/include/aclnnop" | ||
| 1616 | - done | ||
| 1617 | - cust_rpath_flags="${cust_rpath_flags#:}" | ||
| 1618 | - else | ||
| 1619 | - cust_include_flags="-I ${ASCEND_HOME_PATH}/opp/vendors/${VENDOR}_cv/op_api/include" | ||
| 1620 | - cust_library_flags="-L ${ASCEND_HOME_PATH}/opp/vendors/${VENDOR}_cv/op_api/lib" | ||
| 1621 | - cust_rpath_flags="${ASCEND_HOME_PATH}/opp/vendors/${VENDOR}_cv/op_api/lib" | ||
| 1622 | - cust_aclnnop_paths="${ASCEND_HOME_PATH}/opp/vendors/${VENDOR}_cv/op_api/include/aclnnop" | ||
| 1623 | - fi | ||
| 1624 | - | ||
| 1625 | - for aclnnop_path in ${cust_aclnnop_paths}; do | ||
| 1626 | - local include_dir=$(dirname ${aclnnop_path}) | ||
| 1627 | - local include_dir_mode=$(stat -c %a ${include_dir} 2>/dev/null) | ||
| 1628 | - if [ ! -L ${aclnnop_path} ]; then | ||
| 1629 | - chmod u+w ${include_dir} 2>/dev/null | ||
| 1630 | - ln -s ${include_dir} ${aclnnop_path} 2>/dev/null | ||
| 1631 | - fi | ||
| 1632 | - done | ||
| 1633 | - | ||
| 1634 | - if [[ -n "$sim_lib_path" ]]; then | ||
| 1635 | - export LD_LIBRARY_PATH=${sim_lib_path}:${LD_LIBRARY_PATH} | ||
| 1636 | - ln -sf ${sim_lib_path}/libruntime_camodel.so ${sim_lib_path}/libruntime.so | ||
| 1637 | - ln -sf ${sim_lib_path}/libnpu_drv_camodel.so ${sim_lib_path}/libascend_hal.so | ||
| 1638 | - g++ ${f} \ | ||
| 1639 | - ${cust_include_flags} \ | ||
| 1640 | - -I ${INCLUDE_PATH} \ | ||
| 1641 | - -I ${INCLUDE_PATH}/aclnnop \ | ||
| 1642 | - ${cust_library_flags} \ | ||
| 1643 | - -L ${EAGER_LIBRARY_PATH} \ | ||
| 1644 | - -lcust_opapi -lascendcl -lnnopbase \ | ||
| 1645 | - -L ${sim_lib_path} \ | ||
| 1646 | - -lruntime_camodel -lnpu_drv_camodel \ | ||
| 1647 | - -o test_aclnn_${EXAMPLE_NAME} \ | ||
| 1648 | - -Wl,-rpath=${cust_rpath_flags}:${sim_lib_path} | ||
| 1649 | - else | ||
| 1650 | - g++ ${f} \ | ||
| 1651 | - ${cust_include_flags} \ | ||
| 1652 | - -I ${INCLUDE_PATH} \ | ||
| 1653 | - -I ${INCLUDE_PATH}/aclnnop \ | ||
| 1654 | - ${cust_library_flags} \ | ||
| 1655 | - -L ${EAGER_LIBRARY_PATH} \ | ||
| 1656 | - -lcust_opapi -lascendcl -lnnopbase \ | ||
| 1657 | - -o test_aclnn_${EXAMPLE_NAME} \ | ||
| 1658 | - -Wl,-rpath=${cust_rpath_flags} | ||
| 1659 | - fi | ||
| 1660 | - | ||
| 1661 | - for aclnnop_path in ${cust_aclnnop_paths}; do | ||
| 1662 | - if [ -L ${aclnnop_path} ]; then | ||
| 1663 | - local include_dir=$(dirname ${aclnnop_path}) | ||
| 1664 | - local include_dir_mode=$(stat -c %a ${include_dir} 2>/dev/null) | ||
| 1665 | - rm ${aclnnop_path} 2>/dev/null | ||
| 1666 | - chmod ${include_dir_mode} ${include_dir} 2>/dev/null | ||
| 1667 | - fi | ||
| 1668 | - done | ||
| 1669 | - | ||
| 1670 | - else | ||
| 1671 | - echo "Error: pkg_mode(${PKG_MODE}) must be cust." | ||
| 1672 | - exit 1 | ||
| 1673 | - fi | ||
| 1674 | - | ||
| 1675 | - if [[ -n "$sim_lib_path" ]]; then | ||
| 1676 | - ASCEND_SLOG_PRINT_TO_STDOUT=${ASCEND_SLOG_PRINT_TO_STDOUT:-0} \ | ||
| 1677 | - ASCEND_GLOBAL_LOG_LEVEL=${ASCEND_GLOBAL_LOG_LEVEL:-3} \ | ||
| 1678 | - ./test_aclnn_${EXAMPLE_NAME} | ||
| 1679 | - else | ||
| 1680 | - ./test_aclnn_${EXAMPLE_NAME} | ||
| 1681 | - fi | ||
| 1682 | - | ||
| 1683 | - if [ $? -eq 0 ]; then | ||
| 1684 | - echo "run test_aclnn_${EXAMPLE_NAME}, execute samples success" | ||
| 1685 | - else | ||
| 1686 | - echo "run test_aclnn_${EXAMPLE_NAME}, execute samples failed" | ||
| 1687 | - exit 1 | ||
| 1688 | - fi | ||
| 1689 | - done | ||
| 1690 | -} | ||
| 1691 | - | ||
| 1692 | -get_simulator_chip_version() { | ||
| 1693 | - local soc=$1 | ||
| 1694 | - case "$soc" in | ||
| 1695 | - ascend910) echo "dav_1001" ;; | ||
| 1696 | - ascend910_93|ascend910b) echo "dav_2201" ;; | ||
| 1697 | - ascend310p) echo "dav_2002" ;; | ||
| 1698 | - ascend310b) echo "dav_3002" ;; | ||
| 1699 | - ascend950) echo "dav_3510" ;; | ||
| 1700 | - *) | ||
| 1701 | - echo "[ERROR] Unsupported soc version for simulator: $soc" >&2 | ||
| 1702 | - return 1 | ||
| 1703 | - ;; | ||
| 1704 | - esac | ||
| 1705 | -} | ||
| 1706 | - | ||
| 1707 | -get_simulator_args() { | ||
| 1708 | - if [[ "$ENABLE_SIMULATOR" == "FALSE" ]]; then | ||
| 1709 | - return 0 | ||
| 1710 | - fi | ||
| 1711 | - if [[ "$ENABLE_SIMULATOR" == "TRUE" ]] && [[ -n "$COMPUTE_UNIT" ]]; then | ||
| 1712 | - local chip_version | ||
| 1713 | - chip_version=$(get_simulator_chip_version "$COMPUTE_UNIT") | ||
| 1714 | - if [[ $? -ne 0 ]]; then | ||
| 1715 | - exit 1 | ||
| 1716 | - fi | ||
| 1717 | - if [[ -n "$chip_version" ]]; then | ||
| 1718 | - local sim_lib_path="${ASCEND_HOME_PATH}/tools/simulator/${chip_version}/lib" | ||
| 1719 | - if [[ ! -d "$sim_lib_path" ]]; then | ||
| 1720 | - echo "[ERROR] Simulator lib path not found: $sim_lib_path" >&2 | ||
| 1721 | - exit 1 | ||
| 1722 | - else | ||
| 1723 | - echo "[INFO] Successfully linked simulator libraries: ${sim_lib_path}/libruntime_camodel.so, ${sim_lib_path}/libnpu_drv_camodel.so" >&2 | ||
| 1724 | - fi | ||
| 1725 | - echo "$sim_lib_path" | ||
| 1726 | - return 0 | ||
| 1727 | - fi | ||
| 1728 | - fi | ||
| 1729 | - echo "" | ||
| 1730 | - return 1 | ||
| 1731 | -} | ||
| 1732 | - | ||
| 1733 | -####################################### | ||
| 1734 | -# graph mode | ||
| 1735 | -####################################### | ||
| 1736 | -build_example_graph() { | ||
| 1737 | - local file | ||
| 1738 | - | ||
| 1739 | - if [[ "$ENABLE_EXPERIMENTAL" == "TRUE" ]]; then | ||
| 1740 | - file=$(find ../experimental -path "*/${EXAMPLE_NAME}/examples/*" -name test_geir_*.cpp) | ||
| 1741 | - else | ||
| 1742 | - file=$(find ../ -path "*/${EXAMPLE_NAME}/examples/*" -name test_geir_*.cpp -not -path "*/experimental/*") | ||
| 1743 | - if [[ "$COMPUTE_UNIT" == "ascend950" ]]; then | ||
| 1744 | - file+=($(find ../ -path "*/${EXAMPLE_NAME}/examples/arch35/*" -name test_geir_*.cpp)) | ||
| 1745 | - fi | ||
| 1746 | - fi | ||
| 1747 | - | ||
| 1748 | - if [ -z "$file" ]; then | ||
| 1749 | - echo "ERROR: ${EXAMPLE_NAME} do not have graph examples" | ||
| 1750 | - exit 1 | ||
| 1751 | - fi | ||
| 1752 | - | ||
| 1753 | - for f in $file; do | ||
| 1754 | - echo "Start compile and run examples file: $f" | ||
| 1755 | - | ||
| 1756 | - g++ ${f} \ | ||
| 1757 | - -I ${GRAPH_INCLUDE_PATH} \ | ||
| 1758 | - -I ${GE_INCLUDE_PATH} \ | ||
| 1759 | - -I ${INCLUDE_PATH} \ | ||
| 1760 | - -I ${INC_INCLUDE_PATH} \ | ||
| 1761 | - -I ${BASE_PATH}/common/inc \ | ||
| 1762 | - -I ${CP_GRAPH_INCLUDE_PATH} \ | ||
| 1763 | - -I ${CP_GE_INCLUDE_PATH} \ | ||
| 1764 | - -I ${CP_GE_EXTERNAL_INCLUDE_PATH} \ | ||
| 1765 | - -L ${GRAPH_LIBRARY_STUB_PATH} \ | ||
| 1766 | - -L ${GRAPH_LIBRARY_PATH} \ | ||
| 1767 | - -L ${CP_GRAPH_LIBRARY_STUB_PATH} \ | ||
| 1768 | - -L ${CP_GRAPH_LIBRARY_PATH} \ | ||
| 1769 | - -L ${CP_EXECUTOR_LIBRARY_PATH} \ | ||
| 1770 | - -lgraph -lge_runner -lgraph_base -lge_compiler \ | ||
| 1771 | - -o test_geir_${EXAMPLE_NAME} | ||
| 1772 | - | ||
| 1773 | - ./test_geir_${EXAMPLE_NAME} | ||
| 1774 | - | ||
| 1775 | - if [ $? -eq 0 ]; then | ||
| 1776 | - echo "run test_geir_${EXAMPLE_NAME}, execute samples success" | ||
| 1777 | - else | ||
| 1778 | - echo "run test_geir_${EXAMPLE_NAME}, execute samples failed" | ||
| 1779 | - exit 1 | ||
| 1780 | - fi | ||
| 1781 | - done | ||
| 1782 | -} | ||
| 1783 | - | ||
| 1784 | -gen_op() { | ||
| 1785 | - if [[ -z "$GENOP_NAME" ]] || [[ -z "$GENOP_TYPE" ]]; then | ||
| 1786 | - echo "Error: op_class or op_name is not set." | ||
| 1787 | - usage "genop" | ||
| 1788 | - fi | ||
| 1789 | - | ||
| 1790 | - echo $dotted_line | ||
| 1791 | - echo "Start to create the initial directory for ${GENOP_NAME} under ${GENOP_TYPE}" | ||
| 1792 | - | ||
| 1793 | - # 检查 python 或 python3 是否存在 | ||
| 1794 | - local python_cmd="" | ||
| 1795 | - if command -v python3 &> /dev/null; then | ||
| 1796 | - python_cmd="python3" | ||
| 1797 | - elif command -v python &> /dev/null; then | ||
| 1798 | - python_cmd="python" | ||
| 1799 | - fi | ||
| 1800 | - | ||
| 1801 | - if [ -n "${python_cmd}" ]; then | ||
| 1802 | - ${python_cmd} "${BASE_PATH}/scripts/opgen/opgen_standalone.py" -t ${GENOP_TYPE} -n ${GENOP_NAME} -p ${GENOP_BASE} | ||
| 1803 | - echo "Create the initial directory for ${GENOP_NAME} under ${GENOP_TYPE} success" | ||
| 1804 | - return $? | ||
| 1805 | - else | ||
| 1806 | - echo "Please install Python to generate op project framework." | ||
| 1807 | - fi | ||
| 1808 | -} | ||
| 1809 | - | ||
| 1810 | -gen_aicpu_op() { | ||
| 1811 | - if [[ -z "$GENOP_NAME" ]] || [[ -z "$GENOP_TYPE" ]]; then | ||
| 1812 | - echo "Error: op_class or op_name is not set." | ||
| 1813 | - usage "genop" | ||
| 1814 | - fi | ||
| 1815 | - | ||
| 1816 | - echo $dotted_line | ||
| 1817 | - echo "Start to create the AI CPU initial directory for ${GENOP_NAME} under ${GENOP_TYPE}" | ||
| 1818 | - | ||
| 1819 | - # 检查 python 或 python3 是否存在 | ||
| 1820 | - local python_cmd="" | ||
| 1821 | - if command -v python3 &> /dev/null; then | ||
| 1822 | - python_cmd="python3" | ||
| 1823 | - elif command -v python &> /dev/null; then | ||
| 1824 | - python_cmd="python" | ||
| 1825 | - fi | ||
| 1826 | - | ||
| 1827 | - if [ -n "${python_cmd}" ]; then | ||
| 1828 | - ${python_cmd} "${BASE_PATH}/scripts/opgen/opgen_standalone.py" -t ${GENOP_TYPE} -n ${GENOP_NAME} -p ${GENOP_BASE} -v aicpu | ||
| 1829 | - echo "Create the AI CPU initial directory for ${GENOP_NAME} under ${GENOP_TYPE} success" | ||
| 1830 | - return $? | ||
| 1831 | - else | ||
| 1832 | - echo "Please install Python to generate op project framework." | ||
| 1833 | - fi | ||
| 1834 | -} | ||
| 1835 | - | ||
| 1836 | -package_static() { | ||
| 1837 | - # Check weather BUILD_OUT_PATH directory exists | ||
| 1838 | - if [ ! -d "$BUILD_OUT_PATH" ]; then | ||
| 1839 | - echo "Error: Directory $BUILD_OUT_PATH does not exist" | ||
| 1840 | - return 1 | ||
| 1841 | - fi | ||
| 1842 | - | ||
| 1843 | - # Check weather *.run is exists and verify the file numbers | ||
| 1844 | - local run_files=("$BUILD_OUT_PATH"/*.run) | ||
| 1845 | - if [ ${#run_files[@]} -eq 0 ]; then | ||
| 1846 | - echo "Error: No .run files found in $BUILD_OUT_PATH directory" | ||
| 1847 | - return 1 | ||
| 1848 | - fi | ||
| 1849 | - if [ ${#run_files[@]} -gt 1 ]; then | ||
| 1850 | - echo "Error: Multiple .run files found in $BUILD_OUT_PATH directory:" | ||
| 1851 | - printf '%s\n' "${run_files[@]}" | ||
| 1852 | - return 1 | ||
| 1853 | - fi | ||
| 1854 | - | ||
| 1855 | - # Get filename of *.run file and set new directory name | ||
| 1856 | - local run_file=$(basename "${run_files[0]}") | ||
| 1857 | - if [[ "$run_file" != *"ops-cv"* ]]; then | ||
| 1858 | - echo "Error: Filename '$run_file' does not contain 'ops-cv'" | ||
| 1859 | - return 1 | ||
| 1860 | - fi | ||
| 1861 | - local new_name="${run_file/ops-cv/ops-cv-static}" | ||
| 1862 | - new_name="${new_name%.run}" | ||
| 1863 | - | ||
| 1864 | - # Check weather $BUILD_PATH/static_library_files directory exists and not empty | ||
| 1865 | - local static_files_dir="$BUILD_PATH/static_library_files" | ||
| 1866 | - if [ ! -d "$static_files_dir" ]; then | ||
| 1867 | - return 0 | ||
| 1868 | - fi | ||
| 1869 | - if [ -z "$(ls -A "$static_files_dir")" ]; then | ||
| 1870 | - echo "Error: Directory $static_files_dir is empty" | ||
| 1871 | - return 1 | ||
| 1872 | - fi | ||
| 1873 | - | ||
| 1874 | - # Rename directory | ||
| 1875 | - local new_dir_path="$BUILD_PATH/$new_name" | ||
| 1876 | - if mv "$static_files_dir" "$new_dir_path"; then | ||
| 1877 | - echo "Preparing for packaging: renamed $static_files_dir to $new_dir_path" | ||
| 1878 | - else | ||
| 1879 | - echo "Packaging preparation failed: directory rename failed ($static_files_dir -> $new_dir_path)" | ||
| 1880 | - return 1 | ||
| 1881 | - fi | ||
| 1882 | - | ||
| 1883 | - # Create compressed package and restore directory name | ||
| 1884 | - local new_filename="${new_name}.tar.gz" | ||
| 1885 | - if tar -czf "$BUILD_OUT_PATH/$new_filename" -C "$BUILD_PATH" "$new_name"; then | ||
| 1886 | - echo "[SUCCESS] Build static lib success!" | ||
| 1887 | - echo "Successfully created compressed package: $BUILD_OUT_PATH/$new_filename" | ||
| 1888 | - # Restore original directory name | ||
| 1889 | - echo "Restoring original directory name: $new_dir_path -> $static_files_dir" | ||
| 1890 | - mv "$new_dir_path" "$static_files_dir" | ||
| 1891 | - return 0 | ||
| 1892 | - else | ||
| 1893 | - echo "Error: Failed to create compressed package" | ||
| 1894 | - # Attempt to restore original directory name | ||
| 1895 | - mv "$new_dir_path" "$static_files_dir" | ||
| 1896 | - return 1 | ||
| 1897 | - fi | ||
| 1898 | -} | ||
| 1899 | 25 | ||
| 1900 | main() { | 26 | main() { |
| 1901 | checkopts "$@" | 27 | checkopts "$@" |
| @@ -1933,8 +59,8 @@ main() { | |||
| 1933 | fi | 59 | fi |
| 1934 | } | 60 | } |
| 1935 | 61 | ||
| 1936 | -set -o pipefail | ||
| 1937 | if [ $# -eq 0 ]; then | 62 | if [ $# -eq 0 ]; then |
| 1938 | usage | 63 | usage |
| 1939 | fi | 64 | fi |
| 65 | +set -o pipefail | ||
| 1940 | main "$@" | while IFS= read -r line; do echo "$(date '+[%Y-%m-%d %H:%M:%S]') $line"; done | 66 | main "$@" | while IFS= read -r line; do echo "$(date '+[%Y-%m-%d %H:%M:%S]') $line"; done |
| @@ -0,0 +1,41 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | +# | ||
| 12 | +# Build clean functions. | ||
| 13 | + | ||
| 14 | +clean_build() { | ||
| 15 | + if [ -d "${BUILD_PATH}" ]; then | ||
| 16 | + rm -rf "${BUILD_PATH}"/* | ||
| 17 | + fi | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +clean_build_out() { | ||
| 21 | + if [ -d "${BUILD_OUT_PATH}" ]; then | ||
| 22 | + rm -rf "${BUILD_OUT_PATH}"/* | ||
| 23 | + fi | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +clean_build_binary() { | ||
| 27 | + if [ -d "${BUILD_PATH}/tbe" ]; then | ||
| 28 | + rm -rf "${BUILD_PATH}/tbe/" | ||
| 29 | + fi | ||
| 30 | + if [ -d "${BUILD_PATH}/autogen" ]; then | ||
| 31 | + rm -rf "${BUILD_PATH}/autogen/" | ||
| 32 | + fi | ||
| 33 | + if [ -d "${BUILD_PATH}/binary" ]; then | ||
| 34 | + rm -rf "${BUILD_PATH}/binary/" | ||
| 35 | + fi | ||
| 36 | + if [[ "$ENABLE_STATIC" == "TRUE" ]]; then | ||
| 37 | + if [ -d "${BUILD_PATH}/static_library_files" ]; then | ||
| 38 | + rm -rf "${BUILD_PATH}/static_library_files/" | ||
| 39 | + fi | ||
| 40 | + fi | ||
| 41 | +} | ||
| @@ -0,0 +1,147 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | +# | ||
| 12 | +# CMake argument assembly and project initialization. | ||
| 13 | + | ||
| 14 | +custom_cmake_args() { | ||
| 15 | + if [[ -n $COMPILED_OPS ]]; then | ||
| 16 | + COMPILED_OPS="${COMPILED_OPS//,/;}" | ||
| 17 | + CMAKE_ARGS="$CMAKE_ARGS -DASCEND_OP_NAME=$COMPILED_OPS" | ||
| 18 | + fi | ||
| 19 | + if [[ -n $VENDOR_NAME ]]; then | ||
| 20 | + CMAKE_ARGS="$CMAKE_ARGS -DVENDOR_NAME=$VENDOR_NAME" | ||
| 21 | + fi | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +assemble_cmake_args() { | ||
| 25 | + if [[ "$ENABLE_ASAN" == "TRUE" ]]; then | ||
| 26 | + set +e | ||
| 27 | + echo 'int main() {return 0;}' | gcc -x c -fsanitize=address - -o asan_test >/dev/null 2>&1 | ||
| 28 | + if [ $? -ne 0 ]; then | ||
| 29 | + echo "This environment does not have the ASAN library, no need enable ASAN" | ||
| 30 | + ENABLE_ASAN=FALSE | ||
| 31 | + else | ||
| 32 | + $(rm -f asan_test) | ||
| 33 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_ASAN=TRUE" | ||
| 34 | + fi | ||
| 35 | + set -e | ||
| 36 | + fi | ||
| 37 | + if [[ "$ENABLE_VALGRIND" == "TRUE" ]]; then | ||
| 38 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_VALGRIND=TRUE" | ||
| 39 | + fi | ||
| 40 | + if [[ -n "$BUILD_TYPE" ]]; then | ||
| 41 | + CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=${BUILD_TYPE}" | ||
| 42 | + fi | ||
| 43 | + if [[ "$ENABLE_MSSANITIZER" == "TRUE" ]]; then | ||
| 44 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_MSSANITIZER=TRUE" | ||
| 45 | + fi | ||
| 46 | + if [[ "$ENABLE_OOM" == "TRUE" ]]; then | ||
| 47 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_OOM=TRUE" | ||
| 48 | + fi | ||
| 49 | + if [[ "$DISABLE_AICPU" == "TRUE" ]]; then | ||
| 50 | + CMAKE_ARGS="$CMAKE_ARGS -DDISABLE_AICPU=TRUE" | ||
| 51 | + fi | ||
| 52 | + if [[ "$ENABLE_DUMP_CCE" == "TRUE" ]]; then | ||
| 53 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_DUMP_CCE=TRUE" | ||
| 54 | + fi | ||
| 55 | + if [[ "x$BISHENG_FLAGS" != "x" ]]; then | ||
| 56 | + CMAKE_ARGS="$CMAKE_ARGS -DBISHENG_FLAGS=${BISHENG_FLAGS}" | ||
| 57 | + fi | ||
| 58 | + if [[ "$KERNEL_TEMPLATE_INPUT" != "" ]]; then | ||
| 59 | + CMAKE_ARGS="$CMAKE_ARGS -DKERNEL_TEMPLATE_INPUT=$KERNEL_TEMPLATE_INPUT" | ||
| 60 | + fi | ||
| 61 | + if [[ "$ENABLE_TEST" == "TRUE" ]]; then | ||
| 62 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_TEST=TRUE" | ||
| 63 | + custom_cmake_args | ||
| 64 | + fi | ||
| 65 | + if [[ "$ENABLE_UT_EXEC" == "TRUE" ]]; then | ||
| 66 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_UT_EXEC=TRUE" | ||
| 67 | + fi | ||
| 68 | + if [[ "$ENABLE_COVERAGE" == "TRUE" ]]; then | ||
| 69 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_COVERAGE=TRUE" | ||
| 70 | + fi | ||
| 71 | + if [[ "$ENABLE_BINARY" == "TRUE" ]]; then | ||
| 72 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_BINARY=TRUE" | ||
| 73 | + fi | ||
| 74 | + if [[ "$ENABLE_CUSTOM" == "TRUE" ]]; then | ||
| 75 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_CUSTOM=TRUE -DENABLE_BINARY=TRUE" | ||
| 76 | + custom_cmake_args | ||
| 77 | + fi | ||
| 78 | + if [[ "$ENABLE_PACKAGE" == "TRUE" ]]; then | ||
| 79 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_PACKAGE=TRUE -DPACKAGE_TYPE=${PACKAGE_TYPE}" | ||
| 80 | + fi | ||
| 81 | + if [[ "$ENABLE_EXPERIMENTAL" == "TRUE" ]]; then | ||
| 82 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_EXPERIMENTAL=TRUE" | ||
| 83 | + fi | ||
| 84 | + if [[ "$ENABLE_STATIC" == "TRUE" ]]; then | ||
| 85 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_STATIC=${ENABLE_STATIC}" | ||
| 86 | + fi | ||
| 87 | + if [[ "x$BUILD_MODE" != "x" ]]; then | ||
| 88 | + CMAKE_ARGS="$CMAKE_ARGS -DBUILD_MODE=${BUILD_MODE}" | ||
| 89 | + fi | ||
| 90 | + if [[ "$OP_HOST_UT" == "TRUE" ]]; then | ||
| 91 | + CMAKE_ARGS="$CMAKE_ARGS -DOP_HOST_UT=TRUE" | ||
| 92 | + fi | ||
| 93 | + if [[ "$OP_API_UT" == "TRUE" ]]; then | ||
| 94 | + CMAKE_ARGS="$CMAKE_ARGS -DOP_API_UT=TRUE" | ||
| 95 | + fi | ||
| 96 | + if [[ "$OP_GRAPH_UT" == "TRUE" ]]; then | ||
| 97 | + CMAKE_ARGS="$CMAKE_ARGS -DOP_GRAPH_UT=TRUE" | ||
| 98 | + fi | ||
| 99 | + if [[ "$OP_KERNEL_UT" == "TRUE" ]]; then | ||
| 100 | + CMAKE_ARGS="$CMAKE_ARGS -DOP_KERNEL_UT=TRUE" | ||
| 101 | + fi | ||
| 102 | + if [[ "$OP_KERNEL_AICPU_UT" == "TRUE" ]]; then | ||
| 103 | + CMAKE_ARGS="$CMAKE_ARGS -DOP_KERNEL_AICPU_UT=TRUE" | ||
| 104 | + fi | ||
| 105 | + if [[ "$UT_TEST_ALL" == "TRUE" ]]; then | ||
| 106 | + CMAKE_ARGS="$CMAKE_ARGS -DUT_TEST_ALL=TRUE" | ||
| 107 | + fi | ||
| 108 | + if [[ -n $COMPUTE_UNIT ]]; then | ||
| 109 | + COMPUTE_UNIT=$(normalize_compute_unit "$COMPUTE_UNIT") | ||
| 110 | + found=0 | ||
| 111 | + for support_unit in "${SUPPORT_COMPUTE_UNIT_SHORT[@]}"; do | ||
| 112 | + if [[ "$COMPUTE_UNIT" == "$support_unit" ]]; then | ||
| 113 | + COMPUTE_UNIT_SHORT=$support_unit | ||
| 114 | + found=1 | ||
| 115 | + break | ||
| 116 | + fi | ||
| 117 | + done | ||
| 118 | + if [[ $found -eq 0 ]]; then | ||
| 119 | + echo "soc only support : ${SUPPORT_COMPUTE_UNIT_SHORT[@]}" | ||
| 120 | + exit 1 | ||
| 121 | + fi | ||
| 122 | + echo "COMPUTE_UNIT: ${COMPUTE_UNIT}" | ||
| 123 | + CMAKE_ARGS="$CMAKE_ARGS -DASCEND_COMPUTE_UNIT=$COMPUTE_UNIT" | ||
| 124 | + fi | ||
| 125 | + if [[ "x$ENABLE_RULE_LAUNCH" != "x" ]]; then | ||
| 126 | + CMAKE_ARGS="$CMAKE_ARGS -DRULE_LAUNCH=${ENABLE_RULE_LAUNCH}" | ||
| 127 | + fi | ||
| 128 | + CMAKE_ARGS="$CMAKE_ARGS -DENABLE_CCACHE=${ENABLE_CCACHE}" | ||
| 129 | + CMAKE_ARGS="$CMAKE_ARGS -DCANN_3RD_LIB_PATH=${CANN_3RD_LIB_PATH}" | ||
| 130 | + CMAKE_ARGS="$CMAKE_ARGS -DASCEND_INSTALL_PATH=${ASCEND_INSTALL_PATH}" | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | +cmake_init() { | ||
| 134 | + if [[ "$ENABLE_GENOP" == "TRUE" || "$ENABLE_GENOP_AICPU" == "TRUE" ]]; then | ||
| 135 | + return | ||
| 136 | + fi | ||
| 137 | + if [ ! -d "${BUILD_PATH}" ]; then | ||
| 138 | + mkdir -p "${BUILD_PATH}" | ||
| 139 | + fi | ||
| 140 | + if [ ! -d "${BUILD_OUT_PATH}" ]; then | ||
| 141 | + mkdir -p "${BUILD_OUT_PATH}" | ||
| 142 | + fi | ||
| 143 | + | ||
| 144 | + [ -f "${BUILD_PATH}/CMakeCache.txt" ] && rm -f "${BUILD_PATH}/CMakeCache.txt" | ||
| 145 | + | ||
| 146 | + cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} .. | ||
| 147 | +} | ||
| @@ -0,0 +1,163 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | +# | ||
| 12 | +# Global config: variables, paths, utility functions shared across all build scripts. | ||
| 13 | + | ||
| 14 | +RELEASE_TARGETS=("ophost" "opapi" "opgraph" "opkernel" "opkernel_aicpu" "onnxplugin") | ||
| 15 | +SUPPORTED_UT_TARGETS=("ophost_test" "opapi_test" "opgraph_test" "opkernel_test" "opkernel_aicpu_test") | ||
| 16 | +SUPPORT_COMPUTE_UNIT_SHORT=("ascend031" "ascend035" "ascend310b" "ascend310p" "ascend610lite" "ascend630" | ||
| 17 | + "ascend910_93" "ascend950" "ascend910b" "ascend910" "mc62" "kirinx90" "kirin9030") | ||
| 18 | + | ||
| 19 | +# 所有支持的短选项 | ||
| 20 | +SUPPORTED_SHORT_OPTS="hj:vO:uf:-:" | ||
| 21 | + | ||
| 22 | +# 所有支持的长选项 | ||
| 23 | +SUPPORTED_LONG_OPTS=( | ||
| 24 | + "help" "ops=" "soc=" "vendor_name=" "build-type=" "cov" "noexec" "aicpu" "noaicpu" "opkernel" "opkernel_aicpu" "jit" | ||
| 25 | + "pkg" "asan" "valgrind" "make_clean" "static" "simulator" | ||
| 26 | + "ophost" "opapi" "opgraph" "ophost_test" "opapi_test" "opgraph_test" "opkernel_test" "opkernel_aicpu_test" | ||
| 27 | + "run_example" "genop=" "genop_aicpu=" "cann_3rd_lib_path" "experimental" "mssanitizer" "oom" "onnxplugin" "dump_cce" | ||
| 28 | + "bisheng_flags=" "kernel_template_input=" "rule_launch=" "ccache=" "pkg-type=" | ||
| 29 | +) | ||
| 30 | + | ||
| 31 | +dotted_line="----------------------------------------------------------------" | ||
| 32 | +export BUILD_PATH="${BASE_PATH}/build" | ||
| 33 | +export BUILD_OUT_PATH="${BASE_PATH}/build_out" | ||
| 34 | +REPOSITORY_NAME="cv" | ||
| 35 | + | ||
| 36 | +CORE_NUMS=$(nproc 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || grep -c "processor" /proc/cpuinfo 2>/dev/null || echo 8) | ||
| 37 | +ARCH_INFO=$(uname -m) | ||
| 38 | +CANN_3RD_LIB_PATH="${BASE_PATH}/third_party" | ||
| 39 | + | ||
| 40 | +if [ -z "$ASCEND_INSTALL_PATH" ]; then | ||
| 41 | + if [ -n "$ASCEND_HOME_PATH" ]; then | ||
| 42 | + ASCEND_INSTALL_PATH="$ASCEND_HOME_PATH" | ||
| 43 | + else | ||
| 44 | + ASCEND_INSTALL_PATH="/usr/local/Ascend/cann" | ||
| 45 | + fi | ||
| 46 | +fi | ||
| 47 | + | ||
| 48 | +# Base paths | ||
| 49 | +export INCLUDE_PATH="${ASCEND_HOME_PATH}/include" | ||
| 50 | +export LIB_PATH="${ASCEND_HOME_PATH}/lib64" | ||
| 51 | + | ||
| 52 | +# Include paths | ||
| 53 | +export ACLNN_INCLUDE_PATH="${INCLUDE_PATH}/aclnn" | ||
| 54 | +export GRAPH_INCLUDE_PATH="${INCLUDE_PATH}/graph" | ||
| 55 | +export CP_GRAPH_INCLUDE_PATH="${INCLUDE_PATH}/graph" | ||
| 56 | +export GE_INCLUDE_PATH="${INCLUDE_PATH}/ge" | ||
| 57 | +export CP_GE_INCLUDE_PATH="${INCLUDE_PATH}/ge" | ||
| 58 | +export CP_GE_EXTERNAL_INCLUDE_PATH="${INCLUDE_PATH}/external" | ||
| 59 | +export INC_INCLUDE_PATH="${ASCEND_OPP_PATH}/built-in/op_proto/inc" | ||
| 60 | + | ||
| 61 | +# Library paths | ||
| 62 | +export EAGER_LIBRARY_PATH="${LIB_PATH}" | ||
| 63 | +export GRAPH_LIBRARY_PATH="${LIB_PATH}" | ||
| 64 | +export CP_GRAPH_LIBRARY_PATH="${LIB_PATH}" | ||
| 65 | +export CP_EXECUTOR_LIBRARY_PATH="${LIB_PATH}" | ||
| 66 | + | ||
| 67 | +# Stub paths | ||
| 68 | +export GRAPH_LIBRARY_STUB_PATH="${LIB_PATH}/stub" | ||
| 69 | +export CP_GRAPH_LIBRARY_STUB_PATH="${LIB_PATH}/stub" | ||
| 70 | + | ||
| 71 | +in_array() { | ||
| 72 | + local needle="$1" | ||
| 73 | + shift | ||
| 74 | + local haystack=("$@") | ||
| 75 | + for item in "${haystack[@]}"; do | ||
| 76 | + if [[ "$item" == "$needle" ]]; then | ||
| 77 | + return 0 | ||
| 78 | + fi | ||
| 79 | + done | ||
| 80 | + return 1 | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +check_pkg_type() { | ||
| 84 | + local pkg_type="$1" | ||
| 85 | + if [[ "$pkg_type" != "run" && "$pkg_type" != "rpm" && "$pkg_type" != "deb" && "$pkg_type" != "all" ]]; then | ||
| 86 | + echo "[ERROR] --pkg-type only supports run/rpm/deb/all, got: $pkg_type" | ||
| 87 | + exit 1 | ||
| 88 | + fi | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +normalize_compute_unit() { | ||
| 92 | + local compute_unit="$1" | ||
| 93 | + local compute_unit_lower | ||
| 94 | + compute_unit_lower=$(echo "$compute_unit" | tr '[:upper:]' '[:lower:]') | ||
| 95 | + if [[ "$compute_unit_lower" =~ ^ascend950[0-9a-z_-]*$ ]]; then | ||
| 96 | + echo "ascend950" | ||
| 97 | + else | ||
| 98 | + echo "$compute_unit_lower" | ||
| 99 | + fi | ||
| 100 | +} | ||
| 101 | + | ||
| 102 | +check_option_validity() { | ||
| 103 | + local arg="$1" | ||
| 104 | + | ||
| 105 | + if [[ "$arg" =~ ^-[^-] ]]; then | ||
| 106 | + local opt_chars=${arg:1} | ||
| 107 | + | ||
| 108 | + local needs_arg_opts=$(echo "$SUPPORTED_SHORT_OPTS" | grep -o "[a-zA-Z]:" | tr -d ':') | ||
| 109 | + | ||
| 110 | + local i=0 | ||
| 111 | + while [ $i -lt ${#opt_chars} ]; do | ||
| 112 | + local char="${opt_chars:$i:1}" | ||
| 113 | + | ||
| 114 | + if [[ ! "$SUPPORTED_SHORT_OPTS" =~ "$char" ]]; then | ||
| 115 | + echo "[ERROR] Invalid short option: -$char" | ||
| 116 | + return 1 | ||
| 117 | + fi | ||
| 118 | + | ||
| 119 | + if [[ "$needs_arg_opts" =~ "$char" ]]; then | ||
| 120 | + while [ $i -lt ${#opt_chars} ] && [[ "${opt_chars:$i:1}" =~ [0-9a-zA-Z] ]]; do | ||
| 121 | + i=$((i + 1)) | ||
| 122 | + done | ||
| 123 | + else | ||
| 124 | + i=$((i + 1)) | ||
| 125 | + fi | ||
| 126 | + done | ||
| 127 | + return 0 | ||
| 128 | + fi | ||
| 129 | + | ||
| 130 | + if [[ "$arg" =~ ^-- ]]; then | ||
| 131 | + local long_opt="${arg:2}" | ||
| 132 | + local opt_name="${long_opt%%=*}" | ||
| 133 | + | ||
| 134 | + for supported_opt in "${SUPPORTED_LONG_OPTS[@]}"; do | ||
| 135 | + # with "=" in long options | ||
| 136 | + if [[ "$supported_opt" =~ =$ ]]; then | ||
| 137 | + local base_opt="${supported_opt%=}" | ||
| 138 | + if [[ "$opt_name" == "$base_opt" ]]; then | ||
| 139 | + return 0 | ||
| 140 | + fi | ||
| 141 | + else | ||
| 142 | + # without "=" in long options | ||
| 143 | + if [[ "$opt_name" == "$supported_opt" ]]; then | ||
| 144 | + return 0 | ||
| 145 | + fi | ||
| 146 | + fi | ||
| 147 | + done | ||
| 148 | + | ||
| 149 | + echo "[ERROR] Invalid long option: --$opt_name" | ||
| 150 | + return 1 | ||
| 151 | + fi | ||
| 152 | + | ||
| 153 | + return 0 | ||
| 154 | +} | ||
| 155 | + | ||
| 156 | +print_error() { | ||
| 157 | + echo | ||
| 158 | + echo $dotted_line | ||
| 159 | + local msg="$1" | ||
| 160 | + echo -e "\033[31m[ERROR] ${msg}\033[0m" | ||
| 161 | + echo $dotted_line | ||
| 162 | + echo | ||
| 163 | +} | ||
| @@ -0,0 +1,268 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | +# | ||
| 12 | +# Example build and run functions. | ||
| 13 | + | ||
| 14 | +build_example() { | ||
| 15 | + echo $dotted_line | ||
| 16 | + echo "Start to run examples,name:${EXAMPLE_NAME} mode:${EXAMPLE_MODE}" | ||
| 17 | + | ||
| 18 | + mkdir -p "${BUILD_PATH}" | ||
| 19 | + cd "${BUILD_PATH}" || exit 1 | ||
| 20 | + | ||
| 21 | + if [[ "${EXAMPLE_MODE}" == "eager" ]]; then | ||
| 22 | + build_example_eager | ||
| 23 | + elif [[ "${EXAMPLE_MODE}" == "graph" ]]; then | ||
| 24 | + build_example_graph | ||
| 25 | + else | ||
| 26 | + usage | ||
| 27 | + exit 1 | ||
| 28 | + fi | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +####################################### | ||
| 32 | +# eager mode | ||
| 33 | +####################################### | ||
| 34 | +build_example_eager() { | ||
| 35 | + local file | ||
| 36 | + local sim_lib_path | ||
| 37 | + sim_lib_path=$(get_simulator_args) | ||
| 38 | + local ret=$? | ||
| 39 | + if [ $ret -ne 0 ]; then | ||
| 40 | + exit 1 | ||
| 41 | + fi | ||
| 42 | + | ||
| 43 | + if [[ "$ENABLE_EXPERIMENTAL" == "TRUE" ]]; then | ||
| 44 | + file=$(find ../experimental -path "*/${EXAMPLE_NAME}/examples/*" -name test_aclnn_*.cpp) | ||
| 45 | + else | ||
| 46 | + file=$(find ../ -path "*/${EXAMPLE_NAME}/examples/*" -name test_aclnn_*.cpp -not -path "*/experimental/*") | ||
| 47 | + if [[ "$COMPUTE_UNIT" == "ascend950" ]]; then | ||
| 48 | + file+=($(find ../ -path "*/${EXAMPLE_NAME}/examples/arch35/*" -name test_aclnn_*.cpp)) | ||
| 49 | + fi | ||
| 50 | + fi | ||
| 51 | + | ||
| 52 | + if [ -z "$file" ]; then | ||
| 53 | + echo "ERROR: ${EXAMPLE_NAME} do not have eager examples" | ||
| 54 | + exit 1 | ||
| 55 | + fi | ||
| 56 | + | ||
| 57 | + for f in $file; do | ||
| 58 | + if [[ "${PKG_MODE}" == "cust" && "$f" == *add_example_aicpu* && "$f" == *opgen* ]]; then | ||
| 59 | + continue | ||
| 60 | + fi | ||
| 61 | + | ||
| 62 | + echo "Start compile and run examples file: $f" | ||
| 63 | + | ||
| 64 | + if [[ "${PKG_MODE}" == "" ]]; then | ||
| 65 | + if [[ -n "$sim_lib_path" ]]; then | ||
| 66 | + export LD_LIBRARY_PATH=${sim_lib_path}:${LD_LIBRARY_PATH} | ||
| 67 | + ln -sf ${sim_lib_path}/libruntime_camodel.so ${sim_lib_path}/libruntime.so | ||
| 68 | + ln -sf ${sim_lib_path}/libnpu_drv_camodel.so ${sim_lib_path}/libascend_hal.so | ||
| 69 | + g++ ${f} \ | ||
| 70 | + -I ${INCLUDE_PATH} \ | ||
| 71 | + -I ${ACLNN_INCLUDE_PATH} \ | ||
| 72 | + -L ${EAGER_LIBRARY_PATH} \ | ||
| 73 | + -lopapi_cv -lascendcl -lnnopbase \ | ||
| 74 | + -L ${sim_lib_path} \ | ||
| 75 | + -lruntime_camodel -lnpu_drv_camodel \ | ||
| 76 | + -o test_aclnn_${EXAMPLE_NAME} \ | ||
| 77 | + -Wl,-rpath=${sim_lib_path} | ||
| 78 | + else | ||
| 79 | + g++ ${f} \ | ||
| 80 | + -I ${INCLUDE_PATH} \ | ||
| 81 | + -I ${ACLNN_INCLUDE_PATH} \ | ||
| 82 | + -L ${EAGER_LIBRARY_PATH} \ | ||
| 83 | + -lopapi_cv -lascendcl -lnnopbase \ | ||
| 84 | + -o test_aclnn_${EXAMPLE_NAME} | ||
| 85 | + fi | ||
| 86 | + | ||
| 87 | + elif [[ "${PKG_MODE}" == "cust" ]]; then | ||
| 88 | + echo "pkg_mode:${PKG_MODE} vendor_name:${VENDOR}" | ||
| 89 | + | ||
| 90 | + local cust_include_flags="" | ||
| 91 | + local cust_library_flags="" | ||
| 92 | + local cust_rpath_flags="" | ||
| 93 | + local cust_aclnnop_paths="" | ||
| 94 | + | ||
| 95 | + if [[ -n "${ASCEND_CUSTOM_OPP_PATH}" ]]; then | ||
| 96 | + IFS=':' read -ra PATH_ARRAY <<< "${ASCEND_CUSTOM_OPP_PATH}" | ||
| 97 | + for path in "${PATH_ARRAY[@]}"; do | ||
| 98 | + cust_include_flags="${cust_include_flags} -I ${path}/op_api/include" | ||
| 99 | + cust_library_flags="${cust_library_flags} -L ${path}/op_api/lib" | ||
| 100 | + cust_rpath_flags="${cust_rpath_flags}:${path}/op_api/lib" | ||
| 101 | + cust_aclnnop_paths="${cust_aclnnop_paths} ${path}/op_api/include/aclnnop" | ||
| 102 | + done | ||
| 103 | + cust_rpath_flags="${cust_rpath_flags#:}" | ||
| 104 | + else | ||
| 105 | + cust_include_flags="-I ${ASCEND_HOME_PATH}/opp/vendors/${VENDOR}_cv/op_api/include" | ||
| 106 | + cust_library_flags="-L ${ASCEND_HOME_PATH}/opp/vendors/${VENDOR}_cv/op_api/lib" | ||
| 107 | + cust_rpath_flags="${ASCEND_HOME_PATH}/opp/vendors/${VENDOR}_cv/op_api/lib" | ||
| 108 | + cust_aclnnop_paths="${ASCEND_HOME_PATH}/opp/vendors/${VENDOR}_cv/op_api/include/aclnnop" | ||
| 109 | + fi | ||
| 110 | + | ||
| 111 | + for aclnnop_path in ${cust_aclnnop_paths}; do | ||
| 112 | + local include_dir=$(dirname ${aclnnop_path}) | ||
| 113 | + local include_dir_mode=$(stat -c %a ${include_dir} 2>/dev/null) | ||
| 114 | + if [ ! -L ${aclnnop_path} ]; then | ||
| 115 | + chmod u+w ${include_dir} 2>/dev/null | ||
| 116 | + ln -s ${include_dir} ${aclnnop_path} 2>/dev/null | ||
| 117 | + fi | ||
| 118 | + done | ||
| 119 | + | ||
| 120 | + if [[ -n "$sim_lib_path" ]]; then | ||
| 121 | + export LD_LIBRARY_PATH=${sim_lib_path}:${LD_LIBRARY_PATH} | ||
| 122 | + ln -sf ${sim_lib_path}/libruntime_camodel.so ${sim_lib_path}/libruntime.so | ||
| 123 | + ln -sf ${sim_lib_path}/libnpu_drv_camodel.so ${sim_lib_path}/libascend_hal.so | ||
| 124 | + g++ ${f} \ | ||
| 125 | + ${cust_include_flags} \ | ||
| 126 | + -I ${INCLUDE_PATH} \ | ||
| 127 | + -I ${INCLUDE_PATH}/aclnnop \ | ||
| 128 | + ${cust_library_flags} \ | ||
| 129 | + -L ${EAGER_LIBRARY_PATH} \ | ||
| 130 | + -lcust_opapi -lascendcl -lnnopbase \ | ||
| 131 | + -L ${sim_lib_path} \ | ||
| 132 | + -lruntime_camodel -lnpu_drv_camodel \ | ||
| 133 | + -o test_aclnn_${EXAMPLE_NAME} \ | ||
| 134 | + -Wl,-rpath=${cust_rpath_flags}:${sim_lib_path} | ||
| 135 | + else | ||
| 136 | + g++ ${f} \ | ||
| 137 | + ${cust_include_flags} \ | ||
| 138 | + -I ${INCLUDE_PATH} \ | ||
| 139 | + -I ${INCLUDE_PATH}/aclnnop \ | ||
| 140 | + ${cust_library_flags} \ | ||
| 141 | + -L ${EAGER_LIBRARY_PATH} \ | ||
| 142 | + -lcust_opapi -lascendcl -lnnopbase \ | ||
| 143 | + -o test_aclnn_${EXAMPLE_NAME} \ | ||
| 144 | + -Wl,-rpath=${cust_rpath_flags} | ||
| 145 | + fi | ||
| 146 | + | ||
| 147 | + for aclnnop_path in ${cust_aclnnop_paths}; do | ||
| 148 | + if [ -L ${aclnnop_path} ]; then | ||
| 149 | + local include_dir=$(dirname ${aclnnop_path}) | ||
| 150 | + local include_dir_mode=$(stat -c %a ${include_dir} 2>/dev/null) | ||
| 151 | + rm ${aclnnop_path} 2>/dev/null | ||
| 152 | + chmod ${include_dir_mode} ${include_dir} 2>/dev/null | ||
| 153 | + fi | ||
| 154 | + done | ||
| 155 | + | ||
| 156 | + else | ||
| 157 | + echo "Error: pkg_mode(${PKG_MODE}) must be cust." | ||
| 158 | + exit 1 | ||
| 159 | + fi | ||
| 160 | + | ||
| 161 | + if [[ -n "$sim_lib_path" ]]; then | ||
| 162 | + ASCEND_SLOG_PRINT_TO_STDOUT=${ASCEND_SLOG_PRINT_TO_STDOUT:-0} \ | ||
| 163 | + ASCEND_GLOBAL_LOG_LEVEL=${ASCEND_GLOBAL_LOG_LEVEL:-3} \ | ||
| 164 | + ./test_aclnn_${EXAMPLE_NAME} | ||
| 165 | + else | ||
| 166 | + ./test_aclnn_${EXAMPLE_NAME} | ||
| 167 | + fi | ||
| 168 | + | ||
| 169 | + if [ $? -eq 0 ]; then | ||
| 170 | + echo "run test_aclnn_${EXAMPLE_NAME}, execute samples success" | ||
| 171 | + else | ||
| 172 | + echo "run test_aclnn_${EXAMPLE_NAME}, execute samples failed" | ||
| 173 | + exit 1 | ||
| 174 | + fi | ||
| 175 | + done | ||
| 176 | +} | ||
| 177 | + | ||
| 178 | +get_simulator_chip_version() { | ||
| 179 | + local soc=$1 | ||
| 180 | + case "$soc" in | ||
| 181 | + ascend910) echo "dav_1001" ;; | ||
| 182 | + ascend910_93|ascend910b) echo "dav_2201" ;; | ||
| 183 | + ascend310p) echo "dav_2002" ;; | ||
| 184 | + ascend310b) echo "dav_3002" ;; | ||
| 185 | + ascend950) echo "dav_3510" ;; | ||
| 186 | + *) | ||
| 187 | + echo "[ERROR] Unsupported soc version for simulator: $soc" >&2 | ||
| 188 | + return 1 | ||
| 189 | + ;; | ||
| 190 | + esac | ||
| 191 | +} | ||
| 192 | + | ||
| 193 | +get_simulator_args() { | ||
| 194 | + if [[ "$ENABLE_SIMULATOR" == "FALSE" ]]; then | ||
| 195 | + return 0 | ||
| 196 | + fi | ||
| 197 | + if [[ "$ENABLE_SIMULATOR" == "TRUE" ]] && [[ -n "$COMPUTE_UNIT" ]]; then | ||
| 198 | + local chip_version | ||
| 199 | + chip_version=$(get_simulator_chip_version "$COMPUTE_UNIT") | ||
| 200 | + if [[ $? -ne 0 ]]; then | ||
| 201 | + exit 1 | ||
| 202 | + fi | ||
| 203 | + if [[ -n "$chip_version" ]]; then | ||
| 204 | + local sim_lib_path="${ASCEND_HOME_PATH}/tools/simulator/${chip_version}/lib" | ||
| 205 | + if [[ ! -d "$sim_lib_path" ]]; then | ||
| 206 | + echo "[ERROR] Simulator lib path not found: $sim_lib_path" >&2 | ||
| 207 | + exit 1 | ||
| 208 | + else | ||
| 209 | + echo "[INFO] Successfully linked simulator libraries: ${sim_lib_path}/libruntime_camodel.so, ${sim_lib_path}/libnpu_drv_camodel.so" >&2 | ||
| 210 | + fi | ||
| 211 | + echo "$sim_lib_path" | ||
| 212 | + return 0 | ||
| 213 | + fi | ||
| 214 | + fi | ||
| 215 | + echo "" | ||
| 216 | + return 1 | ||
| 217 | +} | ||
| 218 | + | ||
| 219 | +####################################### | ||
| 220 | +# graph mode | ||
| 221 | +####################################### | ||
| 222 | +build_example_graph() { | ||
| 223 | + local file | ||
| 224 | + | ||
| 225 | + if [[ "$ENABLE_EXPERIMENTAL" == "TRUE" ]]; then | ||
| 226 | + file=$(find ../experimental -path "*/${EXAMPLE_NAME}/examples/*" -name test_geir_*.cpp) | ||
| 227 | + else | ||
| 228 | + file=$(find ../ -path "*/${EXAMPLE_NAME}/examples/*" -name test_geir_*.cpp -not -path "*/experimental/*") | ||
| 229 | + if [[ "$COMPUTE_UNIT" == "ascend950" ]]; then | ||
| 230 | + file+=($(find ../ -path "*/${EXAMPLE_NAME}/examples/arch35/*" -name test_geir_*.cpp)) | ||
| 231 | + fi | ||
| 232 | + fi | ||
| 233 | + | ||
| 234 | + if [ -z "$file" ]; then | ||
| 235 | + echo "ERROR: ${EXAMPLE_NAME} do not have graph examples" | ||
| 236 | + exit 1 | ||
| 237 | + fi | ||
| 238 | + | ||
| 239 | + for f in $file; do | ||
| 240 | + echo "Start compile and run examples file: $f" | ||
| 241 | + | ||
| 242 | + g++ ${f} \ | ||
| 243 | + -I ${GRAPH_INCLUDE_PATH} \ | ||
| 244 | + -I ${GE_INCLUDE_PATH} \ | ||
| 245 | + -I ${INCLUDE_PATH} \ | ||
| 246 | + -I ${INC_INCLUDE_PATH} \ | ||
| 247 | + -I ${BASE_PATH}/common/inc \ | ||
| 248 | + -I ${CP_GRAPH_INCLUDE_PATH} \ | ||
| 249 | + -I ${CP_GE_INCLUDE_PATH} \ | ||
| 250 | + -I ${CP_GE_EXTERNAL_INCLUDE_PATH} \ | ||
| 251 | + -L ${GRAPH_LIBRARY_STUB_PATH} \ | ||
| 252 | + -L ${GRAPH_LIBRARY_PATH} \ | ||
| 253 | + -L ${CP_GRAPH_LIBRARY_STUB_PATH} \ | ||
| 254 | + -L ${CP_GRAPH_LIBRARY_PATH} \ | ||
| 255 | + -L ${CP_EXECUTOR_LIBRARY_PATH} \ | ||
| 256 | + -lgraph -lge_runner -lgraph_base -lge_compiler \ | ||
| 257 | + -o test_geir_${EXAMPLE_NAME} | ||
| 258 | + | ||
| 259 | + ./test_geir_${EXAMPLE_NAME} | ||
| 260 | + | ||
| 261 | + if [ $? -eq 0 ]; then | ||
| 262 | + echo "run test_geir_${EXAMPLE_NAME}, execute samples success" | ||
| 263 | + else | ||
| 264 | + echo "run test_geir_${EXAMPLE_NAME}, execute samples failed" | ||
| 265 | + exit 1 | ||
| 266 | + fi | ||
| 267 | + done | ||
| 268 | +} | ||
| @@ -0,0 +1,72 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | +# | ||
| 12 | +# Operator code generation functions. | ||
| 13 | + | ||
| 14 | +gen_op() { | ||
| 15 | + if [[ -z "$GENOP_NAME" ]] || [[ -z "$GENOP_TYPE" ]]; then | ||
| 16 | + echo "Error: op_class or op_name is not set." | ||
| 17 | + usage "genop" | ||
| 18 | + fi | ||
| 19 | + | ||
| 20 | + echo $dotted_line | ||
| 21 | + echo "Start to create the initial directory for ${GENOP_NAME} under ${GENOP_TYPE}" | ||
| 22 | + | ||
| 23 | + # 检查 python 或 python3 是否存在 | ||
| 24 | + local python_cmd="" | ||
| 25 | + if command -v python3 &> /dev/null; then | ||
| 26 | + python_cmd="python3" | ||
| 27 | + elif command -v python &> /dev/null; then | ||
| 28 | + python_cmd="python" | ||
| 29 | + fi | ||
| 30 | + | ||
| 31 | + if [ -n "${python_cmd}" ]; then | ||
| 32 | + ${python_cmd} "${BASE_PATH}/scripts/opgen/opgen_standalone.py" -t ${GENOP_TYPE} -n ${GENOP_NAME} -p ${GENOP_BASE} | ||
| 33 | + local ret=$? | ||
| 34 | + if [ $ret -eq 0 ]; then | ||
| 35 | + echo "Create the initial directory for ${GENOP_NAME} under ${GENOP_TYPE} success" | ||
| 36 | + fi | ||
| 37 | + return $ret | ||
| 38 | + else | ||
| 39 | + echo "Please install Python to generate op project framework." | ||
| 40 | + return 1 | ||
| 41 | + fi | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +gen_aicpu_op() { | ||
| 45 | + if [[ -z "$GENOP_NAME" ]] || [[ -z "$GENOP_TYPE" ]]; then | ||
| 46 | + echo "Error: op_class or op_name is not set." | ||
| 47 | + usage "genop" | ||
| 48 | + fi | ||
| 49 | + | ||
| 50 | + echo $dotted_line | ||
| 51 | + echo "Start to create the AI CPU initial directory for ${GENOP_NAME} under ${GENOP_TYPE}" | ||
| 52 | + | ||
| 53 | + # 检查 python 或 python3 是否存在 | ||
| 54 | + local python_cmd="" | ||
| 55 | + if command -v python3 &> /dev/null; then | ||
| 56 | + python_cmd="python3" | ||
| 57 | + elif command -v python &> /dev/null; then | ||
| 58 | + python_cmd="python" | ||
| 59 | + fi | ||
| 60 | + | ||
| 61 | + if [ -n "${python_cmd}" ]; then | ||
| 62 | + ${python_cmd} "${BASE_PATH}/scripts/opgen/opgen_standalone.py" -t ${GENOP_TYPE} -n ${GENOP_NAME} -p ${GENOP_BASE} -v aicpu | ||
| 63 | + local ret=$? | ||
| 64 | + if [ $ret -eq 0 ]; then | ||
| 65 | + echo "Create the AI CPU initial directory for ${GENOP_NAME} under ${GENOP_TYPE} success" | ||
| 66 | + fi | ||
| 67 | + return $ret | ||
| 68 | + else | ||
| 69 | + echo "Please install Python to generate op project framework." | ||
| 70 | + return 1 | ||
| 71 | + fi | ||
| 72 | +} | ||
| @@ -0,0 +1,286 @@ | |||
| 1 | +#!/bin/bash | ||
| 2 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 3 | +# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd. | ||
| 4 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | +# ----------------------------------------------------------------------------------------------------------- | ||
| 11 | +# | ||
| 12 | +# Library, binary, and package build functions. | ||
| 13 | + | ||
| 14 | +build_static_lib() { | ||
| 15 | + echo $dotted_line | ||
| 16 | + echo "Start to build static lib." | ||
| 17 | + | ||
| 18 | + cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} .. | ||
| 19 | + local all_targets=$(cmake --build . --target help) | ||
| 20 | + rm -fr "${BUILD_PATH}/bin_tmp" | ||
| 21 | + mkdir -p "${BUILD_PATH}/bin_tmp" | ||
| 22 | + if grep -wq "ophost_cv_static" <<< "${all_targets}"; then | ||
| 23 | + cmake --build . --target ophost_cv_static -- ${VERBOSE} -j $THREAD_NUM | ||
| 24 | + fi | ||
| 25 | + | ||
| 26 | + local UNITS=(${COMPUTE_UNIT_SHORT//;/ }) | ||
| 27 | + if [[ ${#UNITS[@]} -eq 0 ]]; then | ||
| 28 | + UNITS+=("ascend910b") | ||
| 29 | + fi | ||
| 30 | + if grep -wq "opapi_cv_static" <<< "${all_targets}"; then | ||
| 31 | + cmake --build . --target opapi_cv_static -- ${VERBOSE} -j $THREAD_NUM | ||
| 32 | + fi | ||
| 33 | + local jit_command="" | ||
| 34 | + if [[ "$ENABLE_JIT" == "TRUE" ]]; then | ||
| 35 | + jit_command="-j" | ||
| 36 | + fi | ||
| 37 | + for unit in "${UNITS[@]}"; do | ||
| 38 | + rm -fr "${BUILD_PATH}/bin_tmp/${unit}" | ||
| 39 | + python3 "${BASE_PATH}/scripts/util/build_opp_kernel_static.py" GenStaticOpResourceIni -s ${unit} -b "${BUILD_PATH}" ${jit_command} | ||
| 40 | + python3 "${BASE_PATH}/scripts/util/build_opp_kernel_static.py" StaticCompile -s ${unit} -b "${BUILD_PATH}" -n=0 -a=${ARCH_INFO} ${jit_command} | ||
| 41 | + done | ||
| 42 | + cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} .. | ||
| 43 | + if grep -wq "cann_cv_static" <<< "${all_targets}"; then | ||
| 44 | + cmake --build . --target cann_cv_static -- ${VERBOSE} -j $THREAD_NUM | ||
| 45 | + fi | ||
| 46 | + echo "Build static lib success!" | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +build_lib() { | ||
| 50 | + echo $dotted_line | ||
| 51 | + echo "Start to build libs ${BUILD_LIBS[@]}" | ||
| 52 | + | ||
| 53 | + git submodule init && git submodule update | ||
| 54 | + if [ ! -d "${BUILD_PATH}" ]; then | ||
| 55 | + mkdir -p "${BUILD_PATH}" | ||
| 56 | + fi | ||
| 57 | + | ||
| 58 | + cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} -UENABLE_STATIC .. | ||
| 59 | + | ||
| 60 | + for lib in "${BUILD_LIBS[@]}"; do | ||
| 61 | + echo "Building target ${lib}" | ||
| 62 | + cmake --build . --target ${lib} -- ${VERBOSE} -j $THREAD_NUM | ||
| 63 | + done | ||
| 64 | + | ||
| 65 | + echo $dotted_line | ||
| 66 | + echo "Build libs ${BUILD_LIBS[@]} success" | ||
| 67 | + echo $dotted_line | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +build_binary() { | ||
| 71 | + if [[ "$ENABLE_TEST" == "TRUE" ]]; then | ||
| 72 | + return | ||
| 73 | + fi | ||
| 74 | + | ||
| 75 | + echo $dotted_line | ||
| 76 | + echo "Start to build binary" | ||
| 77 | + | ||
| 78 | + if [ ! -d "${BUILD_PATH}" ]; then | ||
| 79 | + mkdir -p "${BUILD_PATH}" | ||
| 80 | + fi | ||
| 81 | + | ||
| 82 | + cd "${BUILD_PATH}" && cmake .. ${CMAKE_ARGS} | ||
| 83 | + | ||
| 84 | + echo "--------------- prepare build start ---------------" | ||
| 85 | + local all_targets=$(cmake --build . --target help) | ||
| 86 | + if echo "${all_targets}" | grep -wq "ascendc_impl_gen"; then | ||
| 87 | + cmake --build . --target ascendc_impl_gen -- ${VERBOSE} -j $THREAD_NUM || { | ||
| 88 | + echo "[ERROR] Failed to execute ascendc_impl_gen." | ||
| 89 | + exit 1; | ||
| 90 | + } | ||
| 91 | + else | ||
| 92 | + echo "[WARNING] Build target 'ascendc_impl_gen' not found in cmake targets, available targets: ${all_targets}" | ||
| 93 | + fi | ||
| 94 | + | ||
| 95 | + if echo "${all_targets}" | grep -wq "gen_bin_scripts"; then | ||
| 96 | + cmake --build . --target gen_bin_scripts -- ${VERBOSE} -j $THREAD_NUM || { | ||
| 97 | + echo "[ERROR] Failed to execute gen_bin_scripts." | ||
| 98 | + exit 1; | ||
| 99 | + } | ||
| 100 | + else | ||
| 101 | + echo "[WARNING] Build target 'gen_bin_scripts' not found in cmake targets, available targets: ${all_targets}" | ||
| 102 | + fi | ||
| 103 | + echo "--------------- prepare build end ---------------" | ||
| 104 | + | ||
| 105 | + echo "--------------- binary build start ---------------" | ||
| 106 | + local UNITS=(${COMPUTE_UNIT_SHORT//;/ }) | ||
| 107 | + if [[ ${#UNITS[@]} -eq 0 ]]; then | ||
| 108 | + UNITS+=("ascend910b") | ||
| 109 | + fi | ||
| 110 | + for unit in "${UNITS[@]}"; do | ||
| 111 | + rm -rf "${BUILD_PATH}/binary/${unit}/bin/opc_cmd" | ||
| 112 | + if grep -wq "prepare_binary_compile_${unit}" <<< "${all_targets}"; then | ||
| 113 | + cmake --build . --target prepare_binary_compile_${unit} -- ${VERBOSE} -j 1 || { | ||
| 114 | + print_error "opc gen failed!" && exit 1 | ||
| 115 | + } | ||
| 116 | + fi | ||
| 117 | + OPC_CMD_FILE="${BUILD_PATH}/binary/${unit}/bin/opc_cmd/opc_cmd.sh" | ||
| 118 | + [[ -f "$OPC_CMD_FILE" ]] && opc_list_num=$(wc -l < "$OPC_CMD_FILE") || opc_list_num=0 | ||
| 119 | + CMAKE_ARGS="${CMAKE_ARGS} -DOPC_NUM_${unit}=${opc_list_num}" | ||
| 120 | + done | ||
| 121 | + cd "$BUILD_PATH" && cmake .. ${CMAKE_ARGS} | ||
| 122 | + | ||
| 123 | + local cur_path=$(pwd) | ||
| 124 | + mkdir -p "${cur_path}/op_impl/ai_core/tbe/op_tiling" | ||
| 125 | + if [ ! -L op_impl/ai_core/tbe/op_tiling/liboptiling.so ]; then | ||
| 126 | + if [ -e "${cur_path}/libophost_cv.so" ]; then | ||
| 127 | + ln -s "${cur_path}/libophost_cv.so" op_impl/ai_core/tbe/op_tiling/liboptiling.so | ||
| 128 | + else | ||
| 129 | + cmake --build . --target ophost_cv -- ${VERBOSE} -j $THREAD_NUM | ||
| 130 | + ln -s "${cur_path}/libophost_cv.so" op_impl/ai_core/tbe/op_tiling/liboptiling.so | ||
| 131 | + fi | ||
| 132 | + fi | ||
| 133 | + export ASCEND_CUSTOM_OPP_PATH="${cur_path}" | ||
| 134 | + if echo "${all_targets}" | grep -wq "binary"; then | ||
| 135 | + cmake --build . --target binary -- ${VERBOSE} -j $THREAD_NUM || { | ||
| 136 | + echo "[ERROR] Kernel compile failed!" && exit 1 | ||
| 137 | + } | ||
| 138 | + else | ||
| 139 | + echo "[WARNING] Compile kernel 'binary' failed! Build target 'binary' not found in cmake targets. Available targets: ${all_targets}" | ||
| 140 | + fi | ||
| 141 | + if echo "${all_targets}" | grep -wq "gen_bin_info_config"; then | ||
| 142 | + cmake --build . --target gen_bin_info_config -- ${VERBOSE} -j $THREAD_NUM || { exit 1; } | ||
| 143 | + else | ||
| 144 | + echo "[WARNING] Generate 'gen_bin_info_config' failed! Build target 'gen_bin_info_config' not found in cmake targets. Available targets: ${all_targets}" | ||
| 145 | + fi | ||
| 146 | + echo "--------------- binary build end ---------------" | ||
| 147 | + | ||
| 148 | + echo "Build binary success" | ||
| 149 | + echo $dotted_line | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +build_package() { | ||
| 153 | + echo "--------------- build package start ---------------" | ||
| 154 | + clean_build_out | ||
| 155 | + | ||
| 156 | + local all_targets=$(cmake --build . --target help) | ||
| 157 | + if [[ "$ENABLE_BINARY" != "TRUE" && "$ENABLE_CUSTOM" != "TRUE" ]]; then | ||
| 158 | + # gen impl python files | ||
| 159 | + if echo "${all_targets}" | grep -wq "ascendc_impl_gen"; then | ||
| 160 | + cmake --build . --target ascendc_impl_gen -- ${VERBOSE} -j $THREAD_NUM || { exit 1; } | ||
| 161 | + fi | ||
| 162 | + fi | ||
| 163 | + | ||
| 164 | + cd "${BUILD_PATH}" && cmake ${CMAKE_ARGS} .. | ||
| 165 | + if echo "${all_targets}" | grep -wq "build_es_cv"; then | ||
| 166 | + cmake --build . --target build_es_cv -- ${VERBOSE} -j $THREAD_NUM || { echo "[ERROR] target:build_es_cv compile failed!" && exit 1; } | ||
| 167 | + fi | ||
| 168 | + clean_rpm_deb_package | ||
| 169 | + cmake --build . --target package -- ${VERBOSE} -j $THREAD_NUM || { | ||
| 170 | + echo "[ERROR] target:package build failed!" | ||
| 171 | + exit 1 | ||
| 172 | + } | ||
| 173 | + collect_rpm_deb_package | ||
| 174 | + echo "--------------- build package end ---------------" | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | +find_rpm_deb_package() { | ||
| 178 | + if [[ "$PACKAGE_TYPE" == "run" ]]; then | ||
| 179 | + return 0 | ||
| 180 | + fi | ||
| 181 | + | ||
| 182 | + find "${BUILD_PATH}" -type f -name "cann-ops-cv*.${PACKAGE_TYPE}" | sort | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +clean_rpm_deb_package() { | ||
| 186 | + if [[ "$PACKAGE_TYPE" == "run" ]]; then | ||
| 187 | + return 0 | ||
| 188 | + fi | ||
| 189 | + | ||
| 190 | + local package_files=() | ||
| 191 | + while IFS= read -r package_file; do | ||
| 192 | + package_files+=("${package_file}") | ||
| 193 | + done < <(find_rpm_deb_package) | ||
| 194 | + | ||
| 195 | + if [[ ${#package_files[@]} -eq 0 ]]; then | ||
| 196 | + return 0 | ||
| 197 | + fi | ||
| 198 | + | ||
| 199 | + for package_file in "${package_files[@]}"; do | ||
| 200 | + rm -f "${package_file}" | ||
| 201 | + echo "[INFO] Removed stale package artifact: ${package_file}" | ||
| 202 | + done | ||
| 203 | +} | ||
| 204 | + | ||
| 205 | +collect_rpm_deb_package() { | ||
| 206 | + if [[ "$PACKAGE_TYPE" == "run" ]]; then | ||
| 207 | + return 0 | ||
| 208 | + fi | ||
| 209 | + | ||
| 210 | + local package_files=() | ||
| 211 | + while IFS= read -r package_file; do | ||
| 212 | + package_files+=("${package_file}") | ||
| 213 | + done < <(find_rpm_deb_package) | ||
| 214 | + | ||
| 215 | + for package_file in "${package_files[@]}"; do | ||
| 216 | + cp -f "${package_file}" "${BUILD_OUT_PATH}/" | ||
| 217 | + echo "[INFO] Package artifact copied to ${BUILD_OUT_PATH}/$(basename "${package_file}")" | ||
| 218 | + done | ||
| 219 | +} | ||
| 220 | + | ||
| 221 | +package_static() { | ||
| 222 | + # Check weather BUILD_OUT_PATH directory exists | ||
| 223 | + if [ ! -d "$BUILD_OUT_PATH" ]; then | ||
| 224 | + echo "Error: Directory $BUILD_OUT_PATH does not exist" | ||
| 225 | + return 1 | ||
| 226 | + fi | ||
| 227 | + | ||
| 228 | + # Check weather *.run is exists and verify the file numbers | ||
| 229 | + local run_files=() | ||
| 230 | + shopt -s nullglob | ||
| 231 | + run_files=("$BUILD_OUT_PATH"/*.run) | ||
| 232 | + shopt -u nullglob | ||
| 233 | + if [ ${#run_files[@]} -eq 0 ]; then | ||
| 234 | + echo "Error: No .run files found in $BUILD_OUT_PATH directory" | ||
| 235 | + return 1 | ||
| 236 | + fi | ||
| 237 | + if [ ${#run_files[@]} -gt 1 ]; then | ||
| 238 | + echo "Error: Multiple .run files found in $BUILD_OUT_PATH directory:" | ||
| 239 | + printf '%s\n' "${run_files[@]}" | ||
| 240 | + return 1 | ||
| 241 | + fi | ||
🟡 Medium Priority
触发条件: 建议:在 glob 之前开启 ![]() ![]() | |||
| 242 | + | ||
| 243 | + # Get filename of *.run file and set new directory name | ||
| 244 | + local run_file=$(basename "${run_files[0]}") | ||
| 245 | + if [[ "$run_file" != *"ops-cv"* ]]; then | ||
| 246 | + echo "Error: Filename '$run_file' does not contain 'ops-cv'" | ||
| 247 | + return 1 | ||
| 248 | + fi | ||
| 249 | + local new_name="${run_file/ops-cv/ops-cv-static}" | ||
| 250 | + new_name="${new_name%.run}" | ||
| 251 | + | ||
| 252 | + # Check weather $BUILD_PATH/static_library_files directory exists and not empty | ||
| 253 | + local static_files_dir="$BUILD_PATH/static_library_files" | ||
| 254 | + if [ ! -d "$static_files_dir" ]; then | ||
| 255 | + return 0 | ||
| 256 | + fi | ||
| 257 | + if [ -z "$(ls -A "$static_files_dir")" ]; then | ||
| 258 | + echo "Error: Directory $static_files_dir is empty" | ||
| 259 | + return 1 | ||
| 260 | + fi | ||
| 261 | + | ||
| 262 | + # Rename directory | ||
| 263 | + local new_dir_path="$BUILD_PATH/$new_name" | ||
| 264 | + if mv "$static_files_dir" "$new_dir_path"; then | ||
| 265 | + echo "Preparing for packaging: renamed $static_files_dir to $new_dir_path" | ||
| 266 | + else | ||
| 267 | + echo "Packaging preparation failed: directory rename failed ($static_files_dir -> $new_dir_path)" | ||
| 268 | + return 1 | ||
| 269 | + fi | ||
| 270 | + | ||
| 271 | + # Create compressed package and restore directory name | ||
| 272 | + local new_filename="${new_name}.tar.gz" | ||
| 273 | + if tar -czf "$BUILD_OUT_PATH/$new_filename" -C "$BUILD_PATH" "$new_name"; then | ||
| 274 | + echo "[SUCCESS] Build static lib success!" | ||
| 275 | + echo "Successfully created compressed package: $BUILD_OUT_PATH/$new_filename" | ||
| 276 | + # Restore original directory name | ||
| 277 | + echo "Restoring original directory name: $new_dir_path -> $static_files_dir" | ||
| 278 | + mv "$new_dir_path" "$static_files_dir" | ||
| 279 | + return 0 | ||
| 280 | + else | ||
| 281 | + echo "Error: Failed to create compressed package" | ||
| 282 | + # Attempt to restore original directory name | ||
| 283 | + mv "$new_dir_path" "$static_files_dir" | ||
| 284 | + return 1 | ||
| 285 | + fi | ||
| 286 | +} | ||


🟡 Medium Priority
build_genop.sh中gen_op()函数(第 31–37 行)和gen_aicpu_op()函数(第 57–63 行)存在两处错误处理缺陷:缺陷 1 — 退出码被覆盖:第 34 行
return $?意图返回 python 脚本的退出码,但第 33 行的echo "Create the initial directory..."已经成功执行并将$?重置为 0。因此return $?始终返回 0,python 脚本的失败被静默吞没。缺陷 2 — Python 缺失时无错误退出:第 35–36 行的
else分支仅打印提示信息但未return 1或exit 1,函数正常返回 0。调用方(build.sh第 56–57 行)无法感知 genop 失败,脚本继续执行后续构建步骤。建议:在 echo 之前捕获退出码再返回;else 分支添加 return 1。gen_aicpu_op 同样处理。