已关闭
[Requirement|需求建议]: 新增FusedMulAddNL2loss算子ascend950实现 #2305
AlfengYuan创建于  7月23日关闭于  7月24日
AlfengYuan
AlfengYuan成员
7月23日 创建

Thanks for sending an requirement! Please fill in the following template to help quickly solve your problem.

一、背景信息 (必填)

新增FusedMulAddNL2loss算子ascend950实现

二、价值/作用 (必填)

新增FusedMulAddNL2loss算子ascend950实现

三、设计方案 (必填)

3.1 使能方式(涉及哪些框架:如Aclnn直调、Pytorch训练等)

geir 图模式

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

fp16/fp3

3.2.2 host侧设计
  • OpDef 与 Proto 注册: 新增 fused_mul_add_nl2loss_def.cpp 以 OpDef 注册 ascend950 AICore 配置(支持动态 shape/rank、fp16/fp32、ND 格式),并指定 ExtendCfgInfo 关联 kernel 二进制;新增 fused_mul_add_nl2loss_proto.h 以 REG_OP 定义三输入(x1/x2/x3)两输出(y1/y2)的算子原型。

  • Infershape 与 InferDataType: 新增 fused_mul_add_nl2loss_infershape.cpp 将 y1 shape 设为与 x1 一致、y2 设为 0 维标量;新增 fused_mul_add_nl2loss_graph_infer.cpp 使 y1/y2 的 dtype 与 x1 保持一致。

  • Arch35 Tiling: 新增 fused_mul_add_nl2loss_tiling_arch35.cpp/h,将输入展平为一维并按核均分,计算 UB tile 大小(64 对齐),通过 FusedMulAddNL2lossTilingData 结构体传递 totalElements / coreElements / tailCoreElements / ubTileSize 四个字段;不使用 workspace,y2 归约直接走 GM 原子加或 core0 串行。

3.2.3 kernel侧设计

Arch35 Kernel: 新增 fused_mul_add_nl2loss.h,模板类 FusedMulAddNL2lossKernel 实现双缓冲流水线:fp32 路径 ComputeY1AndPartialFp32 + ReduceY2Atomic(core0 清零 → SyncAll → 各核 AtomicAdd);fp16 路径 ComputeY1Fp16 + ReduceY2Serial(core0 只读 x1 串行累加后单次写回)。新增 fused_mul_add_nl2loss_apt.cpp 入口以 DTYPE_X1 编译期分发半精度/单精度。

3.3 支持硬件

ascend950

3.4 算子约束限制

  • x1、x2 的 shape 必须一致(tiling 强校验)。
  • x1/x2/x3/y1/y2 数据类型必须一致,仅支持 FLOAT、FLOAT16。
  • x3 为单元素标量张量,实现上仅取 x3[0],不校验其元素个数。
  • y2 为 0 维标量输出(空 dims)。
  • FLOAT16 数据类型下,y2 结果超过 65504 时溢出(与 910b 内置实现一致,为数据类型固有限制)。
  • 该算子不提供 aclnn 接口,仅支持图模式调用。

💡 备注(选填)

likedislike
AlfengYuanAlfengYuan成员
7月23日 添加了label:requirement
AlfengYuanAlfengYuan成员
7月23日 将 alfengyuan 设为负责人
AlfengYuanAlfengYuan成员
7月23日 修改了issue 的描述
AlfengYuanAlfengYuan成员
7月23日 修改了issue 的描述
AlfengYuanAlfengYuan成员
7月23日 修改了issue 的描述
CANN-robotCANN-robot成员
7月24日 关闭了 issue
AlfengYuanAlfengYuan成员
7月24日 issue状态由 进行中 改变为 已完成
CANN-robotCANN-robot成员
7月24日 添加了label:Accepted
CANN-robotCANN-robot成员
7月24日 添加了label:resolved