Closed
[Requirement|需求建议]: 新增 ConfusionMatrix 算子 Ascend950 实现 #3211
shengleAdd on Sep 17Closed at Oct 8
Sep 17 Added label: requirement
shengle
Sep 17 Comments:
Sep 17 Comments:
/assign @SeanDictionary


Sep 17 Assign SeanDictionary as responsible person
liuchenghao
Sep 17 Comments:
Sep 17 Comments:
【Multica 同步】状态:backlog(待认领);说明:本算子任务已同步至 Multica「CANN 算子开发迁移」项目,将按社区规格承接开发与质检(承接前会先核对关联 PR !5444 进展,避免重复实现);详情:AI4ME-289


Oct 8 Close issue
Oct 8 Added label: resolved
一、背景信息 (必填)
ConfusionMatrix 计算分类任务的混淆矩阵:对每个索引 i 将 weights[i](缺省为 1)累加到
y[labels[i], predictions[i]],输出 num_classes×num_classes 矩阵,兼容 TensorFlow
tf.math.confusion_matrix。canndev built-in 已有 A2(Ascend910B/910C)TBE 实现,ops-math 下一代仓尚缺 Ascend950(arch35)实现。
二、价值/作用 (必填)
补齐 ops-math 仓 Ascend950 平台的算子覆盖;配合 common tf-plugin(#5653 已合入)支撑
tf 图调用,同时提供 GE 图通路;分类评估、长尾 scatter-add 类场景可直接使用。
三、设计方案 (必填)
3.1 使能方式
GE 图(REG_OP 注册 + InferShape/InferDataType 双挂);tf 图(common/src/framework/
confusion_matrix_tf_plugin.cpp)。不交付 aclnn——对齐 built-in 支持面(A2 无 aclnn 源码)。
3.2 总体设计
3.2.1 算子支持的数据类型
labels/predictions:FLOAT / FLOAT16 / INT32 / INT8 / UINT8(两者 dtype 相同);
weights 与输出 dtype 相同:FLOAT / FLOAT16 / INT32 / INT8 / UINT8;共 25 种组合。
输出 dtype 由属性 dtype 指定("float32"/"int32"/"int8"/"float16"/"uint8")。
3.2.2 host侧设计
arch35 tiling:按输出矩阵与 UB 容量关系选择调度策略(full_load / batch_load /
not_full_load / determine),TilingKey = 策略 × 输出 dtype × weights 有无;
shape/dtype/num_classes 校验使用 OP_LOGE_FOR_INVALID_* 结构化宏。
3.2.3 kernel侧设计
SIMT 范式(参照 bincount):2D scatter-add,偏移 = label × num_classes + prediction;
full_load 在 UB 上原子加后 SetAtomicAdd 回写;not_full_load 直接 GM 原子加;
determine 按输出行切核消除跨核原子加(确定性模式,int8/uint8 固定走此路径)。
3.3 支持硬件
Ascend950(arch35)
3.4 算子约束限制
labels/predictions/weights 均为 1D 且 shape 相同;1 ≤ num_classes ≤ 4096;
仅支持 ND 格式;labels/predictions 值域不做校验(与 built-in TBE 行为一致)。
💡 备注:关联 PR:https://gitcode.com/cann/ops-math/pull/5444