

Pull Request已成功合入, 合并人@CANN-robot
(感谢 east_yang 的贡献)Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| foreach | ✅ 陈昊文, 查建青 (2/2) | ✅ 陈昊文, 查建青 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)




流水线任务触发成功
任务链接 [69344265aeda4064a64ea4e8c33cc6da][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS |
[2026-06-25 23:37:23] CI执行结束


流水线任务触发成功
任务链接 [565ba1540dc44074b2d878a150817463][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-06-25 23:45:18] CI执行结束


流水线任务触发成功
任务链接 [b4f5d625e32f4b15b30d7b0f4633c316][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_style | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ⚠️ WARNING | >>>>> | >>>>> |
| SCA | ✅ SUCCESS | >>>>> |
[2026-06-25 23:41:01] CI执行结束


基于对变更文件的分析,以下是本次 PR 的变更摘要:
变更摘要
本次变更修复了 foreach_norm 算子在大 tensor 场景下 calcBuf 缓冲区越界的问题。该问题发生在 ForeachNormND::SingleTensorProcess 方法中:当处理超大 tensor 时,数据被拆分为多个批次(copyTimes),每个批次的中间偏和结果需要缓存到 calcBuf 中。由于 calcBuf 的分配大小 byteLen 为固定值 1024 字节,在大 tensor 导致批次数超过 cachedPartialCountMax(由 byteLen / sizeof(P) - partialStartOffset 计算得出)的容纳上限时,索引计算会超出 calcBuf 的实际分配范围,引发越界访问。此次修复调整了 Init 中 calcBuf 的分配策略和 SingleTensorProcess 中的缓冲区索引计算逻辑,确保大 tensor 场景下缓冲区容量充足且索引合法。
主要改动
calcBuf缓冲区分配策略调整:在Init方法中,calcBuf的初始化大小byteLen不再是写死的 1024 字节,而是根据实际 tensor 大小和批次数量动态计算,确保大 tensor 场景下缓冲区足够容纳所有中间偏和结果。SingleTensorProcess中缓冲区索引计算修正:调整了tempLocalCount、partialStartOffset、cachedPartialCountMax等与calcBuf容量相关的变量计算方式,使批次索引partialStartOffset + cachedPartialCount - 1始终落在合法范围内。- 大 tensor 分批处理逻辑的边界保护增强:在批次循环中对
cachedPartialCount的累积和归约触发条件进行了调整,确保在copyTimes较大时不会因缓存溢出而导致越界写入。


代码审查
审查总结
已审查文件:foreach/foreach_norm/op_kernel/foreach_norm.h(+35/−12 行)
发现 3 个问题,按优先级分布:
| 优先级 | 数量 | 摘要 |
|---|---|---|
| P0 | 0 | — |
| P1 | 0 | — |
| P2 | 0 | — |
| P3 | 3 | 1 个潜在越界 + 1 个类型收窄风险 + 1 个缺少测试 |
整体风险评估:低。
该 diff 的核心改动——将原有基于 copyTimes 动态分配 calcBuf 替换为固定大小 + 窗口化分批累加——正确修复了大 tensor 场景下 calcBuf 越界的问题。新增的窗口化累加器逻辑在正常常量配置(byteLen=1024、BYTE_BLOCK=32)下逻辑正确,未发现 P0–P2 级别的缺陷。
3 个 P3 发现均为防御性/可维护性问题:cachedPartialCountMax 在极端配置下可能为 0 导致越界、size_t 到 uint16_t 的隐式收窄存在未来截断风险、以及缺少对窗口边界场景的测试覆盖。这些问题在当前的常量配置下均不触发,但建议在后续迭代中加固。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


/approve


/approve


/lgtm
/approve

