| Files | Last commit | Last update |
|---|---|---|
style(all): Apply additional clang-format corrections across codebase Co-authored-by: junjieHuang<huangjunjie38@h-partners.com> # message auto-generated for no-merge-commit merge: !4883 merge style-cpp into master style(all): Apply additional clang-format corrections across codebase Created-by: junjieHuang Commit-by: junjieHuang Merged-by: cann-robot Description: Apply additional clang-format corrections across codebase See merge request: cann/pypto!4883 | 4 months ago | |
style(all): Apply additional clang-format corrections across codebase Co-authored-by: junjieHuang<huangjunjie38@h-partners.com> # message auto-generated for no-merge-commit merge: !4883 merge style-cpp into master style(all): Apply additional clang-format corrections across codebase Created-by: junjieHuang Commit-by: junjieHuang Merged-by: cann-robot Description: Apply additional clang-format corrections across codebase See merge request: cann/pypto!4883 | 4 months ago | |
fix(machine): Aicpu stream restricted to process-level reuse Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> # message auto-generated for no-merge-commit merge: !7641 merge depend into master fix(machine): Aicpu stream restricted to process-level reuse Created-by: LordOfMysteries Commit-by: LordOfMysteries Merged-by: cann-robot Description: https://gitcode.com/cann/pypto/issues/3869 ## 0. 现象 **现象**:长稳 mha_eager.py 跑在 device 8 上,同卡另起短生命周期进程(acl.init → set_device(8) → 不 reset_device → 正常退出),长稳随后 synchronize 失败,报 timeout or trap error / fftsplus aicore error / 507015。 **根因:** ## 1. 根因链 ### 1.1 宿主侧:流被改成线程级(分界提交 092d359f3) **改动前**:流由进程级单例 RuntimeAgent 持有,CreateStream() 一次建 3 条: cpp static RuntimeAgent* GetAgent() { static RuntimeAgent inst; return &inst; } // L124-128 void CreateStream() { // L98-103 RuntimeStreamCreate(raStreamInstance); // aicore RuntimeStreamCreate(raStreamInstanceSche); // sche RuntimeStreamCreate(raStreamInstanceCtrl); // ctrl } AICPU 只用 sche、ctrl 两条 —— 与「一开始进程级只有两条」的记忆一致。 **分界点**: | 项 | 值 | |---|---| | commit | 092d359f333046bfc49b03ff202f1fe45cd4cb08 | | 作者 / 日期 | arthur_morgan_hw <lipeijie@huawei.com> / 2026-05-09 09:07:26 +0800 | | 标题 / MR | fix(machine): Support dev run log with DEV_EVENT marco and add stream context / !3029 | 提交描述原文第 2 条:「抽离stream context对象,用于管理stream对象,**目前规划为线程级别**」——线程级是设计,不是回归。该提交删除 RuntimeAgent 的流成员,新增 stream_context.{h,cpp},GetStreamContext() 首行即: cpp static thread_local StreamContext context; 之后 3ecacf2e0(2026-05-20 解耦 launcher)、981397545(2026-07-16 clang-format)均未触碰该行;b02295a68(9.2.0 分支)只是同内容拷贝,不在当前 depend 历史里。 ### 1.2 本用例为什么天然跑在两个线程 [mha_eager.py](file:///home/d00502325/PyPTO_Test/ops/machine/stable/mha_eager.py) 自身没有线程:只有一个训练循环,model(x) 调 MhaPyPTO.forward,loss.backward() 调 MhaPyPTO.backward。分裂来自 PyTorch: - MhaPyPTO 是 torch.autograd.Function,backward 由 autograd engine 调度; - 对非 CPU 设备(NPU = PrivateUse1),engine 派生一个常驻 device 线程(Python 侧名 Dummy-1),backward 节点在该线程执行;forward 仍在主线程。 板上实测(device 0,纯 torch + torch_npu): multithreading=True fwd=MainThread bwd=Dummy-1 multithreading=False fwd=MainThread bwd=MainThread 3 次迭代:('fwd', MainThread) count=3,('bwd','Dummy-1') count=3 CPU 张量在两种模式下 backward 都在主线程 → 该现象是设备相关的,与 pypto 无关。 于是 thread_local 下每个线程各建一套 aicore/sche/ctrl 流,kfc task 日志里能看到两条独立流对交替出现。 ### 1.3 设备侧:进程级调度器 + 跨轮计数 - DynMachineManager g_machine_mgr 是**进程级全局实例**,持有 schExitNum_ / cpumask_ / threadIdxBitmap_ / initSch_ / arbitrationLevel_ / ctrlWaitLevel_ / globalThreadIdx_,不带 round / prog / stream 身份。 - ++schExitNum_ == devArgs.nrAicpu 即触发 RunSchPost(触发 block 的 devProg) + RunSchDeInit(),**没有 round 校验**;tid == -1 的落选 block 同样走到 SyncSchExit 计数。 - RunSchPost(devProg) 用的是「碰巧第 5 个自增」那个线程自己的 kargs->cfgdata;块与轮错配时,释放的是**下一轮的 ring**。 - Deallocate 断言拿 GetRuntimeData(fin+1) 与传入指针比,而调用方传的正是 GetRuntimeDataCurrent()(= fin+1),所以**重复释放恒过断言、静默 +1**。 ### 1.4 外部触发:兄弟进程制造 29 ms 分发停顿 两次命中的时间对照(host 时钟;device 日志 ≈ host + 181 ms): | 命中 | 兄弟子进程 | drvDeviceClose(8) | 关 manager fd | hdcdrv_close_remote_session | 受害进程停顿 | |---|---|---|---|---|---| | Run1 | 1877142 | 17:42:43.470 | 17:42:44.394 | 17:42:44.510 | 44.524 ~ 44.553 | | Run2 | 1901870 | 17:47:18.162 | 17:47:19.070 | 17:47:19.144 | 19.157 ~ 19.187 | 停顿起点在 hdcdrv_close_remote_session 之后约 13 ms,持续约 29 ms;长稳整份日志里其余所有轮次的 block 分发偏差都 < 1 ms,说明这是外部扰动而非协议抖动。 ### 1.5 完整时序(Run2,device 日志时间) 18.976.115 sche.enter idx=1/2/3 round=2401(第 4 个仲裁失败 tid=-1;第 5 个未随批进入) 18.976.119 ctrl.enter round=2401 18.985.0 round 2401 的 4 个 block exit:exitNum=1..4 18.985.9 launch 2401 仅凭 4 个 exit 就被 retire,同一 sche 流开始 2402 18.985 round 2402 的 5 个 block 因 ctrl 2402 未就绪、100 µs 超时被丢弃(tid=-1) exitNum=5 trig=1 ← 携带 round 2402 的 devProg,提前 RunSchPost 18.986 release even ring:fin 1200 → 1201,pend=1201 ⇒ fin==pend (round 2401 自己的 ring 始终没被 post) 19.005.730 2401 漏掉的 task 被再次派发,重复进入 round=2401 19.005.761 sche.ctrlok idx=1 round=2401,重新 dequeue,但队列已在 18.985 被排空 29.005.791 +10.0 s:F7200A dequeueFinish=0 timeout / F3F060 ret=466954 31.219 host rtDeviceSynchronizeWithTimeout: aicpu exception → python 退出 一句话:**close 没有直接改受害进程的数据,而是在设备侧制造了一次 ~29 ms 的 AICPU 派发停顿,打破了「一个 launch 的 5 个 block 一定在本轮内退完」这个从未被显式编码的假设。** --- ## 4. 关键证据 ### 4.1 两条流(round ↔ streamId) | 流对 | 承载 | 宿主线程 | |---|---|---| | 40 / 41 | grad kernel(约 32 ms) | autograd device 线程 Dummy-1 | | 43 / 44 | forward kernel(约 10 ms) | Python 主线程 | 日志中每步固定「43/44 先、约 10 ms 后 40/41」,GRAD Stitch Finish 紧随 40/41。注意流 id 大小不能反推创建顺序,线程归属以 §3.2 实测为准。 ### 4.2 两次命中的同一签名 | 命中 | PID | 卡死轮对 | 延迟 block | 触发轮 / 携带 prog | 该 ring 提前 release | |---|---|---|---|---|---| | Run1 | 1867919 | 2209 → 2210 | idx=1,晚 29.0 ms | round=2210,prog=0x12c0a0c00000 | fin=1104 pend=1104 → 1105/1105 | | Run2 | 1894392 | 2401 → 2402 | idx=1,晚 29.6 ms | round=2402,prog=0x12c0a0c00000 | fin=1200 pend=1201 → 1201/1201 | 统计:每轮 5 个 block、nrAicpu=5、blockDim=5;除命中轮外「一轮内 sche.enter 最大时间差」全部为 0.000 s;Run1 整份日志 4418 次 release 中只有 1 次发生在空环上,正是混合触发那次。 ### 4.3 跨轮计数混算 崩溃前最后一次触发 trig round=2194:trig.slot round=2194 cnt=4、round=2193 cnt=4,且 blk.late.exit round=2193 maxRound=2194 出现两次 —— 凑满 5 的批次里混进了上一轮的退出。 ### 4.4 单流对照(验证性实验) | 配置 | 结果 | |---|---| | 默认(两套流) | 3/3 DEAD@7/8 | | torch.autograd.set_multithreading_enabled(False)(一套流) | SURVIVED 30 轮,Step 1367→5089;设备侧 0 次 blk.late,每次 trig.slot 只有一个 round 且 cnt=5,ctrlStart==round、scheFinish==round-1 | ### 4.5 时间常数 20 例对齐「最近的 stars_app_exit_proc_vpid: host app exit end」,Δ 全部落在 −1.18 ~ −1.12 s,即 T(err) − T(app exit end) = 15.15 s ± 0.03 s。全天 1142 次随机 app exit 不可能产生 0.06 s 极差,因此这是同一个定时器:14 s aicore 等待 + 1.15 s 上报。 --- ## 5. 走过的弯路(方向不对,仅留存) | 曾经的判断 | 为什么不对 | |---|---| | HDC remote RELEASE 直接改坏长稳的 SVM 映射(§9.12 / §10) | 只是触发动作。真正传导是 **29 ms 分发停顿 + 跨轮计数混算**;SVM pagefault 是结果不是起点 | | aicore「饿死」/ 早退,PC 停在退出路径 | 否。核在 GetCoreFunctionData 的 while(true) 里空转,14 s 后走 AICORE_DEVICE_TASK_WAIT_TIMEOUT 主动 Trap() | | ctrl 没起来 | 已作废(复跑推翻了当时的探针读数) | | mte 0x400beefbe 是故障码 | 是 reset 后的哨兵;真实判据是 aicError == 0 → 超时 | | 「两份 devProg 视图错位」 | 已更正为「跨轮计数 + 用错 prog 的提前 release」 | | 「同一 sche 流内 task 交错」 | 已更正为「两条 sche 流并发」(thread_local 造成) | | PadLocalBuffer JIT 报错是库问题 | 同一 ASCEND_WORK_PATH 下并发跑两个 MHA 进程导致;单进程即恢复 | | HalMemCtl / StarsResumeRtsq / 单纯缺 TsdClose / 单纯 _exit | 均已实验排除 | | 打开 DEBUG_SWITCH 后 set_status 采样 | 探针被编译宏关掉,不能作为判据 | --- See merge request: cann/pypto!7641 | 8 days ago | |
style(all): Apply additional clang-format corrections across codebase Co-authored-by: junjieHuang<huangjunjie38@h-partners.com> # message auto-generated for no-merge-commit merge: !4883 merge style-cpp into master style(all): Apply additional clang-format corrections across codebase Created-by: junjieHuang Commit-by: junjieHuang Merged-by: cann-robot Description: Apply additional clang-format corrections across codebase See merge request: cann/pypto!4883 | 4 months ago |
| Files | Last commit | Last update |
|---|---|---|
| 4 months ago | ||
| 4 months ago | ||
| 8 days ago | ||
| 4 months ago |