已关闭
[Bug-Report|缺陷反馈][工具检测]: simd_simt_gather_and_adds存在内存越界 #1743
liusa002创建于  8 天前关闭于  6 天前
liusa002
8 天前 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

使用内存检测拉起算子,报了512条非法写,非误报,需要算子修复。

Environment / 环境信息 (Mandatory / 必填)

  • HDK 版本:25.1.rc2
  • CANN 版本:9.2.0
  • 硬件形态:Ascend950DT
  • 操作系统版本:openEuler 24.03

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

1.下载并安装CANN包
https://cmc-szv.clouddragon.huawei.com/cmcversion/index/releaseView?deltaId=14913606472500480&isSelect=Software

bash Ascend-cann-toolkit_9.2.0_linux-aarch64.run --install --install-path=/home/Ascend-B070 --quiet
bash Ascend-cann-950-ops_9.2.0_linux-aarch64.run --install --install-path=/home/Ascend-B070 --quiet
source /home/Ascend-B070/cann/set_env.sh

2.下载asc-devkit并切换到对应版本:
git clone https://gitcode.com/cann/asc-devkit.git
git checkout c65e4db9
3.切到算子路径:
cd asc-devkit/examples/05_simd_simt_hybrid/00_introduction/simd_simt_gather_and_adds
4.在CMakeLists.txt中加上检测编译选项--cce-enable-sanitizer -g:
image.png
5.编译算子并使用检测拉起:

mkdir -p build && cd build
cmake -DCMAKE_ASC_ARCHITECTURES=dav-3510 ..;make -j36
python3 ../scripts/gen_data.py
mssanitizer -t memcheck --log-level=error --full-backtrace=yes --log-file=san_error.log ./demo
python3 ../scripts/verify_result.py output/output.bin output/golden.bin

6.能够看到类似这样的告警:

====== ERROR: illegal write of size 4
======    at 0x800 on UB in "gather_and_adds_kernel(float*, unsigned int*, float*, unsigned int, unsigned int)"
======    by thread (512,0,0) in block aiv(0-7) on device 3
======    code in pc current 0x458 (serialNo:19)
======    #0 /home/asc-devkit/examples/05_simd_simt_hybrid/00_introduction/simd_simt_gather_and_adds/gather_and_adds.asc:59:32
======    #1 /home/Ascend/cann-9.2.0/tools/bisheng_compiler/lib/clang/15.0.5/include/__clang_cce_simt.h:398:3
======    #2 /home/Ascend-B070/cann-9.2.0/asc/include/simt_api/common_functions.h:39:5
======    #3 /home/asc-devkit/examples/05_simd_simt_hybrid/00_introduction/simd_simt_gather_and_adds/gather_and_adds.asc:107:5

Describe the expected behavior / 预期结果 (Mandatory / 必填)

预期没有非法读告警。

算子168行分配的动态UB大小只有2048字节,而后续105行和111行申请UB空间各需要4096字节,因此gather_output前512个thread写满2048字节,后512个threads越界,每个thread越界写4字节。将168行改为4096就不会报越界,考虑到111行也申请了UB空间,建议改为8192。

Special notes for this issue/备注 (Optional / 选填)

likedislike
Lliusa002
8 天前 修改了issue 的描述
LLycheeeee成员
6 天前 将 shaonaite 设为负责人
shaonaiteshaonaite成员
6 天前 将 ruoshuisixue 设为负责人
shaonaiteshaonaite成员
6 天前 移除了负责人 shaonaite
ruoshuisixue成员
6 天前 评论:

使用c65e4db9已复现问题,代码中ub的申请为4096,申请为2048,后续代码整改过程中已发现问题整改,最新代码已修复此问题,可以使用最新版进行复测

likedislike
ruoshuisixue成员
6 天前 评论:

最新代码已修复此问题,issue先关闭,如有问题后续可通过issue在进行交流

likedislike
Rruoshuisixue成员
6 天前 issue状态由 待办的 改变为 已完成
Rruoshuisixue成员
6 天前 关闭了 issue
Rruoshuisixue成员
2 天前 关联了pull request:SIMD与SIMT混合算子实现资料优化
Rruoshuisixue成员
2 天前 删除了关联的pull request:SIMD与SIMT混合算子实现资料优化