Pull Request已成功合入, 合并人@CANN-robot
(感谢 chenyifeng 的贡献)变更摘要
本 PR 为纯代码风格(cleancode)整改,针对 GRU 及 GRUGrad 算子(aclnn_gru.cpp、aclnn_gru_backward.cpp、gru_tiling.cpp、gru_grad_tiling.cpp/.h)进行规范化重构,不涉及功能或算法行为变更。核心工作包括:将 C 风格强制类型转换统一替换为 static_cast、以具名常量替代魔法数字、修正形参命名与 lambda 捕获方式、为输出参数补充 const 限定,并清理冗余空行与变量声明方式。
主要改动
- C 风格强转改为
static_cast:在aclnn_gru.cpp与aclnn_gru_backward.cpp中,将(uint64_t)numLayers、(unsigned long long)i等写法统一替换为static<uint64_t>、static<unsigned long long>,消除编码规范告警。 - 魔法数字常量化:在
aclnn_gru_backward.cpp中新增常量GATE_LIST_COUNT = 5,门控列表(r/z/n/hn/h)校验循环由硬编码的5改为引用该常量。 CheckShapeValid输出参数增加const限定:dxOut、dhPrevOut、dparamsOut形参类型改为const指针,并相应调整CheckParams中的调用。GruGradTiling形参与捕获清理:ValidateInputShape/ValidateOutputShape的idx/e重命名为index/expected_dims,CheckParamsShape中 lambda 捕获由[&]收紧为[this];.h中CalculateCutBatchTiling的形参重命名为短名ub/al/act/ml/b。- 细节清理:
aclnn_gru.cpp中ret变量改为声明即初始化,aclnn_gru_backward.cpp删除冗余空行,gru_tiling.cpp删除多余空行。


代码审查
审查结论
各文件审查结果
| 文件 | 结论 |
|---|---|
rnn/gru/op_api/aclnn_gru.cpp |
发现问题:第 244、300 行 static<uint64_t>(numLayers) 为非法 C++ 语法,应为 static_cast<uint64_t>(P0 编译失败)。第 635 行 ret 声明与初始化合并无问题。 |
rnn/gru/op_host/gru_tiling.cpp |
无问题(仅删除一个空行,纯格式变更)。 |
rnn/gru_grad/op_api/aclnn_gru_backward.cpp |
发现问题:第 116、121、241、256、273 行 static<unsigned long long>(...) 为非法 C++ 语法,应为 static_cast<unsigned long long>(P0 编译失败)。CheckShapeValid 签名变更(移除未使用的 batchSizes 参数、输出参数改 const)经核实:函数体不再引用 batchSizes,调用点参数顺序与签名一致,GATE_LIST_COUNT 与 gate 数组长度匹配,无其他问题。 |
rnn/gru_grad/op_host/gru_grad_tiling.cpp |
发现问题:第 188、202 行 static<int64_t>(expected_dims.size()) 为非法 C++ 语法,应为 static_cast<int64_t>(P0 编译失败)。lambda 捕获从 [&] 改为 [this] 后成员访问(context_、nodeName_、成员函数)均可用,无问题。 |
rnn/gru_grad/op_host/gru_grad_tiling.h |
无问题(CalculateCutBatchTiling 参数重命名与 .cpp 第 425 行定义保持一致,参数名不影响编译)。 |
发现统计
- P0:3 个(均为本 diff 引入的
static<T>笔误导致的编译错误,涉及 3 个不同翻译单元) - P1:0
- P2:0
- P3:0
总体风险评估
高风险,必须打回。 本次"cleancode"重构在 3 个文件中把 C 风格转换改写成了 static<T>(...),但漏写了 _cast,导致 3 个翻译单元全部无法编译(P0 构建失败),PR 无法合入。同文件中未被改动的 static_cast(如 aclnn_gru_backward.cpp:253、ValidateShape:173)可佐证这是笔误而非有意为之。修复方式简单明确:将全部 9 处 static<...> 改为 static_cast<...>。除此之外,其余变更(签名清理、参数重命名、lambda 捕获调整、常量提取)经核实无正确性/行为回归。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 3 |
| 🟡 建议 | 0 |
⛔ 需要修改


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.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| rnn | ✅ 刘闯, 唐超 (2/2) | ✅ 刘闯 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
chen_0715, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/check-pr


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
修复Gru\GruGrad算子的cleancode问题
关联的Issue
https://gitcode.com/cann/ops-nn/issues/4892
测试
跑example无问题
文档更新
类型标签
AI/Agent生成声明