已关闭
[Bug-Report|缺陷反馈]: [工具检测]ops-nn仓 loss/cross_entropy_loss 算子扫描出现异常内存告警,分析确认存在内存越界写风险 #5257
Goldfish_of_Siris创建于  13 天前关闭于  2 天前
Goldfish_of_Siris
Goldfish_of_Siris
13 天前 创建

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

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

使用检测工具扫描 loss/cross_entropy_loss 算子,扫描结果告警中存在异常内存写入告警:
image.png

经分析该告警为算子代码异常:
cross_entropy_loss_full_load.h:162中InitBuffer初始化了32B的内存,在895行inputQueue_.AllocTensor出来的有效内存只有32B,但在896行的DataCopyPad一共写入了196B的数据,有160B的越界写入

调用链:

kernel_meta/CrossEntropyLoss..._kernel.cpp:382
  └─> Process()                              [full_load.h:200]
        ├─> ProcessEachCore() → ComputeEachCoreOnce()
        │     └─> CopyInInput()              [605]  inputQueue_.AllocTensor<T1>() ← 分配 ncOnce*4B
        │     └─> ...每核累加部分和到 clearUb_[0/8/16]
        │     └─> DataCopyWorkspace()        [869]  本核3个部分和写回 GM workspace(每核32B对齐)
        ├─> SyncAll()
        └─> ComputeNLast()                   [882]  block0 跨核 reduce 收尾  ❌ 越界点
              ├─> 895: allReduceUb = inputQueue_.AllocTensor<float>()  ← 只分到 32B
              ├─> 896: DataCopyPad(allReduceUb, workspaceGm_[0], ...)  ← 写入 192B ❌ 越界160B
              └─> 900: VfAllSum(16, allReduceUb, clearUb)              ← 读 allReduceUb[0..47] ❌

请确认算子代码行为是否符合预期

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

环境:Ascend950PR
cann包版本:730商发
ops-nn代码仓:9.1.0分支

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

使用以下命令运行算子
bash build.sh --pkg --soc=ascend950 --ops=aipp -j96 --mssanitizer > test_result/9_aipp/compile.log 2>&1
./build_out/cann-ops-cv-custom-linux.x86_64.run --force
export LD_LIBRARY_PATH=/home/lishuo/cann/730/cann-9.1.0/opp/vendors/custom_cv/op_api/lib/😒{LD_LIBRARY_PATH}
bash build.sh --run_example aipp graph cust --soc=ascend950 > test_result/9_aipp/example.log 2>&1
time mssanitizer -t memcheck --log-level=error -- bash build.sh --run_example aipp graph cust --soc=ascend950 > test_result/9_aipp/memcheck.log 2>&1
time mssanitizer -t memcheck --log-level=error -- build/test_aclnn_cross_entropy_loss --soc=ascend950 > test_result/233_cross_entropy_loss/memcheck_ge.log 2>&1
随后可看到内存告警信息

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

预期算子运行正常无告警

见附件:

3309d61306c84923a742a4238398d80a.zip

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

likedislike
yuning_chen
yuning_chen成员
13 天前 评论:

/assign @zhu-lei0614

likedislike
CANN-robot
CANN-robot成员
13 天前 评论:

Notice

This issue can not be assigned to zhu-lei0614. Please try to assign to the repository members.

likedislike
yuning_chenyuning_chen成员
13 天前 将 yolic 设为负责人
yuning_chen
yuning_chen成员
13 天前 评论:

您好,问题已收到,目前 @zhu-lei0614 正在跟踪处理。

likedislike
CANN-robotCANN-robot成员
2 天前 关闭了 issue
CANN-robotCANN-robot成员
2 天前 添加了label:resolved