Merged
feat: RadixTopK 新增 int64 索引变体并修复 largest 场景 NaN 与 WS 同步问题 #6335
Nice tryAdd on Oct 14
feat: RadixTopK 新增 int64 索引变体并修复 largest 场景 NaN 与 WS 同步问题 #6335
Merged
Merged fromNice_try/ops-math_workRadixTopKInt64Nanintocann/ops-mathmaster
Pull Request has been successfully merged by CANN-robot.
(Thank you for Nice try's contribution.)atomgit-bot
Oct 14 Comments:
Oct 14 Comments:
变更摘要
本次改动为 RadixTopK 算子引入了 int64 大 shape 变体:当排序轴长度 sortLen 超过 int32 上限(INT32_SORT_LEN_MAX)时,走新的 int64 模板并输出 int64 索引;同时统一了 ±NaN 在计数相与提取相的语义(largest=true 时 NaN 必入选、largest=false 时 NaN 不入选)。改动范围覆盖 tiling 判定与 TilingKey 模板参数、内核模板分发、op_api 支持判断及二进制组合配置。
主要改动
- 新增 int64 大 shape 内核变体: 新增
radix_top_k_ws_i64.h,RadixTopKWsI64继承RadixTopKWs,将跨核globalHist归约、边界查找、边界计数前缀和等改为 int64 标量累加,并通过VectorMergeI64向量拼装 int64 索引、CopyOutResultI64写回 int64 输出,outIndexBuf_按 int64 加倍;radix_top_k_ws.h相应将相关成员由private改为protected供子类复用。 - Tiling 判定、校验与 TilingKey 扩展:
radix_top_k_tiling.cpp/.h新增isInt64Shape_标志、常量INT32_SORT_LEN_MAX与CalcInt64TilingParams,在 int64 场景校验输出indices必须为DT_INT64、kValue与 per-core 元素数不超 int32 上限,并让needWorkspace覆盖 int64 变体;GET_TPL_TILING_KEY追加isInt64Shape参数,radix_top_k_tiling_key.h相应新增该 BOOL 模板参数(追加在最高位,保证既有 key 编码不变)。 - 内核模板分发扩展:
radix_top_k.cpp主 kernel 模板参数由<sorted, largest, isLargeShape>扩展为<sorted, largest, isLargeShape, isInt64Shape>,并包含、优先分派到RadixTopKWsI64实例。 - NaN 语义统一处理:
radix_top_k_common.h将NegateDataForLargest重命名为CanonicalizeDataForLargest,把±NaN规范化为同一正 NaN(bf16 借 fp32 域、fp16 原生Muls(+1));TwiddleInB16对largest=false追加键域取补以实现降序并将 NaN 落到序键最底端;SubTopKAndCopyOut对largest=true的非 EQ 通过改用NOT(LE)掩码(= (x > b) ∪ isNaN),并将rsvdCntV按 tile 配额curTileK封顶避免越界写。 - op_api 支持与二进制配置:
topk.cpp的IsRadixTopKSupport增加indicesDType参数,sortLen > MAX_INT32_INPUTSIZE且indices为DT_INT64时通过并分配 int64 索引输出;ascend910b、ascend910_93的radix_top_k_binary.json新增bfloat16/float16+indices_int64(indices_dtype=9)的组合项。
🧩 本次 Review 已使用自定义 Skill:


Incorrect?
atomgit-bot
Oct 14 Comments:
Oct 14 Comments:


Incorrect?
Oct 14 Added label: stat/needs-squash
Oct 14 Added label: cann-cla/yes
83 messages are collapsed here。 See more
Oct 15 Added label: approved
chenxingyu18
Oct 15 Comments:
Oct 15 Comments:
/lgtm
/approve


Oct 15 Added label: lgtm
Oct 15 Closed associated issue
Oct 15 Merged pull request
描述
本次改动为 RadixTopK 算子新增 int64 索引变体 RadixTopKWsI64,使排序轴长度 sortLen 超过 int32 上限(2^31-1)的超大 shape 场景可正常执行;同时修复 largest=true 场景下 ±NaN 的计数/提取口径不一致缺陷,以及 WS 变体在多轮归约、多块搬运中的同步问题。
改动原因
改动方法
host 侧
kernel 侧
关联的Issue
测试
文档更新
无
类型标签