已开启
Introduce PrivateUse1 Profiler Manager Architecture #45369
denis_g创建于 8月26日
Introduce PrivateUse1 Profiler Manager Architecture #45369
已开启
合并受阻
atomgit-bot
8月26日 评论:
8月26日 评论:
变更摘要
本 PR 为 torch_npu 引入 PrivateUse1 活动 profiler 后端管理的基础架构,将 PrivateUse1 profiler 的注册与会话管理从原有 MSPTI 实现中解耦,形成可支持多 profiler 后端的通用架构。注册链路为 REGISTER_PRIVATEUSE1_PROFILER → NPUActivityProfilerPlugin → NPUActivityProfilerFactory → MSPTI/ACLprof → PrivateUse1ProfilerManager → libkineto::IActivityProfilerSession。后端选择由 CUSTOM_CONFIG 中的 backend 字段决定,默认及非法配置回退到 MSPTI,backend="aclprof" 选择 ACLprof 桩实现;同时新增 _NPUExperimentalConfig 用于在 Python 侧传递 NPU 特有后端配置,现有默认 MSPTI 行为保持不变。
主要改动
- 新增公共后端抽象与工厂:新增
NPUActivityProfiler接口(start/stop/processTrace/errors/设备信息等)与NPUActivityProfilerFactory::create,根据config.getCustomConfig()解析的backend字段在MsptiActivityProfiler与AclprofActivityProfiler之间选择,未指定或非法值时回退 MSPTI。 - 新增插件与管理器:
NPUActivityProfilerPlugin通过REGISTER_PRIVATEUSE1_PROFILER(无宏时回退libkineto::api().registerProfilerFactory)注册,其configure调用工厂创建后端;PrivateUse1ProfilerManager作为libkineto::IActivityProfilerSession将生命周期、processTrace、相关 ID 推送/弹出等操作委托给所选后端。 - 重构
MsptiActivityProfiler:改为继承NPUActivityProfiler,删除原MsptiActivityProfilerPoc类及其configure/注册逻辑(privateUse1Requested移至npu_activity_profiler.cpp),MSPTI 活动采集、回调与缓冲等既有逻辑不变。 - 新增 ACLprof 后端桩:
AclprofActivityProfiler仅实现生命周期(start进入RECORDING、stop进入PROCESSING),processTrace不产出设备活动并发出ACLprof activity collection is not implemented yet警告,为后续实现划定架构边界。 - 新增 Python 配置与测试:新增
_NPUExperimentalConfig(继承torch._C._profiler._ExperimentalConfig,通过custom_profiler_config序列化{"backend": ...})并在torch_npu/profiler/__init__.py导出;新增 C++ 测试(后端选择、插件→管理器创建、生命周期与 trace 委托、顺序独立 ACLprof 桩会话)及 Python 测试(校验_NPUExperimentalConfig序列化内容)。


不准确?
ascend-robot
8月26日 评论:
8月26日 评论:
atomgit-bot
8月26日 评论:
8月26日 评论:
8月26日 添加了label:ascend-cla/yes
此处折叠了344条消息 查看更多
1 天前 关联了里程碑:v26.3.0
chenhao_1209
1 天前 评论:
1 天前 评论:
/lgtm


梁松伟
1 天前 评论:
1 天前 评论:
/approve


ascend-robot
1 天前 评论:
1 天前 评论:
The following users do not have permission to comment /lgtm or /approve on any module in this PR:
/lgtm: eejiechu


1 天前 添加了label:approved
【Source of Change】
This PR introduces a common architecture for managing PrivateUse1 activity profiler backends in
torch_npu.The purpose is to decouple PrivateUse1 profiler registration and session management from the existing MSPTI implementation, provide a common foundation for multiple profiler backends, and extend the NPU-specific experimental configuration mechanism.
The existing MSPTI profiling behavior is preserved. ACLprof support is introduced as a nonfunctional backend stub for future implementation.
【Modification】
The following changes are included:
1. Common profiler abstraction
Introduced
NPUActivityProfileras the common abstraction for PrivateUse1 profiler backends.2. PrivateUse1 profiler plugin
Added
NPUActivityProfilerPluginas the backend-neutral plugin registered through:3. Backend factory
Added
NPUActivityProfilerFactoryto select the profiler backend for each profiling session.Backend selection behavior:
Backend selection remains explicit.
The additional
profiler_levelandexport_typeparameters do not implicitly select ACLprof.4. Profiler session manager
Added
PrivateUse1ProfilerManageras thelibkineto::IActivityProfilerSessionimplementation responsible for delegating profiler lifecycle and trace-processing operations to the selected backend.The resulting architecture is:
5. MSPTI backend integration
Refactored
MsptiActivityProfilerto inherit from the commonNPUActivityProfilerinterface.Existing MSPTI activity collection, callbacks, buffer handling, draining, conversion, correlation, and metadata processing are not modified by this PR.
6. ACLprof backend stub
Added an ACLprof backend stub to establish the architectural boundary for future ACLprof implementation.
The stub supports the profiler lifecycle but does not collect or convert ACLprof activities.
Current behavior:
When trace processing is requested, the stub emits:
Functional ACLprof collection and export are intentionally excluded from this PR.
7. Extended NPU experimental configuration
Extended
_NPUExperimentalConfigto support three optional parameters:backendprofiler_levelexport_typeThe existing backend-only configuration remains compatible.
Example:
from torch_npu.profiler import _NPUExperimentalConfig from torch_npu.profiler.experimental_config import ProfilerLevel, ExportType npu_config = _NPUExperimentalConfig( backend="aclprof", profiler_level=ProfilerLevel.Level1, export_type=ExportType.Db, ) experimental_config = torch.profiler._ExperimentalConfig( custom_profiler_config=str(npu_config) )The serialized configuration is:
{"backend":"aclprof","profiler_level":"Level1","export_type":["db"]}The configuration implementation provides:
custom_profiler_config.Backend selection depends exclusively on
backend.The default backend remains MSPTI, even when
profiler_levelorexport_typeis provided without an explicit backend.The additional configuration values are validated, parsed, and retained by the selected profiler instance. They are not applied to ACLprof collection or export in this PR.
8. Extended test coverage
Added and extended C++ and Python tests covering:
custom_profiler_configcompatibility.9. Scope limitation
This PR provides the PrivateUse1 profiler management architecture and configuration infrastructure only.
It does not implement functional ACLprof activity collection, device activity conversion, database export, or report generation.
【Documentation Changes】
No user-facing documentation changes.
This PR introduces internal profiler architecture and extends an experimental configuration helper. Functional ACLprof usage documentation is deferred until the corresponding backend implementation is available.
【Interface Changes】
No changes to stable customer-facing APIs or cross-repository interfaces are introduced.
The internal PrivateUse1 profiler architecture is extended, and the experimental Python helper
_NPUExperimentalConfignow accepts optionalprofiler_levelandexport_typeparameters in addition tobackend.The configuration is transferred through the existing PyTorch
custom_profiler_configmechanism.Existing backend-only configuration remains compatible:
_NPUExperimentalConfig(backend="aclprof")The default backend remains MSPTI. ACLprof selection requires an explicit
backend="aclprof".【Functional Verification】
Linux / Ascend hardware integration
Integration validation was performed using:
The test uses the standard
torch.profiler.profile()API with CPU and NPU activities, scheduled profiling,prof.step(), and a CPU trace callback.Four configuration scenarios were executed:
All four scenarios completed without runtime errors.
The following behavior was observed:
AclprofActivityProfiler::processTrace(), confirmed by the expected stub warning.Verification limitations
The integration test confirms runtime execution of the ACLprof stub through the standard PyTorch profiling API.
MSPTI scenarios completed successfully, but runtime backend selection was not independently instrumented in those scenarios. Backend selection behavior is additionally covered by C++ unit tests.
No device activities were present in the collected traces. Therefore, full MSPTI hardware activity-collection regression is not claimed by these results.
The runtime test also does not directly inspect retained configuration values inside the C++ backend; parsing and retention are verified separately by C++ and bridge tests.
Functional ACLprof collection and DB export are outside the scope of this PR.
【CheckList】