已关闭
[Requirement|需求建议]: 增加sort lib全局排序公共库,供索引类算子全局排序模板使用 #4913
李鑫创建于  18 天前关闭于  18 天前
李鑫
李鑫成员
18 天前 创建

Thanks for sending an requirement! Please fill in the following template to help quickly solve your problem.

Backgroud(背景信息)

索引类算子在涉及处理多个重复索引时,由于atomicadd等导致的计算顺序不确定,可能出现多次执行结果不一致问题。针对该类算子提供一套统一解决方案,索引线性化+索引全局排序+按序处理。考虑到排序方案可复用,需要增加sort lib全局排序公共库,供索引类算子全局排序方案使用。

Origin(信息来源)

算子设计团队

Benefit / Necessity (价值/作用)

增加sort lib全局排序公共库,供索引类算子全局排序方案使用,简化索引类算子确定性方案开发成本

Design(设计方案)

1.1 定位与目标

SortLib 是 ops-nn/index 目录下的 header-only 公共排序库,为 index 类算子(scatter_addindex_add等)提供统一的 稳定基数排序(SIMT LSD radix sort)能力,避免各算子重复实现排序 + 索引 permutation 逻辑。

  • 输入:待排序键数组 x(长度 totalElements)。
  • 输出:排序后的值 sortedValues 与排序索引 sortedIndices(permutation,满足 sortedValues[i] == x[sortedIndices[i]])。
  • 稳定:相等元素保持原始相对顺序(依赖 LSD radix 的稳定 scatter)。

1.2 支持范围

维度 范围
芯片 仅 Ascend950 / Ascend350(DAV_3510SUPPORT_COMPUTE_UNIT "ascend950"TILING_DIR "arch35"
键类型 ValT int8/16/32/64、uint8/16/32/64、half、bfloat16_t、float
索引 IdxT int32 / int64
计数 CountT uint32(元素数 ≤ 2³⁰)/ int64(> 2³⁰,64 位计数)
方向 升序 / 降序(编译期 isDescending

1.3 关键特性

  1. 双路径:小 N 走单核硬件 AscendC::Sort 快路径(0 SyncAll、0 workspace);大 N 走自研多核 LSD radix sort。
  2. 稳定排序:LSD 每轮按字节(256 bin)稳定重排,保证 permutation 语义。
  3. 跨核前缀和:多核直方图通过 GM workspace + lookback 协议做全局 exclusive sum,支持跨 core 分桶。
  4. 空输入安全totalElements==0 时 host 返回固定配置、kernel 直接 return,不写 workspace(避免 0 字节越界)。
  5. header-onlyDISABLE_IN_OPP TRUE,无独立 op,由依赖方通过 ../sort_lib/ 引用;编译依赖自动解析(dependency_parser.py)。
likedislike
李鑫李鑫成员
18 天前 添加了label:requirement
李鑫
李鑫成员
18 天前 评论:

/assign

likedislike
CANN-robotCANN-robot成员
18 天前 将 lixin433 设为负责人
李鑫李鑫成员
18 天前 修改了issue 的描述
CANN-robotCANN-robot成员
18 天前 关闭了 issue
CANN-robotCANN-robot成员
18 天前 添加了label:resolved