Closed
[Requirement|需求建议]: diag算子适配Ascend960并补齐arg_max/arg_min_with_value图模式Ascend960DT数据类型推导 #3689
jzj007Add on 21 days agoClosed at 20 days ago
21 days ago Added label: requirement
21 days ago Assign jzj007 as responsible person
20 days ago Close issue
20 days ago Added label: resolved


一、背景信息 (必填)
ops-math 仓需要支持 Ascend960DT 平台(
ascend960dt,NpuArch 为dav_9201,映射关系见cmake/soc_arch_variables.cmake的ASCEND_ALL_COMPUTE_UNIT/SOC_TO_ARCH_VALUES)。当前存在两处缺口: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 上该算子无法编译与运行。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训练等)
op_graph/*_graph_infer.cpp中的IMPL_OP(...).InferDataType(...)。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(NpuArchdav_9201)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