Closed
[Requirement|需求建议]: RadixTopK 支持 sortLen 超 int32 上限的 int64 索引大 shape #3564
Nice tryAdd on  Oct 14Closed at  Oct 15
Nice try
Nice tryCollaborators
Oct 14 Create

一、背景信息 (必填)

RadixTopK 算子当前受 int32 值域限制:当排序轴长度 sortLen 超过 int32 上限(2147483647)时,索引值域与跨核计数会溢出,IsRadixTopKSupport 直接返回不支持,算子无法处理超大 shape 的 top-k 场景。

二、价值/作用 (必填)

补齐 RadixTopK 在排序轴长度超过 2^31-1 的极端大 shape(K=240000 级别)下 fp16/bf16 + int64 索引的支持能力;同时修复 largest=true 时 ±NaN 计数口径不一致导致的槽位错位缺陷,提升与 torch 语义的一致性。

三、设计方案 (必填)

3.1 使能方式

Aclnn 直调路径(op_api/topk.cpp)。当 sortLen > int32 上限且 indices 输出为 int64 时,IsRadixTopKSupport 判为支持并进入 RadixTopK 路径。

3.2 总体设计
3.2.1 算子支持的数据类型

输入 x:float16 / bfloat16;输出 indices:int64(超大 shape 场景)。

3.2.2 host侧设计

新增 isInt64Shape 标志与 CalcInt64TilingParams;TilingKey 追加第 4 个模板参数 isInt64Shape(兼容原 3 参数 key);新增 indices dtype / kValue / per-core 元素数校验;binary.json 新增 int64 索引编译配置。

3.2.3 kernel侧设计

新增 RadixTopKWsI64 子类复用 RadixTopKWs,将跨核归约、边界计算等 int64 值域算术改为标量实现;索引输出 int32 域压缩 + int64 后向扩展写。同时修正 ±NaN 规范化与提取掩码口径、补齐 WS 同步。

3.3 支持硬件

ascend910b、ascend910_93(新增对应 binary.json 配置)。

3.4 算子约束限制

  • int64 索引仅在 sortLen > int32 上限时启用;kValue 需 ≤ int32 上限;per-core 元素数需 < 2^31。
  • sorted 仍仅支持 false。

关联 PR:https://gitcode.com/cann/ops-math/pull/6335

likedislike
Nice tryNice tryCollaborators
Oct 14 Added label: requirement
Nice try
Nice tryCollaborators
Oct 14 Comments:

/assign @Nice_try

likedislike
CANN-robotCANN-robotCollaborators
Oct 14 Assign Nice_try as responsible person
CANN-robotCANN-robotCollaborators
Oct 15 Close issue
CANN-robotCANN-robotCollaborators
Oct 15 Added label: resolved