Merged
feat: broadcast 5维以上特殊场景路由至UB BRC模板 #797
hahaha22Add on Aug 29
feat: broadcast 5维以上特殊场景路由至UB BRC模板 #797
Merged
hahaha22Add on Aug 29
hahaha22
hahaha22Collaborators
Aug 29

描述

broadcast 模板 tiling 新增 5 维以上特殊场景识别 IsSpecialDimAboveFive,命中时路由至 UB BRC 模板执行。

改动方法:

  1. broadcast_tiling_base.h 新增 6 个常量:SPECIAL_DIM_THRESHOLD(5)、SPECIAL_DIM_IN_THRESHOLD(64)、SPECIAL_DIM_MAX_IN_OUT_NUM(3)、OUTER_PRODUCT_THRESHOLD(32768)、DTYPE_BYTES_2(2)、DTYPE_BYTES_4(4)
  2. broadcast_tiling.h 新增 IsSpecialDimAboveFive(dTypeSize) 判定,需同时满足:
    • 输入输出总个数 ≤ 3(SPECIAL_DIM_MAX_IN_OUT_NUM)
    • dtype 为 2 或 4 字节
    • 输出维度数 > 5(合轴后),且从右往左第 5 维 ≤ 2
    • 存在 last brc 输入(尾轴 stride 为 0):全维度元素个数 × dTypeSize < 512B(CACHE_LINE_512)
    • 存在纯搬运输入(无任何广播轴):内 5 维(从右往左)之积 ≤ 64,外层维度之积 ∈ [32768, 65536]
  3. IsUbBroadcast() 在既有尾轴对齐白名单判断之前接入该分支,命中即选择 UB BRC kernel

关联的Issue

#342
https://gitcode.com/cann/opbase/issues/342

测试

(待补充:二级冒烟、算子泛化等验证情况)

文档更新

无

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for hahaha22's contribution.)
hahaha22hahaha22Collaborators
Aug 29 Created pull request, commit d0624cee
CANN-robotCANN-robotCollaborators
Aug 29 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Aug 29 Comments:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to 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
pkg_inc ✅ 汤磊, 宋恺 (2/2) ✅ 汤磊 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
CANN-robot
CANN-robotCollaborators
Aug 29 Comments:

CLA Signature Pass

hahaha22, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robotCANN-robotCollaborators
Aug 29 Set pengjiahao96,zhou-qilong,wangrui_,rxtfeng,loov1,tang-lei01,jia0liang,zl_hw,songkai111,pingchuantang,llimwang,gubaocheng,wangyongguang as approver
5 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Aug 29 Added label: cann-cla/yes
hahaha22
hahaha22Collaborators
Aug 29 Comments:

compile

likedislike
hahaha22hahaha22Collaborators
Aug 29 Pre merge succeeded (commit_id: 72c85f7bdbf66662685da3ff99ef3a018b0c37dd)
CANN-robotCANN-robotCollaborators
Aug 29 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Aug 29 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Aug 29 Added label: ci-pipeline-passed
hahaha22hahaha22Collaborators
Aug 31 Change title to "feat: broadcast 5维以上特殊场景路由至UB BRC模板", originally titled "feat: 5维以上特殊场景走ub brc".
hahaha22hahaha22Collaborators
Aug 31 Modify description of pull request
zzz2048
zzz2048CollaboratorsAug 31Start code review2
pkg_inc/op_common/atvoss/broadcast/broadcast_tiling.h
@@ -425,29 +466,30 @@
466+ checkB = true;
467+ } else {
468+ int64_t innerProduct = 1;
469+ int64_t outerProduct = 1;
470+ for (uint64_t j = 0; j < tilingData.dims[i].size(); j++) {
471+ if (tilingData.strides[i][j] == 0) {
472+ return false;
473+ }
474+ if (j < static_cast<uint64_t>(innerStart)) {
475+ outerProduct *= tilingData.dims[i][j];
476+ } else {
477+ innerProduct *= tilingData.dims[i][j];
478+ }
479+ }
480+ if (innerProduct > SPECIAL_DIM_IN_THRESHOLD || outerProduct < OUTER_PRODUCT_THRESHOLD ||
481+ outerProduct > VALUE_TWO * OUTER_PRODUCT_THRESHOLD) {
482+ return false;
483+ }
484+ checkA = true;
485+ }
486+ }
487+ return checkA && checkB;
488+ }
425489 /**
426490 * 判断是否为nlast brc并且尾轴大于4096场景, 该场景走ub brc。
427491 * 1. 该输入必须是copyInBrc节点
@@ -506,6 +570,9 @@ private:
506570 OP_CHECK_NULL_WITH_CONTEXT(context_, inputDesc);
507571 auto inputDtype = inputDesc->GetDataType();
508572 int64_t dTypeSize = ge::GetSizeByDataType(inputDtype);
573+ if (IsSpecialDimAboveFive(dTypeSize)) {
zzz2048
zzz2048Aug 31Comments:

IsSpecialDimAboveFive 命中后直接改走 UB BRC,会改变现网这类 5 维以上非对齐场景的默认执行路径(原来走 NDDMA)。另外该分支放开了 dtype 约束:原有白名单 ubBroadcastDtypes 只包含 1/2 字节类型,fp32/int32/uint32 等 4 字节 dtype 配合 CopyInBrc 走 UB BRC 属于新增组合。PR 描述中测试栏还是"待补充",建议合入前补齐二级冒烟和算子泛化验证,重点覆盖 4 字节 dtype 与非对齐尾轴的精度和性能回归。

likedislike
hahaha22
hahaha22Collaborators
Aug 31 Comments:

已测试无问题

likedislike
zzz2048
zzz2048CollaboratorsAug 31Start code review1
pkg_inc/op_common/atvoss/broadcast/broadcast_tiling.h
@@ -425,0 +458,4 @@
458+ if (tilingData.strides[i].back() == 0) {
459+ int64_t inputProduct = 1;
460+ for (const auto& dim : tilingData.dims[i]) {
461+ inputProduct *= dim;
zzz2048
zzz2048Aug 31Comments:

这一段新增代码里有 9 行(461-483 行间)用了 tab 开头再接空格的缩进,比如 inputProduct *= dim; 和 outerProduct *= tilingData.dims[i][j];,而整个文件其余部分都是纯空格缩进,混用后不同编辑器下对齐会漂移,建议统一改成空格。

likedislike
zzz2048
zzz2048CollaboratorsAug 31Start code review2
pkg_inc/op_common/atvoss/broadcast/broadcast_tiling.h
@@ -428,0 +435,4 @@
435+ * @param dTypeSize dtype大小
436+ * @return
437+ */
438+ bool IsSpecialDimAboveFive(int64_t dTypeSize)
zzz2048
zzz2048Aug 31Comments:

IsSpecialDimAboveFive 命中时没有任何日志。目前 DoBroadcastOpTiling 里的日志只能看到最终的 isUbBroadcast 结果,无法区分是白名单、IsBigNLastBrc 还是这个新分支命中的。这类路由判定后续排查性能问题时不好定位,建议命中时补一条 INFO 日志说明走了 5 维以上特殊场景分支。

likedislike
hahaha22
hahaha22Collaborators
Aug 31 Comments:

当前pattern易识别,模板中Nlast等也没有加日志,后续可以统一添加。

likedislike
fanzhaoyun001
fanzhaoyun001Aug 31Start code review2
pkg_inc/op_common/atvoss/broadcast/broadcast_tiling.h
@@ -423,2 +423,4 @@
423423 }
424424 }
425+ /**
426+ * 判断是否为5维以上的特殊场景, 该场景走ub brc。
fanzhaoyun001
fanzhaoyun001Aug 31Comments:

条件约束太多了,需要更通用的约束条件

likedislike
hahaha22
hahaha22Collaborators
Aug 31 Comments:

当前有相应问题需要解决,先使用保守修改,后续针对这种场景再进一步优化,减少约束条件。

likedislike
songkai111
songkai111Collaborators
Sep 1 Comments:

/lgtm

likedislike
tang-lei01
tang-lei01Collaborators
Sep 1 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 1 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Sep 1 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 1 Merged pull request