已合并
kernel ut 增加防卡死超时,快速模式,覆盖率控制 #8187
chenqi317创建于 8月3日
kernel ut 增加防卡死超时,快速模式,覆盖率控制 #8187
已合并
chenqi317创建于 8月3日
23 个文件变更+355-150
@@ -74,6 +74,9 @@ option(OP_KERNEL_AICPU_UT "Enable aicpu kernel ut" OFF)
74option(UT_TEST_ALL "Enable all ut" OFF)74option(UT_TEST_ALL "Enable all ut" OFF)
75option(ENABLE_GEN_ACLNN "Enable gen aclnn" OFF)75option(ENABLE_GEN_ACLNN "Enable gen aclnn" OFF)
76option(DOWNLOAD_OPS_TEST_KIT "Download ops-test-kit repository" OFF)76option(DOWNLOAD_OPS_TEST_KIT "Download ops-test-kit repository" OFF)
77+option(ENABLE_UT_SYMBOLIZE "Enable addr2line symbolization on kernel UT failure" ON)
atomgit-bot
atomgit-botatomgit-bot8月3日

🟠 High Priority

build.sh 中 ENABLE_UT_SYMBOLIZE 使用 TRUE/FALSE 值,通过 -DENABLE_UT_SYMBOLIZE=${ENABLE_UT_SYMBOLIZE} 传递给 cmake。CMakeLists.txt 中 option(ENABLE_UT_SYMBOLIZE ... ON) 将 FALSE 转为 CMake bool 值 OFF。在 tests/ut/op_kernel/CMakeLists.txt 中 ${ENABLE_UT_SYMBOLIZE} 展开为 OFF(而非 FALSE),作为参数传给 run_kernel_ut.sh。但 run_kernel_ut.sh 第 43 行 [[ "$ENABLE_SYMBOLIZE" == "FALSE" ]] 仅匹配字面量 FALSE,不匹配 OFF。因此当用户使用 --ut_mode=fast 时,符号化并不会被禁用。

建议:方案一(推荐):将 CMakeLists.txt 中的 option(ENABLE_UT_SYMBOLIZE ...) 改为 set(ENABLE_UT_SYMBOLIZE "TRUE" CACHE STRING ...),保持字符串值原样传递。方案二:在 run_kernel_ut.sh 中同时匹配 FALSEOFF(以及 0NO 等)。

改动建议
77
- option(ENABLE_UT_SYMBOLIZE "Enable addr2line symbolization on kernel UT failure" ON)
77
+ set(ENABLE_UT_SYMBOLIZE "TRUE" CACHE STRING "Enable addr2line symbolization on kernel UT failure (TRUE/FALSE)")
应用建议
likedislike
78+set(UT_CASE_TIMEOUT 120 CACHE STRING "Per-case timeout in seconds for kernel UT")
79+set(UT_DEBUG_FLAG "-g" CACHE STRING "Debug flag for UT: -g/-g0")
77 80 
78set(BISHENG_FLAGS "" CACHE STRING "bisheng compiler flags")81set(BISHENG_FLAGS "" CACHE STRING "bisheng compiler flags")
79 82 
@@ -2,22 +2,22 @@
2# -*- coding: utf-8 -*-2# -*- coding: utf-8 -*-
3# ----------------------------------------------------------------------------3# ----------------------------------------------------------------------------
4# Copyright (c) 2025 Huawei Technologies Co., Ltd.4# Copyright (c) 2025 Huawei Technologies Co., Ltd.
5-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of 5+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
6# CANN Open Software License Agreement Version 2.0 (the "License").6# CANN Open Software License Agreement Version 2.0 (the "License").
7# Please refer to the License for details. You may not use this file except in compliance with the License.7# Please refer to the License for details. You may not use this file except in compliance with the License.
8-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, 8+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
10# See LICENSE in the root of the software repository for the full text of the License.10# See LICENSE in the root of the software repository for the full text of the License.
11# ----------------------------------------------------------------------------11# ----------------------------------------------------------------------------
12import sys12import sys
13import numpy as np13import numpy as np
14-import tensorflow as tf14+import ml_dtypes
15import traceback15import traceback
16 16 
17 17 
18def compare_data(tiling_key="301"):18def compare_data(tiling_key="301"):
19 if tiling_key in ["101", "102", "103", "701", "702", "703"]:19 if tiling_key in ["101", "102", "103", "701", "702", "703"]:
20- d_type = tf.bfloat16.as_numpy_dtype20+ d_type = ml_dtypes.bfloat16
21 precision_value = 4 / 100021 precision_value = 4 / 1000
22 elif tiling_key in ["201", "202", "203", "801", "802", "803"]:22 elif tiling_key in ["201", "202", "203", "801", "802", "803"]:
23 d_type = np.float1623 d_type = np.float16
@@ -27,8 +27,8 @@ def compare_data(tiling_key="301"):
27 precision_value = 1 / 1000027 precision_value = 1 / 10000
28 data_same = True28 data_same = True
29 print("===============compare data start==============")29 print("===============compare data start==============")
30- output_dx = np.fromfile(f"output_dx.bin", d_type)30+ output_dx = np.fromfile("output_dx.bin", d_type)
31- output_golden = np.fromfile(f"output_golden.bin", d_type)31+ output_golden = np.fromfile("output_golden.bin", d_type)
32 32 
33 diff_count = 033 diff_count = 0
34 for j in range(len(output_golden)):34 for j in range(len(output_golden)):
@@ -2,10 +2,10 @@
2# -*- coding: utf-8 -*-2# -*- coding: utf-8 -*-
3# ----------------------------------------------------------------------------3# ----------------------------------------------------------------------------
4# Copyright (c) 2025 Huawei Technologies Co., Ltd.4# Copyright (c) 2025 Huawei Technologies Co., Ltd.
5-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of 5+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
6# CANN Open Software License Agreement Version 2.0 (the "License").6# CANN Open Software License Agreement Version 2.0 (the "License").
7# Please refer to the License for details. You may not use this file except in compliance with the License.7# Please refer to the License for details. You may not use this file except in compliance with the License.
8-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, 8+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
10# See LICENSE in the root of the software repository for the full text of the License.10# See LICENSE in the root of the software repository for the full text of the License.
11# ----------------------------------------------------------------------------11# ----------------------------------------------------------------------------
@@ -13,7 +13,7 @@ import sys
13import os13import os
14import numpy as np14import numpy as np
15import re15import re
16-import tensorflow as tf16+from ml_dtypes import bfloat16
17import torch17import torch
18import stat18import stat
19import traceback19import traceback
@@ -48,7 +48,7 @@ def self_gelu(x):
48 48 
49def gen_data_and_golden(shape_str, attr_str, tiling_key="301"):49def gen_data_and_golden(shape_str, attr_str, tiling_key="301"):
50 if tiling_key in ["101", "102", "103", "701", "702", "703"]:50 if tiling_key in ["101", "102", "103", "701", "702", "703"]:
51- d_type = tf.bfloat16.as_numpy_dtype51+ d_type = bfloat16
52 elif tiling_key in ["201", "202", "203", "801", "802", "803"]:52 elif tiling_key in ["201", "202", "203", "801", "802", "803"]:
53 d_type = np.float1653 d_type = np.float16
54 else:54 else:
@@ -58,10 +58,10 @@ def gen_data_and_golden(shape_str, attr_str, tiling_key="301"):
58 attr_list = parse_str_to_attr_list(attr_str)58 attr_list = parse_str_to_attr_list(attr_str)
59 59 
60 data_dy = np.random.uniform(10, 20, tuple(shape_list[0])).astype(d_type)60 data_dy = np.random.uniform(10, 20, tuple(shape_list[0])).astype(d_type)
61- data_dy.tofile(f"input_dy.bin")61+ data_dy.tofile("input_dy.bin")
62 data_x = np.random.uniform(100, 200, tuple(shape_list[1])).astype(d_type)62 data_x = np.random.uniform(100, 200, tuple(shape_list[1])).astype(d_type)
63- data_x.tofile(f"input_x.bin")63+ data_x.tofile("input_x.bin")
64- if d_type == tf.bfloat16.as_numpy_dtype:64+ if d_type == bfloat16:
65 data_x = data_x.astype(np.float32)65 data_x = data_x.astype(np.float32)
66 data_dy = data_dy.astype(np.float32)66 data_dy = data_dy.astype(np.float32)
67 tensor_x = torch.from_numpy(data_x)67 tensor_x = torch.from_numpy(data_x)
@@ -75,23 +75,23 @@ def gen_data_and_golden(shape_str, attr_str, tiling_key="301"):
75 if d_type != np.float32:75 if d_type != np.float32:
76 gate = gate.to(torch.float32)76 gate = gate.to(torch.float32)
77 if torch.__version__ >= "1.13.1":77 if torch.__version__ >= "1.13.1":
78- y_gelu = torch.nn.functional.gelu(gate, approximate='tanh')78+ y_gelu = torch.nn.functional.gelu(gate, approximate="tanh")
79 else:79 else:
80 y_gelu = self_gelu(gate)80 y_gelu = self_gelu(gate)
81- y_gelu.clone().detach().numpy().astype(d_type).tofile(f"input_gelu.bin")81+ y_gelu.clone().detach().numpy().astype(d_type).tofile("input_gelu.bin")
82 if d_type == np.float16:82 if d_type == np.float16:
83 y_gelu = y_gelu.to(torch.float16)83 y_gelu = y_gelu.to(torch.float16)
84- elif d_type == tf.bfloat16.as_numpy_dtype:84+ elif d_type == bfloat16:
85 y_gelu = y_gelu.to(torch.bfloat16)85 y_gelu = y_gelu.to(torch.bfloat16)
86 86 
87- if d_type == tf.bfloat16.as_numpy_dtype:87+ if d_type == bfloat16:
88 y_gelu = y_gelu.to(torch.float32)88 y_gelu = y_gelu.to(torch.float32)
89 89 
90 y = x * y_gelu90 y = x * y_gelu
91 y.backward(tensor_dy)91 y.backward(tensor_dy)
92 x_grad = tensor_x.grad.numpy()92 x_grad = tensor_x.grad.numpy()
93- if d_type == tf.bfloat16.as_numpy_dtype:93+ if d_type == bfloat16:
94- x_grad = x_grad.astype(tf.bfloat16.as_numpy_dtype)94+ x_grad = x_grad.astype(bfloat16)
95 95 
96 x_grad.tofile("output_golden.bin")96 x_grad.tofile("output_golden.bin")
97 97 
Mbuild.sh+45-0
@@ -28,6 +28,7 @@ SUPPORTED_LONG_OPTS=(
28 "jit" "pkg" "asan" "make_clean_all" "make_clean" "no_force"28 "jit" "pkg" "asan" "make_clean_all" "make_clean" "no_force"
29 "ophost" "opgraph" "opapi" "run_example" "example_name=" "genop=" "genop_aicpu=" "experimental" "cann_3rd_lib_path=" "oom" "onnxplugin" "tfplugin" "dump_cce"29 "ophost" "opgraph" "opapi" "run_example" "example_name=" "genop=" "genop_aicpu=" "experimental" "cann_3rd_lib_path=" "oom" "onnxplugin" "tfplugin" "dump_cce"
30 "simulator" "bisheng_flags=" "kernel_template_input=" "module_extension=" "noaclnn" "mssanitizer" "rule_launch=" "ccache=" "torch_extension" "pkg-type="30 "simulator" "bisheng_flags=" "kernel_template_input=" "module_extension=" "noaclnn" "mssanitizer" "rule_launch=" "ccache=" "torch_extension" "pkg-type="
31+ "ut_mode=" "ut_timeout="
31)32)
32 33 
33source "./install_deps.sh"34source "./install_deps.sh"
@@ -241,10 +242,17 @@ usage() {
241 echo " --opgraph -u Same as opgraph test"242 echo " --opgraph -u Same as opgraph test"
242 echo " --opapi -u Same as opapi test"243 echo " --opapi -u Same as opapi test"
243 echo " --opkernel -u Same as opkernel test"244 echo " --opkernel -u Same as opkernel test"
245+ echo " --ut_mode=<MODE> UT mode for all UT types (MODE: debug/fast)"
246+ echo " debug: enable addr2line symbolization, -g, -O0 (for development)"
247+ echo " fast: disable symbolization, -g0, -O2 (for quick validation, anti-hang)"
248+ echo " Affects: op_kernel, op_host(tiling/infershape), op_api, op_graph, op_kernel_aicpu"
249+ echo " Default: debug"
250+ echo " --ut_timeout=<N> Per-case timeout in seconds for kernel UT, Default: 120"
244 echo $dotted_line251 echo $dotted_line
245 echo "Examples:"252 echo "Examples:"
246 echo " bash build.sh -u"253 echo " bash build.sh -u"
247 echo " bash build.sh -u --ophost"254 echo " bash build.sh -u --ophost"
255+ echo " bash build.sh -u --opkernel --ut_mode=fast --ut_timeout=60"
248 return256 return
249 ;;257 ;;
250 clean)258 clean)
@@ -411,6 +419,12 @@ usage() {
411 echo " --bisheng_flags Specify bisheng compiler config, like: --bisheng_flags=ccec_g,oom, use ',' to separate different compiler flags"419 echo " --bisheng_flags Specify bisheng compiler config, like: --bisheng_flags=ccec_g,oom, use ',' to separate different compiler flags"
412 echo " --kernel_template_input Specify kernel template input arguments, like: --kernel_template_input="args0=args0;args1=args1;args2=args2;args3=args3""420 echo " --kernel_template_input Specify kernel template input arguments, like: --kernel_template_input="args0=args0;args1=args1;args2=args2;args3=args3""
413 echo " Use ';' to separate different kernel template args, can only specify a single kernel template input"421 echo " Use ';' to separate different kernel template args, can only specify a single kernel template input"
422+ echo " --ut_mode=<MODE> UT mode for all UT types (MODE: debug/fast)"
423+ echo " debug: enable addr2line symbolization, -g, -O0 (for development)"
424+ echo " fast: disable symbolization, -g0, -O2 (for quick validation, anti-hang)"
425+ echo " Affects: op_kernel, op_host(tiling/infershape), op_api, op_graph, op_kernel_aicpu"
426+ echo " Default: debug"
427+ echo " --ut_timeout=<N> Per-case timeout in seconds for kernel UT, Default: 120"
414 echo "to be continued ..."428 echo "to be continued ..."
415}429}
416 430 
@@ -739,6 +753,11 @@ checkopts() {
739 NO_ACLNN=FALSE753 NO_ACLNN=FALSE
740 ENABLE_CCACHE=TRUE754 ENABLE_CCACHE=TRUE
741 755 
756+ ENABLE_UT_SYMBOLIZE=TRUE
757+ UT_CASE_TIMEOUT=120
758+ UT_MODE=debug
759+ UT_DEBUG_FLAG=-g
760+ 
742 if [ $# -eq 0 ]; then761 if [ $# -eq 0 ]; then
743 usage "$SHOW_HELP"762 usage "$SHOW_HELP"
744 exit 0763 exit 0
@@ -932,6 +951,29 @@ checkopts() {
932 check_pkg_type "${PACKAGE_TYPE}"951 check_pkg_type "${PACKAGE_TYPE}"
933 PACKAGE_TYPE_SET=TRUE952 PACKAGE_TYPE_SET=TRUE
934 ;;953 ;;
954+ ut_mode=*)
955+ UT_MODE=${OPTARG#*=}
956+ if [[ "$UT_MODE" == "fast" ]]; then
957+ ENABLE_UT_SYMBOLIZE=FALSE
958+ UT_DEBUG_FLAG=-g0
959+ if [[ -z "$BUILD_MODE" ]]; then
960+ BUILD_MODE="-O2"
961+ fi
962+ elif [[ "$UT_MODE" == "debug" ]]; then
963+ ENABLE_UT_SYMBOLIZE=TRUE
964+ UT_DEBUG_FLAG=-g
965+ else
966+ print_error "--ut_mode only support debug/fast"
967+ exit 1
968+ fi
969+ ;;
970+ ut_timeout=*)
971+ UT_CASE_TIMEOUT=${OPTARG#*=}
972+ if ! [[ "$UT_CASE_TIMEOUT" =~ ^[0-9]+$ ]] || [[ "$UT_CASE_TIMEOUT" -eq 0 ]]; then
973+ print_error "--ut_timeout must be a positive integer"
974+ exit 1
975+ fi
976+ ;;
935 *)977 *)
936 ## 如果不在RELEASE_TARGETS,不做处理978 ## 如果不在RELEASE_TARGETS,不做处理
937 if ! in_array "$OPTARG" "${RELEASE_TARGETS[@]}"; then979 if ! in_array "$OPTARG" "${RELEASE_TARGETS[@]}"; then
@@ -1068,6 +1110,9 @@ assemble_cmake_args() {
1068 CMAKE_ARGS="$CMAKE_ARGS -DOP_KERNEL_UT=${OP_KERNEL_UT}"1110 CMAKE_ARGS="$CMAKE_ARGS -DOP_KERNEL_UT=${OP_KERNEL_UT}"
1069 CMAKE_ARGS="$CMAKE_ARGS -DOP_KERNEL_AICPU_UT=${OP_KERNEL_AICPU_UT}"1111 CMAKE_ARGS="$CMAKE_ARGS -DOP_KERNEL_AICPU_UT=${OP_KERNEL_AICPU_UT}"
1070 CMAKE_ARGS="$CMAKE_ARGS -DUT_TEST_ALL=${UT_TEST_ALL}"1112 CMAKE_ARGS="$CMAKE_ARGS -DUT_TEST_ALL=${UT_TEST_ALL}"
1113+ CMAKE_ARGS="$CMAKE_ARGS -DENABLE_UT_SYMBOLIZE=${ENABLE_UT_SYMBOLIZE}"
1114+ CMAKE_ARGS="$CMAKE_ARGS -DUT_CASE_TIMEOUT=${UT_CASE_TIMEOUT}"
1115+ CMAKE_ARGS="$CMAKE_ARGS -DUT_DEBUG_FLAG=${UT_DEBUG_FLAG}"
1071 if [[ "x$BISHENG_FLAGS" != "x" ]]; then1116 if [[ "x$BISHENG_FLAGS" != "x" ]]; then
1072 CMAKE_ARGS="$CMAKE_ARGS -DBISHENG_FLAGS=${BISHENG_FLAGS}"1117 CMAKE_ARGS="$CMAKE_ARGS -DBISHENG_FLAGS=${BISHENG_FLAGS}"
1073 fi1118 fi
@@ -1,9 +1,9 @@
1# ----------------------------------------------------------------------------1# ----------------------------------------------------------------------------
2# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd.2# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd.
3-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of 3+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4# CANN Open Software License Agreement Version 2.0 (the "License").4# CANN Open Software License Agreement Version 2.0 (the "License").
5# Please refer to the License for details. You may not use this file except in compliance with the License.5# Please refer to the License for details. You may not use this file except in compliance with the License.
6-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, 6+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8# See LICENSE in the root of the software repository for the full text of the License.8# See LICENSE in the root of the software repository for the full text of the License.
9# ----------------------------------------------------------------------------9# ----------------------------------------------------------------------------
@@ -21,19 +21,16 @@ target_compile_definitions(intf_llt_pub INTERFACE
21 CFG_BUILD_DEBUG21 CFG_BUILD_DEBUG
22)22)
23target_compile_options(intf_llt_pub INTERFACE23target_compile_options(intf_llt_pub INTERFACE
24- -g24+ $<$<BOOL:${ENABLE_COVERAGE}>:--coverage -fprofile-arcs -ftest-coverage>
25- --coverage
26- -fprofile-arcs
27- -ftest-coverage
28 -w25 -w
29 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>26 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
30 -fPIC27 -fPIC
31)28)
atomgit-bot
atomgit-botatomgit-bot8月3日

🟡 Medium Priority

变更从 intf_pub_llt_gccnative.cmake 的四个 interface library(intf_llt_pubintf_llt_pub_asanintf_llt_pub_asan_cxx14intf_llt_pub_asan_cxx17)的 target_compile_options 中移除了无条件的 -g 标志。

旧行为:所有链接这些 interface library 的目标都会无条件获得 -g(调试符号)。 新行为:

受影响的目标:

  • ut.cmake 中的 tiling UT(add_optiling_ut_modules,第 56 行链接 intf_llt_pub_asan_cxx17
  • ut.cmake 中的 infershape UT(add_infershape_ut_modules,第 102 行)
  • ut.cmake 中的 opapi UT(add_opapi_ut_modules,第 150 行)
  • ut.cmake 中的 graph UT(add_op_graph_ut_modules,第 226 行)

这些目标均未在自身 target_compile_options 中添加 -g${UT_DEBUG_FLAG}。默认情况下 ENABLE_ASAN=FALSE(仅通过 --asan 开启),因此在默认构建中这些非 kernel UT 目标将失去调试符号,影响崩溃定位和调试能力。

触发条件:bash build.sh -u(不带 --asan),执行 tiling/infershape/opapi/graph UT 时。 失败模式:UT 崩溃后无法通过 addr2line 或 gdb 获取有意义的堆栈信息。

建议:为保持向后兼容,可在 intf_llt_pub_asan_cxx17(及其 cxx14/asan 变体)的 target_compile_options 中增加一个条件表达式,当 ENABLE_COVERAGEENABLE_ASAN 均关闭时仍保留 -g;或者更彻底的方式:参照 kernel UT 的做法,在 tiling/infershape/opapi/graph UT 的 target_compile_options 中也添加 ${UT_DEBUG_FLAG}。推荐后者以保持一致性。

likedislike
32target_link_options(intf_llt_pub INTERFACE29target_link_options(intf_llt_pub INTERFACE
33- -fprofile-arcs -ftest-coverage30+ $<$<BOOL:${ENABLE_COVERAGE}>:-fprofile-arcs -ftest-coverage>
34)31)
35target_link_libraries(intf_llt_pub INTERFACE32target_link_libraries(intf_llt_pub INTERFACE
36- gcov33+ $<$<BOOL:${ENABLE_COVERAGE}>:gcov>
37 pthread34 pthread
38)35)
39 36 
@@ -51,21 +48,18 @@ target_compile_definitions(intf_llt_pub_asan INTERFACE
51 CFG_BUILD_DEBUG48 CFG_BUILD_DEBUG
52)49)
53target_compile_options(intf_llt_pub_asan INTERFACE50target_compile_options(intf_llt_pub_asan INTERFACE
54- -g51+ $<$<BOOL:${ENABLE_COVERAGE}>:--coverage -fprofile-arcs -ftest-coverage>
55- --coverage
56- -fprofile-arcs
57- -ftest-coverage
58 -w52 -w
59 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>53 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
60 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address -fsanitize-recover=address,all -fno-omit-frame-pointer -g>54 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address -fsanitize-recover=address,all -fno-omit-frame-pointer -g>
61 -fPIC55 -fPIC
62)56)
63target_link_options(intf_llt_pub_asan INTERFACE57target_link_options(intf_llt_pub_asan INTERFACE
64- -fprofile-arcs -ftest-coverage58+ $<$<BOOL:${ENABLE_COVERAGE}>:-fprofile-arcs -ftest-coverage>
65 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address>59 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address>
66)60)
67target_link_libraries(intf_llt_pub_asan INTERFACE61target_link_libraries(intf_llt_pub_asan INTERFACE
68- gcov62+ $<$<BOOL:${ENABLE_COVERAGE}>:gcov>
69 pthread63 pthread
70)64)
71 65 
@@ -83,21 +77,18 @@ target_compile_definitions(intf_llt_pub_asan_cxx14 INTERFACE
83 CFG_BUILD_DEBUG77 CFG_BUILD_DEBUG
84)78)
85target_compile_options(intf_llt_pub_asan_cxx14 INTERFACE79target_compile_options(intf_llt_pub_asan_cxx14 INTERFACE
86- -g80+ $<$<BOOL:${ENABLE_COVERAGE}>:--coverage -fprofile-arcs -ftest-coverage>
87- --coverage
88- -fprofile-arcs
89- -ftest-coverage
90 -w81 -w
91 $<$<COMPILE_LANGUAGE:CXX>:-std=c++14>82 $<$<COMPILE_LANGUAGE:CXX>:-std=c++14>
92 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address -fsanitize-recover=address,all -fno-omit-frame-pointer -g>83 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address -fsanitize-recover=address,all -fno-omit-frame-pointer -g>
93 -fPIC84 -fPIC
94)85)
95target_link_options(intf_llt_pub_asan_cxx14 INTERFACE86target_link_options(intf_llt_pub_asan_cxx14 INTERFACE
96- -fprofile-arcs -ftest-coverage87+ $<$<BOOL:${ENABLE_COVERAGE}>:-fprofile-arcs -ftest-coverage>
97 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address>88 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address>
98)89)
99target_link_libraries(intf_llt_pub_asan_cxx14 INTERFACE90target_link_libraries(intf_llt_pub_asan_cxx14 INTERFACE
100- gcov91+ $<$<BOOL:${ENABLE_COVERAGE}>:gcov>
101 pthread92 pthread
102)93)
103 94 
@@ -115,20 +106,17 @@ target_compile_definitions(intf_llt_pub_asan_cxx17 INTERFACE
115 CFG_BUILD_DEBUG106 CFG_BUILD_DEBUG
116)107)
117target_compile_options(intf_llt_pub_asan_cxx17 INTERFACE108target_compile_options(intf_llt_pub_asan_cxx17 INTERFACE
118- -g109+ $<$<BOOL:${ENABLE_COVERAGE}>:--coverage -fprofile-arcs -ftest-coverage>
119- --coverage
120- -fprofile-arcs
121- -ftest-coverage
122 -w110 -w
123 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>111 $<$<COMPILE_LANGUAGE:CXX>:-std=c++17>
124 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address -fsanitize-recover=address,all -fno-omit-frame-pointer -g>112 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address -fsanitize-recover=address,all -fno-omit-frame-pointer -g>
125 -fPIC113 -fPIC
126)114)
127target_link_options(intf_llt_pub_asan_cxx17 INTERFACE115target_link_options(intf_llt_pub_asan_cxx17 INTERFACE
128- -fprofile-arcs -ftest-coverage116+ $<$<BOOL:${ENABLE_COVERAGE}>:-fprofile-arcs -ftest-coverage>
129 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address>117 $<$<BOOL:${ENABLE_ASAN}>:-fsanitize=address>
130)118)
131target_link_libraries(intf_llt_pub_asan_cxx17 INTERFACE119target_link_libraries(intf_llt_pub_asan_cxx17 INTERFACE
132- gcov120+ $<$<BOOL:${ENABLE_COVERAGE}>:gcov>
133 pthread121 pthread
134)122)
@@ -59,6 +59,7 @@ function(add_optiling_ut_modules OP_TILING_MODULE_NAME)
59 )59 )
60 60 
61 target_compile_options(${OP_TILING_MODULE_NAME}_cases_obj PRIVATE61 target_compile_options(${OP_TILING_MODULE_NAME}_cases_obj PRIVATE
62+ ${UT_DEBUG_FLAG}
62 -fno-access-control63 -fno-access-control
63 )64 )
64 65 
@@ -107,6 +108,7 @@ function(add_infershape_ut_modules OP_INFERSHAPE_MODULE_NAME)
107 )108 )
108 109 
109 target_compile_options(${OP_INFERSHAPE_MODULE_NAME}_cases_obj PRIVATE110 target_compile_options(${OP_INFERSHAPE_MODULE_NAME}_cases_obj PRIVATE
111+ ${UT_DEBUG_FLAG}
110 -fno-access-control112 -fno-access-control
111 )113 )
112 114 
@@ -151,6 +153,10 @@ function(add_opapi_ut_modules OP_API_MODULE_NAME)
151 $<BUILD_INTERFACE:dlog_headers>153 $<BUILD_INTERFACE:dlog_headers>
152 gtest154 gtest
153 )155 )
156+ target_compile_options(${OP_API_MODULE_NAME}_cases_obj PRIVATE
157+ ${UT_DEBUG_FLAG}
158+ -fno-access-control
159+ )
154endfunction()160endfunction()
155 161 
156function(add_opkernel_ut_modules OP_KERNEL_MODULE_NAME)162function(add_opkernel_ut_modules OP_KERNEL_MODULE_NAME)
@@ -190,7 +196,7 @@ function(add_opkernel_ut_modules OP_KERNEL_MODULE_NAME)
190 target_link_libraries(${OP_KERNEL_MODULE_NAME}_${socVersion}_cases PRIVATE196 target_link_libraries(${OP_KERNEL_MODULE_NAME}_${socVersion}_cases PRIVATE
191 $<BUILD_INTERFACE:intf_llt_pub_asan_cxx17>197 $<BUILD_INTERFACE:intf_llt_pub_asan_cxx17>
192 ${OP_KERNEL_MODULE_NAME}_common_obj198 ${OP_KERNEL_MODULE_NAME}_common_obj
193- gcov199+ $<$<BOOL:${ENABLE_COVERAGE}>:gcov>
194 )200 )
195 endforeach()201 endforeach()
196endfunction()202endfunction()
@@ -236,6 +242,7 @@ function(add_op_graph_ut_modules OP_GRAPH_MODULE_NAME)
236 )242 )
237 243 
238 target_compile_options(${OP_GRAPH_MODULE_NAME}_cases_obj PRIVATE244 target_compile_options(${OP_GRAPH_MODULE_NAME}_cases_obj PRIVATE
245+ ${UT_DEBUG_FLAG}
239 -fno-access-control246 -fno-access-control
240 )247 )
241 248 
@@ -280,7 +287,7 @@ if(UT_TEST_ALL OR OP_KERNEL_AICPU_UT)
280 if(NOT TARGET ${AICPU_OP_KERNEL_MODULE_NAME}_cases_obj)287 if(NOT TARGET ${AICPU_OP_KERNEL_MODULE_NAME}_cases_obj)
281 add_library(${AICPU_OP_KERNEL_MODULE_NAME}_cases_obj OBJECT ${UT_PATH}/empty.cpp)288 add_library(${AICPU_OP_KERNEL_MODULE_NAME}_cases_obj OBJECT ${UT_PATH}/empty.cpp)
282 endif()289 endif()
283- target_link_libraries(${AICPU_OP_KERNEL_MODULE_NAME}_cases_obj PRIVATE gcov -ldl)290+ target_link_libraries(${AICPU_OP_KERNEL_MODULE_NAME}_cases_obj PRIVATE $<$<BOOL:${ENABLE_COVERAGE}>:gcov> -ldl)
284 target_sources(${AICPU_OP_KERNEL_MODULE_NAME}_cases_obj PRIVATE ${OP_KERNEL_AICPU_UT_UTILS_SRC})291 target_sources(${AICPU_OP_KERNEL_MODULE_NAME}_cases_obj PRIVATE ${OP_KERNEL_AICPU_UT_UTILS_SRC})
285 292 
286 ## add opkernel ut cases shared lib: libnn_aicpu_op_kernel_ut_cases.so293 ## add opkernel ut cases shared lib: libnn_aicpu_op_kernel_ut_cases.so
@@ -558,7 +565,7 @@ function(AddOpTestCase opName supportedSocVersion otherCompileOptions)
558 -Wl,--whole-archive565 -Wl,--whole-archive
559 tiling_api566 tiling_api
560 -Wl,--no-whole-archive567 -Wl,--no-whole-archive
561- gcov568+ $<$<BOOL:${ENABLE_COVERAGE}>:gcov>
562 metadef569 metadef
563 register570 register
564 opp_registry571 opp_registry
@@ -666,7 +673,7 @@ function(AddOpTestCase opName supportedSocVersion otherCompileOptions)
666 add_library(opkernel_${opName} OBJECT ${OPKERNEL_CASES_SRC} ${kernelFile})673 add_library(opkernel_${opName} OBJECT ${OPKERNEL_CASES_SRC} ${kernelFile})
667 add_dependencies(opkernel_${opName} ${gen_tiling_head_tag} ${KERNEL_COPY_TARGET})674 add_dependencies(opkernel_${opName} ${gen_tiling_head_tag} ${KERNEL_COPY_TARGET})
668 target_compile_options(opkernel_${opName} PRIVATE675 target_compile_options(opkernel_${opName} PRIVATE
669- -g ${compileOptions} -DUT_SOC_VERSION="${socVersion}" -DKERNELUT=1676+ ${UT_DEBUG_FLAG} ${compileOptions} -DUT_SOC_VERSION="${socVersion}" -DKERNELUT=1
670 )677 )
671 target_link_libraries(opkernel_${opName} PRIVATE678 target_link_libraries(opkernel_${opName} PRIVATE
672 $<BUILD_INTERFACE:intf_llt_pub_asan_cxx17>679 $<BUILD_INTERFACE:intf_llt_pub_asan_cxx17>
@@ -691,7 +698,7 @@ function(AddOpTestCase opName supportedSocVersion otherCompileOptions)
691 add_library(opkernel_${src_name} OBJECT ${src_file})698 add_library(opkernel_${src_name} OBJECT ${src_file})
692 add_dependencies(opkernel_${src_name} ${gen_tiling_head_tag} ${KERNEL_COPY_TARGET})699 add_dependencies(opkernel_${src_name} ${gen_tiling_head_tag} ${KERNEL_COPY_TARGET})
693 target_compile_options(opkernel_${src_name} PRIVATE700 target_compile_options(opkernel_${src_name} PRIVATE
694- -g ${compileOptions} -DUT_SOC_VERSION="${socVersion}"701+ ${UT_DEBUG_FLAG} ${compileOptions} -DUT_SOC_VERSION="${socVersion}"
695 )702 )
696 target_link_libraries(opkernel_${src_name} PRIVATE703 target_link_libraries(opkernel_${src_name} PRIVATE
697 $<BUILD_INTERFACE:intf_llt_pub_asan_cxx17>704 $<BUILD_INTERFACE:intf_llt_pub_asan_cxx17>
@@ -743,7 +750,7 @@ if(UT_TEST_ALL OR OP_KERNEL_AICPU_UT)
743 ${OPKERNEL_CASES_SRC}750 ${OPKERNEL_CASES_SRC}
744 )751 )
745 target_compile_options(${opName}_cases_obj PRIVATE752 target_compile_options(${opName}_cases_obj PRIVATE
746- -g753+ ${UT_DEBUG_FLAG}
747 )754 )
748 message(STATUS "111******************** ${AICPU_INCLUDE}")755 message(STATUS "111******************** ${AICPU_INCLUDE}")
749 ## add op_kernel_aicpu test header file search path, so that header files can be referenced based on relative path756 ## add op_kernel_aicpu test header file search path, so that header files can be referenced based on relative path
@@ -13,7 +13,7 @@ import sys
13import numpy as np13import numpy as np
14import glob14import glob
15import os15import os
16-import tensorflow as tf16+import ml_dtypes
17 17 
18curr_dir = os.path.dirname(os.path.realpath(__file__))18curr_dir = os.path.dirname(os.path.realpath(__file__))
19 19 
@@ -34,7 +34,7 @@ def compare_data(golden_file_lists, output_file_lists, d_type):
34 elif d_type == "float32":34 elif d_type == "float32":
35 precision = 1 / 1000035 precision = 1 / 10000
36 elif d_type == "bfloat16_t":36 elif d_type == "bfloat16_t":
37- np_dtype = tf.bfloat16.as_numpy_dtype37+ np_dtype = ml_dtypes.bfloat16
38 precision = 4 / 100038 precision = 4 / 1000
39 else:39 else:
40 precision = 1 / 100040 precision = 1 / 1000
@@ -13,7 +13,7 @@ import sys
13import os13import os
14import numpy as np14import numpy as np
15import re15import re
16-import tensorflow as tf16+from ml_dtypes import bfloat16
17 17 
18 18 
19def parse_str_to_shape_list(shape_str):19def parse_str_to_shape_list(shape_str):
@@ -34,7 +34,7 @@ def gen_data_and_golden(shape_str, scale_value=2.0, d_type="float32"):
34 "int16": np.int16,34 "int16": np.int16,
35 "int8": np.int8,35 "int8": np.int8,
36 "uint8": np.uint8,36 "uint8": np.uint8,
37- "bfloat16_t": tf.bfloat16.as_numpy_dtype,37+ "bfloat16_t": bfloat16,
38 }38 }
39 np_type = d_type_dict[d_type]39 np_type = d_type_dict[d_type]
40 shape_list = parse_str_to_shape_list(shape_str)40 shape_list = parse_str_to_shape_list(shape_str)
@@ -14,7 +14,7 @@ import sys
14import numpy as np14import numpy as np
15import glob15import glob
16import os16import os
17-import tensorflow as tf17+import ml_dtypes
18 18 
19curr_dir = os.path.dirname(os.path.realpath(__file__))19curr_dir = os.path.dirname(os.path.realpath(__file__))
20 20 
@@ -36,7 +36,7 @@ def compare_data(golden_file_lists, output_file_lists, d_type):
36 np_dtype = np.uint836 np_dtype = np.uint8
37 precision = 037 precision = 0
38 elif d_type == "bfloat16_t":38 elif d_type == "bfloat16_t":
39- np_dtype = tf.bfloat16.as_numpy_dtype39+ np_dtype = ml_dtypes.bfloat16
40 precision = 4 / 100040 precision = 4 / 1000
41 else:41 else:
42 precision = 1 / 1042 precision = 1 / 10
@@ -14,7 +14,7 @@ import sys
14import os14import os
15import numpy as np15import numpy as np
16import re16import re
17-import tensorflow as tf17+from ml_dtypes import bfloat16
18 18 
19 19 
20def parse_str_to_shape_list(shape_str):20def parse_str_to_shape_list(shape_str):
@@ -33,7 +33,7 @@ def gen_data_and_golden(shape_str, d_type="float32"):
33 "int16": np.int16,33 "int16": np.int16,
34 "int8": np.int8,34 "int8": np.int8,
35 "uint8": np.uint8,35 "uint8": np.uint8,
36- "bfloat16_t": tf.bfloat16.as_numpy_dtype,36+ "bfloat16_t": bfloat16,
37 }37 }
38 np_type = d_type_dict[d_type]38 np_type = d_type_dict[d_type]
39 shape_list = parse_str_to_shape_list(shape_str)39 shape_list = parse_str_to_shape_list(shape_str)
@@ -12,14 +12,14 @@
12 12 
13import sys13import sys
14import numpy as np14import numpy as np
15-import tensorflow as tf15+import ml_dtypes
16 16 
17 17 
18def compare_data(tensor_count, tiling_key="1"):18def compare_data(tensor_count, tiling_key="1"):
19 if tiling_key == "2":19 if tiling_key == "2":
20 d_type = np.float1620 d_type = np.float16
21 elif tiling_key == "3":21 elif tiling_key == "3":
22- d_type = tf.bfloat16.as_numpy_dtype22+ d_type = ml_dtypes.bfloat16
23 else:23 else:
24 d_type = np.float3224 d_type = np.float32
25 data_same = True25 data_same = True
@@ -28,12 +28,12 @@ def compare_data(tensor_count, tiling_key="1"):
28 tmp_output = np.fromfile(f"output_t{i}.bin", d_type)28 tmp_output = np.fromfile(f"output_t{i}.bin", d_type)
29 tmp_golden = np.fromfile(f"golden_t{i}.bin", d_type)29 tmp_golden = np.fromfile(f"golden_t{i}.bin", d_type)
30 if d_type == np.float32:30 if d_type == np.float32:
31- precision_value = 1/1000031+ precision_value = 1 / 10000
32 else:32 else:
33- precision_value = 1/100033+ precision_value = 1 / 1000
34 print(f"===============tensor[{i}]==============")34 print(f"===============tensor[{i}]==============")
35 for j in range(len(tmp_golden)):35 for j in range(len(tmp_golden)):
36- if abs(tmp_golden[j]-tmp_output[j]) > precision_value:36+ if abs(tmp_golden[j] - tmp_output[j]) > precision_value:
37 print(f"index:{j}, golden:{tmp_golden[j]}, output:{tmp_output[j]}")37 print(f"index:{j}, golden:{tmp_golden[j]}, output:{tmp_output[j]}")
38 data_same = False38 data_same = False
39 print("===============compare data finish==============")39 print("===============compare data finish==============")
@@ -14,7 +14,7 @@ import sys
14import os14import os
15import numpy as np15import numpy as np
16import re16import re
17-import tensorflow as tf17+from ml_dtypes import bfloat16
18 18 
19 19 
20def parse_str_to_shape_list(shape_str):20def parse_str_to_shape_list(shape_str):
@@ -30,12 +30,12 @@ def gen_data_and_golden(shape_str, scale_value="2", tiling_key="1"):
30 if tiling_key == "2":30 if tiling_key == "2":
31 d_type = np.float1631 d_type = np.float16
32 elif tiling_key == "3":32 elif tiling_key == "3":
33- d_type = tf.bfloat16.as_numpy_dtype33+ d_type = bfloat16
34 else:34 else:
35 d_type = np.float3235 d_type = np.float32
36 shape_list = parse_str_to_shape_list(shape_str)36 shape_list = parse_str_to_shape_list(shape_str)
37 for index, shape in enumerate(shape_list):37 for index, shape in enumerate(shape_list):
38- tmp_input = np.random.rand(*shape)*10038+ tmp_input = np.random.rand(*shape) * 100
39 tmp_input = tmp_input.astype(d_type)39 tmp_input = tmp_input.astype(d_type)
40 # tmp_input[0] = np.PINF40 # tmp_input[0] = np.PINF
41 tmp_golden = tmp_input.astype(np.float32) * float(scale_value)41 tmp_golden = tmp_input.astype(np.float32) * float(scale_value)
@@ -1,24 +1,25 @@
1#!/usr/bin/env python31#!/usr/bin/env python3
2# coding: utf-82# coding: utf-8
3# Copyright (c) 2025 Huawei Technologies Co., Ltd.3# Copyright (c) 2025 Huawei Technologies Co., Ltd.
4-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of 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").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.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, 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.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.9# See LICENSE in the root of the software repository for the full text of the License.
10 10 
11import sys11import sys
12import numpy as np12import numpy as np
13import torch13import torch
14-import tensorflow as tf14+from ml_dtypes import bfloat16 as bf16
15-bf16 = tf.bfloat16.as_numpy_dtype
16 15 
17 16 
18def gen_golden_data_simple(batch_size, vocab_size, dtype_str):17def gen_golden_data_simple(batch_size, vocab_size, dtype_str):
19 logits = np.random.random([batch_size, vocab_size]).astype(np.float32)18 logits = np.random.random([batch_size, vocab_size]).astype(np.float32)
20 19 
21- sorted_value, sorted_indices = torch.from_numpy(logits).sort(dim=-1, descending=False, stable=True)20+ sorted_value, sorted_indices = torch.from_numpy(logits).sort(
21+ dim=-1, descending=False, stable=True
22+ )
22 sorted_value = sorted_value.numpy()23 sorted_value = sorted_value.numpy()
23 sorted_indices = sorted_indices.to(torch.int32).numpy()24 sorted_indices = sorted_indices.to(torch.int32).numpy()
24 p = np.random.random([batch_size]).astype(np.float32)25 p = np.random.random([batch_size]).astype(np.float32)
@@ -31,11 +32,11 @@ def gen_golden_data_simple(batch_size, vocab_size, dtype_str):
31 sorted_value = sorted_value.astype(bf16)32 sorted_value = sorted_value.astype(bf16)
32 p = p.astype(bf16)33 p = p.astype(bf16)
33 34 
34- 
35 sorted_value.tofile("./sortedValue.bin")35 sorted_value.tofile("./sortedValue.bin")
36 sorted_indices.tofile("./sortedIndices.bin")36 sorted_indices.tofile("./sortedIndices.bin")
37 p.tofile("./p.bin")37 p.tofile("./p.bin")
38 k.tofile("./k.bin")38 k.tofile("./k.bin")
39 39 
40+ 
40if __name__ == "__main__":41if __name__ == "__main__":
41- gen_golden_data_simple(int(sys.argv[1]), int(sys.argv[2]), sys.argv[3])42+ gen_golden_data_simple(int(sys.argv[1]), int(sys.argv[2]), sys.argv[3])
@@ -112,10 +112,11 @@ TEST_F(chamfer_distance_grad_test, test_case_fp16)
112 tilingDatafromBin->num = 2;112 tilingDatafromBin->num = 2;
113 tilingDatafromBin->ub_size = 195538;113 tilingDatafromBin->ub_size = 195538;
114 tilingDatafromBin->task_per_core = 1;114 tilingDatafromBin->task_per_core = 1;
115- tilingDatafromBin->core_used = 4;115+ tilingDatafromBin->core_used = 48;
116 tilingDatafromBin->task_tail_core = 1;116 tilingDatafromBin->task_tail_core = 1;
117 117 
118 ICPU_SET_TILING_KEY(2);118 ICPU_SET_TILING_KEY(2);
119+ AscendC::SetKernelMode(KernelMode::AIV_MODE);
119 ICPU_RUN_KF(chamfer_distance_grad, blockDim, xyz1, xyz2, idx1, idx2, grad_dist1, grad_dist2, grad_xyz1, grad_xyz2,120 ICPU_RUN_KF(chamfer_distance_grad, blockDim, xyz1, xyz2, idx1, idx2, grad_dist1, grad_dist2, grad_xyz1, grad_xyz2,
120 workspace, tiling);121 workspace, tiling);
121 AscendC::GmFree(xyz1);122 AscendC::GmFree(xyz1);
@@ -128,4 +129,4 @@ TEST_F(chamfer_distance_grad_test, test_case_fp16)
128 AscendC::GmFree(grad_xyz2);129 AscendC::GmFree(grad_xyz2);
129 AscendC::GmFree(workspace);130 AscendC::GmFree(workspace);
130 AscendC::GmFree(tiling);131 AscendC::GmFree(tiling);
131-}132+}
@@ -1,8 +1,8 @@
1# Copyright (c) 2025 Huawei Technologies Co., Ltd.1# Copyright (c) 2025 Huawei Technologies Co., Ltd.
2-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of 2+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
3# CANN Open Software License Agreement Version 2.0 (the "License").3# CANN Open Software License Agreement Version 2.0 (the "License").
4# Please refer to the License for details. You may not use this file except in compliance with the License.4# Please refer to the License for details. You may not use this file except in compliance with the License.
5-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, 5+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
6# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.6# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
7# See LICENSE in the root of the software repository for the full text of the License.7# See LICENSE in the root of the software repository for the full text of the License.
8 8 
@@ -11,7 +11,8 @@
11import sys11import sys
12import numpy as np12import numpy as np
13import torch13import torch
14-import tensorflow as tf14+import ml_dtypes
15+ 
15 16 
16def gen_golden_data_simple(shape, dtype, input_range, dim):17def gen_golden_data_simple(shape, dtype, input_range, dim):
17 x1_tensor = np.random.uniform(input_range[0], input_range[1], shape).astype(dtype)18 x1_tensor = np.random.uniform(input_range[0], input_range[1], shape).astype(dtype)
@@ -30,9 +31,10 @@ def gen_golden_data_simple(shape, dtype, input_range, dim):
30 x2_tensor.tofile("./x2.bin")31 x2_tensor.tofile("./x2.bin")
31 golden.tofile("./golden.bin")32 golden.tofile("./golden.bin")
32 33 
34+ 
33case_list = {35case_list = {
34- "test_case_float_0" : {"shape":[320, 3], "input_range":[-5, 5], "dim":1},36+ "test_case_float_0": {"shape": [320, 3], "input_range": [-5, 5], "dim": 1},
35- "test_case_float_1" : {"shape":[3, 320], "input_range":[-5, 5], "dim":0},37+ "test_case_float_1": {"shape": [3, 320], "input_range": [-5, 5], "dim": 0},
36}38}
37if __name__ == "__main__":39if __name__ == "__main__":
38 case_name = sys.argv[1]40 case_name = sys.argv[1]
@@ -46,7 +48,7 @@ if __name__ == "__main__":
46 "float32": np.float32,48 "float32": np.float32,
47 "float": np.float32,49 "float": np.float32,
48 "float16": np.float16,50 "float16": np.float16,
49- "bfloat16": tf.bfloat16.as_numpy_dtype,51+ "bfloat16": ml_dtypes.bfloat16,
50 }52 }
51 dtype = d_type_dict.get(dtype)53 dtype = d_type_dict.get(dtype)
52- gen_golden_data_simple(param["shape"], dtype, param["input_range"], param["dim"])54+ gen_golden_data_simple(param["shape"], dtype, param["input_range"], param["dim"])
@@ -142,6 +142,7 @@ TEST_F(add_rms_norm_quant_v2_test, test_case_5)
142{142{
143 InitParams();143 InitParams();
144 uint32_t tiling_key = 10101U;144 uint32_t tiling_key = 10101U;
145+ AscendC::SetKernelMode(KernelMode::AIV_MODE);
145 ICPU_SET_TILING_KEY(tiling_key);146 ICPU_SET_TILING_KEY(tiling_key);
146 ICPU_RUN_KF(add_rms_norm_quant_v2, blockDim, x1, x2, gamma, scales1, scales2, zero_points1, zero_points2, beta, y1,147 ICPU_RUN_KF(add_rms_norm_quant_v2, blockDim, x1, x2, gamma, scales1, scales2, zero_points1, zero_points2, beta, y1,
147 y2, x, res_out, workspace, (uint8_t*)(tilingDatafromBin));148 y2, x, res_out, workspace, (uint8_t*)(tilingDatafromBin));
@@ -192,4 +193,4 @@ TEST_F(add_rms_norm_quant_v2_test, test_case_8)
192// add_rms_norm_quant_v2, blockDim, x1, x2, gamma, scales1, scales2, zero_points1, zero_points2, beta, y1, y2,193// add_rms_norm_quant_v2, blockDim, x1, x2, gamma, scales1, scales2, zero_points1, zero_points2, beta, y1, y2,
193// x, res_out, workspace, (uint8_t*)(tilingDatafromBin));194// x, res_out, workspace, (uint8_t*)(tilingDatafromBin));
194// FreeGM();195// FreeGM();
195-// }196+// }
@@ -1,12 +1,11 @@
1/**1/**
2- * This program is free software, you can redistribute it and/or modify.
3 * Copyright (c) 2025 Huawei Technologies Co., Ltd.2 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
4- * This file is a part of the CANN Open Software.3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
5- * Licensed under CANN Open Software License Agreement Version 2.0 (the "License").4+ * 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.5 * 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, INCLUDING6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
8- * BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. See LICENSE in the root of7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
9- * the software repository for the full text of the License.8+ * See LICENSE in the root of the software repository for the full text of the License.
10 */9 */
11 10 
12/*!11/*!
@@ -77,6 +76,7 @@ TEST_F(layer_norm_v4_test, test_case_0003)
77 tilingDatafromBin->nullptrBeta = 0;76 tilingDatafromBin->nullptrBeta = 0;
78 tilingDatafromBin->epsilon = 0;77 tilingDatafromBin->epsilon = 0;
79 tilingDatafromBin->apiTempBufferSize = 0;78 tilingDatafromBin->apiTempBufferSize = 0;
79+ AscendC::SetKernelMode(KernelMode::AIV_MODE);
80 80 
81 ICPU_SET_TILING_KEY(400);81 ICPU_SET_TILING_KEY(400);
82 ICPU_RUN_KF(layer_norm_v4, numBlocks, x, nullptr, gamma, beta, y, mean, rstd, workspace,82 ICPU_RUN_KF(layer_norm_v4, numBlocks, x, nullptr, gamma, beta, y, mean, rstd, workspace,
@@ -1,37 +1,36 @@
1-#!/usr/bin/env python31+# Copyright (c) 2025 Huawei Technologies Co., Ltd.
2-# -*- coding: utf-8 -*-2+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
3-# ----------------------------------------------------------------------------3+# CANN Open Software License Agreement Version 2.0 (the "License").
4-# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
5-# This file is a part of the CANN Open Software.
6-# Licensed under CANN Open Software License Agreement Version 2.0 (the "License").
7# Please refer to the License for details. You may not use this file except in compliance with the License.4# Please refer to the License for details. You may not use this file except in compliance with the License.
8# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,5# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.6# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
10# See LICENSE in the root of the software repository for the full text of the License.7# See LICENSE in the root of the software repository for the full text of the License.
11-# ----------------------------------------------------------------------------8+ 
12 9 
13import sys10import sys
14import numpy as np11import numpy as np
15-import tensorflow as tf12+import ml_dtypes
13+ 
14+BFLOAT16_DTYPE = ml_dtypes.bfloat16
16 15 
17 16 
18def compare_data(dtype):17def compare_data(dtype):
19 if dtype == "bfloat16":18 if dtype == "bfloat16":
20- dtype = tf.bfloat16.as_numpy_dtype19+ dtype = BFLOAT16_DTYPE
21- 20+ 
22 data_same = True21 data_same = True
23- tmp_output = np.fromfile(f"y.bin", dtype)22+ tmp_output = np.fromfile("y.bin", dtype)
24- tmp_golden = np.fromfile(f"golden_y.bin", dtype)23+ tmp_golden = np.fromfile("golden_y.bin", dtype)
25 if dtype == "float32":24 if dtype == "float32":
26- precision_value = 1/1000025+ precision_value = 1 / 10000
27 else:26 else:
28- precision_value = 1/100027+ precision_value = 1 / 1000
29 for j in range(len(tmp_golden)):28 for j in range(len(tmp_golden)):
30- if abs(tmp_golden[j]-tmp_output[j]) > precision_value:29+ if abs(tmp_golden[j] - tmp_output[j]) > precision_value:
31 print(f"index:{j}, golden:{tmp_golden[j]}, output:{tmp_output[j]}")30 print(f"index:{j}, golden:{tmp_golden[j]}, output:{tmp_output[j]}")
32 data_same = False31 data_same = False
33 break32 break
34- if dtype == tf.bfloat16.as_numpy_dtype:33+ if dtype == BFLOAT16_DTYPE:
35 data_same = True34 data_same = True
36 return data_same35 return data_same
37 36 
@@ -1,21 +1,15 @@
1-#!/usr/bin/env python31+# Copyright (c) 2025 Huawei Technologies Co., Ltd.
2-# -*- coding: utf-8 -*-2+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
3-# ----------------------------------------------------------------------------3+# CANN Open Software License Agreement Version 2.0 (the "License").
4-# Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
5-# This file is a part of the CANN Open Software.
6-# Licensed under CANN Open Software License Agreement Version 2.0 (the "License").
7# Please refer to the License for details. You may not use this file except in compliance with the License.4# Please refer to the License for details. You may not use this file except in compliance with the License.
8# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,5# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.6# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
10# See LICENSE in the root of the software repository for the full text of the License.7# See LICENSE in the root of the software repository for the full text of the License.
11-# ----------------------------------------------------------------------------
12 8 
13-import os
14import numpy as np9import numpy as np
15-from numpy import array10+import ml_dtypes
16import sys11import sys
17-import torch12+ 
18-import tensorflow as tf
19 13 
20def softmax(x, dtype):14def softmax(x, dtype):
21 x = x.astype(np.float32)15 x = x.astype(np.float32)
@@ -29,38 +23,55 @@ def softmax(x, dtype):
29 x_sum = x_sum.astype(np.float16)23 x_sum = x_sum.astype(np.float16)
30 return ans, x_max, x_sum24 return ans, x_max, x_sum
31 25 
26+ 
32def masked_softmax_with_rel_pos_bias_data(BS, W, N, S1, S2, dtype, tilingkey):27def masked_softmax_with_rel_pos_bias_data(BS, W, N, S1, S2, dtype, tilingkey):
33 x_shape = [BS, W, N, S1, S2]28 x_shape = [BS, W, N, S1, S2]
34 atten_mask_shape = [1, W, 1, S1, S2]29 atten_mask_shape = [1, W, 1, S1, S2]
35 bias_shape = [1, 1, N, S1, S2]30 bias_shape = [1, 1, N, S1, S2]
36- 31+ 
37 if dtype == "bfloat16":32 if dtype == "bfloat16":
38- dtype = tf.bfloat16.as_numpy_dtype33+ dtype = ml_dtypes.bfloat16
39 x = np.random.uniform(-1.0, 1.0, x_shape).astype(dtype)34 x = np.random.uniform(-1.0, 1.0, x_shape).astype(dtype)
40- x.tofile(f"x.bin")35+ x.tofile("x.bin")
41 scaleValue = 1.036 scaleValue = 1.0
42- atten_mask = np.zeros(atten_mask_shape).astype(dtype);37+ atten_mask = np.zeros(atten_mask_shape).astype(dtype)
43 if (tilingkey % 10) == 1:38 if (tilingkey % 10) == 1:
44- atten_mask = np.random.uniform(-1.0, 1.0, atten_mask_shape).astype(dtype) 39+ atten_mask = np.random.uniform(-1.0, 1.0, atten_mask_shape).astype(dtype)
45 scaleValue = 2.040 scaleValue = 2.0
46 elif (tilingkey % 10) == 2:41 elif (tilingkey % 10) == 2:
47 atten_mask = np.random.uniform(-1.0, 1.0, atten_mask_shape).astype(dtype)42 atten_mask = np.random.uniform(-1.0, 1.0, atten_mask_shape).astype(dtype)
48 elif (tilingkey % 10) == 3:43 elif (tilingkey % 10) == 3:
49 scaleValue = 2.044 scaleValue = 2.0
50 45 
51- atten_mask.tofile(f"atten_mask.bin")46+ atten_mask.tofile("atten_mask.bin")
52 bias = np.random.uniform(-1.0, 1.0, bias_shape).astype(dtype)47 bias = np.random.uniform(-1.0, 1.0, bias_shape).astype(dtype)
53- bias.tofile(f"bias.bin")48+ bias.tofile("bias.bin")
54 49 
55 y = np.multiply(x, scaleValue)50 y = np.multiply(x, scaleValue)
56 y = np.add(y, atten_mask)51 y = np.add(y, atten_mask)
57 y = np.add(y, bias)52 y = np.add(y, bias)
58 y, x_mas, x_sum = softmax(y, dtype)53 y, x_mas, x_sum = softmax(y, dtype)
59- y.astype(dtype).tofile(f"golden_y.bin")54+ y.astype(dtype).tofile("golden_y.bin")
60 55 
61-if __name__ == '__main__':56+ 
57+if __name__ == "__main__":
62 BS, W, N, S1, S2 = [int(p) for p in sys.argv[1:6]]58 BS, W, N, S1, S2 = [int(p) for p in sys.argv[1:6]]
63 dtype = sys.argv[6]59 dtype = sys.argv[6]
64 tilingkey = int(sys.argv[7])60 tilingkey = int(sys.argv[7])
65- print("BS", BS, "W", W, "N", N, "S1", S1, "S2", S2, "dtype", dtype, "tilingkey", tilingkey)61+ print(
62+ "BS",
63+ BS,
64+ "W",
65+ W,
66+ "N",
67+ N,
68+ "S1",
69+ S1,
70+ "S2",
71+ S2,
72+ "dtype",
73+ dtype,
74+ "tilingkey",
75+ tilingkey,
76+ )
66 masked_softmax_with_rel_pos_bias_data(BS, W, N, S1, S2, dtype, tilingkey)77 masked_softmax_with_rel_pos_bias_data(BS, W, N, S1, S2, dtype, tilingkey)
@@ -1,6 +1,3 @@
1-#!/usr/bin/python
2-# -*- coding: utf-8 -*-
3-# ----------------------------------------------------------------------------
4# Copyright (c) 2025 Huawei Technologies Co., Ltd.1# Copyright (c) 2025 Huawei Technologies Co., Ltd.
5# This program is free software, you can redistribute it and/or modify it under the terms and conditions of2# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
6# CANN Open Software License Agreement Version 2.0 (the "License").3# CANN Open Software License Agreement Version 2.0 (the "License").
@@ -8,33 +5,34 @@
8# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,5# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.6# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
10# See LICENSE in the root of the software repository for the full text of the License.7# See LICENSE in the root of the software repository for the full text of the License.
11-# ----------------------------------------------------------------------------8+ 
12 9 
13import sys10import sys
14import numpy as np11import numpy as np
15import glob12import glob
16import os13import os
17-import tensorflow as tf14+import ml_dtypes
18 15 
19curr_dir = os.path.dirname(os.path.realpath(__file__))16curr_dir = os.path.dirname(os.path.realpath(__file__))
20 17 
18+ 
21def compare_data(golden_file_lists, output_file_lists, d_type):19def compare_data(golden_file_lists, output_file_lists, d_type):
22 np_dtype = np.float3220 np_dtype = np.float32
23 if d_type == "float16":21 if d_type == "float16":
24 np_dtype = np.float1622 np_dtype = np.float16
25- precision = 1/100023+ precision = 1 / 1000
26 elif d_type == "float32":24 elif d_type == "float32":
27- precision = 1/1000025+ precision = 1 / 10000
28 else:26 else:
29- np_dtype = tf.bfloat16.as_numpy_dtype27+ np_dtype = ml_dtypes.bfloat16
30- precision = 1/100028+ precision = 1 / 1000
31- 29+ 
32 data_same = True30 data_same = True
33 for gold, out in zip(golden_file_lists, output_file_lists):31 for gold, out in zip(golden_file_lists, output_file_lists):
34 tmp_out = np.fromfile(out, np_dtype)32 tmp_out = np.fromfile(out, np_dtype)
35 tmp_gold = np.fromfile(gold, np_dtype)33 tmp_gold = np.fromfile(gold, np_dtype)
36 diff_res = np.isclose(tmp_out, tmp_gold, precision, 0, True)34 diff_res = np.isclose(tmp_out, tmp_gold, precision, 0, True)
37- diff_idx = np.where(diff_res != True)[0]35+ diff_idx = np.where(~diff_res)[0]
38 if len(diff_idx) == 0:36 if len(diff_idx) == 0:
39 print("PASSED!")37 print("PASSED!")
40 else:38 else:
@@ -44,14 +42,18 @@ def compare_data(golden_file_lists, output_file_lists, d_type):
44 data_same = False42 data_same = False
45 return data_same43 return data_same
46 44 
45+ 
47def get_file_lists(dtype):46def get_file_lists(dtype):
48 golden_file_lists = sorted(glob.glob(curr_dir + "/*golden*.bin"))47 golden_file_lists = sorted(glob.glob(curr_dir + "/*golden*.bin"))
49 output_file_lists = sorted(glob.glob(curr_dir + "/*output*.bin"))48 output_file_lists = sorted(glob.glob(curr_dir + "/*output*.bin"))
50 return golden_file_lists, output_file_lists49 return golden_file_lists, output_file_lists
51 50 
51+ 
52def process(d_type):52def process(d_type):
53 golden_file_lists, output_file_lists = get_file_lists(d_type)53 golden_file_lists, output_file_lists = get_file_lists(d_type)
54 result = compare_data(golden_file_lists, output_file_lists, d_type)54 result = compare_data(golden_file_lists, output_file_lists, d_type)
55+ return result
55 56 
56-if __name__ == '__main__':57+ 
57- process(sys.argv[1])58+if __name__ == "__main__":
59+ process(sys.argv[1])
@@ -1 +1,3 @@
1-tensorflow==2.20.01+tensorflow==2.20.0
2+ml-dtypes
3+en-dtypes>=0.0.4
@@ -1,9 +1,9 @@
1# ----------------------------------------------------------------------------1# ----------------------------------------------------------------------------
2# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd.2# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd.
3-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of 3+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4# CANN Open Software License Agreement Version 2.0 (the "License").4# CANN Open Software License Agreement Version 2.0 (the "License").
5# Please refer to the License for details. You may not use this file except in compliance with the License.5# Please refer to the License for details. You may not use this file except in compliance with the License.
6-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, 6+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8# See LICENSE in the root of the software repository for the full text of the License.8# See LICENSE in the root of the software repository for the full text of the License.
9# ----------------------------------------------------------------------------9# ----------------------------------------------------------------------------
@@ -51,6 +51,7 @@ if(UT_TEST_ALL OR OP_KERNEL_UT)
51 )51 )
52 52 
53 if(ENABLE_UT_EXEC)53 if(ENABLE_UT_EXEC)
54+ set(UT_RUN_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/scripts/run_kernel_ut.sh)
54 if(ENABLE_ASAN)55 if(ENABLE_ASAN)
55 execute_process(56 execute_process(
56 COMMAND ${CMAKE_C_COMPILER} -print-file-name=libasan.so57 COMMAND ${CMAKE_C_COMPILER} -print-file-name=libasan.so
@@ -61,19 +62,19 @@ if(UT_TEST_ALL OR OP_KERNEL_UT)
61 if(NOT result EQUAL 0)62 if(NOT result EQUAL 0)
62 message(FATAL_ERROR "compiler not support asan, please disable asan")63 message(FATAL_ERROR "compiler not support asan, please disable asan")
63 endif()64 endif()
64- set(PRELOAD "LD_PRELOAD=${LIBASAN_PATH}:/usr/lib/x86_64-linux-gnu/libstdc++.so.6")65+ set(PRELOAD "${LIBASAN_PATH}:/usr/lib/x86_64-linux-gnu/libstdc++.so.6")
65 add_custom_command(66 add_custom_command(
66 TARGET ${OP_KERNEL_UT_EXE}_${socVersion} POST_BUILD67 TARGET ${OP_KERNEL_UT_EXE}_${socVersion} POST_BUILD
67- COMMAND
68 COMMAND export LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} &&68 COMMAND export LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} &&
69- ${PRELOAD} ASAN_OPTIONS=detect_leaks=0 ./${OP_KERNEL_UT_EXE}_${socVersion}69+ bash ${UT_RUN_SCRIPT} ./${OP_KERNEL_UT_EXE}_${socVersion} ${ENABLE_UT_SYMBOLIZE} ${UT_CASE_TIMEOUT} ${PRELOAD}
atomgit-bot
atomgit-botatomgit-bot8月3日

🟡 Medium Priority

旧代码中 ASAN 模式的 COMMAND 行内显式设置了 ASAN_OPTIONS=detect_leaks=0(原 diff 第 70 行:${PRELOAD} ASAN_OPTIONS=detect_leaks=0 ./${OP_KERNEL_UT_EXE}_${socVersion})。新代码改为调用 run_kernel_ut.sh,但脚本内和 CMake COMMAND 中均未再设置此选项。其他 UT 类型(op_host、op_graph、op_api、op_kernel_aicpu)均保留了 ASAN_OPTIONS=detect_leaks=0。缺少该选项时 ASAN 会检测内存泄漏,可能导致原本无泄漏问题的测试用例报 FAIL,或产生大量噪音输出。

建议:在 run_kernel_ut.sh 的 run_with_preload 函数或 run_cmd 中,当 $ASAN_PRELOAD 非空时追加 ASAN_OPTIONS=detect_leaks=0;或者在 CMake COMMAND 行中直接在 bash 调用前加上该环境变量。

likedislike
70- COMMENT "Run fast op utest with asan"70+ COMMENT "Run fast op utest with asan (symbolize=${ENABLE_UT_SYMBOLIZE}, timeout=${UT_CASE_TIMEOUT}s)"
71 )71 )
72 else()72 else()
73 add_custom_command(73 add_custom_command(
74 TARGET ${OP_KERNEL_UT_EXE}_${socVersion} POST_BUILD74 TARGET ${OP_KERNEL_UT_EXE}_${socVersion} POST_BUILD
75- COMMAND export LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} && ./${OP_KERNEL_UT_EXE}_${socVersion}75+ COMMAND export LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} &&
76- COMMENT "Run fast op utest"76+ bash ${UT_RUN_SCRIPT} ./${OP_KERNEL_UT_EXE}_${socVersion} ${ENABLE_UT_SYMBOLIZE} ${UT_CASE_TIMEOUT}
77+ COMMENT "Run fast op utest (symbolize=${ENABLE_UT_SYMBOLIZE}, timeout=${UT_CASE_TIMEOUT}s)"
77 )78 )
78 endif()79 endif()
79 endif()80 endif()
@@ -88,4 +89,4 @@ if(UT_TEST_ALL OR OP_KERNEL_UT)
88 89 
89 add_custom_target(${OP_KERNEL_UT_EXE} DEPENDS ${AllSocVersion_OP_KERNEL_UT_EXE})90 add_custom_target(${OP_KERNEL_UT_EXE} DEPENDS ${AllSocVersion_OP_KERNEL_UT_EXE})
90 91 
91-endif()92+endif()
@@ -0,0 +1,142 @@
1+# Copyright (c) 2025-2026 Huawei Technologies Co., Ltd.
2+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
3+# CANN Open Software License Agreement Version 2.0 (the "License").
4+# Please refer to the License for details. You may not use this file except in compliance with the License.
5+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
6+# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
7+# See LICENSE in the root of the software repository for the full text of the License.
8+# ============================================================================
9+# Usage: bash run_kernel_ut.sh <exe_path> [SYMBOLIZE] [TIMEOUT] [ASAN_PRELOAD]
10+# exe_path : path to the kernel ut executable
11+# SYMBOLIZE : TRUE/FALSE, whether to enable addr2line symbolization (default TRUE)
12+# TIMEOUT : per-case timeout in seconds (default 120)
13+# ASAN_PRELOAD : LD_PRELOAD string for ASAN mode (optional)
14+set -o pipefail
15+ 
16+EXE_PATH="$1"
17+ENABLE_SYMBOLIZE="${2:-TRUE}"
18+CASE_TIMEOUT="${3:-120}"
19+ASAN_PRELOAD="$4"
20+ 
21+DOTTED_LINE="----------------------------------------------------------------"
22+PASS_COUNT=0
23+FAIL_COUNT=0
24+TIMEOUT_COUNT=0
25+FAILED_CASES=()
26+TIMEOUT_CASES=()
27+ 
28+if [[ -z "$EXE_PATH" || ! -x "$EXE_PATH" ]]; then
29+ echo "[ERROR] Invalid executable: ${EXE_PATH}"
30+ exit 1
31+fi
32+ 
33+# Disable core dump to avoid filling disk
34+ulimit -c 0 2>/dev/null || true
35+ 
36+# Reduce CANN log verbosity to minimize output
37+export ASCEND_GLOBAL_LOG_LEVEL="${ASCEND_GLOBAL_LOG_LEVEL:-3}"
38+ 
39+# When symbolization is disabled, create a fake addr2line that echoes the address.
40+# libcpudebug.so calls popen("addr2line -e <bin> -f -p -a -i -C 0x<addr>"),
41+# so the fake script must accept those flags and print the raw address.
42+FAKE_DIR=""
43+if [[ "$ENABLE_SYMBOLIZE" == "FALSE" ]]; then
44+ FAKE_DIR=$(mktemp -d)
45+ cat > "${FAKE_DIR}/addr2line" <<'EOF'
46+#!/bin/bash
47+# Fake addr2line: skip symbolization, echo last argument (the address)
48+for arg in "$@"; do
49+ last="$arg"
50+done
51+echo "??:0"
52+echo "${last}"
53+EOF
54+ chmod +x "${FAKE_DIR}/addr2line"
55+ export PATH="${FAKE_DIR}:${PATH}"
56+ echo "[INFO] Symbolization disabled (fake addr2line at ${FAKE_DIR})"
57+else
58+ echo "[INFO] Symbolization enabled"
59+fi
60+ 
61+cleanup() {
62+ if [[ -n "$FAKE_DIR" && -d "$FAKE_DIR" ]]; then
63+ rm -rf "$FAKE_DIR"
64+ fi
65+}
66+trap cleanup EXIT
67+ 
68+# List all test cases
69+RAW_LIST=$("$EXE_PATH" --gtest_list_tests 2>/dev/null)
70+if [[ $? -ne 0 ]]; then
71+ echo "[ERROR] Failed to list test cases from ${EXE_PATH}"
72+ exit 1
73+fi
74+ 
75+# Parse gtest list into fully-qualified "Suite.Case" names
76+CASES=()
77+CURRENT_SUITE=""
78+while IFS= read -r line; do
79+ # Lines with no leading space are suite names ending with "."
80+ if [[ "$line" =~ ^[^[:space:]] ]]; then
81+ CURRENT_SUITE="${line}"
82+ elif [[ "$line" =~ ^[[:space:]]+(.+) ]]; then
83+ local_case="${BASH_REMATCH[1]}"
84+ CASES+=("${CURRENT_SUITE}${local_case}")
85+ fi
86+done <<< "$RAW_LIST"
87+ 
88+TOTAL=${#CASES[@]}
89+if [[ $TOTAL -eq 0 ]]; then
90+ echo "[WARN] No test cases found"
91+ exit 0
92+fi
93+ 
94+echo "$DOTTED_LINE"
95+echo "Running ${TOTAL} test cases (timeout=${CASE_TIMEOUT}s, symbolize=${ENABLE_SYMBOLIZE})"
96+echo "$DOTTED_LINE"
97+ 
98+run_with_preload() {
99+ local cmd="$1"
100+ if [[ -n "$ASAN_PRELOAD" ]]; then
101+ LD_PRELOAD="${ASAN_PRELOAD}" ASAN_OPTIONS=detect_leaks=0 timeout --foreground "${CASE_TIMEOUT}" bash -c "$cmd"
102+ else
103+ timeout --foreground "${CASE_TIMEOUT}" bash -c "$cmd"
104+ fi
105+}
106+ 
107+for case_name in "${CASES[@]}"; do
108+ run_cmd="export LD_LIBRARY_PATH=\"\$LD_LIBRARY_PATH\" && \"${EXE_PATH}\" --gtest_filter=\"${case_name}\""
109+ echo "[RUN] ${case_name}"
110+ run_with_preload "$run_cmd" 2>&1
111+ rc=$?
112+ 
113+ if [[ $rc -eq 124 ]]; then
114+ TIMEOUT_COUNT=$((TIMEOUT_COUNT + 1))
115+ TIMEOUT_CASES+=("$case_name")
116+ echo "[ERROR] Test case TIMEOUT (${CASE_TIMEOUT}s): ${case_name}"
117+ elif [[ $rc -eq 0 ]]; then
118+ PASS_COUNT=$((PASS_COUNT + 1))
119+ echo "[OK] ${case_name}"
120+ else
121+ FAIL_COUNT=$((FAIL_COUNT + 1))
122+ FAILED_CASES+=("$case_name")
123+ echo "[FAIL] ${case_name} (exit=${rc})"
124+ fi
125+done
126+ 
127+echo "$DOTTED_LINE"
128+echo "Summary: total=${TOTAL}, pass=${PASS_COUNT}, fail=${FAIL_COUNT}, timeout=${TIMEOUT_COUNT}"
129+if [[ ${#FAILED_CASES[@]} -gt 0 ]]; then
130+ echo "Failed cases:"
131+ printf ' %s\n' "${FAILED_CASES[@]}"
132+fi
133+if [[ ${#TIMEOUT_CASES[@]} -gt 0 ]]; then
134+ echo "Timeout cases:"
135+ printf ' %s\n' "${TIMEOUT_CASES[@]}"
136+fi
137+echo "$DOTTED_LINE"
138+ 
139+if [[ $FAIL_COUNT -gt 0 || $TIMEOUT_COUNT -gt 0 ]]; then
140+ exit 1
141+fi
142+exit 0