Closed
[Feature] 支持通过 ASCEND_RT_LAUNCH_BLOCKING 控制 AICPU 调度阻塞下发 #3188
wan_jianfenAdd on  Sep 1Closed at  Sep 3
wan_jianfen
wan_jianfenCollaborators
Sep 1 Create

背景与问题

PyPTO 当前在 DeviceLauncher::LaunchKernel 中采用三流模型(aicore/sche/ctrl)下发算子。AICPU 调度(sche stream)与 AICore 计算(aicore stream)之间默认通过 RunPreSync + ring event 实现跨轮依赖同步,AICore kernel 下发时用 AclRtNoBlockingLaunchBegin/End 包裹以实现非阻塞。

但在某些调试/性能排查场景下,用户希望通过环境变量 ASCEND_RT_LAUNCH_BLOCKING=1 强制 AICPU 调度流阻塞下发(即 sche stream 上的 launch 必须等待前序 aicore 完成),以便:

  • 按下发顺序逐算子执行,便于定位时序问题
  • 排查 launch_early_mode / ring event 同步引入的偶发问题

当前框架未接入该环境变量,且 adapter 层缺少 aclrtNoBlockingLaunchBegin/End 和 aclrtSetStreamAttribute 的符号加载(libascendcl.so 未导出 aclrtNoBlockingLaunchBegin,实际实现位于 libruntime.so 中,符号名为 aclrtNoBlockingLaunchBeginImpl)。

期望方案

  1. adapter 层:新增 AclRtNoBlockingLaunchBegin/End(从 libruntime.so 加载 aclrtNoBlockingLaunchBeginImpl/EndImpl)和 AclRtSetStreamAttribute(从 libascendcl.so 加载)的 dlsym 加载
  2. 运行时:在 common.h 新增 IsLaunchBlockingEnabled() 读取 ASCEND_RT_LAUNCH_BLOCKING 环境变量(static 缓存,进程级)
  3. 下发逻辑:在 DeviceLauncher::LaunchKernel 中,当 !IsCaptureMode() && IsLaunchBlockingEnabled() 时,用 AclRtNoBlockingLaunchBegin/End 包裹 sche stream 上的 AICPU 调度下发,实现阻塞控制
  4. 测试:新增 test_blocking_launch.py ST 用例,通过 spawn 子进程在 import torch 前继承环境变量验证功能

涉及文件

  • framework/src/adapter/api/acl_api.cpp / acl_api.h
  • framework/src/adapter/manager/types/acl_adapter_types.h / runtime_adapter_types.h
  • framework/src/adapter/stubs/acl_stubs.cpp / acl_stubs.h
  • framework/src/interface/utils/common.h
  • framework/src/machine/runtime/launcher/device_launcher.cpp
  • python/tests/st/test_blocking_launch.py

验证标准

  • 环境变量未设置时:行为不变(走原有 ring event / RunPreSync 同步)
  • ASCEND_RT_LAUNCH_BLOCKING=1 时:sche stream 阻塞下发,AICPU 调度等待前序 AICore 完成
  • ST 用例 test_launch_blocking 通过
  • CANN 版本不兼容时(缺少 aclrtNoBlockingLaunchBeginImpl 符号)打印 warning 但不中断执行
likedislike
wan_jianfenwan_jianfenCollaborators
Sep 1 Assign wan_jianfen as responsible person
CANN-robotCANN-robotCollaborators
Sep 3 Close issue
CANN-robotCANN-robotCollaborators
Sep 3 Added label: resolved