| Files | Last commit | Last update |
|---|---|---|
feat(operation): Optimizing Fz Scene Data Loading Issues Co-authored-by: yangfulai<yangfulai3@huawei.com> # message auto-generated for no-merge-commit merge: !6367 merge fz2 into master feat(operation): Optimizing Fz Scene Data Loading Issues Created-by: yangfulai Commit-by: yangfulai Merged-by: cann-robot Description: feat(operation): Optimizing Fz Scene Data Loading Issues NCHW->Fractal_Z shape大多是[N, C, 1, 1]、[N, C, 3, 3]、[N, C, 5, 5]、[N, C, 7, 7],如果按照常规shape load,耗时比较久,因此我们会将后三根轴合并在load,C轴切分大小是C0倍数,按照2维输入时,尾轴已经32B对齐,tload效率较高。 约束: 最后几根轴的情况有:[1,W], [H,W], [D,H,W], D、H、W取值为[1,3,5,7....],而且这些轴不存在无效值,因此这些轴可以直接合并到C轴,为了避免不必要的精度问题,这些轴均不切分,即tileshape:[tileshapeN, tileshapeC * tileshapeH * tileshapeC] 在pad时,逻辑与之前一样:tileshape切分时只pad shape,不更新validshape,validshape的更新放到tileop中 See merge request: cann/pypto!6367 | 29 days ago | |
feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Co-authored-by: Zehai<wangzehai3@huawei.com> Co-authored-by: hongyiliu111<liuhongyi1@huawei.com> Co-authored-by: yuxin5<yuxin5@huawei.com> Co-authored-by: xutianlong1<xutianlong1@huawei.com> Co-authored-by: zhouxuan78<zhouxuan78@huawei.com> # message auto-generated for no-merge-commit merge: !6752 merge dev into master feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Created-by: yuxin5 Commit-by: Zehai;yuxin5;zhouxuan78;xutianlong1;royccc;hongyiliu111 Merged-by: cann-robot Description: feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Add pypto.conv_backward_filter interface to compute the gradient of convolution with respect to the weight tensor, and implement its 2D support spanning the frontend interface, backend operation implementation and MTE codegen Changes: - Add pypto.conv_backward_filter frontend interface with parameter validation - Implement ConvBackwardFilter 2D backend operation and codegen - Add UT/ST test cases for the 2D implementation See merge request: cann/pypto!6752 | 1 month ago | |
refactor(interface): Remove UpdateTensorDataUsage() Co-authored-by: tsungl4<lidongsheng4@huawei.com> # message auto-generated for no-merge-commit merge: !5451 merge test_data/1 into master refactor(interface): Remove UpdateTensorDataUsage() Created-by: tsungl4 Commit-by: tsungl4 Merged-by: cann-robot Description: Remove per function importDict Related Issue: #2559 See merge request: cann/pypto!5451 | 3 months ago | |
fix(operation): Cap column-chunk count in 2D-merged dynamic transpose and fall back to whole-block transpose for large-column shapes Co-authored-by: Crayon_112<taojianlong1@huawei.com> # message auto-generated for no-merge-commit merge: !7226 merge hotfix/transpose into master fix(operation): Cap column-chunk count in 2D-merged dynamic transpose and fall back to whole-block transpose for large-column shapes Created-by: Crayon_112 Commit-by: Crayon_112 Merged-by: cann-robot Description: Description Problem CumProd LO dim3 case [128, 3, 24576] fp32 with dim=2 (last-axis cum) deterministically hangs: the jit compile never finishes, the kernel is never submitted, and the case times out (~30+ min of no progress). The same symptom is reproduced by a bare pypto.transpose(view, 1, 2) on the same geometry, so the hang is entirely inside the transpose lowering - the CumProd op itself is not involved. Root cause For last-axis cum, CumOperation internally transposes the input (Transpose(input, {n-2, n-1}), cumulative.cpp) and transposes the result back. In dynamice functions this transpose resolves to the 2D merged plan, and since a8da387f1 (!7396, the UB-overflow fix) TransposeMerged2DDynamic materializes the merged output via a column-chunking loop (per-chunk View + Reshape + InnerTranspose + Assemble). For this geometry the chunking degenerates: with pre=128, cols=24576, rows=3, fp32, the per-column materialized size is small (colMatBytes ≈ 4KB) but tmp2DBytes (~36MB) far exceeds the per-op UB budget, so the budget collapses to the UbBytes()/4 floor and yields colChunk=16 - expanding the loop into 1536 View/Reshape/InnerTranspose/Assemble tuples. The resulting multi-thousand-op graph does not converge in the compiler/scheduler. The same failure mode affects Quantize_LO_fp32_16_896_16384 colwise (~16384 chunks), whose colChunk degenerates to 1. Attribution was done by git bisect with a minimal repro: a8da387f1 hangs, its parent 5c28ece9a passes - the regression came in with !7396's chunked path. Fix Introduce a chunk-count cap (MERGE 2D MAX CHUNKS = 64). When ceil(cols / colChunk) exceeds the cap, the merge falls back to the pre-!7396 whole-block path: a single InnerTranspose op whose wide tile the scheduler splits by vecTile - the shipped behavior before chunking existed, verified working for these shapes. Chunking geometries with a moderate chunk count (e.g. the [8,3, 1280] colwise family, 4 chunks) are unaffected and keep the UB-safe chunked path.r Validation - Minimal repros (cumprod-derived and transpose-only, [128,3,24576] fp32 geometry): no return after 7+ min before the fix → complete in 101s / 46s after the fix. Full redline regression (CumProd / Quantize / Transpose suites, 8 NPUs): running; numbers to be appended. Bisect builds installed into isolated targets (pip --target), shared site-packages reinstalled from the fixed wheel. See merge request: cann/pypto!7226 | 20 days ago | |
fix(ir): Dump attr support map Co-authored-by: zhaojunhan<zhaojunhan1@huawei.com> # message auto-generated for no-merge-commit merge: !4577 merge fix_ir_dump into master fix(ir): Dump attr support map Created-by: zhaojunhan Commit-by: zhaojunhan Merged-by: cann-robot Description: Dump operation attributes with support for map-type data. See merge request: cann/pypto!4577 | 4 months ago | |
feat(Conv): conv support L0C2Ub mix Co-authored-by: xinweiliu<xinweiliu@huawei.com> Co-authored-by: xinweiliu<liuxinwei12@huawei.com> # message auto-generated for no-merge-commit merge: !6583 merge Conv_L0C_2_UB_Mix_support into master feat(Conv): conv support L0C2Ub mix Created-by: xinweiliu Commit-by: xinweiliu Merged-by: cann-robot Description: Conv新增L0C2Ub通路mix能力 See merge request: cann/pypto!6583 | 1 month ago | |
refactor(ir): Split io_text attr dump/load and separate static/dynamic offsets Co-authored-by: Immutable01<gaoqiancheng@huawei.com> # message auto-generated for no-merge-commit merge: !6932 merge 1014_attr into master refactor(ir): Split io_text attr dump/load and separate static/dynamic offsets Created-by: Immutable01 Commit-by: Immutable01 Merged-by: cann-robot Description: refactor(ir): Split io_text attr dump/load and separate static/dynamic offsets Move the io_text attribute dump/load logic out of io_text_dumper.cpp and io_text_loader.cpp into dedicated attr files sharing a private parser base, and make assemble/view offsets round-trip unambiguous by separating their static and dynamic parts. Changes: - Split attr dump/load logic into io_text_dumper_attr.cpp and io_text_loader_attr.cpp with private header io_text_parser.h - Dump offsets as static #toOffset/#fromOffset (vector<int64_t>) and dynamic #toDynOffset/#fromDynOffset (vector<SymbolicScalar>); all-immediate dyn lists are filtered to avoid duplicate output - Apply tensor op attrs symmetrically on load via ApplyTensorOpAttrs (VIEW/SLICE -> ViewOpAttribute, ASSEMBLE/CONTRACT -> AssembleOpAttribute); legacy text carrying dynamic values under #toOffset/#fromOffset is still accepted - Remove unused OpAttribute::CollectAttrs and refresh golden .pypto snapshots for the new dump format Related Issues: #3555 See merge request: cann/pypto!6932 | 1 month ago | |
fix(conv): Fix Conv3d SymbolicScalar pad bug Co-authored-by: luyakun_hw<luyakun@h-partners.com> # message auto-generated for no-merge-commit merge: !7221 merge fix_dyn_pad into master fix(conv): Fix Conv3d SymbolicScalar pad bug Created-by: luyakun_hw Commit-by: luyakun_hw Merged-by: cann-robot Description: 修复Conv3d表达式pad精度失败的问题 https://gitcode.com/cann/pypto/issues/3690 See merge request: cann/pypto!7221 | 1 month ago | |
feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Co-authored-by: Zehai<wangzehai3@huawei.com> Co-authored-by: hongyiliu111<liuhongyi1@huawei.com> Co-authored-by: yuxin5<yuxin5@huawei.com> Co-authored-by: xutianlong1<xutianlong1@huawei.com> Co-authored-by: zhouxuan78<zhouxuan78@huawei.com> # message auto-generated for no-merge-commit merge: !6752 merge dev into master feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Created-by: yuxin5 Commit-by: Zehai;yuxin5;zhouxuan78;xutianlong1;royccc;hongyiliu111 Merged-by: cann-robot Description: feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Add pypto.conv_backward_filter interface to compute the gradient of convolution with respect to the weight tensor, and implement its 2D support spanning the frontend interface, backend operation implementation and MTE codegen Changes: - Add pypto.conv_backward_filter frontend interface with parameter validation - Implement ConvBackwardFilter 2D backend operation and codegen - Add UT/ST test cases for the 2D implementation See merge request: cann/pypto!6752 | 1 month ago | |
feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Co-authored-by: Zehai<wangzehai3@huawei.com> Co-authored-by: hongyiliu111<liuhongyi1@huawei.com> Co-authored-by: yuxin5<yuxin5@huawei.com> Co-authored-by: xutianlong1<xutianlong1@huawei.com> Co-authored-by: zhouxuan78<zhouxuan78@huawei.com> # message auto-generated for no-merge-commit merge: !6752 merge dev into master feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Created-by: yuxin5 Commit-by: Zehai;yuxin5;zhouxuan78;xutianlong1;royccc;hongyiliu111 Merged-by: cann-robot Description: feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Add pypto.conv_backward_filter interface to compute the gradient of convolution with respect to the weight tensor, and implement its 2D support spanning the frontend interface, backend operation implementation and MTE codegen Changes: - Add pypto.conv_backward_filter frontend interface with parameter validation - Implement ConvBackwardFilter 2D backend operation and codegen - Add UT/ST test cases for the 2D implementation See merge request: cann/pypto!6752 | 1 month ago | |
perf(ir): Skip token inference for parallel batch matmul assembles Co-authored-by: zhaojunhan<zhaojunhan1@huawei.com> # message auto-generated for no-merge-commit merge: !7346 merge skip_parallel_assemble_tokens into master perf(ir): Skip token inference for parallel batch matmul assembles Created-by: zhaojunhan Commit-by: zhaojunhan Merged-by: cann-robot Description: ### 问题与改动 大 batch matmul 在 C++ 构图时展开大量 Assemble。对这些互不重叠的写回推导串行 token,会增加后续 RemoveRedundantTokenPass 的删边及后继扫描开销。 - 将 cube_operation_impl.cpp 的全部 7 处 Assemble 标记为 parallel:普通 3D/4D、GM 累加 3D/4D、MX 3D/4D,以及 TransposedBatchMatmul。 - 各 batch 写回区域互不重叠;TransposedBatchMatmul 按不同列区间写回,GM 路径在写回前完成 K 累加。 - InferTokenPass 对 parallel Assemble 直接返回,跳过其输入读、输出写 token 推导,不更新读写状态。 - 新增最小 4D batch matmul 前端 IR 快照,检查两次 Assemble 的 parallel(true) 和空 token 列表。 ### 验证与范围 - 跳过范围包括全部读写 token,不仅是 Assemble 之间的写依赖。尚未验证设备执行正确性及大规模用例编译提速;新增快照覆盖 4D 普通路径,其他路径尚无新增专项测试。 ### CI 快照修复(0e19e0ee6) 更新 test_reshape 的 12 处内部三维 batch matmul Assemble 为 parallel(true),其他 IR 不变。扫描确认 test_c2v2 也使用三维 matmul,但没有快照。37 个快照测试文件共 123 项:122 通过,test_branch_config 因全局 atomic scope 编号顺序差异失败;该项单独复跑通过,与 test_reshape、token 测试合计 18 项通过。 See merge request: cann/pypto!7346 | 25 days ago | |
fix(Operation): modify cleancode Co-authored-by: chenbl<chenbinglin7@huawei.com> # message auto-generated for no-merge-commit merge: !5748 merge fix/docs into master fix(Operation): modify cleancode Created-by: chenbl Commit-by: chenbl Merged-by: cann-robot Description: cleancode修改: - 拆分过长的 Operation 和 TileOp 文件 - 重构过长函数并提取重复代码 - 使用公共常量替换 Magic Number - 修复报错日志的拼写和语法问题 - 补充报错日志中的实际参数值 - 删除自定义调试打印 - 清理无用变量和重复实现 - 迁移并补充 Vector Operation 单元测试 See merge request: cann/pypto!5748 | 2 months ago | |
style(all): Apply additional clang-format corrections across codebase Co-authored-by: junjieHuang<huangjunjie38@h-partners.com> # message auto-generated for no-merge-commit merge: !4883 merge style-cpp into master style(all): Apply additional clang-format corrections across codebase Created-by: junjieHuang Commit-by: junjieHuang Merged-by: cann-robot Description: Apply additional clang-format corrections across codebase See merge request: cann/pypto!4883 | 4 months ago | |
fix(operation): Intersect valid shapes for arithmetic binary operations Co-authored-by: bynshard<zhangbingshuai@huawei.com> # message auto-generated for no-merge-commit merge: !7362 merge codex/arithmetic-validshape-min into master fix(operation): Intersect valid shapes for arithmetic binary operations Created-by: bynshard Commit-by: bynshard Merged-by: cann-robot Description: 部分场景中的会出现 将一个 [128, 64] 的累加器与仅包含 [53, 64] 个有效元素的乘积相加。 从左操作数重新推断输出可以将有效范围扩展到 128 行,并可能覆盖 75 个保护行。 所以需要在推导shape 的时候,取一次min See merge request: cann/pypto!7362 | 24 days ago | |
fix(pass): Avoid null pointer errors. Co-authored-by: wangqun23<wangqun23@huawei.com> # message auto-generated for no-merge-commit merge: !7445 merge master into master fix(pass): Avoid null pointer errors. Created-by: wangqun23 Commit-by: wangqun23 Merged-by: cann-robot Description: ## 背景 由于框架的修改,在Token开启的情况下,存在与Assemble输出同RawMagic的Incast不与其他op相连接的情况,目前仅限于Incast存在类似情况,即Incast游离在其他连接关系之外。导致ReplaceTensor里的map的value存储空指针,后续使用空指针导致段错误。 ## 方案 针对map可能访问不存在的key做补充和校验。 对可能的空指针使用新增校验。 Related Issue: [#3806](https://gitcode.com/cann/pypto/issues/3806) See merge request: cann/pypto!7445 | 19 days ago | |
feat(operation): Add quant hif4 Co-authored-by: 杨志邈<yangzhimiao@huawei.com> # message auto-generated for no-merge-commit merge: !7229 merge master into master feat(operation): Add quant hif4 Created-by: yangzhimiao Commit-by: 杨志邈 Merged-by: cann-robot Description: 新增算子Quant Hif4。用于A6设备上BF16到Hif4的量化。支持Scale_alg为0/1,尾轴量化。 Related Issue: [#3684](https://gitcode.com/cann/pypto/issues/3684) See merge request: cann/pypto!7229 | 30 days ago | |
feat(operation): Add quant hif4 Co-authored-by: 杨志邈<yangzhimiao@huawei.com> # message auto-generated for no-merge-commit merge: !7229 merge master into master feat(operation): Add quant hif4 Created-by: yangzhimiao Commit-by: 杨志邈 Merged-by: cann-robot Description: 新增算子Quant Hif4。用于A6设备上BF16到Hif4的量化。支持Scale_alg为0/1,尾轴量化。 Related Issue: [#3684](https://gitcode.com/cann/pypto/issues/3684) See merge request: cann/pypto!7229 | 30 days ago | |
feat(operation): Add quant hif4 Co-authored-by: 杨志邈<yangzhimiao@huawei.com> # message auto-generated for no-merge-commit merge: !7229 merge master into master feat(operation): Add quant hif4 Created-by: yangzhimiao Commit-by: 杨志邈 Merged-by: cann-robot Description: 新增算子Quant Hif4。用于A6设备上BF16到Hif4的量化。支持Scale_alg为0/1,尾轴量化。 Related Issue: [#3684](https://gitcode.com/cann/pypto/issues/3684) See merge request: cann/pypto!7229 | 30 days ago | |
feat(operation): Add quant hif4 Co-authored-by: 杨志邈<yangzhimiao@huawei.com> # message auto-generated for no-merge-commit merge: !7229 merge master into master feat(operation): Add quant hif4 Created-by: yangzhimiao Commit-by: 杨志邈 Merged-by: cann-robot Description: 新增算子Quant Hif4。用于A6设备上BF16到Hif4的量化。支持Scale_alg为0/1,尾轴量化。 Related Issue: [#3684](https://gitcode.com/cann/pypto/issues/3684) See merge request: cann/pypto!7229 | 30 days ago | |
fix(operation): Add empty tensor validation for vector operations Co-authored-by: xiefangming<xiefangming@huawei.com> # message auto-generated for no-merge-commit merge: !7109 merge check into master fix(operation): Add empty tensor validation for vector operations Created-by: xiefangming Commit-by: xiefangming Merged-by: cann-robot Description: 增加空tensor校验 [#3645](https://gitcode.com/cann/pypto/issues/3645) See merge request: cann/pypto!7109 | 30 days ago | |
fix(operation): Add empty tensor validation for vector operations Co-authored-by: xiefangming<xiefangming@huawei.com> # message auto-generated for no-merge-commit merge: !7109 merge check into master fix(operation): Add empty tensor validation for vector operations Created-by: xiefangming Commit-by: xiefangming Merged-by: cann-robot Description: 增加空tensor校验 [#3645](https://gitcode.com/cann/pypto/issues/3645) See merge request: cann/pypto!7109 | 30 days ago | |
fix(token): Preserve tensor read token ownership across branches Co-authored-by: zhaojunhan<zhaojunhan1@huawei.com> # message auto-generated for no-merge-commit merge: !7198 merge fix_if_else_read into master fix(token): Preserve tensor read token ownership across branches Created-by: zhaojunhan Commit-by: zhaojunhan Merged-by: cann-robot Description: ## 问题场景 在 loop 前创建 tensor A,if/else 分支内先读取 A,再通过 assemble 覆盖 A。例如: - then:计算 A + B,随后 assemble 写 A。 - else:计算 A + B,随后 assemble 写 A。 不同分支共享同一个 LogicalTensor,但原实现仅用一个 readToken_ 保存读取 token。推断后一个分支时会覆盖前一个分支的记录,导致 ExpandFunction 无法将前一个分支的 READ 正确匹配到 A 的 SLICE。 这可能使后续写入缺少对实际读取的等待,造成读写乱序和精度异常。原复现中,部分行出现固定偏差;float16 下受调度顺序影响可能偶现。 ## 修复方案 将 LogicalTensor 上单个 READ/WRITE token 改为按身份去重的列表,保留不同访问对应的 token。 保持 InferToken 原有的连续读复用规则: - 连续读取 A 共用同一个 READ,重复登记后列表仍只有一项。 - 不同分支产生不同 READ 时,同时保存,避免相互覆盖。 展开时通过“输入 tensor 的 READ 列表与当前 op 的 result token 的交集”确定归属。对于 A+B 等多输入操作,可准确匹配 A 和 B 各自的读取,无需根据输入数量猜测。 ## 核心修改 1. **保存和匹配访问归属** InferToken 追加登记 token;ExpandFunction 使用列表成员关系匹配 READ,将对应的 NORMAL 挂到实际读取输入的 SLICE 上。 2. **维护克隆后的归属** LogicalTensor Clone 复制访问列表;操作及 token 重映射时,将新 token 登记到对应的新输入、输出 tensor,避免只保留旧 token 指针。 3. **处理 AutoCast** 按当前 op 与输入 tensor 的 token 交集,将 READ 完成信号迁移到实际读取原始输入的 CAST,并同步更新依赖缓存。 4. **保留展开后的依赖** InheritTokenContract 仅追加原操作已有的 NORMAL token,并按身份去重,避免覆盖展开阶段已建立的 SLICE/CONTRACT 依赖。 5. **精确删除及接口清理** 删除无用 token 时仅移除对应元素,保留同一 tensor 上的其他访问记录;移除无生产调用的单 READ getter 和旧 setter 接口。 WRITE 虽改为列表保存,但 if/loop 合并仍沿用逻辑版本最后一次 WRITE 的语义;NextVersion 不继承旧版本的访问列表。 ## 验证情况 - 已验证旧实现会在共享输入的 READ 被覆盖后,无法将前一读取的 token 挂到输入 SLICE。 - 回归测试覆盖连续读复用、双分支 A+B、三种 dtype、AutoCast、尾块、克隆重映射及精确删除。 - 简化前版本通过 128 项 host 测试;正常 NPU 包运行原始 pass_token_issue_7.py ## 范围说明 本次不覆盖同一 op 的两个不同别名输入共享 READ、且需要分别迁移到 CAST 的场景;未新增访问列表的文本 IR 序列化支持。 See merge request: cann/pypto!7198 | 30 days ago | |
feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Co-authored-by: Zehai<wangzehai3@huawei.com> Co-authored-by: hongyiliu111<liuhongyi1@huawei.com> Co-authored-by: yuxin5<yuxin5@huawei.com> Co-authored-by: xutianlong1<xutianlong1@huawei.com> Co-authored-by: zhouxuan78<zhouxuan78@huawei.com> # message auto-generated for no-merge-commit merge: !6752 merge dev into master feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Created-by: yuxin5 Commit-by: Zehai;yuxin5;zhouxuan78;xutianlong1;royccc;hongyiliu111 Merged-by: cann-robot Description: feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Add pypto.conv_backward_filter interface to compute the gradient of convolution with respect to the weight tensor, and implement its 2D support spanning the frontend interface, backend operation implementation and MTE codegen Changes: - Add pypto.conv_backward_filter frontend interface with parameter validation - Implement ConvBackwardFilter 2D backend operation and codegen - Add UT/ST test cases for the 2D implementation See merge request: cann/pypto!6752 | 1 month ago | |
fix(operation): Transpose 尾轴不对齐时临时空间分配错误并重构增加可读性 Co-authored-by: Crayon_112<taojianlong1@huawei.com> # message auto-generated for no-merge-commit merge: !7127 merge hotfix/transpose into master fix(operation): Transpose 尾轴不对齐时临时空间分配错误并重构增加可读性 Created-by: Crayon_112 Commit-by: Crayon_112 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!7127 | 1 month ago | |
feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Co-authored-by: Zehai<wangzehai3@huawei.com> Co-authored-by: hongyiliu111<liuhongyi1@huawei.com> Co-authored-by: yuxin5<yuxin5@huawei.com> Co-authored-by: xutianlong1<xutianlong1@huawei.com> Co-authored-by: zhouxuan78<zhouxuan78@huawei.com> # message auto-generated for no-merge-commit merge: !6752 merge dev into master feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Created-by: yuxin5 Commit-by: Zehai;yuxin5;zhouxuan78;xutianlong1;royccc;hongyiliu111 Merged-by: cann-robot Description: feat(Operation): Add pypto.conv_backward_filter and its 2D implementation on A2/A3 Add pypto.conv_backward_filter interface to compute the gradient of convolution with respect to the weight tensor, and implement its 2D support spanning the frontend interface, backend operation implementation and MTE codegen Changes: - Add pypto.conv_backward_filter frontend interface with parameter validation - Implement ConvBackwardFilter 2D backend operation and codegen - Add UT/ST test cases for the 2D implementation See merge request: cann/pypto!6752 | 1 month ago | |
feat(kirin9050): Support matmul macro instruction with pre-stage quant/dequant Co-authored-by: m0_71310678<lizhexun2@huawei.com> # message auto-generated for no-merge-commit merge: !7126 merge kirin9050-matmul-mergepr into master feat(kirin9050): Support matmul macro instruction with pre-stage quant/dequant Created-by: m0_71310678 Commit-by: m0_71310678 Merged-by: cann-robot Description: feat(kirin9050): Support matmul macro instruction with pre-stage quant/dequant Support Kirin9050 matmul macro instruction bring-up: - macro matmul codegen/tileop (attrs, quant, inplace, infer), decoupled from generic path - route quant_pre through macro matmul; GEMV routing and fp16/int8 K-slice clamps - L1->GM TSTORE direct store, l12ub/ub2l1 support - rework matmul quant UT ids, shapes and tile-split coverage (Q16.16 semantics) Changes: - Add Kirin9050 (NCH) LiteNPU platform support and matmul macro instruction codegen/tileop - Add l12ub/ub2l1 data path and per-channel quant_pre routing through macro matmul - Add Kirin9030/Kirin9050/KirinX90 codegen UT coverage for matmul, attention and other single operations See merge request: cann/pypto!7126 | 1 month ago | |
feat(Operation): Add input tile shape resolver. Co-authored-by: Immutable01<gaoqiancheng@huawei.com> # message auto-generated for no-merge-commit merge: !5126 merge 0727_viewtile into master feat(Operation): Add input tile shape resolver. Created-by: Immutable01 Commit-by: Immutable01 Merged-by: cann-robot Description: # TileShapeResolver:算子输入/输出 Tile 形状解析器 ## 1. 背景与目标 PyPTO 的 tensor-graph 算子在展开( ExpandFunction)前只携带一个 **op 级 TileShape**(描述"输出怎么切")。但算子的**每个输入/输出 tensor 实际被切成的第一刀 tile 形状**并不等于 op 级 TileShape: - 广播算子的输入要按自身 shape 做 min clamp; - reduce 算子的 reduce 轴保持 full、非 reduce 轴按 vecTile 切; - gather/scatter/sort/topk/matmul/transdata 等各有专属切法; - 输出侧 cube 算子按 CubeTile 切、transdata 输出维度与输入不同…… 下游(内存估算、调度、合轴等)需要在不真正展开的前提下,**直接从一个 Operation 推断其每个输入/输出的真实 tile 形状**。TileShapeResolver 就是提供这个能力的单例工具类。 ## 2. 整体设计 framework/src/interface/operation/tile_shape_resolver.h cpp class TileShapeResolver { public: static TileShapeResolver& Instance(); // 由 op 的 opcode + op 级 TileShape + 各 operand 自身 shape,推算第 index 个输入的真实 tile 形状 TileShape GetInputTileShape(const Operation& op, int index) const; // 由 op 的 opcode + op 级 TileShape + 各 operand 自身 shape,推算第 index 个输出的真实 tile 形状 TileShape GetOutputTileShape(const Operation& op, int index) const; private: TileShapeResolver() = default; TileShapeResolver(const TileShapeResolver&) = delete; TileShapeResolver& operator=(const TileShapeResolver&) = delete; }; - **单例 + 无状态**:所有信息从 Operation 现取,线程安全。 - **只覆盖 tensor op**:只对有 REGISTER_OPERATION_TILED_FUNC(即有 tile 展开的 tensor op)的 opcode 给出语义;tile op 不在本解析器职责内。 - **返回 TileShape**:当前只填 VecTile(cube 算子填 CubeTile),其余 sub-tile 保持默认。 ## 3. 实现侧:GetInputTileShape framework/src/interface/operation/tile_shape_resolver.cpp ### 3.1 公共辅助 | 辅助 | 作用 | |---|---| | ElementwiseInputVecTile(inShape, opVecTile) | 逐轴 min(inShape, vecTile),超出 vecTile 维数的轴保持 full。elementwise 默认。 | | VecTileAxisFull(inShape, clampShape, opVecTile, fullAxis) | 指定轴保持 full,其余轴 min(clampShape, vecTile)。用于 reduce/gather/scatter 的"轴 full"语义。 | | TransDataInputVecTile(inShape, opVecTile, group, groupAxis) | groupAxis 按 inShape/group 切,其余 elementwise。用于 TransData 系列。 | | MakeTileShapeFromVec(vec) | 把 vector<int64_t> 包成 TileShape(只设 VecTile)。 | ### 3.2 分支策略 按 opcode switch,**默认分支**为 ElementwiseInputVecTile(覆盖所有 elementwise 算子:Add/Div/Cast/Expand/Axpy/Where/OneHot/PReLU…)。特殊分支: | 类别 | opcode | 输入 tile 规则 | |---|---|---| | **轴 full 类** | OP_ROW*_SINGLE(Sum/Amax/Amin/Prod/ArgMax/ArgMin) | reduce 轴 full,其余 min。axis 取 OP_ATTR_PREFIX+"AXIS"(缺失回退 0)。 | | | OP_ROWEXPMAX / OP_ROWEXPSUM | 2-D 专用,axis=1 full,axis0 min。 | | | OP_BITSORT / OP_MRGSORT | sort 轴(OP_ATTR_PREFIX+"axis")full,其余 min。 | | | OP_ARGSORT | sort 轴 full;axis 取**裸键 "axis"**(与 ArgSortOperationTileFunc 实际读取一致,非注册声明的带前缀键)。 | | | OP_EXTRACT | 末轴 full,其余 min。 | | | OP_SORT_UB | sort 轴 full。 | | | OP_INDEX_ADD / OP_INDEX_ADD_UB | self(index 0)轴 full;src(index 1)elementwise;indices full。 | | **gather/scatter 类** | OP_GATHER | params:axis full,其余按输出轴映射 min;indices:按 axis+j 映射 min。 | | | OP_GATHER_ELEMENT | params 轴 full;indices elementwise。 | | | OP_SCATTER / OP_SCATTER_ELEMENT | self 与 idx 都按 idx.shape 在 axis full、其余 min。 | | | OP_INDEX_OUTCAST | [src, index, dst]:src/dst 轴 full、非轴 min;index(2-D)axis full,**字面 axis 0 仅当 axis!=0 时按 vecTile[0] 切**,其余非轴 full(对齐 TiledScatterUpdate)。axis 取**裸键 "axis"**。 | | | OP_INDEX_PUT | self 前导轴 full、尾部按 values 轴 min;values elementwise;其余输入按 {min(in[0], vecTile[0])}。 | | **topk** | OP_TOPK | 非轴 elementwise;axis 按 32 对齐 chunk(复刻 TopkOperationTileFunc 的 align 逻辑:maxNumValue=8192、kBlockSize=32 阈值)。 | | **where** | OP_WHERE_TT/TS/ST/SS | cond(index 0)若为 DT_UINT8 末轴按 vecTile/8 切(mask 位宽);其余 elementwise。 | | **transdata** | OP_NCHW2NC1HWC0 等 6 个 | TransDataInputVecTile,groupAxis 按输入 layout 定(NCHW 系列为 1,NCDHW 系列为 2)。 | | **pack** | OP_PACK | 输出 1-D,输入 tile = {min(in[0], ∏vecTile)}。 | | **prelu** | OP_PRELU | input elementwise;weight 取 {min(weight[0], vecTile[1])}(channel 轴)。 | | **cube matmul** | OP_A_MUL_B / A_MUL_BT / A_MULACC_B / A_MULACC_BT | A={m[0],k[0]}(transA 反转),B={k[0],n[0]}(transB 反转);MX/bias/scale 等附加输入按 Matrix::CopyInMode::DN2NZ 等属性决定 scale 的 NZ 排布与 ceil(k/64)。属性键统一用 Matrix:: 限定。 | | 其它 | OP_RANGE / OP_UNIFORM / OP_VEC_DUP / OP_CUBE_CONV_D2S / OP_CUBE_CONCAT_C | 无 tensor 输入或非 vec 切,直接返回 op 级 TileShape。 | > **属性键一致性**:解析器严格对齐各 TileFunc 实际读取的键。OP_INDEX_OUTCAST/OP_ARGSORT 用裸 "axis"(与 TileFunc 一致),OP_BITSORT/OP_MRGSORT/OP_GATHER/... 用 OP_ATTR_PREFIX+"axis",reduce 单算子用 OP_ATTR_PREFIX+"AXIS"。 ## 4. 实现侧:GetOutputTileShape 与输入侧对称,按 opcode switch,**默认分支**为 ElementwiseInputVecTile(outShape, opVecTile)(逐轴 min(outShape, vecTile))。默认分支正确的前提:① op 级 VecTile 维数 == 输出维数;② 输出按 VecTile 逐轴 elementwise 切("必须 full 的轴"在合法展开下 vecTile[fullAxis] >= shape[fullAxis],min 自然得 full,故 scatter/sort/indexadd/inplace 等无需专门分支)。 需要专门分支的输出: | opcode | 输出 tile 规则 | |---|---| | OP_A_MUL_B / A_MUL_BT / A_MULACC_B / A_MULACC_BT | 输出 C 按 CubeTile 的 L0 {m[0], n[0]} 切,clamp 到真实 {M, N}(参考 SetVecTileBasedOnUbSize)。 | | TransData 6 个 | 输出是变换后 layout(C0/N0/group),输出维数 ≠ 输入维数,op 级 VecTile 维数跟输入走,逐轴 min 对不上。Handle*Format 把**整张 dstTensor** 作为 tile op 的 oOperand(非切片 View),即每个 tile op 写整份输出,故 first-cut 输出 tile = **完整 outShape**。 | | OP_PACK | 输出 1-D 字节流:outShape[0] = inShape[0]*byte。PackOperationTileFunc 产 outputShape{ min(inShape[0], tile)*byte }(tile = ∏vecTile),故 first-cut 输出 tile = {min(outShape[0], tile*byte)},byte = BytesOf(input[0])。 | | OP_PERMUTE / OP_PERMUTE_ELEMENT | 输出轴 i ← 输入轴 perm[i],op 级 VecTile 跟输入轴序,故输出 tile = **VecTile 按 perm 重排**后逐轴 clamp 到 outShape(TiledPermuteOperation:resultTileShape = PermuteTileVector(inputTile.shape, perm))。 | | OP_TRANSPOSE_MOVEOUT / MOVEIN / VNCHWCONV | 二轴转置:输出 tile = op 级 VecTile 的 shape[0]/shape[1] 两轴**互换**后 clamp 到 outShape(TiledInnerTranspose:resultTileShape = inputTile.shape 交换 shape[0]/shape[1])。 | | OP_UNPACK | 输出 1-D:outShape[0] = inShape[0]/dstByte。UnPackOperationTileFunc 产 outputShape{ min(inShape[0], vecTile[0]) / dstByte },dstByte = BytesOf(output)。 | | OP_DEINTERLEAVE_SINGLE | 末轴减半:outShape[last] = inShape[last]/2,末轴 tile = min(outShape[last], vecTile[last]/2),其余 min(两输出同形)。 | | OP_EXTRACT | 末轴不切(full),其余 min(TiledExtract 跳过末轴)——与输入侧一致。 | | OP_BITSORT / OP_MRGSORT | sort 轴(OP_ATTR_PREFIX+"axis")不切(full),其余 min(TiledBitSort/TiledMrgSort 跳过 sort 轴)——与输入侧一致。 | | OP_GATHER_MASK_BUILDIN | 末轴按 patternMode 缩:mode 1/2 → vecTile/2,mode 3-6 → vecTile/4,其余 vecTile;其它轴 min。 | | OP_CUBE_CONV_D2S / OP_CUBE_CONCAT_C | OpCalcType::CONV 且无注册 TileFunc,不被 ExpandFunction 展开,tiling 由 ConvTile 驱动——**不在本解析器职责内**,返回 op 级 TileShape 作安全占位(tensor-graph 路径不会调到)。 | **走默认分支的代表性类目**(已逐一核对 TileFunc 源码): - **elementwise**:Add/Div/Cast/Expand/Axpy/Where/OneHot/PReLU … - **reduction**:tensor-graph reduce 算子恒把 reduce 轴置为 dim 1(ProcessResultShape 把 keepDim=false 的 squeeze 放到**独立的 OP_RESHAPE** 里做,而 OP_RESHAPE 不是 tensor op),故 min(1, vecTile[axis]) = 1,默认分支正确——**keepDim=false 不是缺口**。 - **gather/scatter/topk**:op 级 VecTile 维数已与输出维数对齐,默认 min 即可。 - **cumsum/cumprod/interleave/pad/fillpad/quantize/dequantize/expand_exp_dif**:输出按 min(outShape, vecTile) 逐轴切,默认即可。 - **生成型 1-D 算子 OP_RANGE / OP_UNIFORM / OP_VEC_DUP**:TiledRange/TiledUniformBuildIn/TiledFull 各自按 vecTile[0] 切 1-D 输出,正是 min(outShape[0], vecTile[0])——**归入默认分支**(原先误放到"返回 op 级"分支,已修正)。 ## 5. 测试方案 framework/tests/ut/interface/src/operation/test_tile_shape_resolver.cpp **核心思想**:用 DSL 在 FUNCTION{} 里建**单算子** tensor graph,让算子吃 TileShape::Current();展开前用 resolver 算"期望"的 per-input/per-output tile,展开后扫 tile op 找首个消费/产出对应 RawTensor 的 View 取"实际"first-cut tile,逐 operand 比对。 **harness 关键点**: 1. **输出 Tensor 提到 FUNCTION{} 外持有**——其底层 LogicalTensor 因此存活,可被 harness 捕获身份。 2. **oOperand 补挂**:本 harness 语境下 tensor-graph 算子的 oOperand 在展开前还是空的(输出要等展开流水线里才挂上)。harness 在 op->GetOOperands() 为空时把 fixture 提供的输出 LogicalTensor 挂上去——这正是 ExpandFunction/TileFunc 实际消费的输出;inplace 算子(oOperand 已非空 {self})则不动。 3. **展开失败显式断言**:ASSERT_NE(expandFunction.RunOnFunction(*fn), Status::FAILED),避免展开失败被后续扫描误判为 tile 形状不匹配。 4. **RawTensor 身份匹配**:LogicalTensor::View 共享底层 RawTensor,故输入/输出身份用 GetRawTensor().get() 唯一标识。 **覆盖 26 个 representative fixture**:elementwise(Div/Where/OneHot/Cast/Expand/Axpy)、permute(Permute_AxisSwap,**判别性** fixture:默认分支会产 {2,4,8},正确分支产 {4,2,8})、gather/scatter(Gather/Scatter/GatherElements/ScatterElement)、index(IndexAdd/IndexAddUb)、reduce 单算子(Sum/Amax/Amin/Prod/ArgMax/ArgMin 6 个)、rowexp(RowExpMax/RowExpSum,手动构建)、sort(MrgSort/BitSort/Extract)、topk(TopK 双输出)、prelu。多输出用 std::tie,inplace 用 self 作输出,手动构建用外部 Tensor out。 See merge request: cann/pypto!5126 | 4 months ago | |
fix(machine): fix log level mismatch, magic number and grammar errors Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5720 merge pyptolog_fix2 into master fix(machine): fix log level mismatch, magic number and grammar errors Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: 日志规范性整改 See merge request: cann/pypto!5720 | 3 months ago |
| Files | Last commit | Last update |
|---|---|---|
| 29 days ago | ||
| 1 month ago | ||
| 3 months ago | ||
| 20 days ago | ||
| 4 months ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 25 days ago | ||
| 2 months ago | ||
| 4 months ago | ||
| 24 days ago | ||
| 19 days ago | ||
| 30 days ago | ||
| 30 days ago | ||
| 30 days ago | ||
| 30 days ago | ||
| 30 days ago | ||
| 30 days ago | ||
| 30 days ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 1 month ago | ||
| 4 months ago | ||
| 3 months ago |