已合并
[dx]aclnn通路新增前置transpose,优化超大Cin轴场景性能 #1462
Zehai创建于 2月3日
[dx]aclnn通路新增前置transpose,优化超大Cin轴场景性能 #1462
已合并
Zehai创建于 2月3日
已删除 :wzh_feature02合入到cann/ops-nnmaster
Zehai
Zehai成员
2月3日

描述

需求背景:
在dx算子中,B矩阵有一个转置逆序的过程,从ND format (Cout, Cin, Hk, Wk)转到Nz format (Cout1, -Hk, -Wk, Cin1, Cin0, Cout0),但是MTE2 DN2NZ的transpose的效率很低,如果将转置的过程都交给MTE2处理,会导致严重MTE2 bound。

整体方案:
在aclnn通路侧增加前置transpose的准入条件,通过对特定用例的filter进行转置,从而优化目标网络用例性能。前置transpose的目的在于,去掉MTE2对B矩阵做transpose的任务,提高MTE2效率,提升最终的性能。

关联的Issue

https://gitcode.com/cann/ops-nn/issues/1452

测试

测试用例规格约束:
gradOutput & gradInput:NCHW、NCDHW
filter:NCHW、NCDHW
cout < 1.5 * cin || cin < 1.5 * cout
cin > Dk * HK * Wk & cin >= 32
Dk * Hk * Wk > 1
group = 1

测试结果:
目标测试网络用例平均性能提升10%,单case波动5%以内

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 Zehai 的贡献)
CANN-robotCANN-robot成员
2月3日 将crystalhu,chenqi317,lileizheng,liubo75,tangweiwei2,zhangyuxiang0119,zhang-wu设为审查人
CANN-robot
CANN-robot成员
2月3日 评论:

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
conv lileizheng, chenqi317 (2/2) lileizheng, chenqi317 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
CANN-robotCANN-robot成员
2月3日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
2月3日 评论:

🔵 source code change are detected, tasks labels is removed in this pull request!

likedislike
CANN-robot
CANN-robot成员2月3日进行代码检视1
conv/convolution_backward/op_api/convolutionbackward.cpp
@@ -1,6 +1,6 @@
11/**
22 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
33 * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
CANN-robot
CANN-robot2月3日评论:

代码结构与可维护性: 新增的常量 WEIGHT_TRANSPOSE_SHAPE_DIMS 与已有的 WEIGHT_N2H_SHAPE_DIMS 值完全相同,存在重复定义。这增加了代码冗余,降低了可维护性。

问题类型: 代码结构与可维护性
文件路径: conv/convolution_backward/op_api/convolutionbackward.cpp
行号: 3
问题代码:

const FVector<int64_t> WEIGHT_N2H_SHAPE_DIMS = {0, 2, 3, 4, 1};
const FVector<int64_t> WEIGHT_TRANSPOSE_SHAPE_DIMS = {0, 2, 3, 4, 1};

修改建议:

建议删除 WEIGHT_TRANSPOSE_SHAPE_DIMS 的定义,在需要使用该转置维度的地方直接使用已有的 WEIGHT_N2H_SHAPE_DIMS 常量。如果这两个常量在未来可能有不同的语义或用途,应为其添加清晰的注释说明区别。

此评论由代码审查工具自动生成

likedislike
此处折叠了110条消息 查看更多
Xxutianlong1成员
3月12日 解决了最后一个问题
CANN-robot
CANN-robot成员
3月12日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: lileizheng, chenqi317.
Reviewers who wrote a comment of /lgtm are: lileizheng, chenqi317.

likedislike
CANN-robotCANN-robot成员
3月12日 关闭了关联的issue
CANN-robotCANN-robot成员
3月12日 合入了pull request
yuxin5成员3月13日进行代码检视1
conv/convolution_backward/op_api/convolutionbackward.cpp
@@ -2148,2 +2186,4 @@
21482186 }
21492187 }
2188+ 
2189+ if (CheckWeightPreTransposeEnable(weight, groups)) {
yuxin53月13日评论:

加一下Ops::NN::AclnnUtil::IsRegbase()芯片代际隔离判断

likedislike