Closed
[Requirement|需求建议]: diag算子适配Ascend960并补齐arg_max/arg_min_with_value图模式Ascend960DT数据类型推导 #3689
jzj007Add on  21 days agoClosed at  20 days ago
jzj007
jzj007
21 days ago Create

一、背景信息 (必填)

ops-math 仓需要支持 Ascend960DT 平台(ascend960dt,NpuArch 为 dav_9201,映射关系见 cmake/soc_arch_variables.cmake 的 ASCEND_ALL_COMPUTE_UNIT / SOC_TO_ARCH_VALUES)。当前存在两处缺口:

  1. Diag 算子未使能 960DT:conversion/diag/CMakeLists.txt 的 SUPPORT_COMPUTE_UNIT 仅有 ascend950 / ascend350,conversion/diag/op_host/diag_def.cpp 只注册了这两个平台的 AICore 配置,conversion/diag/op_host/config/ 下也没有 ascend960dt 目录,scripts/kernel/binary_config/ascendc_config.json 中 Diag 的 compute_units 同样只有这两个平台,结果 Ascend960DT 上该算子无法编译与运行。
  2. ArgMaxWithValue / ArgMinWithValue 的图模式数据类型推导未覆盖 960DT:两个算子的 op_graph/*_graph_infer.cpp 在判定是否读取 indice_dtype 属性时,分别使用 NpuArch 白名单 {NpuArch::DAV_3510} 与 short_soc_version == "Ascend950" 字符串比较,均匹配不到 dav_9201。因此 Ascend960DT 上索引输出类型被固定为 DT_INT32,与 Ascend950 行为不一致。

二、价值/作用 (必填)

  • 补齐 Diag(TF 风格对角线展开算子)在 Ascend960DT 上的算子能力,使上层框架在 960DT 上可正常构图与执行,无需回退到其他平台。
  • 使 ArgMaxWithValue / ArgMinWithValue 在 Ascend960DT 上的 indice_dtype 属性语义与 Ascend950 保持一致,避免图模式与单算子模式下索引输出 dtype 不一致(int32 / int64)导致的精度比对失败或下游算子类型不匹配。
  • 判定逻辑从 short_soc_version 字符串比较改为 NpuArch 枚举白名单,后续新增同 arch 的 SoC 只需追加枚举值,无需再改动字符串分支。

三、设计方案 (必填)

3.1 使能方式(涉及哪些框架:如 Aclnn直调、Pytorch训练等)
  • 图模式(GE)数据类型推导:op_graph/*_graph_infer.cpp 中的 IMPL_OP(...).InferDataType(...)。
  • AscendC 二进制编译配置:scripts/kernel/binary_config/ascendc_config.json、op_host/config/<soc>/*_binary.json、*_simplified_key.ini。
  • Diag 在 CMake 中为 ACLNNTYPE aclnn_exclude,不产出 aclnn 接口,通过 IR 图方式使能。
3.2 总体设计
3.2.1 算子支持的数据类型
  • Diag:输入 / 输出同 dtype,支持 float16、float32、double、bfloat16、int32、int64、complex64(op_host/config/ascend960dt/diag_binary.json 中 7 条组合,输入 shape 为动态 [-2])。
  • ArgMaxWithValue / ArgMinWithValue:indice 输出为 int32 或 int64(由 indice_dtype 属性决定),values 与输入 x 同 dtype。
3.2.2 host侧设计
  • conversion/diag/CMakeLists.txt:SUPPORT_COMPUTE_UNIT 追加 ascend960dt,SUPPORT_TILING_DIR 对应填 arch35,直接复用现有 tiling。
  • conversion/diag/op_host/diag_def.cpp:为 ascend960dt 注册 AICore 配置(DynamicCompileStaticFlag(true)、DynamicFormatFlag(false)、DynamicRankSupportFlag(true)、DynamicShapeSupportFlag(true)、NeedCheckSupportFlag(false)、opFile.value=diag_apt),与 ascend950/ascend350 共用同一配置对象。
  • conversion/diag/op_host/config/ascend960dt/:新增 diag_binary.json(208 行,7 条 dtype/shape 组合)与 diag_simplified_key.ini([Diag] default=0)。
  • scripts/kernel/binary_config/ascendc_config.json:Diag 的 compute_units 追加 ascend960dt,auto_sync 保持 true。
  • math/arg_max_with_value、math/arg_min_with_value:新增 IsSupportedNpuArch(),从 fe::PlatformInfoManager 读取 version/NpuArch,转为 NpuArch 枚举后查询白名单 {NpuArch::DAV_3510, NpuArch::DAV_9201};命中才读取 indice_dtype,否则保持默认 DT_INT32。获取平台信息或 NpuArch 失败时打印 OP_LOGW 并返回 false。
3.2.3 kernel侧设计

本次不新增 kernel 与 tiling 实现。Diag 复用 op_kernel/arch35/diag_apt.cpp(含 diag_simt.h、diag_struct.h)与 op_host/arch35/diag_tiling_arch35.cpp;ArgMaxWithValue / ArgMinWithValue 的改动仅位于图模式 InferDataType,不涉及 kernel。

3.3 支持硬件
  • Ascend960DT:ascend960dt(NpuArch dav_9201)
  • 本次改动不改变 ascend950 / ascend350 的既有行为

3.4 算子约束限制

  • Diag 输入按 1D 展平处理,输出为 n×n 对角矩阵(op_host/diag_infershape.cpp 按输入维度复制两次推导输出 shape);binary 配置使用动态 shape [-2]。
  • ArgMaxWithValue / ArgMinWithValue 在白名单平台(含 ascend960dt)上要求 indice_dtype 属性存在,缺失时 OP_CHECK_NULL_WITH_CONTEXT 直接返回错误。
  • 本次仅在 ascend960dt 上扩展,未涉及 ascend960pr(dav_9202)。

💡 备注(选填)
本次改动未执行 Ascend960DT 上板验证,仅完成语法编译校验。

关联 PR:https://gitcode.com/cann/ops-math/merge_requests/6467

likedislike
jzj007jzj007
21 days ago Added label: requirement
jzj007
jzj007
21 days ago Comments:

/assign @jzj007

likedislike
CANN-robotCANN-robotCollaborators
21 days ago Assign jzj007 as responsible person
CANN-robotCANN-robotCollaborators
20 days ago Close issue
CANN-robotCANN-robotCollaborators
20 days ago Added label: resolved