PyPTO 当前在 DeviceLauncher::LaunchKernel 中采用三流模型(aicore/sche/ctrl)下发算子。AICPU 调度(sche stream)与 AICore 计算(aicore stream)之间默认通过 RunPreSync + ring event 实现跨轮依赖同步,AICore kernel 下发时用 AclRtNoBlockingLaunchBegin/End 包裹以实现非阻塞。
DeviceLauncher::LaunchKernel
RunPreSync
AclRtNoBlockingLaunchBegin/End
但在某些调试/性能排查场景下,用户希望通过环境变量 ASCEND_RT_LAUNCH_BLOCKING=1 强制 AICPU 调度流阻塞下发(即 sche stream 上的 launch 必须等待前序 aicore 完成),以便:
ASCEND_RT_LAUNCH_BLOCKING=1
launch_early_mode
当前框架未接入该环境变量,且 adapter 层缺少 aclrtNoBlockingLaunchBegin/End 和 aclrtSetStreamAttribute 的符号加载(libascendcl.so 未导出 aclrtNoBlockingLaunchBegin,实际实现位于 libruntime.so 中,符号名为 aclrtNoBlockingLaunchBeginImpl)。
aclrtNoBlockingLaunchBegin/End
aclrtSetStreamAttribute
libascendcl.so
aclrtNoBlockingLaunchBegin
libruntime.so
aclrtNoBlockingLaunchBeginImpl
aclrtNoBlockingLaunchBeginImpl/EndImpl
AclRtSetStreamAttribute
common.h
IsLaunchBlockingEnabled()
ASCEND_RT_LAUNCH_BLOCKING
!IsCaptureMode() && IsLaunchBlockingEnabled()
test_blocking_launch.py
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
test_launch_blocking
背景与问题
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)。期望方案
AclRtNoBlockingLaunchBegin/End(从libruntime.so加载aclrtNoBlockingLaunchBeginImpl/EndImpl)和AclRtSetStreamAttribute(从libascendcl.so加载)的 dlsym 加载common.h新增IsLaunchBlockingEnabled()读取ASCEND_RT_LAUNCH_BLOCKING环境变量(static 缓存,进程级)DeviceLauncher::LaunchKernel中,当!IsCaptureMode() && IsLaunchBlockingEnabled()时,用AclRtNoBlockingLaunchBegin/End包裹 sche stream 上的 AICPU 调度下发,实现阻塞控制test_blocking_launch.pyST 用例,通过 spawn 子进程在import torch前继承环境变量验证功能涉及文件
framework/src/adapter/api/acl_api.cpp/acl_api.hframework/src/adapter/manager/types/acl_adapter_types.h/runtime_adapter_types.hframework/src/adapter/stubs/acl_stubs.cpp/acl_stubs.hframework/src/interface/utils/common.hframework/src/machine/runtime/launcher/device_launcher.cpppython/tests/st/test_blocking_launch.py验证标准
ASCEND_RT_LAUNCH_BLOCKING=1时:sche stream 阻塞下发,AICPU 调度等待前序 AICore 完成test_launch_blocking通过aclrtNoBlockingLaunchBeginImpl符号)打印 warning 但不中断执行