| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
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 天前 | |
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 security risks Co-authored-by: W4termy<wangmingyang21@huawei.com> # message auto-generated for no-merge-commit merge: !2467 merge os into master fix(machine): Fix security risks Created-by: W4termy Commit-by: W4termy 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 规范](https://gitcode.com/cann/pypto/blob/master/docs/contribute/pull-request.md#commit-message) See merge request: cann/pypto!2467 | 7 个月前 | |
feat(dfx): Runtime memory overlap check Co-authored-by: duanhaotian<duanhaotian@huawei.com> # message auto-generated for no-merge-commit merge: !5107 merge duanhaotian7 into master feat(dfx): Runtime memory overlap check Created-by: duanhaotian Commit-by: duanhaotian Merged-by: cann-robot Description: dump运行时各个op的读写信息以及每个op的读写范围大小并dump运行时整体内存使用情况统计,基于相关dump数据和topo序,设计内存重叠检测脚本,检测是否存在 内存重叠 See merge request: cann/pypto!5107 | 3 个月前 | |
fix(machine): Compile out host DEV_VERBOSE_ when ENABLE_COMPILE_VERBOSE_LOG=0 Co-authored-by: Snow__Land<songyangyang18@huawei.com> # message auto-generated for no-merge-commit merge: !7244 merge verbose into master fix(machine): Compile out host DEV_VERBOSE_ when ENABLE_COMPILE_VERBOSE_LOG=0 Created-by: songyangyang18 Commit-by: Snow__Land Merged-by: cann-robot Description: ## 背景 host 侧 DEV_VERBOSE_DEBUG / DEV_VERBOSE_DEBUG_SPLIT / DEV_VERBOSE_INFO 原先直接展开为 PYPTO_SIM_LOG,即使未开 DEBUG,热路径仍会执行 setAttr/checkLevel。device 侧已用 DEV_IF_VERBOSE_LOG(ENABLE_COMPILE_VERBOSE_LOG=0 时编译剔除)。 Engram 录 CF 时 cell-match 会命中上述宏数万次,导致 host FAST_STITCH 虚高(约 3.5 ms → 修复后约 1.0 ms)。 ## 改动 host 与 device 对齐:上述三个宏包上 DEV_IF_VERBOSE_LOG。 不影响 stitch/CF 语义。若需输出 verbose/trace:设 ENABLE_COMPILE_VERBOSE_LOG=1 重编,并开 DEBUG 级别(与 device 一致)。 ## 结果  See merge request: cann/pypto!7244 | 29 天前 | |
feat(machine): Cache AOT control-flow binaries in multi-slot LRU pool Co-authored-by: LordOfMysteries<duhongxiang@huawei.com> # message auto-generated for no-merge-commit merge: !5007 merge perf/aot-cf-code-pool into master feat(machine): Cache AOT control-flow binaries in multi-slot LRU pool Created-by: LordOfMysteries Commit-by: LordOfMysteries Merged-by: cann-robot Description: https://gitcode.com/cann/pypto/issues/2597 feat(machine): Cache AOT control-flow binaries in multi-slot LRU pool Replace single-slot AOT CF binary caching with a multi-slot LRU pool, plus coding micro-optimizations that share encode_program surfaces (RuntimeVerify moved out of header, workspace/start-args tidy). Commits: - feat(machine): Cache AOT control-flow binaries in multi-slot LRU pool - refactor(machine): Apply coding and style micro-optimizations Changes: - AOT_CODE_POOL multi-slot LRU - Encode hashKey assert for empty-slot sentinel - ST test_aot_code_pool - RuntimeVerify / workspace micro cleanups Related Issues: N/A See merge request: cann/pypto!5007 | 4 个月前 | |
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 个月前 | |
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): prevent offline exception dump segfault on bundle launch Co-authored-by: W4termy<wangmingyang21@huawei.com> # message auto-generated for no-merge-commit merge: !5936 merge fix/exception-dump-offline into master fix(machine): prevent offline exception dump segfault on bundle launch Created-by: W4termy Commit-by: W4termy Merged-by: cann-robot Description: 修复单算子复现出现段错误的问题 当前bundle启动时会将kername写到opname中,在进行异常复现时先读取opname中的名称,避免由于bundle不走前端而导致的lastfunc为空指针的情况 See merge request: cann/pypto!5936 | 2 个月前 | |
fix(machine): Improve ctrl cache replay performance Co-authored-by: qq_52905393<liuzhen180@huawei.com> # message auto-generated for no-merge-commit merge: !6302 merge dev-restore-pingpong into master fix(machine): Improve ctrl cache replay performance Created-by: qq_52905393 Commit-by: qq_52905393 Merged-by: cann-robot Description: 1、将 PredCount 以及 readyque 改为 A B 两份,通过pingpong 结构,当前轮次 ctrl push task 之后,对 B 做 restore ,利用 ctrl 结尾空闲时间掩盖 restore 开销 See merge request: cann/pypto!6302 | 2 个月前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 19 天前 | ||
| 7 个月前 | ||
| 7 个月前 | ||
| 3 个月前 | ||
| 29 天前 | ||
| 4 个月前 | ||
| 7 个月前 | ||
| 7 个月前 | ||
| 2 个月前 | ||
| 2 个月前 |