Pull Request已成功合入, 合并人@CANN-robot
(感谢 majiajian_hw 的贡献)变更摘要
本次 PR 主要针对 math 仓进行代码清理(cleancode),涉及 chunk_cat 和 random 两个模块共 5 个文件。改动集中在三个方面:对未初始化的成员变量添加默认值,消除潜在未定义行为;将 C 风格强制类型转换替换为 reinterpret_cast;统一代码风格(宏调用换行、常量命名、尾随空格清理等),并新增一处对 useCoreNum 为零的防御性检查。
主要改动
- 成员变量初始化: 在
sim_thread_exponential_tiling_arch32.h中为stepNum、lambda、seed、selfDType等 14 个成员变量补充了默认初始值;在chunk_cat_tiling.h中为isRegBase添加{false}初始化,避免使用未初始化的布尔值。 - C 风格转型替换为
reinterpret_cast: 在aclnn_normal.cpp的两处AllocScalar调用中,将(void*)&alg改为reinterpret_cast<void*>(&alg),提升代码安全性与可读性。 - 魔数替换为命名常量: 在
chunk_cat_tiling.cpp中新增constexpr uint32_t NUM_THIRTY_TWO = 32,并将DoUbSplit()中的硬编码32替换为该常量。 - 新增防御性检查: 在
sim_thread_exponential_tiling_arch32.cpp的Tiling4Block()中新增useCoreNum == 0的判断,防止除零或异常行为。 - 宏调用与链式调用格式统一: 对
OP_CHECK_IF宏调用统一采用多行缩进格式,将IMPL_OP_OPTILING链式调用合并为单行,以及将SetTilingKey/GetTilingKey简化为单行内联实现,提升代码风格一致性。


代码审查
I have now thoroughly reviewed all 5 changed files. Let me provide my analysis for each file and the closing summary.
逐文件审查结论
1. conversion/chunk_cat/op_host/chunk_cat_tiling.cpp
变更内容:添加 NUM_THIRTY_TWO 具名常量替换魔数 32;TilingDataToString() 开大括号换行;多处 OP_CHECK_IF / IMPL_OP_OPTILING 宏调用格式化对齐;删除多余空行及行尾空格。
审查结论:纯格式化与代码清理,逻辑语义无变化。NUM_THIRTY_TWO = 32 与已有的 UB_BLOCK_SIZE = 32 虽然数值相同但语义不同(一为 UB block 大小,一为通用常数32),属于合理的常量命名,无冲突。无问题。
2. conversion/chunk_cat/op_host/chunk_cat_tiling.h
变更内容:bool isRegBase; → bool isRegBase{false};,添加成员默认初始化。
审查结论:isRegBase 在 GetPlatformInfo() 中总是在使用前被赋值,添加 {false} 是安全的防御性初始化,不会改变任何可达路径的行为。无问题。
3. random/dsa_random_normal/op_host/op_api/aclnn_normal.cpp
变更内容:(void*)&alg → reinterpret_cast<void*>(&alg)(两处),C风格强转改为 C++ reinterpret_cast。
审查结论:二者在此上下文中语义完全等价(int64_t* → void* 的指针重解释),reinterpret_cast 使意图更明确。无问题。
4. random/sim_thread_exponential/op_host/arch32/sim_thread_exponential_tiling_arch32.cpp
变更内容:多处 OP_CHECK_IF 宏调用格式化;Tiling4Block() 中新增 useCoreNum == 0 检查;SetTilingKey()/GetTilingKey() 内联为单行;currentWorkspace[0] 赋值语句格式化;DoTiling() 中调用格式化;文件末尾补充换行符。
审查结论:新增的 useCoreNum == 0 检查是合理的防御性编程——当 useCoreNum 为 0 时,后续的 (batchNumTotal + useCoreNum - 1) / useCoreNum 将发生除零错误。该检查虽在正常流程中难以触发(因为 batchNumTotal > 0 时 useCoreNum ≥ 1),但作为防御措施没有负面影响。其余均为格式化变更。无问题。
5. random/sim_thread_exponential/op_host/arch32/sim_thread_exponential_tiling_arch32.h
变更内容:为 stepNum、stepBlock、roundedSizeNum、roundedSizeBlock、range、handleNumLoop、handleNumTail、totalCoreNum、ubSize、count、lambda、seed、offset、threadPerProcessor、streamProcessorCount、selfDType 添加类内默认初始化值;文件末尾补充换行符。
审查结论:所有新增初始化值均与构造函数后的语义一致(零值初始化),属于安全的防御性编程改进。selfDType = ge::DT_UNDEFINED 明确了未初始化状态。无问题。
关闭摘要
- P0 发现: 0
- P1 发现: 0
- P2 发现: 0
- P3 发现: 0
整体风险评估:此变更为纯代码清理(cleancode),包含格式化对齐、魔数常量化、C风格强转改为 reinterpret_cast、成员变量默认初始化、防御性零值检查。所有变更均不改变运行时逻辑语义,没有引入正确性、安全性、可靠性或兼容性问题。风险极低,可放心合入。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


compile


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 |
|---|---|---|
| repo-cann/ops-math | ✅ wangrui_, 冯彤 (2/2) | ✅ wangrui_ (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)


compile


流水线任务触发成功
任务链接 [3ad56f05518945468640b0f62df88796][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-07-08 19:11:49] CI执行结束


流水线任务触发成功
任务链接 [5c4c15a3ff9d4d90938fe267b0af0727][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer-chs-math | ✅ SUCCESS | >>>>> | |
| Compile_kirin-harmony-infer-chs-math-1 | ✅ SUCCESS | >>>>> | |
| UT_Test | ✅ SUCCESS | ||
| UT_Test_experimental | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-07-08 19:17:25] CI执行结束


流水线任务触发成功
任务链接 [a8388b2f5a004effb2c46bfaf9c015b6][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_harmony-infer-chs-math | ✅ SUCCESS | >>>>> | |
| Compile_kirin-harmony-infer-chs-math-1 | ✅ SUCCESS | >>>>> | |
| UT_Test | ✅ SUCCESS | ||
| UT_Test_experimental | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> |
[2026-07-08 19:18:45] CI执行结束


流水线任务触发成功
任务链接 [588423b5732e405097b83aac3488f084][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_Pr | ✅ SUCCESS | ||
| StaticCheck_codespell_check | ✅ SUCCESS | ||
| StaticCheck_link_validity_check | ✅ SUCCESS | ||
| StaticCheck_resource_existence_check | ✅ SUCCESS | ||
| StaticCheck_tag_closed_check | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_codestyle | ✅ SUCCESS | >>>>> | |
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-07-08 19:14:44] CI执行结束


描述
修复cleancode问题:魔鬼数字、成员变量初始化。
关联的Issue
测试
已完成
文档更新
NA
类型标签