Merged
refactor(machine): Remove DeviceRunner and redistribute init flow #5426
refactor(machine): Remove DeviceRunner and redistribute init flow #5426
Merged
wan_jianfenAdd on Aug 13
wan_jianfen
wan_jianfenCollaborators
Aug 13

refactor(machine): Remove DeviceRunner and redistribute init flow

DeviceRunner was a god-class singleton that mixed device init, HostProf management,
DevicePerf management, stream synchronization, and AiCpu .so loading. This PR
dissolves it entirely, redistributing each responsibility to its natural module.

Changes:

  • Move init flow (InitDeviceArgs / InitDeviceArgsCore / GetAicoreRegs / InitAiCpuSoBin / SetAiCpuSoOverride) into KernelBinary with static g_deviceArgs + std::call_once guard (EnsureInitialized / InitMetaData / GetEnableDumpDevPref)
  • Move HostProf methods (SetHostProfFunction / GetHostProfType / ReportHostProfInfo) into HostProf::GetInstance() singleton
  • Move DevicePerf methods (ResetPerData / SyncProfData / SetDebugEnable) into DevicePerf::GetInstance() singleton
  • Move DynamicLaunchSynchronize into DeviceLauncher
  • Move KernelLaunchInfo struct into device_launcher_types.h
  • Delete device_runner.h and device_runner.cpp
  • Update all call sites: device_launcher.cpp, kernel_bundle_launch.cpp, pypto_bundle_api.cpp, test_dev_func_runner.h, UT files
  • Remove device_runner.h from CMakeLists.txt install list

Related Issues: #2967

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for wan_jianfen's contribution.)
wan_jianfenwan_jianfenCollaborators
Aug 13 Created pull request, commit 78d965af
wan_jianfenwan_jianfenCollaborators
Aug 13 Associated issue: [Task|任务跟踪]: Remove DeviceRunner class and redistribute init flow to KernelBinary/HostProf/DevicePerf/DeviceLauncher
atomgit-bot
atomgit-bot
Aug 13 Comments:

变更摘要

本次 PR 主要围绕移除 DeviceRunner 这一“上帝类”单例展开,将其原先混合的初始化流程、HostProf 管理、DevicePerf 管理、流同步和 AiCpu .so 加载等职责拆分到各自的自然归属模块中。设备初始化逻辑被迁移到 KernelBinary,并通过静态 g_deviceArgs 与 std::call_once 实现一次初始化;HostProf 与 DevicePerf 改为各自提供 GetInstance() 单例;DynamicLaunchSynchronize 迁入 DeviceLauncher,KernelLaunchInfo 结构体则移入 device_launcher_types.h。同时更新了相关调用点、单元测试以及头文件引用,最终删除 device_runner.h 和 device_runner.cpp。

主要改动

  • 删除 DeviceRunner 单例类: 删除 device_runner.h 与 device_runner.cpp,消除集中混合设备初始化、性能管理与流同步职责的单一类,并将 device_runner.h 从安装列表中移除。
  • 设备初始化流程迁移至 KernelBinary: 将 InitDeviceArgs、InitDeviceArgsCore、GetAicoreRegs、InitAiCpuSoBin、SetAiCpuSoOverride 等逻辑迁入 KernelBinary,使用静态 g_deviceArgs 和 std::call_once(g_initOnce)保证只初始化一次,并通过 InitMetaData、GetEnableDumpDevPref 对外提供元数据填充与 dump 开关查询。
  • HostProf 单例化并接管性能上报: 新增 HostProf::GetInstance(),将 SetProfFunction、GetHostProfType、ReportHostProfInfo 迁入 HostProf,调用点由 DeviceRunner::Get().ReportHostProfInfo(...) 改为 HostProf::GetInstance().ReportHostProfInfo(...)。
  • DevicePerf 单例化并接管性能数据同步: 新增 DevicePerf::GetInstance(),将 ResetPerData、SyncProfData、SetDebugEnable 迁入 DevicePerf,相关调用点改为 DevicePerf::GetInstance()。
  • 流同步与结构体归属调整: 将 DynamicLaunchSynchronize 移入 DeviceLauncher 并改为静态方法,调用点相应调整;同时将 KernelLaunchInfo 结构体从 device_runner.h 移至 device_launcher_types.h,并补充所需头文件引用。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Aug 13 Comments:

代码审查

我已逐一审查全部 17 个变更文件。核心发现已上报,现给出总结。

审查结论

按严重度统计:P1 × 1,P0/P2/P3 × 0

总体风险判断:中等偏高。 本次重构整体方向清晰(拆分 DeviceRunner 单例、职责归位),正常 DeviceLauncher 启动路径(先构造 KernelBinary 再 InitMetaData)调用顺序正确、不会出问题;但 bundle 离线启动路径 因 InitMetaData/GetEnableDumpDevPref 不再触发 std::call_once 初始化,会读取零初始化的 g_deviceArgs,把设备参数清零并跳过 HostProf/DevicePerf 初始化,导致该功能回归,需要修复后才能合入。

各变更文件审查确认

  • CMakeLists.txt — 无问题(移除已删除的 device_runner.h 安装项,与删除一致)。
  • framework/src/machine/runtime/bundle/kernel_bundle_launch.cpp — 无独立问题(调用替换正确,但受 g_deviceArgs 未初始化回归影响,见 P1)。
  • framework/src/machine/runtime/bundle/kernel_bundle_registry.h — 无问题(仅注释更新)。
  • framework/src/machine/runtime/bundle/pypto_bundle_api.cpp — 无问题(SetAiCpuSoOverride 改挂 KernelBinary,命名空间与 include 正确)。
  • framework/src/machine/runtime/launcher/device_launcher.cpp — 无独立问题(DynamicLaunchSynchronize 逻辑原样迁移,调用替换正确)。
  • framework/src/machine/runtime/launcher/device_launcher.h — 无独立问题(新增声明正确;InitDevArgs 是 P1 回归的入口)。
  • framework/src/machine/runtime/launcher/device_launcher_types.h — 无问题(KernelLaunchInfo 迁移,显式补充了 runtime_define.h/machine_ws_intf.h)。
  • framework/src/machine/runtime/launcher/emulation_launcher.cpp — 无问题(仅注释修正)。
  • framework/src/machine/runtime/runner/device_perf.cpp / .h — 无问题(GetInstance 单例实现正确)。
  • framework/src/machine/runtime/runner/device_runner.cpp / .h — 已删除,无遗留引用,删除干净。
  • framework/src/machine/runtime/runner/host_prof.cpp / .h — 无问题(GetInstance/GetHostProfType/ReportHostProfInfo 逻辑原样迁移)。
  • framework/src/machine/runtime/runner/kernel_binary.cpp / .h — P1 问题所在(InitMetaData/GetEnableDumpDevPref 未触发初始化)。
  • framework/tests/st/utils/include/test_dev_func_runner.h — 无问题(调用替换正确)。
  • framework/tests/ut/machine/src/dynamic/test_dynamic_runner.cpp — 无问题(调用替换正确)。
  • framework/tests/ut/machine/src/test_device_runner.cpp — 无独立问题(对 HostProf::profSwitch_/profType_ 的私有访问与原测试访问 DeviceRunner::args_ 属同一模式,均依赖 -fno-access-control)。
类型 数量
🔴 阻塞 2
🟡 建议 0

⛔ 需要修改

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Aug 13 Added label: cann-cla/yes
53 messages are collapsed here。 See more
wan_jianfenwan_jianfenCollaborators
Aug 14 Resolved final issue
gaoxingwang
gaoxingwangCollaborators
Aug 14 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Aug 14 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Aug 14 Closed associated issue
CANN-robotCANN-robotCollaborators
Aug 14 Merged pull request