已合并
A5增加scatter_add_with_sorted算子 #4175
A5增加scatter_add_with_sorted算子 #4175
已合并
wkkk0528创建于 4月24日
wkkk0528
4月24日

描述

背景一:scatter类算子在索引重复的时候会涉及到同一个gm地址写数据,而david芯片同地址写性能远低于竞品(相差100倍),因此为了性能考虑要尽可能规避同地址写问题。对于scatter这类算子一个解决方法就是在将相同索引对应的计算(累加、替换等)在核内完成。在核内完成同索引的处理,就希望同索引尽可能的挨在一次,因此期望索引是有序的。
背景二:scatter类算子当多核切分在scatter轴时,为了保证确定性计算,需要每个核之间搬出的数据是有序的,一种做法是每个核顺序搬出,这样会有较大的等待开销,相当于开单核,为了提升性能,另外一种做法是对索引做全局排序,然后按索引序搬出。

从性能的角度,希望在部分场景将 scatter_add替换位 sort(索引) + scatter_add_with_sorted两个算子,因此开发了 scatter_add_with_sorted算子,以增强scatter_add在确定性场景的性能。

代码结构

index/scatter_add_with_sorted/
├── op_host/                          # Tiling 层
│   ├── scatter_add_with_sorted_def.cpp           # [修改] 新增算子定义
│   ├── scatter_add_with_sorted_tiling.cpp        # [修改] 注册 ASCENDC 模板化 tiling
│   ├── scatter_add_with_sorted_tiling_base.h     # [新增] 基础 Tiling 类,提取公共逻辑
│   ├── scatter_add_with_sorted_tiling_base.cpp   # [新增] 基础 Tiling 实现(shape 解析、平台信息获取等)
│   ├── scatter_add_with_sorted_simd_tiling.h     # [新增] SIMD Tiling 类声明
│   ├── scatter_add_with_sorted_simd_tiling.cpp   # [新增] SIMD Tiling 实现(多核切分、UB 切分、Buffer 规划)
│   ├── scatter_add_with_sorted_simt_tiling.h     # [新增] SIMT Tiling 类声明
│   ├── scatter_add_with_sorted_simt_tiling.cpp   # [新增] SIMT Tiling 实现
│   ├── scatter_add_with_sorted_tiling.h          # [原有] 旧版 Tiling 数据结构
│   ├── config/ascend950/
│   │   ├── scatter_add_with_sorted_binary.json   # [新增]  二进制配置(8 组 dtype)
│   │   └── scatter_add_with_sorted_simplified_key.ini  # [新增] simplified_key_mode=0
│   └── op_api/
│       └── scatter_add_with_sorted.cpp           # [修改] aclnn 接口适配
│
├── op_kernel/                         # Kernel 层
│   ├── scatter_add_with_sorted_apt.cpp           # [新增] kernel 入口,ASCENDC 模板化分发
│   ├── scatter_add_with_sorted.cpp               # [原有] kernel(保持不变)
│   └── arch35/                                   # [新增] arch35 kernel 实现
│       ├── scatter_add_with_sorted_struct.h      # 模板参数声明 & Tiling 数据结构定义
│       ├── scatter_add_with_sorted_simd_common.h # SIMD 公共工具函数
│       ├── scatter_add_with_sorted_simd.h        # SIMD 模式 kernel
│       ├── scatter_add_with_sorted_simd_determ.h # SIMD 确定性模式 kernel
│       ├── scatter_add_with_sorted_determ_workspace.h # 确定性模式 workspace 处理
│       ├── scatter_add_with_sorted_simt.h        # SIMT 模式 kernel
│       └── scatter_add_with_sorted_simt_determ.h # SIMT 确定性模式 kernel
│
└── tests/ut/
    ├── op_host/
    │   └── test_scatter_add_with_sorted_tiling.cpp  # [修改] 新增tiling UT 用例
    └── op_kernel/
        ├── CMakeLists.txt                          # [修改] 新增编译目标
        ├── scatter_add_with_sorted_tiling_def.h    # [新增] UT tiling 定义
        ├── test_scatter_add_with_sorted_apt.cpp    # [新增]kernel UT
        └── test_scatter_add_with_sorted.cpp        # [修改] 引用新的 tiling_def.h

关联的Issue

关联Issue #2351

测试

出包测试200条泛化用例,精度均pass,aclnn接口的的性能较之前调用scatteradd的方式提升3.9倍;通过冒烟测试

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 wkkk0528 的贡献)
Wwkkk0528
4月24日 创建了 pull request,commit 56dc5620
CANN-robot
CANN-robot成员
4月24日 评论:

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
*/*/README.md 周奇龙, 陈娇, 陈琦 (3/2) 陈娇 (1/1)
*/*/op_host/*_def.cpp 周奇龙, 陈琦, 王永光 (3/2) 王永光 (1/1)
index 周奇龙, 陈琦, 王永光 (3/2) 王永光, 周奇龙, 陈琦 (3/1)
scripts 周奇龙, 陈琦 (2/2) 周奇龙, 陈琦 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
4月24日 添加了label:cann-cla/yes
CANN-robotCANN-robot成员
4月24日 将chenfeng61,FelixTang7,crystalhu,yangyang016,fanqirui,zhou-qilong,chenqi317,liubo75,tangweiwei2,wangyongguang,zhang-wu设为评审人
CANN-robotCANN-robot成员
4月24日 将chenfeng61,FelixTang7,crystalhu,yangyang016,fanqirui,zhou-qilong,chenqi317,liubo75,tangweiwei2,wangyongguang,zhang-wu设为审查人
此处折叠了349条消息 查看更多
chenjiao成员
4月29日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
4月29日 添加了label:approved
CANN-robot
CANN-robot成员
4月29日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: 陈娇, 王永光, 周奇龙, 陈琦.
Reviewers who wrote a comment of /lgtm are: 陈娇, 周奇龙, 陈琦, 王永光.

likedislike
CANN-robotCANN-robot成员
4月29日 关闭了关联的issue
CANN-robotCANN-robot成员
4月29日 合入了pull request