已关闭
[Bug][arch35][norm] AddLayerNormQuant/SyncBatchNormGatherStatsFused kernel 使用 SyncAll 但 Tiling 未设置 SetScheduleMode(BATCH_MODE) #3872
tangweiwei2创建于  7月6日关闭于  7月14日
tangweiwei2成员
7月6日 创建

问题描述 (Describe the current behavior)

在 arch35(Ascend950)场景下,norm 类算子 AddLayerNormQuantSyncBatchNormGatherStatsFused 的 kernel 中使用了 SyncAll() 进行全核同步,但其 op_host tiling 代码中均未调用 SetScheduleMode(BATCH_MODE)(即 SetScheduleMode(1))。

SyncAll() 要求所有参与同步的核同时启动并在同一调度批次内运行。若未设置 BatchMode,系统默认按核分批调度,会导致:

  • 部分核尚未启动时,已启动的核在 SyncAll() 处无限等待,引发死锁/挂起
  • 或核间归约(mean/variance 等)数据依赖未就绪即被读取,导致结果错误

涉及算子与代码位置

# 算子 SyncAll 调用位置 tiling 入口函数 tiling 文件
1 AddLayerNormQuant op_kernel/arch35/add_layer_norm_dynamic_quant_regbase_full_load_kernel.h:526 Tiling4AddLayerNormQuant op_host/add_layer_norm_quant_tiling_arch35.cpp
2 SyncBatchNormGatherStatsFused op_kernel/sync_batch_norm_gather_stats_fused_first_axis_common.h:96,109,112,129,132 Tiling4SyncBatchNormGatherStatsFused op_host/sync_batch_norm_gather_stats_fused_tiling_base.cpp

这两个 norm 算子均通过 SyncAll() 实现核间归约同步(各核计算 partial sum/sum of squares 后,全核交换并汇总 mean/variance)。两者均有明确的 ascend950 binary config,arch35 场景下会触发该问题。

经确认,所有算子 tiling 文件全文无 SetScheduleMode 调用:

$ grep -rn "SetScheduleMode" norm/add_layer_norm_quant/op_host/ norm/sync_batch_norm_gather_stats_fused/op_host/
(无输出)

环境信息 (Environment)

  • 硬件:Atlas A3 / Ascend 950 (arch35)
  • 仓库:cann/ops-nn
  • 分支:master

重现步骤 (Steps to reproduce)

  1. 在 Ascend 950(arch35)环境下编译运行上述任一 norm 算子的 ST 测试;
  2. 当多核参与调度时(blockDim > 1),因未设置 BatchMode,核间调度存在批次差异;
  3. SyncAll() 处可能发生挂起或归约结果异常。

预期结果 (Describe the expected behavior)

各算子 tiling 中应调用 SetScheduleMode(1) 设置为 BatchMode,确保所有核同时启动,使 SyncAll() 全核同步正确生效。参考仓库中已有正确实现,例如:

  • norm/group_norm_grad/op_host/group_norm_grad_tiling_arch35.cpp:666context_->SetScheduleMode(1);
  • norm/layer_norm_grad_v3/op_host/layer_norm_grad_v3_grouped_reduce_big_m_tiling.cpp:197context_->SetScheduleMode(1); // Set to batch mode, all cores start simultaneously

修复建议

在各算子的 tiling 入口函数中添加:

context->SetScheduleMode(1);  // kernel 使用 SyncAll 全核同步,需设置为 BatchMode

具体位置:

  1. AddLayerNormQuantTiling4AddLayerNormQuantadd_layer_norm_quant_tiling_arch35.cpp
  2. SyncBatchNormGatherStatsFusedTiling4SyncBatchNormGatherStatsFusedsync_batch_norm_gather_stats_fused_tiling_base.cpp

备注 (Special notes)

此问题为通过代码静态排查发现(模式:kernel 含 SyncAll 但 tiling 缺 SetScheduleMode)。同类问题在仓库其他算子类别(hash / conv / loss / pooling / quant / index 等)中也存在,已分别提 issue 跟踪。

likedislike
Ttangweiwei2成员
7月6日 将 xieshengwei1024 设为负责人
tangweiwei2成员
7月6日 评论:

问题已收到,norm类算子已对齐,安排@xieshengwei1024跟踪

likedislike
yuning_chenyuning_chen成员
7月6日 将 tangweiwei2 设为负责人
Chao-WuChao-Wu成员
7月7日 关联了pull request:修复SyncBatchNormGatherStatsFused kernel 使用 SyncAll 但 Tiling 未设置 SetScheduleMode(BATCH_MODE)
Ttangweiwei2成员
7月14日 issue状态由 进行中 改变为 已解决
Ttangweiwei2成员
7月14日 关闭了 issue
CANN-robotCANN-robot成员
7月14日 添加了label:resolved