Merged
feat(machine): Support ASCEND_RT_LAUNCH_BLOCKING for AICPU scheduling blocking #5823
wan_jianfenAdd on Aug 31
feat(machine): Support ASCEND_RT_LAUNCH_BLOCKING for AICPU scheduling blocking #5823
Merged
wan_jianfenAdd on Aug 31
wan_jianfen
wan_jianfenCollaborators
Aug 31

修改意图

支持通过环境变量 ASCEND_RT_LAUNCH_BLOCKING=1 控制 AICPU 调度流阻塞下发,用于调试和时序问题排查场景。

修改内容

1. Adapter 层新增 API 加载

  • AclRtNoBlockingLaunchBegin/End:从 libruntime.so 加载 aclrtNoBlockingLaunchBeginImpl/EndImpl(libascendcl.so 未导出这两个符号,实际实现位于 libruntime.so)
  • AclRtSetStreamAttribute:从 libascendcl.so 加载 aclrtSetStreamAttribute

2. 运行时阻塞控制

  • common.h 新增 IsLaunchBlockingEnabled(),读取 ASCEND_RT_LAUNCH_BLOCKING 环境变量(static 缓存)
  • device_launcher.cpp 中 LaunchKernel:当 !IsCaptureMode() && IsLaunchBlockingEnabled() 时,用 AclRtNoBlockingLaunchBegin/End 包裹 sche stream 上的 AICPU 调度下发

3. ST 测试用例

  • 新增 test_blocking_launch.py,通过 spawn 子进程在 import torch 前继承环境变量验证功能

改动文件

文件 说明
framework/src/adapter/api/acl_api.cpp / acl_api.h 新增 AclRtSetStreamAttribute、AclRtNoBlockingLaunchBegin/End 实现
framework/src/adapter/manager/types/acl_adapter_types.h 新增 RtSetStreamAttribute 枚举与符号映射
framework/src/adapter/manager/types/runtime_adapter_types.h 新增 NoBlockingLaunchBegin/End 枚举,映射到 aclrtNoBlockingLaunchBeginImpl/EndImpl
framework/src/adapter/stubs/acl_stubs.cpp / acl_stubs.h 新增 StubRtSetStreamAttribute stub
framework/src/interface/utils/common.h 新增 IsLaunchBlockingEnabled()
framework/src/machine/runtime/launcher/device_launcher.cpp LaunchKernel 中接入阻塞下发控制
python/tests/st/test_blocking_launch.py 新增 ST 用例

验证

  • 环境变量未设置时:行为不变(走原有 ring event / RunPreSync 同步)
  • ASCEND_RT_LAUNCH_BLOCKING=1 时:sche stream 非阻塞下发
  • CANN 版本不兼容时(缺少符号)打印 warning 但不中断执行

Related Issue: #3188

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for wan_jianfen's contribution.)
wan_jianfenwan_jianfenCollaborators
Aug 31 Created pull request, commit 10fe44c5
atomgit-bot
atomgit-bot
Aug 31 Comments:

变更摘要

本 PR 主要聚焦于 launch blocking(启动阻塞)能力:新增 AclRtNoBlockingLaunchBegin/AclRtNoBlockingLaunchEnd 运行时接口,并在非 capture 模式下用其包裹 AICore 与 AICPU 内核启动;同时将 DevicePerf 的性能数据初始化改为首次使用时懒加载,并为分配/拷贝失败引入错误码返回与错误日志;DeviceLauncher::SetDevPerfAddr 相应改为返回错误码并向上传递;此外调整了 LaunchAicpuKernel 的调度顺序,并让 AICore 打印由 ENABLE_AICORE_PRINT 编译开关控制。

主要改动

  • 新增无阻塞启动接口:在 acl_api.h/acl_api.cpp 中新增 AclRtNoBlockingLaunchBegin/AclRtNoBlockingLaunchEnd,通过 AdapterManager 查找并调用运行时适配函数;同时在 runtime_adapter_types.h 的 RuntimeFunc 枚举中增加 NoBlockingLaunchBegin/NoBlockingLaunchEnd,并映射到 aclrtNoBlockingLaunchBeginImpl/aclrtNoBlockingLaunchEndImpl。
  • 内核启动包裹 begin/end 调用:DeviceLauncher::LaunchAicoreKernel 与 LoadAicpuOp::LaunchWithHostArgs 在非 capture 模式下,分别用 AclRtNoBlockingLaunchBegin/AclRtNoBlockingLaunchEnd 包裹 RuntimeKernelLaunchWithHandleV2 与 RuntimeLaunchKernelWithHostArgs。
  • 性能数据懒初始化与错误传播:DevicePerf::InitPerfData/SetDebugEnable 改为返回错误码,perfData_ 的内存分配延迟到首次 SetDebugEnable(由 g_isInitPerfData 控制),malloc/memcpy 失败时记录错误日志并返回;DeviceLauncher::SetDevPerfAddr 返回值由 void 改为 int,LaunchBundleKernelOnce 检查其返回值,LaunchKernel 对失败进行断言。
  • 调整 AICPU 内核启动顺序:DeviceLauncher::LaunchAicpuKernel 将 PyptoRun(sche 流)的启动提前到 ctrl 流之前,并在 IsAicoreResolveEnabled() 时提前返回。
  • AICore 打印按编译开关控制:DeviceDfx::Init 仅在 ENABLE_AICORE_PRINT 开启时初始化 AICore 打印,LaunchAicoreKernel 中的同步条件也由该编译期常量控制;相关 UT(test_device_launcher_host.cpp、test_device_launcher_npu.cpp、test_device_runner.cpp)同步适配了 sharedBuffer 的赋值与清理。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 31 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 31 Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
Aug 31 Added label: cann-cla/yes
94 messages are collapsed here。 See more
CANN-robot
CANN-robotCollaborators
Sep 3 Comments:

The following labels are not ready.

lgtm: Please wait for committers to review the code.

approved: Please wait for committers to review the code.

likedislike
lidongsheng
lidongshengCollaborators
Sep 3 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 3 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Sep 3 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 3 Merged pull request