Merged
feat(operation): Conv api support relu and support unaligned cout #5312
luyakun_hwAdd on Aug 6
feat(operation): Conv api support relu and support unaligned cout #5312
Merged
Merged fromluyakun_hw/pyptoconv_reluintocann/pyptomaster
Pull Request has been successfully merged by CANN-robot.
(Thank you for luyakun_hw's contribution.)Aug 6 Created pull request, commit b1321e5f
Aug 6 Associated issue: [Requirement|需求建议]: Conv+ReLU融合,Conv api支持cout非C0对齐
atomgit-bot
Aug 6 Comments:
Aug 6 Comments:
变更摘要
此 PR 主要为 Conv API 新增了 ReLU 融合能力,并移除了 Arch32 平台上对输出通道数必须 C0 对齐的限制。通过在 Conv 的 Store 管线中传递 reluType 模板参数,使得 L0C 数据写回 DDR 时可选择性地执行 ReLU 激活。同时删除了 coutPerGroup % c0 == 0 的强制校验,并为 Arch32 平台的 NZ2NZ 输出路径补充了 N 维度的对齐计算,从而支持非对齐的 cout。
主要改动
- Conv Store 管线全线支持 ReLU 融合:
TStoreConv、TStoreConvNZ2DN、TStoreConvNZ2NZ及其 2D/3D 变体均新增int64_t reluType模板参数,底层的pto::TSTORE调用根据reluType选择ReluPreMode::NoRelu或ReluPreMode::NormalRelu,实现 L0C→DDR 阶段的 ReLU 激活。 - 移除 Arch32 平台的 cout C0 对齐强制校验: 删除了
CheckAttrShape中coutPerGroup % c0 == 0的检查逻辑,使得 Arch32 平台不再强制要求每组输出通道数为 C0 的整数倍。 - Arch32 平台 NZ2NZ 路径支持非对齐 cout: 在
ConstrucCopyOutTile中,针对IsArch32Platform()分支,将l0cValidMN的 N 维度替换为对齐后的值(dynValidCoutL0 + cin0 - 1) / cin0 * cin0,而非直接使用原始的dstCL0DynValidShape。 - 新增
reluType属性定义与传递链路: 在operation_impl.h中新增CONV_RELU_ATTR常量及ConvAttrParam::reluType、LoadStoreConvOpAttributeKey::reluType字段;在SetConvAttrParam、SetTensorOpAttr、ConstrucCopyOutTile以及代码生成层GenMemL0CCopyOutConv中串联传递该属性。 - Python 接口文档类型修正:
conv.py中将relu_type参数的类型提示从ReLuType改为ConvReLuType,以匹配实际使用的枚举类型。


Incorrect?
atomgit-bot
Aug 6 Comments:
Aug 6 Comments:
代码审查
审查总结
经过对所有 8 个变更文件的逐行审查,发现 1 个问题:
| 优先级 | 数量 |
|---|---|
| P0 | 0 |
| P1 | 0 |
| P2 | 0 |
| P3 | 1 |
各文件审查结果:
- docs/zh/api/operation/pypto-conv.md — 发现 1 个 P3 问题:extend_params 表格中 relu_type 仍标注"当前暂不支持",与功能说明和代码实际支持情况不一致。
- framework/src/codegen/npu/codegen_mte_conv.cpp — 无问题。新增
reluType属性读取并通过模板参数传递给TStoreConv,与现有模式一致。 - framework/src/interface/operation/conv_operation_impl.cpp — 无问题。新增 ReLU 属性贯通整条链路(SetTensorOpAttr → SetConvAttrParam → ConstrucCopyOutTile → Conv),移除 Arch32 的 C0 对齐检查并在 NZ2NZ 路径做隐式对齐,逻辑正确。
- framework/src/interface/operation/operation_impl.h — 无问题。新增
CONV_RELU_ATTR常量和reluType成员,声明一致。 - framework/src/interface/tileop/conv/conv_pto.h — 无问题。
TStoreConv模板签名正确增加int64_t reluType参数并转发至各实现。 - framework/src/interface/tileop/conv/impl/arch35/conv_store_nz2dn_impl.h — 无问题。NZ2DN 路径的 2D/3D 均已正确添加 ReLU 支持的 TSTORE 调用。
- framework/src/interface/tileop/conv/impl/conv_store_nz2nz_impl.h — 无问题。NZ2NZ 路径的 2D/3D 均已正确添加 ReLU 支持的 TSTORE 调用。
- python/pypto/op/conv.py — 无问题。仅更新 docstring 中的类型名称(
ReLuType→ConvReLuType),代码逻辑未变。
整体风险评估:低风险。 变更范围集中在 Conv 算子的 ReLU 融合和非对齐 Cout 支持两条主线,代码链路清晰、模板参数传递一致,无 correctness/security/reliability 回归。唯一的文档不一致问题影响面较小,建议合入前修正。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


Incorrect?
Aug 6 Added label: cann-cla/yes
86 messages are collapsed here。 See more
Jie Yin
Aug 6 Comments:
Aug 6 Comments:
/approve


Aug 6 Added label: approved
Aug 6 Resolved final issue
Aug 6 Closed associated issue
Aug 6 Merged pull request
Conv+ReLU融合,Conv api支持cout非C0对齐
https://gitcode.com/cann/pypto/issues/2896