| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
fix(machine): Add metadata memory usage print Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !7289 merge duanhaotian into master fix(machine): Add metadata memory usage print Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: 新增元数据运行时使用率打印,每一轮devicetask下发时,打印每一类元数据的当前使用量,总评估量,地址分布 See merge request: cann/pypto!7289 | 24 天前 | |
refactor(all): Remove trailing whitespace Co-authored-by: tsungl4<lidongsheng4@huawei.com> # message auto-generated for no-merge-commit merge: !2188 merge pre-commit into master refactor(all): Remove trailing whitespace Created-by: tsungl4 Commit-by: tsungl4 Merged-by: cann-robot Description: Introduce pre-commit tools, and remove trailing white space with default plugin Related Issue: #1017 See merge request: cann/pypto!2188 | 7 个月前 | |
fix(machine): fix log quality issues in machine module. Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5679 merge pyptolog_fix into master fix(machine): fix log quality issues in machine module. Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: PyPTO machine 模块日志整改 See merge request: cann/pypto!5679 | 3 个月前 | |
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 个月前 | |
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 个月前 | |
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 天前 | |
perf(machine): Balance static wrap remainder against dynamic fetch Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> # message auto-generated for no-merge-commit merge: !7318 merge master into master perf(machine): Balance static wrap remainder against dynamic fetch Created-by: lululu40888 Commit-by: LordOfMysteries 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!7318 | 26 天前 | |
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 天前 | |
perf(machine): Prefilter stitch slot lists and isolate device-side checks Co-authored-by: gaoxingwang<camuel.gao@huawei.com> # message auto-generated for no-merge-commit merge: !5584 merge perf/prefilter-stitch-slot-lists into master perf(machine): Prefilter stitch slot lists and isolate device-side checks Created-by: gaoxingwang Commit-by: gaoxingwang Merged-by: cann-robot Description: perf(machine): Prefilter stitch slot lists and isolate device-side checks ## 优化概述 将 stitch slot 预过滤逻辑从编译期前置到 encode 阶段,消除 device 侧热路径的冗余遍历与分支判断。 ## 优化点 ### 1. Stitch Slot 预过滤 - 新增 SlotMaskEntry + stitchUpdateSlotMaskMap,在 RunEncodeStage 中一次性计算所有 slot 的 stitch mask - device 侧 UpdateSlotsImpl / FastStitchConsumer / FastStitchProducer 直接遍历预计算列表,不再逐 slot 判断 ### 2. 统一 Update 数据结构 - DevAscendProgramPartialUpdate → DevAscendProgramUpdate + isPartial 标志 - InitPartialUpdateSlot → InitUpdateSlot,合并 partial/fullcover 遍历为单次循环 - DumpPartialUpdate → DumpUpdate,输出 isPartial + stitchCtrlBitMask ### 3. Mask 计算提取与复用 - 新增静态函数 CalculateStitchCtrlBitMaskForSlot,从 InitSinglePartialUpdateSlot 中抽离 mask 计算 - InitSingleFullCoverSlot / InitSinglePartialUpdateSlot 共用 stitchUpdateSlotMaskMap,避免重复计算 ### 4. Device 侧 Slot 预过滤列表 - 新增 4 个 DevLocalVector slot 列表(stitchIncastSlotList / updateIncastSlotList / stitchOutCastSlotList / updateOutCastSlotList) - InitStitchUpdateSlotPrefilterLists 在 encode 阶段填充,RefilterStitchUpdateSlotLists 二次过滤 ### 5. CellMatch 隔离与防护 - CellMatchHandle 中 DEV_IF_NONDEVICE 隔离 dim-zero 检查 - PrepareRuntimeDynamicPartialUpdateTable 增加 null data 守卫 Related Issues: #5382 See merge request: cann/pypto!5584 | 3 个月前 | |
fix(machine): Align outcast ioIndex with per-entry runtime address table Co-authored-by: gaoxingwang<camuel.gao@huawei.com> # message auto-generated for no-merge-commit merge: !6502 merge fix-outcast-ioindex into master fix(machine): Align outcast ioIndex with per-entry runtime address table Created-by: gaoxingwang Commit-by: gaoxingwang Merged-by: cann-robot Description: fix(machine): Align outcast ioIndex with per-entry runtime address table Since pr !6322 keeps every assemble version of one slot as an outcast, several outcast entries share one RawTensor, so outcastRawList (deduped by raw) no longer lines up with the runtime outcast address table, which holds one entry per outcast. ioIndex taken from the deduped raw list therefore resolves later outcasts onto a wrong address entry: in cell_match_dep case 50 the second output's raw resolves to the shared buf outcast buffer and the host output is never written, while all graph/pass level data stays correct (silent precision failure). Changes: - Resolve outcast ioIndex through the owning outcast entry (first occurrence of the raw in devRoot's outcast list) in InitRawTensorAndMemoryRequirement and HandleActualRaw - Use the incast entry count (devRoot->GetIncast().size()) as the outcast offsetOrIndex base so the COA location encode matches the per-entry address table layout - Fix the sym dump double indexing in DumpIncast/DumpOutcast: offsetAttrIdx is already a global sym offset, read it via GetSymoffset directly Verified: cell_match_dep case 50 restores PASS with metrics identical to the pre-!6322 baseline; 39-case sample regression 79/79 PASS. Related Issues: #3384 See merge request: cann/pypto!6502 | 2 个月前 | |
feat(machine): Support static succ node parallel resolve for large fan-out Co-authored-by: gaoxingwang<camuel.gao@huawei.com> # message auto-generated for no-merge-commit merge: !6829 merge drco-static-succ-unify into master feat(machine): Support static succ node parallel resolve for large fan-out Created-by: gaoxingwang Commit-by: gaoxingwang Merged-by: cann-robot Description: feat(machine): Support static succ node parallel resolve for large fan-out Large fan-out DRCO ops resolve every successor edge from one ordered flat table: the decrement serializes and the scatter skews across cores. This PR chunks large fan-out ops into type-homogeneous 64B static succ nodes and resolves them in parallel across core-type-balanced bands. On top of the original #6737 content it unifies ALL DRCO successors into the succNode storage (flat table removed) and shrinks the stitch matrix slot back to u32. Supersedes #6737 (contains its full changes plus the three refactor commits). Changes (from #6737): - Encode-time HUB expansion: single-pred HUB successors move one hop into the predecessor entry set (edge move, depth 1, parity marking on HUB chains); the expanded HUB keeps a no-op entry so edge conservation holds (drcoSuccCnt == staticEdges asserted at encode time) - Chunking: ops whose DRCO entry count exceeds DRCO_STATIC_SUCC_THRESHOLD (16) with a unique pred and non-HUB_MIX core type are chunked into 64B DevAscendFunctionStaticSuccNode entries (coreType-homogeneous, capacity min(DRCO_SUCC_NODE_TASK_CAP=6, N/2), at least 2 nodes) in a devprog-resident flat array - Balanced parallel scatter: typed row domains per core type (AIC/AIV bands in the shared stitch matrix), per-type push cursors seeded to the domain-next core at node pop; HUB-type nodes ordered last and resolved locally on the producer via its hubStack; typed ready-matrix cursors refreshed from the scatter cursor so producer-side pushes land after the scattered bands Refactor on top: - Unify flat succ table into drcoStaticSuccNodeList_: non-chunked ops append capacity-15 mixed nodes resolved in place by the producer core (no scatter, no cursor seeding, behavior-neutral pairing within node bounds); SuccInfo low 32 bits unify to succNodeIndex/succNodeSize and bit63 narrows to the parallel-resolve flag DRCO_SUCC_PARALLEL_BIT; ResolveHubMixTask iterates nodes per entry with identical semantics - Fold the node region offset into funcInfoAndStaticDataOffset bits 59-30, dropping the standalone staticSuccNodeListOffset field and restoring the upstream two-field DrcoRootFuncData shape - Shrink stitch matrix slots to u32: 21-bit per-func node index + 10-bit producer funcId + 1-bit static flag; consumers restore nodes via funcId -> rootFuncData -> node region base + index; the u64-only atomic primitives are removed Validation (mla_prolog_v3_l0_id0002, C310, from #6737): - capture e2e_mean 239.4 -> 202.1us vs upstream base, eager 513.5/524.3 -> 475.7/476.8us; quant variant capture -19.5% - balance verified Rope 64/64 and qb/qNope 32/32 lanes Commit list: - feat(machine): Emit both flat and static succ node encodings for drco - refactor(drco): Unify flat succ table into static succ node storage - refactor(drco): Shrink stitch matrix slot back to u32 node index - refactor(drco): Rename succ node storage and parallel mode bit Related requirement: #3486 See merge request: cann/pypto!6829 | 1 个月前 | |
fix(machine): Split runtime headers and use secure bundle functions Co-authored-by: W4termy<wangmingyang21@huawei.com> # message auto-generated for no-merge-commit merge: !6428 merge fix/master_cleancode into master fix(machine): Split runtime headers and use secure bundle functions Created-by: W4termy Commit-by: W4termy Merged-by: cann-robot Description: cleancode 超大头文件、不安全函数修改 See merge request: cann/pypto!6428 | 2 个月前 | |
perf(machine): Encode DRCO coreType into taskId and prebuild encoded succStaticList at encode time Co-authored-by: gaoxingwang<camuel.gao@huawei.com> # message auto-generated for no-merge-commit merge: !6253 merge perf-6137-v2 into master perf(machine): Encode DRCO coreType into taskId and prebuild encoded succStaticList at encode time Created-by: gaoxingwang Commit-by: gaoxingwang Merged-by: cann-robot Description: The DRCO runtime resolved each successor task's coreType by dereferencing cceBinary GM memory (cceBinaryIndexList -> cceBinary[i].coreType) on every dependency resolution, which costs extra GM loads on the hot scheduling path. This change moves coreType resolution to encode time: the CoreType enum is encoded directly into the DRCO taskId bits, and succStaticList entries are prebuilt as coreType-encoded values, so the device decodes coreType from the taskId locally without touching cceBinary GM memory. Changes: - Encode CoreType enum into DRCO taskId at encode time and decode it via DrcoTaskCoreTypeOf - Prebuild the DRCO encoded succStaticList once at encode time - Resolve succ coreType from the encoded taskId in DrcoResolveDependOnce/ResolveHubMixTask - Assert DRCO-inconsumable succ coreType at encode time Related Issues: #3312 See merge request: cann/pypto!6253 | 2 个月前 | |
feat(Machine): Pointer Quant optimization Co-authored-by: Jie Yin<yinjie27@huawei.com> # message auto-generated for no-merge-commit merge: !6689 merge aicore-quant-pointer into master feat(Machine): Pointer Quant optimization Created-by: yinjie27_ Commit-by: Jie Yin Merged-by: cann-robot Description: feat(Machine): Pointer Quant optimization See merge request: cann/pypto!6689 | 2 个月前 | |
perf(machine): Prefilter stitch slot lists and isolate device-side checks Co-authored-by: gaoxingwang<camuel.gao@huawei.com> # message auto-generated for no-merge-commit merge: !5584 merge perf/prefilter-stitch-slot-lists into master perf(machine): Prefilter stitch slot lists and isolate device-side checks Created-by: gaoxingwang Commit-by: gaoxingwang Merged-by: cann-robot Description: perf(machine): Prefilter stitch slot lists and isolate device-side checks ## 优化概述 将 stitch slot 预过滤逻辑从编译期前置到 encode 阶段,消除 device 侧热路径的冗余遍历与分支判断。 ## 优化点 ### 1. Stitch Slot 预过滤 - 新增 SlotMaskEntry + stitchUpdateSlotMaskMap,在 RunEncodeStage 中一次性计算所有 slot 的 stitch mask - device 侧 UpdateSlotsImpl / FastStitchConsumer / FastStitchProducer 直接遍历预计算列表,不再逐 slot 判断 ### 2. 统一 Update 数据结构 - DevAscendProgramPartialUpdate → DevAscendProgramUpdate + isPartial 标志 - InitPartialUpdateSlot → InitUpdateSlot,合并 partial/fullcover 遍历为单次循环 - DumpPartialUpdate → DumpUpdate,输出 isPartial + stitchCtrlBitMask ### 3. Mask 计算提取与复用 - 新增静态函数 CalculateStitchCtrlBitMaskForSlot,从 InitSinglePartialUpdateSlot 中抽离 mask 计算 - InitSingleFullCoverSlot / InitSinglePartialUpdateSlot 共用 stitchUpdateSlotMaskMap,避免重复计算 ### 4. Device 侧 Slot 预过滤列表 - 新增 4 个 DevLocalVector slot 列表(stitchIncastSlotList / updateIncastSlotList / stitchOutCastSlotList / updateOutCastSlotList) - InitStitchUpdateSlotPrefilterLists 在 encode 阶段填充,RefilterStitchUpdateSlotLists 二次过滤 ### 5. CellMatch 隔离与防护 - CellMatchHandle 中 DEV_IF_NONDEVICE 隔离 dim-zero 检查 - PrepareRuntimeDynamicPartialUpdateTable 增加 null data 守卫 Related Issues: #5382 See merge request: cann/pypto!5584 | 3 个月前 | |
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 天前 | |
feat(Machine): Local Matrix for scheduling Co-authored-by: Jie Yin<yinjie27@huawei.com> # message auto-generated for no-merge-commit merge: !6222 merge aicore-resolve-in-one into master feat(Machine): Local Matrix for scheduling Created-by: yinjie27_ Commit-by: Jie Yin Merged-by: cann-robot Description: feat(Machine): Local Matrix for scheduling See merge request: cann/pypto!6222 | 2 个月前 | |
feat(docs): Add describe of stitch function num per pool Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !5830 merge duanhaotian_doc into master feat(docs): Add describe of stitch function num per pool Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: 内存精细化控制配置项文档介绍 See merge request: cann/pypto!5830 | 2 个月前 | |
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 天前 | |
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 个月前 | |
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 天前 | |
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 天前 | |
fix(machine): Improve ctrl cache replay performance Co-authored-by: qq_52905393<liuzhen180@huawei.com> # message auto-generated for no-merge-commit merge: !6316 merge dev-inoutreloc-performance into master fix(machine): Improve ctrl cache replay performance Created-by: qq_52905393 Commit-by: qq_52905393 Merged-by: cann-robot Description: 1、删除 funcdata backup 拷贝到 funcdata 的 memcpys,RelocIncastOutCast 流程中直接从 backup 读取信息 2、原 RelocIncastOutCast 流程为遍历所有 device task 和 dupFuncData,逐 input outpu 还原。新流程将 RelocIncastOutCast 放入 push task 之前,per-task reloc 并 push;并将在 host cache 之后记录并构建需要 Reloc 的信息,每个 Kind 记录下有哪些 input oout,在 reloc 时,不遍历所有 input out,而是按照 kind 类别做 reloc; See merge request: cann/pypto!6316 | 2 个月前 | |
fix(machine): Add metadata memory usage print Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !7289 merge duanhaotian into master fix(machine): Add metadata memory usage print Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: 新增元数据运行时使用率打印,每一轮devicetask下发时,打印每一类元数据的当前使用量,总评估量,地址分布 See merge request: cann/pypto!7289 | 24 天前 | |
feat(machine): Add new memory pool for dupped_stitch Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !6534 merge duanhaotian18 into master feat(machine): Add new memory pool for dupped_stitch Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: text Host 编码 CalcStitchWorkspace 共享 stitch 池,不再含 << 4 CalcDuppedStitchWorkspace 独立池 = 页大小 << 2 memBudget.metadata.duppedStitchPool / duppedStitchSlabSize | Launch FillDeviceRuntimeOffset 在 stitch 池之后铺 duppedStitchPoolOffset DevStartArgs 填 duppedStitchPoolAddr = runtime 基址 + offset | Device 初始化 InitMetadataAllocators InitAicpuDuppedStitchSlabAllocator 只注册 WsAicpuSlabMemType::DUPPED_STITCH | 运行中 AllocateStitch -> SlabAlloc(DUPPED_STITCH) -> duppedStitchSlab.Alloc Alloc 成功:allocatedObjCount++,unPopAllocatedObjCount++,挂上 stage 链表 | 切窗 活节点达到 80% SubmitToAicoreAndRecycleMemory SlabGetStageAllocMem -> PopStageAllocMem objCnt = 本窗 unPopAllocatedObjCount 记入 DynDeviceTask.taskStageAllocMem.duppedStitchStageMem | 回收 DeviceTaskMemTryRecycle FreeStageAllocMem:allocatedObjCount -= objCnt,节点回到 freeList 针对 slab metadata 共享内存池中的 type 间资源侵占问题,当前已有的问题中主要导致侵占的元数据是不可评估的DUPPED_STITCH,另外,当前因为DUPPED_STITCH不易评估因此预留了较大的内存池,针对这类不可评估的元数据问题考虑的方案是独立内存池并在即将使用完时直接submit | 算子 |pre ringbuffer | after ring buffer| 减少 | 降幅 | pre metadatasize | after metadatasize | metadata减少 | |---|---:|---:|---:|---:|---:|---:|---:| | glm_attention low_latency | 126,395,688 (120.54 MiB) | 76,168,744 (72.64 MiB) | 50,226,944 (47.90 MiB) | 39.7% | 31,598,904 | 19,042,168 | 12,556,736 | | glm_attention high_throughput | 138,460,904 (132.04 MiB) | 88,270,824 (84.18 MiB) | 50,190,080 (47.87 MiB) | 36.2% | 34,615,216 | 22,067,696 | 12,547,520 | | flash_attention_mha pre_training | 123,784,616 (118.05 MiB) | 73,551,528 (70.14 MiB) | 50,233,088 (47.91 MiB) | 40.6% | 30,946,136 | 18,387,864 | 12,558,272 | | interleave_rope low_latency | 103,559,208 (98.76 MiB) | 53,270,824 (50.80 MiB) | 50,288,384 (47.96 MiB) | 48.6% | 25,889,784 | 13,317,688 | 12,572,096 | See merge request: cann/pypto!6534 | 1 个月前 | |
feat(machine): Add new memory pool for dupped_stitch Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !6534 merge duanhaotian18 into master feat(machine): Add new memory pool for dupped_stitch Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: text Host 编码 CalcStitchWorkspace 共享 stitch 池,不再含 << 4 CalcDuppedStitchWorkspace 独立池 = 页大小 << 2 memBudget.metadata.duppedStitchPool / duppedStitchSlabSize | Launch FillDeviceRuntimeOffset 在 stitch 池之后铺 duppedStitchPoolOffset DevStartArgs 填 duppedStitchPoolAddr = runtime 基址 + offset | Device 初始化 InitMetadataAllocators InitAicpuDuppedStitchSlabAllocator 只注册 WsAicpuSlabMemType::DUPPED_STITCH | 运行中 AllocateStitch -> SlabAlloc(DUPPED_STITCH) -> duppedStitchSlab.Alloc Alloc 成功:allocatedObjCount++,unPopAllocatedObjCount++,挂上 stage 链表 | 切窗 活节点达到 80% SubmitToAicoreAndRecycleMemory SlabGetStageAllocMem -> PopStageAllocMem objCnt = 本窗 unPopAllocatedObjCount 记入 DynDeviceTask.taskStageAllocMem.duppedStitchStageMem | 回收 DeviceTaskMemTryRecycle FreeStageAllocMem:allocatedObjCount -= objCnt,节点回到 freeList 针对 slab metadata 共享内存池中的 type 间资源侵占问题,当前已有的问题中主要导致侵占的元数据是不可评估的DUPPED_STITCH,另外,当前因为DUPPED_STITCH不易评估因此预留了较大的内存池,针对这类不可评估的元数据问题考虑的方案是独立内存池并在即将使用完时直接submit | 算子 |pre ringbuffer | after ring buffer| 减少 | 降幅 | pre metadatasize | after metadatasize | metadata减少 | |---|---:|---:|---:|---:|---:|---:|---:| | glm_attention low_latency | 126,395,688 (120.54 MiB) | 76,168,744 (72.64 MiB) | 50,226,944 (47.90 MiB) | 39.7% | 31,598,904 | 19,042,168 | 12,556,736 | | glm_attention high_throughput | 138,460,904 (132.04 MiB) | 88,270,824 (84.18 MiB) | 50,190,080 (47.87 MiB) | 36.2% | 34,615,216 | 22,067,696 | 12,547,520 | | flash_attention_mha pre_training | 123,784,616 (118.05 MiB) | 73,551,528 (70.14 MiB) | 50,233,088 (47.91 MiB) | 40.6% | 30,946,136 | 18,387,864 | 12,558,272 | | interleave_rope low_latency | 103,559,208 (98.76 MiB) | 53,270,824 (50.80 MiB) | 50,288,384 (47.96 MiB) | 48.6% | 25,889,784 | 13,317,688 | 12,572,096 | See merge request: cann/pypto!6534 | 1 个月前 | |
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 天前 | |
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 个月前 | |
fix(machine) :Fix some issue of runtime worskpace Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !7433 merge duanhaotian1 into master fix(machine) :Fix some issue of runtime worskpace Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: 修复内存相关问题: 1.修复文档表述,当前构造每次JIT入参无变化不触发重编译的场景,配置不生效,默认使用首次配置。提示用户相关场景限制 2.auto_mix场景中实际执行无workspace申请时,提示用户无需精细化控制内存进行内存控制 3.在打开token后,tensor即是incast又是outcast的场景中,对于同一个rawtensor无需打上内存复用标签 4.get_runtime_option实验接口不返回所有runtime_option,只返回实际注册的 See merge request: cann/pypto!7433 | 19 天前 | |
fix(machine): Add metadata memory usage print Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !7289 merge duanhaotian into master fix(machine): Add metadata memory usage print Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: 新增元数据运行时使用率打印,每一轮devicetask下发时,打印每一类元数据的当前使用量,总评估量,地址分布 See merge request: cann/pypto!7289 | 24 天前 | |
feat(machine): Add new memory pool for dupped_stitch Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !6534 merge duanhaotian18 into master feat(machine): Add new memory pool for dupped_stitch Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: text Host 编码 CalcStitchWorkspace 共享 stitch 池,不再含 << 4 CalcDuppedStitchWorkspace 独立池 = 页大小 << 2 memBudget.metadata.duppedStitchPool / duppedStitchSlabSize | Launch FillDeviceRuntimeOffset 在 stitch 池之后铺 duppedStitchPoolOffset DevStartArgs 填 duppedStitchPoolAddr = runtime 基址 + offset | Device 初始化 InitMetadataAllocators InitAicpuDuppedStitchSlabAllocator 只注册 WsAicpuSlabMemType::DUPPED_STITCH | 运行中 AllocateStitch -> SlabAlloc(DUPPED_STITCH) -> duppedStitchSlab.Alloc Alloc 成功:allocatedObjCount++,unPopAllocatedObjCount++,挂上 stage 链表 | 切窗 活节点达到 80% SubmitToAicoreAndRecycleMemory SlabGetStageAllocMem -> PopStageAllocMem objCnt = 本窗 unPopAllocatedObjCount 记入 DynDeviceTask.taskStageAllocMem.duppedStitchStageMem | 回收 DeviceTaskMemTryRecycle FreeStageAllocMem:allocatedObjCount -= objCnt,节点回到 freeList 针对 slab metadata 共享内存池中的 type 间资源侵占问题,当前已有的问题中主要导致侵占的元数据是不可评估的DUPPED_STITCH,另外,当前因为DUPPED_STITCH不易评估因此预留了较大的内存池,针对这类不可评估的元数据问题考虑的方案是独立内存池并在即将使用完时直接submit | 算子 |pre ringbuffer | after ring buffer| 减少 | 降幅 | pre metadatasize | after metadatasize | metadata减少 | |---|---:|---:|---:|---:|---:|---:|---:| | glm_attention low_latency | 126,395,688 (120.54 MiB) | 76,168,744 (72.64 MiB) | 50,226,944 (47.90 MiB) | 39.7% | 31,598,904 | 19,042,168 | 12,556,736 | | glm_attention high_throughput | 138,460,904 (132.04 MiB) | 88,270,824 (84.18 MiB) | 50,190,080 (47.87 MiB) | 36.2% | 34,615,216 | 22,067,696 | 12,547,520 | | flash_attention_mha pre_training | 123,784,616 (118.05 MiB) | 73,551,528 (70.14 MiB) | 50,233,088 (47.91 MiB) | 40.6% | 30,946,136 | 18,387,864 | 12,558,272 | | interleave_rope low_latency | 103,559,208 (98.76 MiB) | 53,270,824 (50.80 MiB) | 50,288,384 (47.96 MiB) | 48.6% | 25,889,784 | 13,317,688 | 12,572,096 | See merge request: cann/pypto!6534 | 1 个月前 | |
feat(machine): Optimize perf Co-authored-by: dty_30041779<daitianyi1@h-partners.com> # message auto-generated for no-merge-commit merge: !5431 merge oom into master feat(machine): Optimize perf Created-by: LordOfMysteries Commit-by: dty_30041779 Merged-by: cann-robot Description: https://gitcode.com/cann/pypto/issues/2597 # AICPU Ctrl / Sche 代码优化摘要 面向动态图 EXEC_DYN 热路径的微优化(不改变语义;DEV_INFO 日志级别保持原样)。 ## 主要改动 1. **Fill I/O / ItemPool** - 新增 ItemPool::AllocateBump / MakeRuntimeOutcastTensorBump:在 RunInit 后首次填充 root I/O 时跳过 freelist 分支与逐元素 ItemAt 检查。 2. **Stitch 挂边** - DevAscendFunctionDuppedStitchList::PushBack 由 std::function 改为模板 AllocFn,避免类型擦除与间接调用。 - Partial-update 表基址由 &table[0] 改为 Data(),空表安全且去掉无意义的下标检查。 3. **Workspace / Dupped 尺寸** - DevFunctionDuppedSlabMemObjSize 对同一 DevAscendProgram 缓存最大 Dupped 尺寸,避免每轮 launch 重复全表扫描。 4. **Ctrl / Sche 其它热路径** - Slot / Stitch / Task / AICore 管理路径的小幅去冗余、指针/数据预取与分支收敛(见对应 device_*_context 与 aicore_manager 改动)。 See merge request: cann/pypto!5431 | 3 个月前 | |
feat(ir): Support dump function attribute Co-authored-by: tsungl4<lidongsheng4@huawei.com> # message auto-generated for no-merge-commit merge: !6675 merge attr into master feat(ir): Support dump function attribute Created-by: tsungl4 Commit-by: tsungl4 Merged-by: cann-robot Description: Related Issue: #2559 See merge request: cann/pypto!6675 | 2 个月前 | |
fix(machine): Fix dynamic partial-update cell match lifecycle Co-authored-by: Songyangyang18<songyangyang18@huawei.com> # message auto-generated for no-merge-commit merge: !2723 merge lp4 into master fix(machine): Fix dynamic partial-update cell match lifecycle Created-by: songyangyang18 Commit-by: Songyangyang18 Merged-by: cann-robot Description: # 一、需求背景 相关issue: https://gitcode.com/cann/pypto/issues/489,//有规避方法,未解决根本问题 https://gitcode.com/cann/pypto/issues/748,//方案说明 https://gitcode.com/cann/pypto/issues/608,//疑似相同问题,本地稳定可以复现 例如在以下用例中,z 的高维大小由 x 的 shape 确定。当 x 是动态 shape 时,z 的大小是动态的。导致 LOOP_1 和 LOOP_2 在 stitch 到一起时,LOOP_1 中对 z 的 assemble 操作无法正确建立指向 LOOP_2 中对 z view 的z_view 等 tensor 的依赖,进而导致在缺少这些依赖时,存在精度问题。 def matmul_kernel(x, y, bias, out): pypto.set_debug_options(runtime_debug_mode=1) bsz, h = x.shape d = y.shape[1] z = pypto.Tensor([bsz, d], dtype=pypto.DT_FP32) b = 128 b_loop = (bsz + b - 1) // b for b_idx in pypto.loop(b_loop, name="LOOP_1", idx_name="b_idx"): b_valid = (bsz-b_idx*b).min(b) x_view = pypto.view(x, [b, h], [b_idx*b, 0], valid_shape=[b_valid, h]) ## Matmul pypto.set_cube_tile_shapes([128, 128], [128, 128], [128, 128]) c = pypto.matmul(x_view, y, pypto.DT_FP32) pypto.assemble(c, [b_idx*b, 0], z) c = 128 c_loop = (bsz + c - 1) // c for c_idx in pypto.loop(c_loop, name="LOOP_2", idx_name="c_idx"): c_valid = (bsz-c_idx*c).min(c) z_view = pypto.view(z, [c, d], [c_idx*c, 0], valid_shape=[c_valid, d]) bias_view = pypto.view(bias, [c, d], [c_idx*c, 0], valid_shape=[c_valid, d]) pypto.set_vec_tile_shapes(128, 128) pypto.assemble(z_view + bias_view, [c_idx*c, 0], out) 由于当前采用 cell match 来动态计算依赖关系,但是 cell match 在匹配时,需要事先分配相应大小的 cell match table,并且由 prod 更新 cell match table,由 con 读取 cell match table 中的值来建立依赖关系。 # 原因分析 根本原因是目前对于局部动态tensor的处理存在不足。 1. cell match 的问题 目前对于patial update slot,局部tensor需要cell match table,这是用于构建dev_task内依赖关系的重要机制。  目前的cell match table需要在编译期确定完整的大小,以准备完整的DevAscendProgram数据,但是动态局部tensor在编译期只能得到符号表达式,而非实际的大小,所以目前的 cell match table 缺乏处理动态大小tensor的能力,目前的做法是忽视动态大小的-1轴,当作正常数值计算,导致计算得到的cell table大小恒为1,这在动态轴大小为更大的数值(如128)时明显计算错误,这个错误会带到运行时,从而导致依赖建立的丢失或错误。  # 方案设计 考虑单独构建局部动态tensor的cell match分配器,用于运行时分配cell match table,尽量将所有需要的数值在launch阶段得到,运行时直接取,减少计算; ## 编译期(Encode) 1. 支持动态 cell-match 延后决策:编译期允许部分 cell-match 描述先不完整(动态维度场景),不再强行一次性定死。 2. 新增动态元数据输出:产物里补充 dynamic cell-match 的预算上限、slot 数量、以及 launch 期补丁所需 meta(offset/cell shape/候选维度表达式)。 3. workspace 预算模型扩展:把 dynamic cell-match 内存纳入 memBudget.metadata,总预算从“两段式”扩为“三段式”(general + dynamicCellMatch + stitchPool)。 ## Launch 阶段 1. 启动前按真实输入 patch 描述符:基于本次输入 shape 计算 stride,并写回 cfgdata(host 或 H2D)。 2. 动态预算随 kArgs 下发并回填设备侧:新增 dynamic assemble / dynamic cell-match 两类预算字段,设备初始化时回填并重算 runtime offset。 3. 地址布局升级:runtime offset 新增 dynamicCellMatchOffset,形成独立内存区,避免与 general/stitchPool 混用。 ## 运行时(Workspace/Slot 生命周期) 1. partial-update slot 标记更准确:按真实 slotIndex + 描述状态 标记,不再依赖旧的隐式假设。 2. 动态 cell-match 表按需分配/初始化:在 slot 更新和 assemble 分配路径中补齐“分配-初始化-绑定”闭环。 3. 回收路径补全:boundary outcast 释放时联动释放 dynamic cell-match 分配,避免残留和泄漏。 ## Cost Model 模块 1. 与真实 launch 对齐:cost model 启动时同步接收 dynamic 预算参数。 2. 同样执行动态 patch 逻辑:仿真前也按输入求值并 patch cell-match desc,避免“仿真和实跑不一致”。 3. 测试链路同步:ST runner 加入同类 budget refill + desc patch,保证测试口径一致。 See merge request: cann/pypto!2723 | 6 个月前 | |
refactor(all): Remove trailing whitespace Co-authored-by: tsungl4<lidongsheng4@huawei.com> # message auto-generated for no-merge-commit merge: !2188 merge pre-commit into master refactor(all): Remove trailing whitespace Created-by: tsungl4 Commit-by: tsungl4 Merged-by: cann-robot Description: Introduce pre-commit tools, and remove trailing white space with default plugin Related Issue: #1017 See merge request: cann/pypto!2188 | 7 个月前 | |
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 个月前 | |
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 个月前 | |
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 个月前 | |
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 个月前 | |
fix(machine): Fix inner temporal memory check Co-authored-by: songyangyang18<songyangyang18@huawei.com> # message auto-generated for no-merge-commit merge: !6875 merge bound into master fix(machine): Fix inner temporal memory check Created-by: songyangyang18 Commit-by: songyangyang18 Merged-by: cann-robot Description: 修复检验逻辑没有适配Inner Temporal内存最大值修改的问题。 See merge request: cann/pypto!6875 | 1 个月前 | |
feat(machine): Add option to control memory reuse of workspace Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !5427 merge duanhaotian13 into master feat(machine): Add option to control memory reuse of workspace Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: ## 改造后:精细 Workspace 总体流程 改造后保留 max_workspace_kb 粗调模式,同时新增 actual_stitch_function_num=[d0,d1,d2] 精细模式。两个模式共用需求收集、memBudget、序列化、Host 申请和 Device allocator,只在容量决策方式上分流。 mermaid flowchart TD Config["配置<br/>max_workspace_kb<br/>actual_stitch_function_num=[d0,d1,d2]"]:::added Load["LoadRuntimeWorkspaceConfig<br/>长度/范围校验并映射三个 depth"]:::added Collect["复用原有需求收集<br/>WorkspaceDesc"]:::legacy Mode{"数组是否为 [0,0,0]"}:::decision Coarse["保留原有 max_workspace_kb / 统一 k_eff 路径"]:::legacy Validate{"每个非空池是否至少支持一个 RootFunction"}:::decision Precise["独立计算三个池容量<br/>CalculatePreciseWorkspaceLayout"]:::added Apply["ResolveStitchDepthConfig<br/>ApplyStitchDepthConfig"]:::added Budget["memBudget.tensor 最终容量<br/>+ workspaceControl 单位需求与深度"]:::added Encode["DevProg 两遍编码并序列化"]:::legacy Dynamic["动态 Shape 求值更新 MaxOutcastMem<br/>深度和池 Slot 数不重算"]:::added HostAlloc["Host 按 memBudget.Total() 申请 Workspace"]:::legacy Init["DeviceWorkspaceAllocator::InitTensorAllocators"]:::legacy Pools["注册原有四池<br/>容量来自精细预算结果"]:::legacy Preflight{"当前 Root 追加前精确预检"}:::decision Alloc["真实申请并绑定地址"]:::legacy Observe["采集三个精细池 current/peak"]:::added Submit["内存不足或原有边界触发 Submit"]:::added Tuning["窗口日志、Launch 汇总和推荐 depth"]:::added Recycle["回收当前窗口并重置窗口峰值"]:::added Config -.-> Load Collect --> Mode Load -.三个 depth.-> Mode Mode -->|是| Coarse Mode -->|否| Validate Validate -->|通过| Precise Validate -->|失败| Error["编码期报错"]:::decision Coarse --> Apply Precise -.-> Apply Collect --> Apply Apply -.-> Budget Budget --> Encode --> Dynamic --> HostAlloc --> Init --> Pools --> Preflight Preflight -->|通过| Alloc --> Observe --> Preflight Preflight -->|失败且窗口非空| Submit Preflight -->|失败且窗口为空| RuntimeError["单个 Root 无法容纳,运行时报错"]:::decision Alloc -->|控制流/硬阈值| Submit Submit --> Tuning --> Recycle --> Preflight classDef legacy fill:#f5f5f5,stroke:#666,stroke-width:1px,color:#222 classDef added fill:#e6f4ff,stroke:#1677ff,stroke-width:3px,color:#102a43 classDef decision fill:#fff7e6,stroke:#d46b08,stroke-width:2px,color:#5c2b00 ### 总体前后差异 | 维度 | 改造前 | 改造后 | |---|---|---| | 外部控制 | max_workspace_kb 总量粗调 | 保留粗调;新增三池 depth 数组 | | 模式启用 | 根据总预算和 Stitch 上限求统一深度 | [0,0,0] 走粗调;任一非零走精细模式 | | 三池容量 | 同一个 k_eff 同步放大 | 三个 depth 独立计算 | | max_workspace_kb | 作为粗调总量依据 | 精细模式下不再截断用户指定的三池容量 | | Boundary Outcast | 拓扑固定 | 仍拓扑固定,不对外精细控制 | | Runtime allocator | 原有四池 | 复用原有四池,无新池 | | 运行时观测 | 无三池闭环推荐 | Window/Launch 峰值、推荐 depth、depth 内存影响 | | 热路径成本 | 无新增采样 | 由 ENABLE_PROFILE_GUIDED 编译期开关隔离 | | 追加前预检 | 聚合 Slot 粗估,失败原因不明确 | 按 Exclusive、InnerTemporal 和 RuntimeItem 分项预检 | | 内存不足处理 | 已有失败后 Submit/重试框架 | 保留框架,增加原因、空窗口保护和更准确预测 | --- See merge request: cann/pypto!5427 | 2 个月前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 24 天前 | ||
| 7 个月前 | ||
| 3 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 19 天前 | ||
| 26 天前 | ||
| 19 天前 | ||
| 3 个月前 | ||
| 2 个月前 | ||
| 1 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 3 个月前 | ||
| 19 天前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 19 天前 | ||
| 1 个月前 | ||
| 28 天前 | ||
| 19 天前 | ||
| 2 个月前 | ||
| 24 天前 | ||
| 1 个月前 | ||
| 1 个月前 | ||
| 19 天前 | ||
| 4 个月前 | ||
| 19 天前 | ||
| 24 天前 | ||
| 1 个月前 | ||
| 3 个月前 | ||
| 2 个月前 | ||
| 6 个月前 | ||
| 7 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 1 个月前 | ||
| 2 个月前 |