| Files | Last commit | Last update |
|---|---|---|
test(machine): Supplement machine UT test cases_12. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5361 merge ut_12 into master test(machine): Supplement machine UT test cases_12. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine ut补充 See merge request: cann/pypto!5361 | 3 months ago | |
test(machine): Supplement machine UT test cases_12. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5361 merge ut_12 into master test(machine): Supplement machine UT test cases_12. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine ut补充 See merge request: cann/pypto!5361 | 3 months 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 | |
feat(machine): Cut ctrlflow cache IO Reloc overhead via host arena Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> # message auto-generated for no-merge-commit merge: !7025 merge fix-ring-event-epoch into master feat(machine): Cut ctrlflow cache IO Reloc overhead via host arena Created-by: LordOfMysteries Commit-by: LordOfMysteries Merged-by: cann-robot Description: # 需求设计:消减控制流 cache 路径上的 ctrl RelocIO 开销 > PR: https://gitcode.com/cann/pypto/pull/7025 > Commit: feat(machine): Cut ctrlflow cache IO Reloc overhead via host arena (1fd1e2ee2) ## 1. 背景与问题 控制流 cache 命中后,每次 launch 仍要把本轮 **incast/outcast 绝对地址**交给叶子任务。原先主要开销在 **AICPU ctrl 热路径**:GELaunchRunCached 对每个 cached DevTask 调用 RelocIncastOutcastTask,按 rawTensorAddrBackup 描述符解析并**写回共享内嵌 IO 表**。 问题: - RelocIO 落在 ctrl 热路径,与 stitch/restore 争用同一条 AICPU-CTRL。 - 写共享内嵌表时,若与 early-launch / 上一轮 AICore 读侧重叠,存在改表竞态风险。 - 每轮 O(全部 I/O 槽) 的解析无法被 Host 侧提前完成。 ## 2. 目标与约束 | 类型 | 内容 | |------|------| | **主目标** | cache replay 跳过 per-task RelocIncastOutcastTask;RelocIO 挪到 Host Materialize(随路 arena,与 AICore launch-args 同寿命) | | **隐含约束** | **不增加 AICore 热路径损失**:无多核 BindIo、无 /8;叶子入口解析一次表起点;GetTensorAddr 仍是 base[i] | | **正确性** | aclgraph 每次捕获各自随路表;partial-cache 后 stitch 的 func 不进 layout(kIoAddressArenaOffsetInvalid),继续内嵌表 | | **兼容** | emulation / aicore-model / dump / shmem 等仍可读内嵌表时,走原 Reloc 回退 | | **工程化** | KernelBinary 与 offline kernel-bundle 共用同一套 AICore launch/arena 帮助函数,避免双份布局逻辑漂移 | ## 3. 改造前:IO 地址刷新与使用 text 每次 Launch Host 下发 tensor / workspace │ ▼ AICPU ctrl: RelocIncastOutcastTask │ 写回共享 DynFuncData 内嵌 rawTensorAddr[] ▼ AICore Leaf GetTensorAddr └── 读 funcData->rawTensorAddr[i] (共享 CF 元数据) | 阶段 | 行为 | |------|------| | Ctrl RelocIO | 热路径写共享内嵌 rawTensorAddr[] | | Leaf | 读 funcData->rawTensorAddr[i] | ## 4. 改造后:流程与元数据路径 ### 4.1 总览 **可变绝对地址**只进本轮随路 arena;共享 CF 只留静态 ioAddressArenaOffset;ctrl 在纯 arena 场景不再 RelocIO;叶子把表起点放进 CoreFuncParam.rawTensorAddr。 text 建 Cache(一次性) AssignIoAddressArenaLayout │ ▼ 静态 ioAddressArenaOffset + ioAddressArenaBytes 每次 Launch Host 准备 AICore 7-slot args(可预留 arena 尾部容量) AICPU GELaunchRunCached └── 有 arena 且无需内嵌刷新时:仅挂 startArgs,跳过 RelocIncastOutcastTask Host MaterializeIncastOutcastAddrs ──► AICore host-args 尾部 arena(AICPU 之后) AICore launch(无 BindIo) KernelEntry: ctx.ioAddressArena = inputs Leaf 入口: param.rawTensorAddr = arena + offset(或内嵌表) GetTensorAddr → param.rawTensorAddr[i] > **时序约束**:Materialize 必须在 AICPU 之后、AICore 之前(与 DeviceLauncher::LaunchKernel / LaunchBundleKernelOnce 一致),避免把绝对 host 指针提前泄漏进仍需设备侧使用的缓冲语义;H2D CF 在 rebase 之前完成。 ### 4.2 元数据访问路径 text 共享 CF(静态) 本轮随路(可变) 叶子私有 ┌─────────────────────┐ ┌──────────────────┐ ┌─────────────────────────┐ │ ioAddressArenaOffset│──(+base)─►│ ioAddressArena[] │───────►│ CoreFuncParam.rawTensorAddr │ │ 内嵌 rawTensorAddr │ │ 绝对地址 │ └───────────┬─────────────┘ │ (stitch / fallback) │──Invalid─►│ │ │ └─────────────────────┘ └──────────────────┘ ▼ GetTensorAddr: base[i] | 阶段 | 写 / 读 | |------|---------| | Assign | 写静态 ioAddressArenaOffset(元素下标,**不是字节 /8**) | | Host Materialize | **写本轮 arena**(承接原 ctrl RelocIO) | | Ctrl replay | 条件满足时只挂 startArgs,**不 RelocIO** | | Leaf 入口 | offset != Invalid → param.rawTensorAddr = arena + offset;否则用内嵌表 | | GetTensorAddr | 读 param.rawTensorAddr[i] | ### 4.3 共享 Host 实现(本批补充) 抽出 framework/src/machine/runtime/runner/aicore_launch_args.{h,cpp},供 **在线 KernelBinary** 与 **离线 kernel_bundle_launch** 共用: | API | 作用 | |-----|------| | PrepareAicoreLaunchArgsBuffer | 按 7-slot + 可选 arena 容量扩缓冲,填 launch slots,先关掉 host-input | | EnsureHostCtrlFlowCacheRebased | 对本轮 host CF mirror 做一次 rebase,供 Materialize 解引用 | | FillAicoreIoAddressArenaBuffer | 调用 MaterializeIncastOutcastAddrs 写入 arena,再打开 RtHostInputInfo(inputs) | LaunchBundleKernelOnce 同步拆成:准备 AICPU / 准备 AICore slots → 推 AICPU → Materialize arena → 推 AICore,避免超长一次性函数、并与 DeviceLauncher 时序对齐。 **RingEvent / slot 复用**:arena 只解决「本轮 IO 绝对地址落点」;host CF cache 槽位复用与 epoch 同步仍依赖既有 RingEvent 机制,**不能**因引入 arena 而删掉。 ### 4.4 关键代码锚点 **Host 物化**(KernelBinary::MaterializeIoAddressArenaForAicore / BundleMaterializeAicoreIoArena):走共享 helper → rebase → Materialize → 挂到 AICore args 尾部。 **Ctrl 跳过条件**(GELaunchRunCached): cpp const bool arenaLive = (devProg->ctrlFlowCacheAnchor->ioAddressArenaBytes != 0); const bool needEmbeddedIo = (devProg->devArgs.hostPid != 0) || (startArgs->commGroupNum != 0); if (arenaLive && !needEmbeddedIo) { dynTask->dynFuncDataList->startArgs = startArgs; // 跳过 Reloc } else { RelocIncastOutcastTask(...); // dump/shmem/无 arena 回退 } **叶子解析**(aicore_entry.h): cpp __gm__ uint64_t* rawTensorAddr = funcData->rawTensorAddr; if (funcData->ioAddressArenaOffset != kIoAddressArenaOffsetInvalid) { rawTensorAddr = ctx->ioAddressArena + funcData->ioAddressArenaOffset; } CoreFuncParam param = { ..., rawTensorAddr }; **热路径**(aicore_runtime.h):GetTensorAddr 改为读 ctx->rawTensorAddr[i],指令形态仍是基址+下标。 ## 5. 与原 Reloc / Workspace 的关系 | 地址类型 | Arena 是否覆盖 | 说明 | |----------|----------------|------| | 用户 Input/Output 槽 | ✅ | Materialize 时按 index 取本轮绝对地址 | | Backup 中 Workspace kind 槽 | ✅ | Materialize 时 +wsShift 写成绝对地址进 arena | | DynFuncData.workspaceAddr / stack / runtime WS **基址** | ❌ | 仍走 TaskAddr*Workspace / TaskAddrRelocWorkspace | | LOCAL tensor | ❌ | AICore:workspaceAddr + offset,不经 rawTensorAddr | 原 RelocIncastOutcastTask:在 device ctrl **原地**把 backup 解到内嵌表;现与 Materialize 共用 ResolveLeafIncastOutcastAddrs,区别是目标缓冲(内嵌 vs arena)与执行位置(ctrl vs host)。 ## 6. 兼容矩阵 | 场景 | 行为 | |------|------| | Full / partial cache(已 Assign layout) | Host 物化;ctrl 可跳过 RelocIO;叶子用 arena;无 BindIo | | 同 launch 后续 device stitch | ioAddressArenaOffset = Invalid,走内嵌表 | | ioAddressArenaBytes == 0 / emulation / aicore-model | 清 arena 标记;ctrl Reloc 刷新内嵌表并置 Invalid | | dump(hostPid != 0)或通信(commGroupNum != 0) | 仍 Reloc 内嵌表(AICPU 侧仍读嵌入地址) | | aclgraph 多次捕获 | 各自随路 arena,互不影响 | ## 7. 主要改动清单 1. **Host arena**:AssignIoAddressArenaLayout / MaterializeIncastOutcastAddrs;launch 挂 AICore 随路 arena 2. **共享 helper**:新增 aicore_launch_args.{h,cpp};KernelBinary + kernel_bundle_launch 共用 Prepare / Rebase / Fill 3. **Bundle 拆分**:LaunchBundleKernelOnce 拆步骤,Materialize 固定在 AICPU 之后 4. **Ctrl**:arena 存活且无需内嵌刷新时跳过 RelocIncastOutcastTask 5. **Device AICore**:ExecuteContext.ioAddressArena;叶子解析 param.rawTensorAddr;stitch 置 kIoAddressArenaOffsetInvalid 6. **统一解析**:ResolveLeafIncastOutcastAddrs 供 Materialize 与 Reloc 共用 7. **测试**:test_aicore_launch_args.cpp(布局 / Prepare / null-safe Fill);既有 ctrlflow cache / kernel_binary UT 同步适配 ## 8. 验收要点 - [ ] cache replay 路径 ctrl 泳道上 RelocIO 段消失或显著缩短(纯计算算子) - [ ] GetTensorAddr 热路径无额外除法 / 多核写共享指针 - [ ] dump / shmem / 通信场景精度与功能不回退 - [ ] aclgraph capture/replay 与 eager 数值一致 - [ ] stitch / non-cache 仍走内嵌表且地址正确 - [ ] KernelBinary 与 bundle 路径 arena 布局一致;AicoreLaunchArgsTest.* 本地通过 See merge request: cann/pypto!7025 | 1 month ago | |
test(machine): Supplement machine UT test cases. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !4935 merge machine_ut into master test(machine): Supplement machine UT test cases. Created-by: chai-hw Commit-by: chai-hw 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!4935 | 4 months ago | |
fix(machine): Detect intra-loop write overlap for single-root cell-match WAW Co-authored-by: songyangyang18<songyangyang18@huawei.com> # message auto-generated for no-merge-commit merge: !5770 merge cell-resolve into master fix(machine): Detect intra-loop write overlap for single-root cell-match WAW Created-by: songyangyang18 Commit-by: songyangyang18 Merged-by: cann-robot Description: ## 1. Background(背景信息) 当前 kernel 输入 tensor 的写后写依赖建立过程,单 root、跨迭代写同一 assemble 区域时,无法建立写后写依赖,导致精度异常。 为了解决场景精度异常问题,新增 PASS 在 IR 层进行写后写区域重叠校验:相对当前循环变量,相邻迭代写窗可分,并进行非重叠标记,用于machine部分的写后写依赖判定依据。 ## 2. 总体流程 1. 在create_function之后新增了infer_multi_iter_overlap_pass,用于检测loop 迭代间的写区域重叠; 2. 对于检测区域不重叠的打上标记,使用rebuildable attribute挂载在function上; 3. 获取function的assemble数量,数量>=2的保守视为存在写后写,只考虑assemble数量为1的场景; 4. 对于整体的function,识别assemble所在循环层的循环变量与步长,进行区域重叠检测,不存在循环变量的视为固定区域写,存在重叠;存在循环变量的进行重叠检测,用循环变量i+step与i的offset之差与assemble的tensor shape做比较。 ## 3. 验证场景一览 | # | scene | assemble offset(示意) | 期望 Mark / WAW | |---|-------|-------------------------|-----------------| | 1 | assemble_disjoint | [i*tile, 0] | Mark / 无 WAW | | 2 | assemble_overlap | [i*(tile//2), 0] | 不 Mark / 有 WAW | | 3 | nested_disjoint | [i*tile, j*tile_n](innermost=j 可分) | Mark / 无 WAW | | 4 | nested_overlap | [i*tile, j*(tile_n//2)](innermost=j 半窗重叠) | 不 Mark / 有 WAW | | 5 | fixed_offset | [0, 0](当前变量不在 offset) | 不 Mark / 有 WAW | | 6 | same_idx_diff_step | sibling:左半窗重叠 + 右 step=2 可分 | 同 raw 多 assemble → 不 Mark | | 7 | nested_inner_immediate_offset | 嵌套:[i*tile, 0],innermost=j 不在 offset | 不 Mark / 有 WAW | ## 4. PR限制约束(#3401 ) 1. 当前实现逻辑只考虑了最内层循环的重叠判定,在循环嵌套场景下,外层循环的影响没有考虑,存在局限。 2. 当前实现逻辑没有考虑循环内部创建tensor的情况,内部创建的tensor会自动根据迭代次数分配不同的地址区域,所以一定不重叠。 3. 更多的泛化性场景需要验证与补充。 See merge request: cann/pypto!5770 | 2 months ago | |
feat(machine): Cut ctrlflow cache IO Reloc overhead via host arena Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> # message auto-generated for no-merge-commit merge: !7025 merge fix-ring-event-epoch into master feat(machine): Cut ctrlflow cache IO Reloc overhead via host arena Created-by: LordOfMysteries Commit-by: LordOfMysteries Merged-by: cann-robot Description: # 需求设计:消减控制流 cache 路径上的 ctrl RelocIO 开销 > PR: https://gitcode.com/cann/pypto/pull/7025 > Commit: feat(machine): Cut ctrlflow cache IO Reloc overhead via host arena (1fd1e2ee2) ## 1. 背景与问题 控制流 cache 命中后,每次 launch 仍要把本轮 **incast/outcast 绝对地址**交给叶子任务。原先主要开销在 **AICPU ctrl 热路径**:GELaunchRunCached 对每个 cached DevTask 调用 RelocIncastOutcastTask,按 rawTensorAddrBackup 描述符解析并**写回共享内嵌 IO 表**。 问题: - RelocIO 落在 ctrl 热路径,与 stitch/restore 争用同一条 AICPU-CTRL。 - 写共享内嵌表时,若与 early-launch / 上一轮 AICore 读侧重叠,存在改表竞态风险。 - 每轮 O(全部 I/O 槽) 的解析无法被 Host 侧提前完成。 ## 2. 目标与约束 | 类型 | 内容 | |------|------| | **主目标** | cache replay 跳过 per-task RelocIncastOutcastTask;RelocIO 挪到 Host Materialize(随路 arena,与 AICore launch-args 同寿命) | | **隐含约束** | **不增加 AICore 热路径损失**:无多核 BindIo、无 /8;叶子入口解析一次表起点;GetTensorAddr 仍是 base[i] | | **正确性** | aclgraph 每次捕获各自随路表;partial-cache 后 stitch 的 func 不进 layout(kIoAddressArenaOffsetInvalid),继续内嵌表 | | **兼容** | emulation / aicore-model / dump / shmem 等仍可读内嵌表时,走原 Reloc 回退 | | **工程化** | KernelBinary 与 offline kernel-bundle 共用同一套 AICore launch/arena 帮助函数,避免双份布局逻辑漂移 | ## 3. 改造前:IO 地址刷新与使用 text 每次 Launch Host 下发 tensor / workspace │ ▼ AICPU ctrl: RelocIncastOutcastTask │ 写回共享 DynFuncData 内嵌 rawTensorAddr[] ▼ AICore Leaf GetTensorAddr └── 读 funcData->rawTensorAddr[i] (共享 CF 元数据) | 阶段 | 行为 | |------|------| | Ctrl RelocIO | 热路径写共享内嵌 rawTensorAddr[] | | Leaf | 读 funcData->rawTensorAddr[i] | ## 4. 改造后:流程与元数据路径 ### 4.1 总览 **可变绝对地址**只进本轮随路 arena;共享 CF 只留静态 ioAddressArenaOffset;ctrl 在纯 arena 场景不再 RelocIO;叶子把表起点放进 CoreFuncParam.rawTensorAddr。 text 建 Cache(一次性) AssignIoAddressArenaLayout │ ▼ 静态 ioAddressArenaOffset + ioAddressArenaBytes 每次 Launch Host 准备 AICore 7-slot args(可预留 arena 尾部容量) AICPU GELaunchRunCached └── 有 arena 且无需内嵌刷新时:仅挂 startArgs,跳过 RelocIncastOutcastTask Host MaterializeIncastOutcastAddrs ──► AICore host-args 尾部 arena(AICPU 之后) AICore launch(无 BindIo) KernelEntry: ctx.ioAddressArena = inputs Leaf 入口: param.rawTensorAddr = arena + offset(或内嵌表) GetTensorAddr → param.rawTensorAddr[i] > **时序约束**:Materialize 必须在 AICPU 之后、AICore 之前(与 DeviceLauncher::LaunchKernel / LaunchBundleKernelOnce 一致),避免把绝对 host 指针提前泄漏进仍需设备侧使用的缓冲语义;H2D CF 在 rebase 之前完成。 ### 4.2 元数据访问路径 text 共享 CF(静态) 本轮随路(可变) 叶子私有 ┌─────────────────────┐ ┌──────────────────┐ ┌─────────────────────────┐ │ ioAddressArenaOffset│──(+base)─►│ ioAddressArena[] │───────►│ CoreFuncParam.rawTensorAddr │ │ 内嵌 rawTensorAddr │ │ 绝对地址 │ └───────────┬─────────────┘ │ (stitch / fallback) │──Invalid─►│ │ │ └─────────────────────┘ └──────────────────┘ ▼ GetTensorAddr: base[i] | 阶段 | 写 / 读 | |------|---------| | Assign | 写静态 ioAddressArenaOffset(元素下标,**不是字节 /8**) | | Host Materialize | **写本轮 arena**(承接原 ctrl RelocIO) | | Ctrl replay | 条件满足时只挂 startArgs,**不 RelocIO** | | Leaf 入口 | offset != Invalid → param.rawTensorAddr = arena + offset;否则用内嵌表 | | GetTensorAddr | 读 param.rawTensorAddr[i] | ### 4.3 共享 Host 实现(本批补充) 抽出 framework/src/machine/runtime/runner/aicore_launch_args.{h,cpp},供 **在线 KernelBinary** 与 **离线 kernel_bundle_launch** 共用: | API | 作用 | |-----|------| | PrepareAicoreLaunchArgsBuffer | 按 7-slot + 可选 arena 容量扩缓冲,填 launch slots,先关掉 host-input | | EnsureHostCtrlFlowCacheRebased | 对本轮 host CF mirror 做一次 rebase,供 Materialize 解引用 | | FillAicoreIoAddressArenaBuffer | 调用 MaterializeIncastOutcastAddrs 写入 arena,再打开 RtHostInputInfo(inputs) | LaunchBundleKernelOnce 同步拆成:准备 AICPU / 准备 AICore slots → 推 AICPU → Materialize arena → 推 AICore,避免超长一次性函数、并与 DeviceLauncher 时序对齐。 **RingEvent / slot 复用**:arena 只解决「本轮 IO 绝对地址落点」;host CF cache 槽位复用与 epoch 同步仍依赖既有 RingEvent 机制,**不能**因引入 arena 而删掉。 ### 4.4 关键代码锚点 **Host 物化**(KernelBinary::MaterializeIoAddressArenaForAicore / BundleMaterializeAicoreIoArena):走共享 helper → rebase → Materialize → 挂到 AICore args 尾部。 **Ctrl 跳过条件**(GELaunchRunCached): cpp const bool arenaLive = (devProg->ctrlFlowCacheAnchor->ioAddressArenaBytes != 0); const bool needEmbeddedIo = (devProg->devArgs.hostPid != 0) || (startArgs->commGroupNum != 0); if (arenaLive && !needEmbeddedIo) { dynTask->dynFuncDataList->startArgs = startArgs; // 跳过 Reloc } else { RelocIncastOutcastTask(...); // dump/shmem/无 arena 回退 } **叶子解析**(aicore_entry.h): cpp __gm__ uint64_t* rawTensorAddr = funcData->rawTensorAddr; if (funcData->ioAddressArenaOffset != kIoAddressArenaOffsetInvalid) { rawTensorAddr = ctx->ioAddressArena + funcData->ioAddressArenaOffset; } CoreFuncParam param = { ..., rawTensorAddr }; **热路径**(aicore_runtime.h):GetTensorAddr 改为读 ctx->rawTensorAddr[i],指令形态仍是基址+下标。 ## 5. 与原 Reloc / Workspace 的关系 | 地址类型 | Arena 是否覆盖 | 说明 | |----------|----------------|------| | 用户 Input/Output 槽 | ✅ | Materialize 时按 index 取本轮绝对地址 | | Backup 中 Workspace kind 槽 | ✅ | Materialize 时 +wsShift 写成绝对地址进 arena | | DynFuncData.workspaceAddr / stack / runtime WS **基址** | ❌ | 仍走 TaskAddr*Workspace / TaskAddrRelocWorkspace | | LOCAL tensor | ❌ | AICore:workspaceAddr + offset,不经 rawTensorAddr | 原 RelocIncastOutcastTask:在 device ctrl **原地**把 backup 解到内嵌表;现与 Materialize 共用 ResolveLeafIncastOutcastAddrs,区别是目标缓冲(内嵌 vs arena)与执行位置(ctrl vs host)。 ## 6. 兼容矩阵 | 场景 | 行为 | |------|------| | Full / partial cache(已 Assign layout) | Host 物化;ctrl 可跳过 RelocIO;叶子用 arena;无 BindIo | | 同 launch 后续 device stitch | ioAddressArenaOffset = Invalid,走内嵌表 | | ioAddressArenaBytes == 0 / emulation / aicore-model | 清 arena 标记;ctrl Reloc 刷新内嵌表并置 Invalid | | dump(hostPid != 0)或通信(commGroupNum != 0) | 仍 Reloc 内嵌表(AICPU 侧仍读嵌入地址) | | aclgraph 多次捕获 | 各自随路 arena,互不影响 | ## 7. 主要改动清单 1. **Host arena**:AssignIoAddressArenaLayout / MaterializeIncastOutcastAddrs;launch 挂 AICore 随路 arena 2. **共享 helper**:新增 aicore_launch_args.{h,cpp};KernelBinary + kernel_bundle_launch 共用 Prepare / Rebase / Fill 3. **Bundle 拆分**:LaunchBundleKernelOnce 拆步骤,Materialize 固定在 AICPU 之后 4. **Ctrl**:arena 存活且无需内嵌刷新时跳过 RelocIncastOutcastTask 5. **Device AICore**:ExecuteContext.ioAddressArena;叶子解析 param.rawTensorAddr;stitch 置 kIoAddressArenaOffsetInvalid 6. **统一解析**:ResolveLeafIncastOutcastAddrs 供 Materialize 与 Reloc 共用 7. **测试**:test_aicore_launch_args.cpp(布局 / Prepare / null-safe Fill);既有 ctrlflow cache / kernel_binary UT 同步适配 ## 8. 验收要点 - [ ] cache replay 路径 ctrl 泳道上 RelocIO 段消失或显著缩短(纯计算算子) - [ ] GetTensorAddr 热路径无额外除法 / 多核写共享指针 - [ ] dump / shmem / 通信场景精度与功能不回退 - [ ] aclgraph capture/replay 与 eager 数值一致 - [ ] stitch / non-cache 仍走内嵌表且地址正确 - [ ] KernelBinary 与 bundle 路径 arena 布局一致;AicoreLaunchArgsTest.* 本地通过 See merge request: cann/pypto!7025 | 1 month ago | |
fix(machine): Ensure cross-loop atomic_add determinism via ordered WAW Co-authored-by: songyangyang18<songyangyang18@huawei.com> # message auto-generated for no-merge-commit merge: !5296 merge assemble-op into master fix(machine): Ensure cross-loop atomic_add determinism via ordered WAW Created-by: songyangyang18 Commit-by: songyangyang18 Merged-by: cann-robot Description: ## Summary 修复跨 loop atomic_add 在 K 分片并行累加时的非确定性:当 compute_determinism_level >= 1 时,machine encode 将原子写退化为有序 NORMAL_WRITE,并通过 stitch **WAW** 建立串行依赖。 ## 问题 - K 轴分片并行时,多个 atomic_add 通过硬件 ATOMIC_WRITE 并发累加到同一 buffer。 - 浮点加法不满足结合律,写入到达顺序不确定 → 多次运行结果不一致。 ## 方案 读取全局配置 compute_determinism_level(由 JIT 入口从 torch_npu.set_deterministic_level 同步,level ≥ 1 即开启)。 **Encode 写类型** - 确定性关:isAtomic() → ATOMIC_WRITE(与原行为一致)。 - 确定性开:isAtomic() → NORMAL_WRITE,并在 outcast tensor 上 SetAttr("NORMAL"),退化为一般 assemble 写场景。 **Stitch WAW** - rootFuncOk 为真:沿用既有逻辑,hasNormalAttr → STITCH_CTRL_WAW(encode 补标后可命中)。 - 单 root 的 kernel input-assemble(rootFuncOk 为假):确定性开且 OutcastHasAtomicProducer(扫 Call 的 isAtomic())→ STITCH_CTRL_WAW。 See merge request: cann/pypto!5296 | 2 months ago | |
fix(machine): Dedup duplicate outcast consumer READs via last-wins Co-authored-by: songyangyang18<songyangyang18@huawei.com> # message auto-generated for no-merge-commit merge: !5656 merge cell-fix into master fix(machine): Dedup duplicate outcast consumer READs via last-wins Created-by: songyangyang18 Commit-by: songyangyang18 Merged-by: cann-robot Description: ### READ 后去重(last-wins) **背景**:同一 outcast 上多 producer 展开后,同一 consumer Call 可能对同一 tensor 注册多次 READ;上游按 operationIdx 去重会丢掉 W→R→W→R 交错形态。 **做法**: - encode 分析 outcast consumer 时允许同一 operationIdx 多次 READ 入表,记录 lastReadPos。 - 若存在重复 READ,调用 RebuildOutcastUseListByLastReadPos:**同一 operationIdx 只保留最后一次 READ**(last-wins),WRITE 条目全部保留。 - 保证 producerConsumerList 能表达「写—读—写—读」交错,同时去掉对 cell-match 无意义的早期重复读。 See merge request: cann/pypto!5656 | 3 months ago | |
test(machine): Supplement machine UT test cases_2. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !4987 merge ut_2 into master test(machine): Supplement machine UT test cases_2. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine ut 补充 See merge request: cann/pypto!4987 | 4 months ago | |
test(machine): Supplement machine UT test cases_11. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5305 merge ut_12 into master test(machine): Supplement machine UT test cases_11. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine ut覆盖 See merge request: cann/pypto!5305 | 3 months 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 | |
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 | |
test(machine): Supplement machine UT test cases_4. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5087 merge ut_5 into master test(machine): Supplement machine UT test cases_4. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine ut覆盖补充 See merge request: cann/pypto!5087 | 4 months 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 | |
perf(machine): Speed up host ctrl-flow cache build Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> # message auto-generated for no-merge-commit merge: !7190 merge optimize/ctrlflow-cache-skip-unused-memset into master perf(machine): Speed up host ctrl-flow cache build Created-by: LordOfMysteries Commit-by: LordOfMysteries Merged-by: cann-robot Description: https://gitcode.com/cann/pypto/issues/3681 ## Summary Host 侧构建 ctrl-flow cache 时,去掉默认路径上不必要的开销: 1. **跳过未使用 payload 的整块 memset** - CreateHostCtrlFlowCache 原先对约 100MB 容量上限做 AllocZero;录制实际只用约 1MB,usedCacheSize 拷 device 也不带走未用尾部。 - 改为只清 cacheData 之前的元数据前缀;payload 在 AllocateCache 按块(含 64B 对齐 padding)清零,保留 ready-queue / mix-task「洞必须为 null」语义。 - Engram ST 上 create_cache 约 5.7ms → 约 64µs。 2. **默认跳过 host stitch 校验 / topo dump** - 新增 HostTopoVerifyEnabled(),与 runtime_debug_mode == VERIFY 对齐。 - 默认关闭 CheckStitch、边校验以及 consumer/producer cell-access dump;VERIFY 时再开启。 - 不改 ENABLE_COMPILE_VERBOSE_LOG;无需为性能重编 verbose 开关。 ## UT - AllocateCache_ZerosPoisonedSlabAndPadding:poison 后分配,校验 slab + 64B padding 清零 - CreateHostCtrlFlowCache_AllocateCacheZerosPoisonedPayload:只清 header 后 poison payload,再经 AllocateCache 清零 - HostTopoVerifyEnabled_TrueWhenRuntimeDebugVerify:VERIFY 模式下门闩为 true - 原有 CreateHostCtrlFlowCache / BuildControlFlowCache 路径无需改断言 See merge request: cann/pypto!7190 | 28 days ago | |
test(machine): Supplement machine UT test cases_11. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5305 merge ut_12 into master test(machine): Supplement machine UT test cases_11. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine ut覆盖 See merge request: cann/pypto!5305 | 3 months ago | |
feat(machine): Cut ctrlflow cache IO Reloc overhead via host arena Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> # message auto-generated for no-merge-commit merge: !7025 merge fix-ring-event-epoch into master feat(machine): Cut ctrlflow cache IO Reloc overhead via host arena Created-by: LordOfMysteries Commit-by: LordOfMysteries Merged-by: cann-robot Description: # 需求设计:消减控制流 cache 路径上的 ctrl RelocIO 开销 > PR: https://gitcode.com/cann/pypto/pull/7025 > Commit: feat(machine): Cut ctrlflow cache IO Reloc overhead via host arena (1fd1e2ee2) ## 1. 背景与问题 控制流 cache 命中后,每次 launch 仍要把本轮 **incast/outcast 绝对地址**交给叶子任务。原先主要开销在 **AICPU ctrl 热路径**:GELaunchRunCached 对每个 cached DevTask 调用 RelocIncastOutcastTask,按 rawTensorAddrBackup 描述符解析并**写回共享内嵌 IO 表**。 问题: - RelocIO 落在 ctrl 热路径,与 stitch/restore 争用同一条 AICPU-CTRL。 - 写共享内嵌表时,若与 early-launch / 上一轮 AICore 读侧重叠,存在改表竞态风险。 - 每轮 O(全部 I/O 槽) 的解析无法被 Host 侧提前完成。 ## 2. 目标与约束 | 类型 | 内容 | |------|------| | **主目标** | cache replay 跳过 per-task RelocIncastOutcastTask;RelocIO 挪到 Host Materialize(随路 arena,与 AICore launch-args 同寿命) | | **隐含约束** | **不增加 AICore 热路径损失**:无多核 BindIo、无 /8;叶子入口解析一次表起点;GetTensorAddr 仍是 base[i] | | **正确性** | aclgraph 每次捕获各自随路表;partial-cache 后 stitch 的 func 不进 layout(kIoAddressArenaOffsetInvalid),继续内嵌表 | | **兼容** | emulation / aicore-model / dump / shmem 等仍可读内嵌表时,走原 Reloc 回退 | | **工程化** | KernelBinary 与 offline kernel-bundle 共用同一套 AICore launch/arena 帮助函数,避免双份布局逻辑漂移 | ## 3. 改造前:IO 地址刷新与使用 text 每次 Launch Host 下发 tensor / workspace │ ▼ AICPU ctrl: RelocIncastOutcastTask │ 写回共享 DynFuncData 内嵌 rawTensorAddr[] ▼ AICore Leaf GetTensorAddr └── 读 funcData->rawTensorAddr[i] (共享 CF 元数据) | 阶段 | 行为 | |------|------| | Ctrl RelocIO | 热路径写共享内嵌 rawTensorAddr[] | | Leaf | 读 funcData->rawTensorAddr[i] | ## 4. 改造后:流程与元数据路径 ### 4.1 总览 **可变绝对地址**只进本轮随路 arena;共享 CF 只留静态 ioAddressArenaOffset;ctrl 在纯 arena 场景不再 RelocIO;叶子把表起点放进 CoreFuncParam.rawTensorAddr。 text 建 Cache(一次性) AssignIoAddressArenaLayout │ ▼ 静态 ioAddressArenaOffset + ioAddressArenaBytes 每次 Launch Host 准备 AICore 7-slot args(可预留 arena 尾部容量) AICPU GELaunchRunCached └── 有 arena 且无需内嵌刷新时:仅挂 startArgs,跳过 RelocIncastOutcastTask Host MaterializeIncastOutcastAddrs ──► AICore host-args 尾部 arena(AICPU 之后) AICore launch(无 BindIo) KernelEntry: ctx.ioAddressArena = inputs Leaf 入口: param.rawTensorAddr = arena + offset(或内嵌表) GetTensorAddr → param.rawTensorAddr[i] > **时序约束**:Materialize 必须在 AICPU 之后、AICore 之前(与 DeviceLauncher::LaunchKernel / LaunchBundleKernelOnce 一致),避免把绝对 host 指针提前泄漏进仍需设备侧使用的缓冲语义;H2D CF 在 rebase 之前完成。 ### 4.2 元数据访问路径 text 共享 CF(静态) 本轮随路(可变) 叶子私有 ┌─────────────────────┐ ┌──────────────────┐ ┌─────────────────────────┐ │ ioAddressArenaOffset│──(+base)─►│ ioAddressArena[] │───────►│ CoreFuncParam.rawTensorAddr │ │ 内嵌 rawTensorAddr │ │ 绝对地址 │ └───────────┬─────────────┘ │ (stitch / fallback) │──Invalid─►│ │ │ └─────────────────────┘ └──────────────────┘ ▼ GetTensorAddr: base[i] | 阶段 | 写 / 读 | |------|---------| | Assign | 写静态 ioAddressArenaOffset(元素下标,**不是字节 /8**) | | Host Materialize | **写本轮 arena**(承接原 ctrl RelocIO) | | Ctrl replay | 条件满足时只挂 startArgs,**不 RelocIO** | | Leaf 入口 | offset != Invalid → param.rawTensorAddr = arena + offset;否则用内嵌表 | | GetTensorAddr | 读 param.rawTensorAddr[i] | ### 4.3 共享 Host 实现(本批补充) 抽出 framework/src/machine/runtime/runner/aicore_launch_args.{h,cpp},供 **在线 KernelBinary** 与 **离线 kernel_bundle_launch** 共用: | API | 作用 | |-----|------| | PrepareAicoreLaunchArgsBuffer | 按 7-slot + 可选 arena 容量扩缓冲,填 launch slots,先关掉 host-input | | EnsureHostCtrlFlowCacheRebased | 对本轮 host CF mirror 做一次 rebase,供 Materialize 解引用 | | FillAicoreIoAddressArenaBuffer | 调用 MaterializeIncastOutcastAddrs 写入 arena,再打开 RtHostInputInfo(inputs) | LaunchBundleKernelOnce 同步拆成:准备 AICPU / 准备 AICore slots → 推 AICPU → Materialize arena → 推 AICore,避免超长一次性函数、并与 DeviceLauncher 时序对齐。 **RingEvent / slot 复用**:arena 只解决「本轮 IO 绝对地址落点」;host CF cache 槽位复用与 epoch 同步仍依赖既有 RingEvent 机制,**不能**因引入 arena 而删掉。 ### 4.4 关键代码锚点 **Host 物化**(KernelBinary::MaterializeIoAddressArenaForAicore / BundleMaterializeAicoreIoArena):走共享 helper → rebase → Materialize → 挂到 AICore args 尾部。 **Ctrl 跳过条件**(GELaunchRunCached): cpp const bool arenaLive = (devProg->ctrlFlowCacheAnchor->ioAddressArenaBytes != 0); const bool needEmbeddedIo = (devProg->devArgs.hostPid != 0) || (startArgs->commGroupNum != 0); if (arenaLive && !needEmbeddedIo) { dynTask->dynFuncDataList->startArgs = startArgs; // 跳过 Reloc } else { RelocIncastOutcastTask(...); // dump/shmem/无 arena 回退 } **叶子解析**(aicore_entry.h): cpp __gm__ uint64_t* rawTensorAddr = funcData->rawTensorAddr; if (funcData->ioAddressArenaOffset != kIoAddressArenaOffsetInvalid) { rawTensorAddr = ctx->ioAddressArena + funcData->ioAddressArenaOffset; } CoreFuncParam param = { ..., rawTensorAddr }; **热路径**(aicore_runtime.h):GetTensorAddr 改为读 ctx->rawTensorAddr[i],指令形态仍是基址+下标。 ## 5. 与原 Reloc / Workspace 的关系 | 地址类型 | Arena 是否覆盖 | 说明 | |----------|----------------|------| | 用户 Input/Output 槽 | ✅ | Materialize 时按 index 取本轮绝对地址 | | Backup 中 Workspace kind 槽 | ✅ | Materialize 时 +wsShift 写成绝对地址进 arena | | DynFuncData.workspaceAddr / stack / runtime WS **基址** | ❌ | 仍走 TaskAddr*Workspace / TaskAddrRelocWorkspace | | LOCAL tensor | ❌ | AICore:workspaceAddr + offset,不经 rawTensorAddr | 原 RelocIncastOutcastTask:在 device ctrl **原地**把 backup 解到内嵌表;现与 Materialize 共用 ResolveLeafIncastOutcastAddrs,区别是目标缓冲(内嵌 vs arena)与执行位置(ctrl vs host)。 ## 6. 兼容矩阵 | 场景 | 行为 | |------|------| | Full / partial cache(已 Assign layout) | Host 物化;ctrl 可跳过 RelocIO;叶子用 arena;无 BindIo | | 同 launch 后续 device stitch | ioAddressArenaOffset = Invalid,走内嵌表 | | ioAddressArenaBytes == 0 / emulation / aicore-model | 清 arena 标记;ctrl Reloc 刷新内嵌表并置 Invalid | | dump(hostPid != 0)或通信(commGroupNum != 0) | 仍 Reloc 内嵌表(AICPU 侧仍读嵌入地址) | | aclgraph 多次捕获 | 各自随路 arena,互不影响 | ## 7. 主要改动清单 1. **Host arena**:AssignIoAddressArenaLayout / MaterializeIncastOutcastAddrs;launch 挂 AICore 随路 arena 2. **共享 helper**:新增 aicore_launch_args.{h,cpp};KernelBinary + kernel_bundle_launch 共用 Prepare / Rebase / Fill 3. **Bundle 拆分**:LaunchBundleKernelOnce 拆步骤,Materialize 固定在 AICPU 之后 4. **Ctrl**:arena 存活且无需内嵌刷新时跳过 RelocIncastOutcastTask 5. **Device AICore**:ExecuteContext.ioAddressArena;叶子解析 param.rawTensorAddr;stitch 置 kIoAddressArenaOffsetInvalid 6. **统一解析**:ResolveLeafIncastOutcastAddrs 供 Materialize 与 Reloc 共用 7. **测试**:test_aicore_launch_args.cpp(布局 / Prepare / null-safe Fill);既有 ctrlflow cache / kernel_binary UT 同步适配 ## 8. 验收要点 - [ ] cache replay 路径 ctrl 泳道上 RelocIO 段消失或显著缩短(纯计算算子) - [ ] GetTensorAddr 热路径无额外除法 / 多核写共享指针 - [ ] dump / shmem / 通信场景精度与功能不回退 - [ ] aclgraph capture/replay 与 eager 数值一致 - [ ] stitch / non-cache 仍走内嵌表且地址正确 - [ ] KernelBinary 与 bundle 路径 arena 布局一致;AicoreLaunchArgsTest.* 本地通过 See merge request: cann/pypto!7025 | 1 month ago | |
fix(machine): Align bundle host control-flow cache Co-authored-by: W4termy<wangmingyang21@huawei.com> # message auto-generated for no-merge-commit merge: !7265 merge fix/bundletestbug into master fix(machine): Align bundle host control-flow cache Created-by: W4termy Commit-by: W4termy Merged-by: cann-robot Description: bundle加载cache时,将其复制到vector<uint_8>,未保证64字节对齐,导致偶现未对齐段错误情况,现改为使用已有的CtrlFlowCacheBlob确保对齐 源码:using CtrlFlowCacheBlob = std::vector<uint8_t, npu::tile_fwk::AlignedAllocator<uint8_t, 0x40>>; See merge request: cann/pypto!7265 | 27 days ago | |
test(machine): Supplement machine UT test cases_12. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5361 merge ut_12 into master test(machine): Supplement machine UT test cases_12. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine ut补充 See merge request: cann/pypto!5361 | 3 months ago | |
feat(machine): Change aicpu kernel launch method Co-authored-by: wan_jianfen<wanjianfen@hisilicon.com> # message auto-generated for no-merge-commit merge: !5045 merge br_aicpuKernelLaunch into master feat(machine): Change aicpu kernel launch method Created-by: wan_jianfen Commit-by: wan_jianfen Merged-by: cann-robot Description: 改变kernel_launch 接口,更换成acl 接口 See merge request: cann/pypto!5045 | 3 months ago | |
test(machine): Supplement machine UT test cases_12. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5361 merge ut_12 into master test(machine): Supplement machine UT test cases_12. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine ut补充 See merge request: cann/pypto!5361 | 3 months ago | |
feat(pypto_pro): auto block_dim for direct calls and explicit over-budget rejection Co-authored-by: liulufang_gitcode<liulufang1@hisilicon.com> # message auto-generated for no-merge-commit merge: !6328 merge llf into master feat(pypto_pro): auto block_dim for direct calls and explicit over-budget rejection Created-by: liulufang_gitcode Commit-by: liulufang_gitcode Merged-by: cann-robot Description: 1、jit运行时的block_dim如果不填,从默认使用的是1改为使用当前device的最大可用值 2、对当前用户传递的block_dim进行校验,如果大于device的最大可用值,则直接报错 See merge request: cann/pypto!6328 | 2 months ago | |
test(machine): Supplement machine UT test cases_2. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !4987 merge ut_2 into master test(machine): Supplement machine UT test cases_2. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine ut 补充 See merge request: cann/pypto!4987 | 4 months ago | |
feat(indexing): Support A5 SIMT gather and index put Co-authored-by: bynshard<zhangbingshuai@huawei.com> # message auto-generated for no-merge-commit merge: !5404 merge feat/a5-simt-mixed into master feat(indexing): Support A5 SIMT gather and index put Created-by: bynshard Commit-by: bynshard Merged-by: cann-robot Description: gather indexput 支持的simt 实现,在离散场景下提升性能 当 Gather 的 source 位于 GM、indices 位于 UB 时,A5 Codegen 会选择 SIMT MGATHER 实现: 1. 使用 SIMD 批量计算 Gather 的元素偏移。 2. 使用 SIMT MGATHER 根据偏移直接从 GM source 读取数据。 3. source 位于 UB 时继续使用原有实现。 4. int64 indices 暂不使用 SIMT,回退到原有 Scalar 实现。 同时补充了 SIMT Kernel 的端到端识别与下发机制: 1. Pass 识别需要 SIMT 的 Gather,并设置 requiresSimt 属性。 2. 将 requiresSimt 信息传递到 Device Program 和编译流程。 3. 为包含 SIMT 的 A5 Kernel 生成相应的 ELF metadata。 4. Runtime 根据 Kernel 是否包含 SIMT,选择对应的 UB 配置。 5. SIMT Kernel 配置 216 KB 动态 UB,并为 DCache 预留 32 KB。 6. 纯 SIMD Kernel 保持原有 Runtime 下发方式和 UB 配置。 此外,完善了 GM GatherElement 在内存类型推导、动态参数注册、动态 valid shape 处理和 OoO 调度中的支持。 Related Issue: #3162 ``` 更多描述信息见:[Commit Message 规范](../docs/zh/contribute/pull-request.md#commit-message) See merge request: cann/pypto!5404 | 2 months ago |
| Files | Last commit | Last update |
|---|---|---|
| 3 months ago | ||
| 3 months ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 4 months ago | ||
| 2 months ago | ||
| 1 month ago | ||
| 2 months ago | ||
| 3 months ago | ||
| 4 months ago | ||
| 3 months ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 4 months ago | ||
| 1 month ago | ||
| 28 days ago | ||
| 3 months ago | ||
| 1 month ago | ||
| 27 days ago | ||
| 3 months ago | ||
| 3 months ago | ||
| 3 months ago | ||
| 2 months ago | ||
| 4 months ago | ||
| 2 months ago |