mindspore-ai / mindspore-ai/hyper-parallel
[Feature]: add mega_kernel profiling
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 53
- Forks
- 63
- Avg merge
- 23h 45m
- Merged PRs (30d)
- 63
Description
🚀 功能描述
为 Torch 版本 MegaKernel 增加运行时 Profiling 能力,用于观测单个融合 Kernel 内部各 AIC/AIV worker
的任务执行过程,解决常规 CANN/Torch Profiling 只能看到整个 MegaKernel 边界、无法定位内部等待和计算瓶颈的问题。
1. 使用场景
- 用户通过统一 context 和 schedule 控制采样窗口,不直接接触 RuntimeConfig、rank、device、
all_event_counters或内部profile_buffer。 - 设备侧分别采集每个 AIC/AIV worker 的依赖等待、任务计算和事件触发区间。
- Host 将设备 buffer 解码为独立 Chrome Trace JSON,可直接使用 Perfetto、
Chrome Trace Viewer 或其他兼容工具打开。 - 用户可以选择只显示阶段名称,也可以显示 owner、阶段和阶段内任务序号。
- 具体 MegaKernel 可以提供自己的阶段名称和 owner 展示名称;没有定制信息时公共框架仍能完成采集与导出。
- 用户可在模型运行结束后,将独立内部 trace 与 Torch 导出的 Chrome Trace 离线融合;采集、独立导出和
融合保持三个独立职责。
2. 功能需求
| 编号 | 需求 | 验收条件 |
|---|---|---|
| FR-01 | 运行时开关 | 每个 RuntimeConfigC 独立决定是否采样,默认关闭 |
| FR-02 | 单一发布产物 | 同一算子产物同时支持关闭和开启 profiling 的调用 |
| FR-03 | 关闭路径 | 不读取 cycle、不执行 profiling barrier、不写 profile record、不加载 owner 元数据 |
| FR-04 | 区间采样 | 记录 WaitDependency、Compute、TriggerEvent 的开始和结束 cycle |
| FR-05 | 多核隔离与按需容量 | 每个 AIC/AIV worker 写自己的独立 slot;Host 按实际调度分别计算 AIC/AIV 容量,向上对齐到 16 条 record,单核最多 256 条 |
| FR-06 | 溢出可见 | 单核 record 满后停止写入并累计 droppedCount |
| FR-07 | 通用数据模型 | record 只包含 desc_id、task_id、stage_task_index、owner_id 等公共字段 |
| FR-08 | 展示兜底 | Kernel builder 未绑定 stage_names 和 owner_label 时使用公共兜底,不影响采集和导出 |
| FR-09 | Kernel 内部定制 | 具体 MegaKernel 的 RuntimeConfig builder 自动绑定自身展示语义,用户侧 mega_kernel_profile() 接口保持统一 |
| FR-10 | 独立导出 | Host 可以直接将设备 buffer 导出为 schema v1 Chrome Trace JSON,其中 traceEvents 兼容 Chromium Trace Event Format |
| FR-11 | 原始数据保留 | 展示名不替代原始 ID;事件参数保留 task、desc、owner 和原始 cycle |
| FR-12 | 诊断失败显式化 | buffer、频率、record 或 trace 无效时抛出异常,不生成看似有效的空结果 |
| FR-13 | 离线融合 | 每个独立 trace invocation 按顺序对齐一个外层 Device kernel,并写入外层 process 下的新 AIC/AIV track |
| FR-14 | 融合安全性 | 默认拒绝 Host-only 对齐;名称回退、越界和显式 Host 对齐均写入可机读诊断 metadata |
现有替代方案
无
与DFX相关性DF
本身为DFX功能的一部分
提议的新API
multicore_profiler.schedule()/multicore_profiler.mega_kernel_profile()/profiler.step()
是否影响现有API
不影响对外API,会要求MegaKernel入参必须包含profiling_buffer一项
补充信息
Thanks for contributing 🎉!
schema_version: 1
source: gitcode
gitcode_repo: mindspore/hyper-parallel
gitcode_issue: 396
source_url: https://gitcode.com/mindspore/hyper-parallel/issues/396
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No implementation files or tests are named. Start by locating the proposed multicore_profiler.schedule(), mega_kernel_profile(), and profiler.step() entry points, then trace how RuntimeConfigC and profiling_buffer are represented. Done means meeting FR-01 through FR-14, including independent Chrome Trace export, overflow and invalid-input diagnostics, and offline fusion behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100