| Files | Last commit | Last update |
|---|---|---|
feat(machine): Support BN parallel for DRCO Co-authored-by: gaoxingwang<camuel.gao@huawei.com> # message auto-generated for no-merge-commit merge: !7246 merge drco-bn-parallel-final into master feat(machine): Support BN parallel for DRCO Created-by: gaoxingwang Commit-by: gaoxingwang Merged-by: cann-robot Description: feat(machine): Support BN parallel for DRCO Add a device-side parallel window for DRCO devTask execution under BN parallel mode (device_sched_parallelism > 1) on 2201: block0 acts as the single admission/handover/recycle/stop leader while all cores visit slots in try-mode rotation, replacing the legacy SyncAllMix barrier per devTask. Squashed from the window feature, its cross-core visibility fixes, the minimal atomic protocol reduction, and two late hardening changes (per-slot activation now issues the ENTIRE_DATA_CACHE invalidation before loading queue/matrix read sets; ready-queue entries are published via atomic release stores ahead of the tail gateway). BN parallel mode and DRCO L2-affinity scheduling are temporarily made mutually exclusive (BN wins): enabling both together exposes a stale-data window between the L2 affinity dispatch order and the BN window admit/handover protocol. Proper fusion is left for a follow-up. Changes: - Add DrcoParallelWindow slot ring, per-slot activation/visit/exit protocol and leader poll loop - Encode stop as cross-launch epoch with entry barrier clear for non-block0 cores - Guard stale slot activation with posId validation and invalidate freed slots on idle - Reset window cursors and BN link fields deterministically across launches and replays - Publish ready-queue entries (func/root/forId/wsId) with atomic release stores - Move UpdateCacheDevTask entire-cache dcci ahead of activation read-set loads - Force DRCO_FLAG_L2_CLOSE=0 when ENABLE_AICORE_BN_PARALLEL=1 (temporary mutex) Related Issues: #7147 See merge request: cann/pypto!7246 | 30 days ago | |
fix(machine): degrade EMULATION to DEVICE_RT under DRCO and keep swimlane complete Co-authored-by: rongziran<rongziran@huawei.com> # message auto-generated for no-merge-commit merge: !7456 merge fix-drco-emulation-degrade into master fix(machine): degrade EMULATION to DEVICE_RT under DRCO and keep swimlane complete Created-by: rongziran Commit-by: rongziran Merged-by: cann-robot Description: PR 应该避免没有描述信息,描述信息的最重要的作用是描述修改意图,应该清晰明了。例如:标题中包含了 fix 标签,如果没有描述信息,就需要Review人员猜测PR具体修复了哪些内容,或者怀疑修改的必要性。如果PR和特定的Issue相关,可以单独包含一行 Related Issue: 放到描述信息最后。 下面是一个典型的PR描述信息: The origin issue template brings too many noise, it's not suitable for git message. eg: comments are not removed, labels are redundant as the PR tile already contains the tag. The guide gives a clear suggestion on how to write the PR body. Related Issue: #1234,#5678 更多描述信息见:[Commit Message 规范](../docs/zh/contribute/pull-request.md#commit-message) See merge request: cann/pypto!7456 | 18 days ago | |
fix(machine): Add value depend check for ifstmt Co-authored-by: qq_52905393<liuzhen180@huawei.com> # message auto-generated for no-merge-commit merge: !7361 merge dev-fix-host-ctrl into master fix(machine): Add value depend check for ifstmt Created-by: qq_52905393 Commit-by: qq_52905393 Merged-by: cann-robot Description: 检测值依赖和 insert wait_aicore_start 的时候,增加 ifstmt 的检测 See merge request: cann/pypto!7361 | 24 days ago | |
feactor(machine): Add built-in pypto tar Co-authored-by: wan_jianfen<wanjianfen@hisilicon.com> # message auto-generated for no-merge-commit merge: !7398 merge br_builtIn into master feactor(machine): Add built-in pypto tar Created-by: wan_jianfen Commit-by: wan_jianfen Merged-by: cann-robot Description: PR 应该避免没有描述信息,描述信息的最重要的作用是描述修改意图,应该清晰明了。例如:标题中包含了 fix 标签,如果没有描述信息,就需要Review人员猜测PR具体修复了哪些内容,或者怀疑修改的必要性。如果PR和特定的Issue相关,可以单独包含一行 Related Issue: 放到描述信息最后。 下面是一个典型的PR描述信息: The origin issue template brings too many noise, it's not suitable for git message. eg: comments are not removed, labels are redundant as the PR tile already contains the tag. The guide gives a clear suggestion on how to write the PR body. Related Issue: #1234,#5678 更多描述信息见:[Commit Message 规范](../docs/zh/contribute/pull-request.md#commit-message) See merge request: cann/pypto!7398 | 19 days ago | |
Normalized framework for pgo Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> Co-authored-by: Jie Yin<yinjie27@huawei.com> # message auto-generated for no-merge-commit merge: !7044 merge pgo-framework into master Normalized framework for pgo Created-by: yinjie27_ Commit-by: Jie Yin;LordOfMysteries Merged-by: cann-robot Description: # feat(machine): 重构 FedProf 为 Holder/Manager 实例化结构,并修复 CTRL 泳道只 dump 一轮的回归 ## 一、背景与问题 fed_prof(device 侧性能数据 dump)原实现是一个单例 FedProf:内部直接持有 perCoreProf_ / aicpuProf_ 两个裸 device 指针,dump 线程、轮次管理、JSON 序列化 全部堆在同一个类里;DeviceArgs 里也以 perCoreProfAddr / aicpuProfAddr 两个散落字段 传地址。新增一类 profile 需要同时改结构体、改分配逻辑、改 dump 分支,扩展成本高。 同时暴露出一个回归:DUMP_DEVICE_PERF=true 时 python/tests/st/test_ctrl_cpu_perf.py 断言 len(metrics) >= 30 失败,实际只解析出 **1 轮** CTRL 数据: AssertionError: expected >= 30 CTRL rounds, got 1 ... assert 1 >= 30 **根因链**: 1. DUMP_DEVICE_PERF=true ⇒ KernelBinary::GetEnableDumpDevPref() 恒为真, 于是**每次** LaunchKernel 都会走到 DeviceLauncher::SetDevPerfAddr()(device_launcher.cpp:658)→ FedProfManager::SetDebugEnable(); 2. SetDebugEnable() 每次都对**所有 core** 全量 memset per-core prof 元数据 (PerCoreProfResetMetadata()),把 device 侧 status.currLaunchRound 清零; 3. 而 currLaunchRound 只在 AICore 退出时 ++(aicore_entry_dfx.h:174), 因此连续 30 次 launch 后它仍然只有 **1**; 4. AicpuProfDumpSwimlaneCheck() 以 currLaunchRound 作为 dump 轮次上界 (fed_prof_manager_aicpu.cpp:101),FedProfLaunchAicpuDumpJson() 只遍历 [lastDumpRound, currLaunchRound)(fed_prof_io_json.cpp:181), 最终 dump 里只剩 round _0。 ## 二、改动总览 共 4 个提交,34 个文件。 ### 1. 数据结构:用 FedProfKind + 地址列表替代散落字段 framework/src/interface/machine/device/tilefwk/aikernel_profile.h - 新增 enum FedProfKind { FED_PROF_PER_CORE_PROF, FED_PROF_AICPU_PROF, FED_PROF_KIND_MAX } 与 struct FedProfDataBase {} 作为类型化基类; - FedProfPerCoreProf / FedProfAicpuProf 改为继承 FedProfDataBase。 framework/src/interface/machine/device/tilefwk/aicpu_common.h - DeviceArgs 中 perCoreProfAddr / aicpuProfAddr 两个字段合并为 uint64_t fedProfAddrList[FED_PROF_KIND_MAX]{},按 FedProfKind 索引。 ### 2. Host 侧:把单例拆成 Holder(数据面)+ Manager(控制面) - fed_prof.h / fed_prof.cpp → **删除**,拆为: - fed_prof_holder.h / fed_prof_holder.cpp:FedProfHolderBase 虚基类 + 模板 FedProfHolder<kind> + FedProfPerCoreProfHolder / FedProfAicpuProfHolder。 device buffer 的分配(DeviceDataAllocate)、清理(DeviceDataClear)、 D2H 搬运(DeviceDataGet<T>)、JSON 序列化(DumpJson<T> / DumpJsonAicpuProf) 全部收敛为按类型实现的虚接口;编排逻辑不再感知具体 profile 类型。 - fed_prof_manager.h / fed_prof_manager.cpp:FedProfManager 单例,负责 dump 线程生命周期、轮次判定(AicpuProfDumpSwimlaneCheck)、dump 编排与落盘。 - fed_prof_aicpu_prof.cpp → fed_prof_manager_aicpu.cpp。 - FedProfManager 内部用 std::unique_ptr<FedProfHolderBase> profList_[FED_PROF_KIND_MAX] 取代原来的两个具名成员,对外统一为 DeviceDataAllocate(FedProfKind), 新增 profile 类型只需在枚举和 profList_ 中登记一处。 - DeviceDfx::Init() 改为按 kind 遍历分配,并在拿到 devDfxArgAddr 后再次 InitDeviceArgs() 刷新 args_(device_dfx.cpp:57-70)。 - 顶层 CMakeLists.txt 的安装头文件清单同步更新(fed_prof.h → fed_prof_manager.h + fed_prof_holder.h)。 ### 3. Device 侧与调用方:地址来源统一切到 fedProfAddrList aicore_entry.h、aicore_entry_drco.h、device_sche.cpp、aicore_hal.h、 aicpu_task_manager.h、aicore_model_launcher.cpp、emulation_launcher.cpp、 kernel_binary.{h,cpp}、device_launcher.{h,cpp}、device_dfx.cpp、 framework/tests/st/utils/include/test_dev_func_runner.h - devArgs->perCoreProfAddr → devArgs->fedProfAddrList[FED_PROF_PER_CORE_PROF]; - devArgs->aicpuProfAddr → devArgs->fedProfAddrList[FED_PROF_AICPU_PROF]; - KernelBinary::InitMetaData() / GetEnableDumpDevPref() 改为按 kind 循环拷贝 / 判空。 ### 4. 关键缺陷修复:per-core 元数据不再被每轮清零 framework/src/machine/runtime/runner/fed_prof_manager.{h,cpp} - void PerCoreProfResetMetadata(const uint32_t coreId); + void PerCoreProfResetMetadata(bool multipleLaunch); - 外层 per-core 循环内移,函数自身负责 reset **全部** core; - 新增成员 bool perCoreProfDataInited_{false},在 multipleLaunch 下每个 core 只 reset 一次(恢复重构前的保护); - SetDebugEnable() 不再自己写循环,改为 PerCoreProfResetMetadata(AicpuProfDevAddr() != 0)——即 aicpu prof 使能 (DUMP_DEVICE_PERF=true)时传 true,否则传 false,保持「每次 launch 全量 reset」的原有语义。 修复后 status.currLaunchRound 随 launch 累加,dump 可覆盖全部 30 轮。 ### 5. 其它 - aikernel_define.h:UNUSED 由单参宏扩展为 1~16 变参宏 (UNUSED_SELECT 参数选择),满足 UNUSED(a, b, ...) 用法; 同时删除 framework/include/tilefwk/data_type.h 中重复的 UNUSED 定义。 - 626560468:析构时显式 AicpuProfReleaseData()(dump 线程 stop 之后), 修正 online 场景的资源释放顺序。 ### 6. UT 适配 test_device_perf.cpp(6 处调用点改 bool 实参,ResetMetadata_IndexOutOfRange 重命名为 ResetMetadata_MultipleLaunch)、test_dynamic_runner.cpp、 test_device_dfx.cpp、test_device_launcher_host/npu.cpp、 test_device_runner.cpp、test_dump_device_perf.cpp 等跟随接口调整。 ## 三、行为对比 | 场景 | 修复前 | 修复后 | |---|---|---| | DUMP_DEVICE_PERF=true(aicpu prof 使能)30 次 launch | 每次 launch 清零 currLaunchRound,dump 只含 1 轮 | 每 core 仅首次 reset,currLaunchRound 累加,dump 覆盖 30 轮 | | 仅 runtime debug / host prof(无 aicpu prof) | 每次 SetDebugEnable 全量 reset | 语义不变(multipleLaunch=false,仍每次全量 reset) | | 新增一类 profile | 需改结构体字段 + FedProf 成员 + dump 分支 | 加 FedProfKind 枚举项 + 一个 Holder 子类即可 | ## 四、验证 - **UT**(tile_fwk_utest,machine 模块,本机设备 0): 受影响的 14 个套件共 **43 例通过**,其中直接覆盖改动的 DevicePerfTest.*(含新增 ResetMetadata_MultipleLaunch)10/10 PASS, TestDeviceRunner.DevicePerf_SetDebugEnable、DeviceLauncherNpuTest.SetDevPerfAddr_*、 DumpDevicePerfTest.*、PerfEvtMgrTest.* / PerfettoMgrTest.* 等均 PASS。 另有 2 例(SetDevPerfAddr_CaptureMode、MiscNoOpFunctions_NoCrash)因本机 UT 运行环境未部署 libtilefwk_backend_server.so / pypto_op_info.json 而失败, 已确认抛错点在 SetDebugEnable 之前的条件求值阶段,与本次改动无关。 - **构建**:tile_fwk_runtime、tile_fwk_interface、tile_fwk_utest 编译通过。 - **待上板回归**:python/tests/st/test_ctrl_cpu_perf.py —— 期望 len(metrics) >= 30(本 PR 修复的目标用例);同时观察 mean/max EXEC_DYN、first DEV_TASK_BUILD 门限是否满足(该用例阈值按 ctrl cpu 效率标定,若仍有回退需单独定位)。 ## 五、影响面与风险 - **接口变更**:DeviceArgs.perCoreProfAddr / aicpuProfAddr → fedProfAddrList[FED_PROF_KIND_MAX],host/device 两侧同步修改, 属不兼容变更;生成侧、模拟器(aicore_model_kernel_meta_hook.h)与 ST 基建已同步。 - **文件结构变更**:fed_prof.h/.cpp 被删除并由 fed_prof_holder.* + fed_prof_manager.* 取代,需注意下游对旧头文件的直接 include(本仓已全部更新)。 - **风险点**:per-core 元数据 reset 时机的语义依赖 multipleLaunch 取值, 已在 UT 中分别覆盖 true / false 两条分支。 - **回滚**:本 PR 为独立重构 + 修复,回滚即回到 FedProf 单例实现。 See merge request: cann/pypto!7044 | 1 month ago | |
fix(machine): Keep non-overlapping cell writes and stitch only overlapping cross-root uses Co-authored-by: songyangyang18<songyangyang18@huawei.com> # message auto-generated for no-merge-commit merge: !7124 merge topo into master fix(machine): Keep non-overlapping cell writes and stitch only overlapping cross-root uses Created-by: songyangyang18 Commit-by: songyangyang18 Merged-by: cann-robot Description: ## 问题背景 当前的依赖通过cell match机制构建,通过将tensor的整个区域分割成一个一个独立的小cell,每一个cell记录当前tile区域上的op操作(Normal Write/Atomic Write/Read)。当前cell shape的计算过程分为两步,第一步统计outcast上的所有assemble(写)大小的最小值作为cell shape,第二步再统计slot中所有outcast的cell shape的最大公约数,形成最终的大小。针对第一步,在assemble操作存在非倍数关系的尾块时,会存在cell大小的异常。 假设在第一个rootfunction中存在连续写操作,但是不重叠区域,W1写[0:63],W2写[64,127]区域,且存在尾块shape为48,在第二个loop存在读操作,读的是一个小区域[48, 63],该场景会导致依赖建立失败。 1. cell shape由于取最小的shape,受到尾块影响,取的是48而不是主块64; 2. cell fill阶段:W1会覆盖到Cell1和Cell2,W2会覆盖到Cell2和Cell3,由于单Cell写操作之间互斥,W2会覆盖掉W1,此时Cell2只保留了W2的信息; 3. 当loopB的Read操作读的区域是[48, 63],命中的是Cell2,Cell2里存的是W2,R和W2建立了依赖,但是W2本身没有写到R的区域,依赖构建存在异常,实际上应该与Cell1建立对应依赖; loopA: pypto.assemble(tmp1, offset=[i],buf) pypto.assemble(tmp2, offset=[i+64],buf) loopB: buf_v = buf.view(shape=[16], offset=[48])  ## 修改方案 ### 编译阶段 1. 每个 outcast:cell 取见过 shape 的 **min**;shapeGcd 取见过 shape 的 **gcd**;另记 shapeMax(写)与 readShapeMin(读,COA shape 取 min)。 2. slot 合并:各 outcast cell 再做 gcd 得到最终 cell。每维: - cell <= 1 → 因子 1; - 否则若每个参与 outcast 的 shapeGcd > 0 且 **cell 整除 shapeGcd**(shapeGcd % cell == 0)→ 因子 1; - 否则若同 slot **min_read >= max_write**(无读/无写也算满足)→ 因子 1; - 否则因子 2。 3. 槽位数 = 各维因子乘积(2^N,N 为因子为 2 的维数)。秩最多 6,乘积最大 64。写入 cacheOpMaxCount[NORMAL_WRITE]。 读/写对比是 **同一 partial slot 内按维的标量**:maxWrite = max(outcast.shapeMax),minRead = min(outcast.readShapeMin ∪ incast.readShapeMin)。不是「某条读对上某条写」的配对。 ### Stitch / Fill 阶段 1. CellMatchIsNormalWriteSlowPath(desc):NORMAL_WRITE 槽位 > 1 且 writeRangeBase != 0 → **Slow**;否则 **Fast**。 2. **Fast**:一格一写,互斥覆盖,不存区间;逻辑与改前一致。 3. **Slow**:每笔 Normal Write 另存整段 (offset, shape)。 - Normal↔Normal:区间重叠则去掉旧写并建边(仅跨 root);不重叠则追加、不建边。 - Normal↔(Read/Atomic)、以及 Read/Atomic 自身:对当前组 **全依赖**(不看区间)。 ## 详细流程 每个 root 先用格子里已有操作建边(Stitch),再把自己的操作填进去(Fill)。编码阶段提前决定槽位与布局。 mermaid flowchart TD A["root 编码: cell 取 min, shapeGcd 取 gcd<br/>shapeMax / readShapeMin 一并记下"] --> B["shapeGcd / shapeMax / readShapeMin<br/>抄进该 root 的 outcast / incast 镜像"] B --> C["各 root cell 做 gcd<br/>按维: divides 或 min_read≥max_write → 因子 1<br/>否则因子 2; 槽位 = 乘积"] C --> D["运行每个 root"] D --> E["Stitch: 读格子已有操作, 决定和谁建边"] E --> F["Fill: 把本 root 操作写入格子"] F --> D | 步骤 | 算法 | 模块 | | --- | --- | --- | | 收集 shape | cell 取 min;shapeGcd 取 gcd;shapeMax 取 max;readShapeMin 取 min | dev_encode.cpp UpdateCellMatchShape / FoldReadShapes | | 交给 program encode | 写入 outcast / incast 镜像 | InitIncastOutcast | | 定槽位和布局 | divides ∪ cover → 因子;2^N;区间尾 | InitPartialUpdateCellMatch,dev_encode_tensor.h | | 选路 | Fast / Slow | CellMatchGetNormalWritePath(dev_cell_match_mem_layout.h) | | 判断两段区间 | 半开区间 | CellMatchWriteRangesOverlap | | 填表 | Slow:重叠旧写整段去掉,其余留下 | CellMatchFillPartialNormalWrite | | 建边 | Slow 普通写:仅跨 root 且重叠 | CellMatchStitchOverlappingNormalWrites | ## 1. 槽位数 同一 outcast 上,cell 每一维取见过 shape 的更小值。shapeGcd 按维累加:初值 0;第一笔 >0 直接写入;之后与槽内值做 gcd。0 和负数不进入。同一 root 里,partial 写(含 atomic)会更新 cell / shapeGcd / shapeMax;后继读进入 readShapeMin。跨 root 的读记在 incast 上,只改 incast 自己的 cell 与 readShapeMin,不回写前面 outcast 的 shapeGcd。 多个 outcast 合成 partial slot 时,cell 按维做 gcd(有非 reshape 时 reshape 不参与)。然后每维一个因子,槽位数是乘积。 mermaid flowchart TD D["看这一维"] --> L{"cell 长度 > 1 ?"} L -->|否| F1["因子 = 1"] L -->|是| M{"每个参与 outcast 的 shapeGcd > 0<br/>且 cell 整除 shapeGcd ?"} M -->|是| F1 M -->|否| R{"min_read ≥ max_write<br/>或无读/无写 ?"} R -->|是| F1 R -->|否| F2["因子 = 2"] F1 --> P["槽位数 = 各维因子相乘"] F2 --> P P --> Q{"槽位数 == 1 ?"} Q -->|是| ONE["Fast: 每格 1 笔普通写, writeRangeBase=0"] Q -->|否| MANY["Slow: 每笔普通写另存 offset/shape"] multipleBits 第 d 位为 1 表示该维因子是 1。镜像里只落乘积到 cacheOpMaxCount[NORMAL_WRITE]。运行时 Fill/Stitch 不重算因子,只看 desc 上的槽位与 writeRangeBase。 text shapeGcd 初值 0 第一笔 24 → 槽 = 24 再来 18 → 槽 = gcd(24, 18) = 6 再来 12 → 槽 = gcd(6, 12) = 6 cell = min(24, 18, 12) = 12 12 不能整除 6,且若 min_read < max_write → 因子 2 同一 root,两笔写 64 和 48 cell = min(64, 48) = 48 shapeGcd = gcd(64, 48) = 16 48 不能整除 16 若同 slot 读 min 也是 48(min_read < max_write=64)→ 因子 2 → 槽位 2 若读全是 64(min_read ≥ max_write)→ 因子 1 → Fast 同一 root,再加入 32 和 16 cell = min(..., 16) = 16 shapeGcd = 16 16 整除 16 → 因子 1 → Fast 两个 root,cell 64 与 48 合并 cell = gcd(64, 48) = 16 各自 shapeGcd 64 / 48,16 都能整除 → 因子 1 → Fast 一边 shape 36/54,另一边 24 合并 cell = gcd(36, 24) = 12 shapeGcd 18 与 24;12 不能整除 18 → 若 cover 也不成立 → 因子 2 两维因子都是 2 → 槽位 4 一维 2、另一维 1 → 槽位 2 长度 ≤1 的维因子固定为 1。atomic 上限 254,读上限 128。CELL_MATCH_MAX_NORMAL_WRITE_COUNT 仍是 1,只给 Fast stub / 单写路径。 ## 2. 格子布局 Fast 与改前相同。Slow 在 op-id 列表后,为每笔普通写、每个维存一对 (offset, shape)(tensor 整段半开区间)。 text Fast(槽位 = 1) [ meta | 普通写×1 | atomic 列表 | read 列表 ] Slow(槽位 = 2,维数 = 2) [ meta | 写0 | 写1 | atomic 列表 | read 列表 | 写0.offset0 | 写0.shape0 | 写0.offset1 | 写0.shape1 | 写1.offset0 | 写1.shape0 | 写1.offset1 | 写1.shape1 ] writeRangeBase == 0 表示无区间尾(Fast)。Fast 路径不读写这段。 两段重叠 ⇔ 每一维都重叠。半开区间:某维 a0 >= b0+bLen 或 b0 >= a0+aLen 则该维不交。任一侧某维长度为 0 → 不重叠。 ## 3. 填表 入口统一 CellMatchFillEnhance → CellMatchIsNormalWriteSlowPath 分支。 mermaid flowchart TD IN["新操作进入格子"] --> W{"IsNormalWriteSlowPath<br/>且当前是普通写 ?"} W -->|否| OLD["Fast / 读 / atomic: 互斥则盖成 1 笔, 同类型读或 atomic 追加"] W -->|是| KEEP["已有普通写里, 与新写不重叠的留下"] KEEP --> FULL{"留下的笔数 < 槽位 ?"} FULL -->|否| ASSERT["DEV_ASSERT 满槽"] FULL -->|是| ADD["追加新写, 存整段 offset/shape"] 重叠的旧写 **整段去掉**,不切剩余区间。 text cell = 48,格子覆盖 [48, 96) 已有 W0 [0, 64) 新写 W2 [112, 160) W1 [64, 112) 与 W0、W1 都不重叠 → 三笔都留 已有 W0 [0, 80) 新写 W2 [16, 48) 与 W0 重叠 → 去掉 W0,只留 W2 同一 tag:当前就是普通写时,拿当前组压缩;当前是读/atomic 时,只拿 prev 里那组普通写压缩。tag 变了,前驱清空,已有写按 0 笔。 ## 4. 建边 Stitch 在 Fill 之前,看到的是更早 root 留下的内容。同 root 读写顺序由 root 内部依赖负责。 入口统一 CellMatchStitchEnhance → Slow / Fast。 mermaid flowchart TD IN["当前 op 覆盖这个 cell"] --> EMPTY{"格子为空, 或 tag 不同 ?"} EMPTY -->|是| STOP["不建边"] EMPTY -->|否| MODE{"Slow 且当前 op 是普通写 ?"} MODE -->|否| ALL["与当前这一组的每一笔建边"] MODE -->|是| TYPE{"格子里当前类型是普通写 ?"} TYPE -->|否| ALL TYPE -->|是| EACH["逐笔旧写"] EACH --> HIT{"区间重叠, 且 FuncID 不是当前 root ?"} HIT -->|是| EDGE["建一条边"] HIT -->|否| SKIP["跳过这一笔"] text 格子里已有两笔普通写, cell = 48, 覆盖 [48, 96) W0 [0, 64) root 1 W1 [64, 112) root 2 下一次普通写来自 root 3: [48, 64) 只与 W0 重叠 → 只依赖 W0 [48, 96) 与 W0、W1 都重叠 → 依赖 W0 和 W1 [112, 128) 与两笔都不重叠 → 不建边 与 W0 同属 root 1, 即使重叠 → 不依赖 W0 下一次是读或 atomic: 不看区间, 当前组有几笔挂几笔 一次 stitch 可能扫到同一 producer 覆盖的多个 cell。栈上 32 项 CellMatchSeenOps 记已判定的 64 位 id;记满后新 op 仍按格判断,依赖集合不变。边去重仍由 stitch cache(rootFuncMaxCallOpsize²)负责。 关键 verbose 日志(默认 ENABLE_COMPILE_VERBOSE_LOG=0,device 侧编译期剔除):Slow Fill 入口/落格;Slow Stitch 入口、早退、overlap / 全组分支。 ## 5. 路径对照 | | Fast | Slow | | --- | --- | --- | | 条件 | 槽位 == 1,writeRangeBase == 0 | 槽位 > 1,writeRangeBase != 0 | | 判定 API | CellMatchIsNormalWriteFastPath | CellMatchIsNormalWriteSlowPath | | Fill | CellMatchHandleFillEnhanceExec | CellMatchFillPartialNormalWrite | | Stitch | CellMatchStitchHandle | CellMatchStitchHandlePartial → overlap / 全组 | | 读 / atomic | 始终走 Fast 那套 concurrent / 互斥逻辑(即使格子是 Slow 布局) | 同左 | See merge request: cann/pypto!7124 | 19 days ago | |
feat(machine): Optimize left pingpong Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> # message auto-generated for no-merge-commit merge: !6866 merge fix-ctrlflow-pypto-page-align into master feat(machine): Optimize left pingpong Created-by: LordOfMysteries Commit-by: LordOfMysteries Merged-by: cann-robot Description: ## Summary 控制流 cache 重放头两处优化:Mix wrap 队列 ping-pong,以及 DRCO ready-queue shadow 与 metadata predcount ping-pong。 PushTask 前不再整段重建这两块。 ## 1. Mix wrap 队列 ping-pong ### 原来的缺点 readyWrapCoreFunctionQue 的 elem 会被调度改掉。旧路径在 PushTask 前 MixTaskDataRestore 整段 memcpy,串在所有核前面。opWrapList / wrapIdNum 录制后只读,却和队列元素捆在同一次恢复里。 ### 现在的做法 录制 MixTaskDataBackup 留下: | 字段 | 含义 | |---|---| | queue.elem | 不可变快照,只作 restore 源 | | queue.head/tail/capacity | 录制时刻游标 | | pingElem / pongElem | 两块工作缓冲;pong OOM 时回退 in-place memcpy | | opWrapList / wrapIdNum | backup 写一次;Swap 时仍写回 live(sche 依赖) | 重放: 1. **头**(须在 ReadyQueue swap **之前**):MixTaskDataPingPongSwap。回退路径 DrcoReadyQueueDataRestore 会读 wrap 队列,必须先干净。 2. **退出** MixTaskDataPingPongRestore:把快照 memcpy 进当前未挂载的那一块。 旧 API MixTaskDataRestore 已删除。 ## 2. DRCO 重放 ping-pong ### 原来的缺点 enableAicoreResolve 时,每次重放都在 PushTask 前做两件事:DrcoPredCountDataRestore 重填 metadata predcount,以及 DrcoReadyQueueDataRestore + DrcoRootFuncListRestorePrecount 按 ready queue 重新铺 per-core pending / local ready。Die ready queue 的 swap 还会再往 per-core 队列灌一次。 ### 现在的做法 录制结束 BackupDrcoReplayShadow 为下列结构各留 canon(不可变快照)、ping(录制时的 live)、pong(第二份工作副本): - per-core pending - local ready queue / local ready matrix - stitch node matrix / hub task matrix metadata predcount 另留 drcoPredCountImage,以及 ping/pong 两个 offset;选中的 offset 写在 funcDynamicDataOffset 低 32 位。 重放: 1. **头** DrcoPredCountPingPongSwap:把 funcDynamicDataOffset 切到另一块 predcount。 2. **头** ReadyQueueDataPingPongSwap:shadow 已就绪(drcoShadowReady)时改走 DrcoShadowPingPongSwap,只交换指针并 RestorePrecount。shadow 未就绪(backup OOM)时仍回退 DrcoReadyQueueDataRestore。 3. Die ready queue 只交换自己的 elem,不再向 per-core 队列重灌;那份镜像由 DRCO shadow swap 负责。 4. **退出** DrcoShadowPingPongRestore / DrcoPredCountPingPongRestore:把 canon / image memcpy 进当前未挂载的那一块。 ## Ping-pong 的数据 录制发生在 PushTask 之前。此时 per-core pending 已经按 wrap、AIC、AIV 和 die 队列派发完;local ready、local matrix、stitch、hub 还是分配时的空表。影子把这个初态 memcpy 成 canon 和 pong,重放只换指针。launch 结束后把 canon 再 memcpy 进没挂上的那一块,下一轮换上来仍是初态。 和主线 DrcoReadyQueueDataRestore 的对应: | 数据 | 作用 | 主线重放 | 影子 | |---|---|---|---| | per-core pending | 每个核开跑时直接执行的初始 leaf 列表 | 先把 head/size 清 0,再按 wrap、AIC、AIV 重入队,die swap 再补 die 任务 | memcpy 录制时已经派发好的队列,换指针。内容与重入队相同,不再重灌 | | local ready queue | 矩阵放不下的后继就绪队列,AIC/AIV/MIX 各一组 | head/tail 置 0,任务区 memset 0 | 录制时空表,memcpy 后换指针,等价于清零 | | local ready matrix | 按消费者行投放刚解开的后继 | rowList memset 0 | 同上 | | stitch node matrix | 跨核帮忙展开的 stitch 槽,空槽为 0 | stitchNodeList memset 0 | 同上 | | hub task matrix | hub 溢出和类型越界的兜底任务槽,空槽为 0 | hubTaskList memset 0 | 同上 | | metadata predcount | AICore 使用的 int32 前驱计数 | 从 uint16 backup 逐项写回当前缓冲 | drcoPredCountImage 加一块 pong,切换 funcDynamicDataOffset。pong 没申请到时仍逐项写回 | | mix wrap elem | mix 任务的 AIC/AIV 包装,DrcoReadyQueueDataRestore 回退路径会读它 | 整段 memcpy 回 live elem | ping/pong 换指针;pong 申请失败时仍 memcpy | 不进影子、两边都直接写的字段: - readyMatrixPushCol:每轮写 0,后继行游标从 0 开始。 - staticExecCount 和完成 flag:DrcoRootFuncListRestorePrecount 写回录制时的预计数。 - shardExecCount:设备运行时的动态分片计数。主线每轮清 0;影子换指针不管这块,所以交换后同样清 0。 - devTaskFinished:每轮写 0。 没有做 ping-pong 的: - middleQueue:队列内容只读,设备不写回 GM,沿用 slab 镜像。 - bitmap:仍是原来的 BitmapDataRestoreTask,full cache 只恢复一次。 - AIC/AIV ready queue 和 die ready queue 的 elem ping-pong 是更早的改动,这次只让 die swap 在影子成功时不再往 per-core 重灌。 影子申请失败时 drcoShadowReady 保持 0,重放退回 DrcoReadyQueueDataRestore,die 任务仍按主线补进 pending。 ## 重放头顺序 text for each deviceTask: RelocIncastOutcastTask PredCountPingPongSwap [enableAicoreResolve] DrcoPredCountPingPongSwap [!fullCache || !bitmapRestoreDone] BitmapDataRestoreTask MixTaskDataPingPongSwap // before ReadyQueue ReadyQueueDataPingPongSwap // publishes DRCO shadow when ready DieReadyQueuePingPongSwap PushTask 优化前后头开销对比:  See merge request: cann/pypto!6866 | 1 month ago |
| Files | Last commit | Last update |
|---|---|---|
| 30 days ago | ||
| 18 days ago | ||
| 24 days ago | ||
| 19 days ago | ||
| 1 month ago | ||
| 19 days ago | ||
| 1 month ago |