| Files | Last commit | Last update |
|---|---|---|
fix(operation): Conv fix bug when tileCinFmap not equal tileCinWeight Co-authored-by: luyakun<luyakun@h-partners.com> # message auto-generated for no-merge-commit merge: !5688 merge cin_not_equal into master fix(operation): Conv fix bug when tileCinFmap not equal tileCinWeight Created-by: luyakun_hw Commit-by: luyakun Merged-by: cann-robot Description: 修复当tileCinFmap不等于tileCinWeight时,Conv3D用例精度失败的问题 https://gitcode.com/cann/pypto/issues/3099 See merge request: cann/pypto!5688 | 3 months 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): clean up implementation and magic numbers | 2 months 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 | |
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(ir): Fix missing replace of scalar vars Co-authored-by: tsungl4<lidongsheng4@huawei.com> # message auto-generated for no-merge-commit merge: !5308 merge shape into master fix(ir): Fix missing replace of scalar vars Created-by: tsungl4 Commit-by: tsungl4 Merged-by: cann-robot Description: Related Issue: #2559 See merge request: cann/pypto!5308 | 3 months ago | |
fix(operation): Conv fix bug when tileCinFmap not equal tileCinWeight Co-authored-by: luyakun<luyakun@h-partners.com> # message auto-generated for no-merge-commit merge: !5688 merge cin_not_equal into master fix(operation): Conv fix bug when tileCinFmap not equal tileCinWeight Created-by: luyakun_hw Commit-by: luyakun Merged-by: cann-robot Description: 修复当tileCinFmap不等于tileCinWeight时,Conv3D用例精度失败的问题 https://gitcode.com/cann/pypto/issues/3099 See merge request: cann/pypto!5688 | 3 months ago | |
fix(machine): fix mismatch and incomplete error descriptions in machine and misc files Co-authored-by: chai-hw<chaizhengtong@huawei.com> # message auto-generated for no-merge-commit merge: !5806 merge pyptolog_fix3 into master fix(machine): fix mismatch and incomplete error descriptions in machine and misc files Created-by: chai-hw Commit-by: chai-hw Merged-by: cann-robot Description: machine 日志内容整改 See merge request: cann/pypto!5806 | 2 months ago | |
fix(operation): Change scaleA/B to per-batch when using scaleMM+BatchMatmul. Co-authored-by: y00957431<yangrui231@huawei.com> # message auto-generated for no-merge-commit merge: !5571 merge scaleBMM into master fix(operation): Change scaleA/B to per-batch when using scaleMM+BatchMatmul. Created-by: yr12318 Commit-by: y00957431 Merged-by: cann-robot Description: 此前 scaled_mm 与 BatchMatmul 组合时,scaleA/scaleB 采用共享 batch的方案: 无论矩阵的 batch 维度如何,scale 始终固定为 3-D,并在所有 batch 间广播同一组 scale。 这不符合按 batch 缩放的语义,当各 batch 携带不同 scale 时会导致结果错误。 本 PR 将 scaleA/scaleB 改为按 batch 语义:每个 scale 的维度需比其配对矩阵多一维, 且 scale 的 batch 维度必须与配对矩阵的 batch 维度一致。 Changes: - Python(matmul.py):要求 scale_dim == input_dim + 1;校验 scale 的 batch 维 等于配对矩阵的 batch 维;scale 元素索引由固定 [0/1/2] 改为 [-3/-2/-1] 以支持 2-D/3-D/4-D 矩阵;收紧 __validate_scale_k1_dimensions(AND 改为 OR,要求所有 k1 维均等于 2);更新 docstring,补充 2-D/3-D/4-D scale 形状示例 - C++(cube_operation_impl.cpp):CheckMXMatmulShape 增加 inputDim∈[2,4]、 scaleDim==inputDim+1 及逐轴 batch 配对校验;通过 scaleDimOffset 泛化 scale 偏移 索引;新增 GetBatchScaleTensor3D/GetBatchScaleTensor4D(按 batch 做 View+Reshape 切片,含 ASSERT 空指针保护,与 GetBatchTensor3D/4D 模式一致),并接入 ConstructBatchMatmulMXTensorGraph3D/4D - 测试:新增 UT test_scaled_mm_batch_scale.py(3-D 拒绝 / 4-D 接受 / 4-D 拒绝); 更新 C++ UT test_operation_impl.cpp、ST test_scaled_bmm.py 与 scaled_bmm_test_case.py See merge request: cann/pypto!5571 | 3 months 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): clean up implementation and magic numbers | 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 | |
feat(indexing): Support A5 SIMT gather and index put Co-authored-by: bynshard<zhangbingshuai@huawei.com> # message auto-generated for no-merge-commit merge: !5404 merge feat/a5-simt-mixed into master feat(indexing): Support A5 SIMT gather and index put Created-by: bynshard Commit-by: bynshard Merged-by: cann-robot Description: gather indexput 支持的simt 实现,在离散场景下提升性能 当 Gather 的 source 位于 GM、indices 位于 UB 时,A5 Codegen 会选择 SIMT MGATHER 实现: 1. 使用 SIMD 批量计算 Gather 的元素偏移。 2. 使用 SIMT MGATHER 根据偏移直接从 GM source 读取数据。 3. source 位于 UB 时继续使用原有实现。 4. int64 indices 暂不使用 SIMT,回退到原有 Scalar 实现。 同时补充了 SIMT Kernel 的端到端识别与下发机制: 1. Pass 识别需要 SIMT 的 Gather,并设置 requiresSimt 属性。 2. 将 requiresSimt 信息传递到 Device Program 和编译流程。 3. 为包含 SIMT 的 A5 Kernel 生成相应的 ELF metadata。 4. Runtime 根据 Kernel 是否包含 SIMT,选择对应的 UB 配置。 5. SIMT Kernel 配置 216 KB 动态 UB,并为 DCache 预留 32 KB。 6. 纯 SIMD Kernel 保持原有 Runtime 下发方式和 UB 配置。 此外,完善了 GM GatherElement 在内存类型推导、动态参数注册、动态 valid shape 处理和 OoO 调度中的支持。 Related Issue: #3162 ``` 更多描述信息见:[Commit Message 规范](../docs/zh/contribute/pull-request.md#commit-message) See merge request: cann/pypto!5404 | 2 months ago | |
feat(operation): Add FZ Reverse Conversion Co-authored-by: yang-fulai-3<yangfulai3@huawei.com> # message auto-generated for no-merge-commit merge: !5464 merge fz into master feat(operation): Add FZ Reverse Conversion Created-by: yangfulai Commit-by: yang-fulai-3 Merged-by: cann-robot Description: feat(operation): Add FZ Reverse Conversion See merge request: cann/pypto!5464 | 3 months ago | |
feat(pass): Add VFFusionClusterIdentify pass Co-authored-by: Catherie<mayuan33@huawei.com> # message auto-generated for no-merge-commit merge: !5669 merge feat/vf-fusion-cluster-identify-v2 into master feat(pass): Add VFFusionClusterIdentify pass Created-by: Catherie Commit-by: Catherie Merged-by: cann-robot Description: feat(pass): Add VFFusionClusterIdentify pass ## 背景与动机 A5(DAV_3510)硬件支持 Vector Fusion(VF)—— CCE 后端可将相邻的 PIPE_V 指令融合为单条融合指令。此前框架存在两个尝试为 VF 创造融合窗口的 pass: - TuneTileOpSeqForVF(OoO 之后):基于 HasDataDependency 检查相邻 PIPE_V op 可合并性,mergedOps 为局部变量不持久化 - TuneSyncForVF(InsertSync 之后):独立重新识别融合分组,基于时序模型决定是否移除 sync 并合并 **核心问题**:两个 pass 各自局部识别、不持久化 cluster 信息,无法保证编译器认为对 VF 融合友好的 pattern 一定被保留到最终调度。 本 PR 引入 **VFFusionCluster** 机制:在子图切分合图后一次性识别可融合的 PIPE_V op 组,通过 Operation::atomicScopeId_(原 oooScopeId_ 重命名)持久化 cluster 信息,约束 OoO 调度、InsertSync、MixSubgraphSplit、LoopaxesProc 等下游 pass 不破坏 cluster 原子性。新 pass VFFusionClusterIdentify 成为唯一识别源,TuneTileOpSeqForVF 和 TuneSyncForVF 后续将被废弃。 **适用范围**:架构仅 DAV_3510(A5),开关 KEY_ENABLE_VF。 ## 方案设计 ### Pass 管线位置 SubgraphToFunction ★ NEW: VFFusionClusterIdentify ← 本 PR InferParamIndex SrcDstBufferMerge AddAlloc OoOSchedule (增强: 识别 atomicScopeId,cluster 内原子 block issue) × TuneTileOpSeqForVF (废弃) RemoveAlloc CopyOutResolve InsertSync (增强: cluster 内不插 sync) × TuneSyncForVF (废弃) MixSubgraphSplit (增强: 不拆分 cluster) ### 核心算法流程 ProcessLeafFunction ├── 1. BuildGraph 构建 op 列表 + producer/consumer 邻接表 ├── 2. BuildDfsPriorityTopoOrder DFS 优先拓扑排序 ├── 3. AncestorBits::Build 构建传递闭包 bitset(O(1) 祖先查询) ├── 4. BuildScheduledList 基于就绪队列 + 拓扑序的初始调度 ├── 5. ProcessFusableOps 贪心多输入合并 │ ├── 冷启动: inputClusterIds 为空 → 独立成簇 │ ├── 单输入: CanMergeToCluster → 合并或独立成簇 │ ├── 多输入: CanMergeMultiInputClusters → 逐个串行合并 │ └── CompactScheduleForCluster 紧凑调度(ScheduleWindow) ├── 6. DissolveSingletonClusters 解散单 op 簇,重置 atomicScopeId = -1 └── 7. VerifyScheduleTopology 拓扑序一致性校验(安全网) ### 识别与合并策略 每个 PIPE_V compute op **先各自成簇,再贪心合并,最后解散单 op 簇**: - inputClusterIds 为空 → 独立成簇(冷启动) - CanMergeToCluster / CanMergeMultiInputClusters 失败 → 独立成簇(兜底) - DissolveSingletonClusters:单 op 簇重置 atomicScopeId = -1,下游 pass 对这些 op 不做任何 cluster 约束 - GetInputClusterIds 只返回 pass 分配的 cluster(ID ≥ VF_CLUSTER_ID_START),用户 scope(1~10000)封闭,不作为合并目标 多输入合并采用**逐个串行合并**策略:先筛选能与 consumer 合并的 cluster,consumer 与第一个合并并修改 scheduleOrder_,然后逐个尝试剩余 cluster。成环风险由 bitset 检查自然阻止——中间 op 既不能往前移(依赖该 cluster)也不能往后移(被 consumer 依赖),IsAdjustableAdjacent 自然返回 false。 ### 传递闭包 bitset 预构建传递闭包 bitset,所有依赖查询均为 O(1): AncestorBits::Build: N = ops.size() 1. 分配 bitset index(按拓扑序) 2. 填充直接邻接 3. 拓扑序倒序 DP + bitset OR 合并 IsAncestor(a, b) = descendants_[a].test(b) 即 "a 的后代集合包含 b" 等价于 "a 是 b 的祖先" - 构建复杂度:O(N²·D/64),N < 10000(leaf function 内 op 数) - 查询复杂度:O(1) - 只存 descendants_ 一个方向,内存减半 CanMergeToCluster / CanMergeClusterIntoTarget / IsAdjustableAdjacent 中的可调相邻检查全部走 bitset 查询。cluster 自身 op 可以自由重排(CanMoveOp 直接返回 true),内部排序由 OoO 调度器负责。 ### 独立编排容器 引入独立的编排容器 scheduleOrder_(vector<Operation*>)承载当前编排顺序,原始 opList 保留为只读: - 传递闭包 bitset 始终基于原始 opList 的 idx,不受合并操作影响 - schedulePosition_ 维护 op → scheduleOrder_ 位置的映射,支持 O(1) 查找 - ScheduleWindow 抽象限制验证范围:只验证 firstPosition ~ lastPosition 区间内的 op 依赖关系,避免全量扫描 - cluster ops 在 scheduleOrder_ 中保持连续,通过 CompactScheduleForCluster 紧凑化 ### 职责边界 VFFusionClusterIdentify 只负责: - ✅ 识别哪些 PIPE_V op 属于同一 cluster - ✅ 保证 cluster ops 在 scheduleOrder_ 中相邻 - ✅ 分配 atomicScopeId(≥ VF_CLUSTER_ID_START) - ✅ 解散单 op 簇 - ❌ cluster 内部执行序 → OoO pass 负责 VF_CLUSTER_SIZE_LIMIT(32)保留在识别 pass 作为硬性上限。buffer 约束由 OoO 实际分配结果决定,失败时自然回退到普通调度。 ### 关键数据结构 | 结构 | 职责 | 复杂度/约束 | |------|------|------------| | AncestorBits | 传递闭包 bitset,O(1) IsAncestor 查询 | 构建 O(N²·D/64),N < 10000 | | GraphContext | op 列表 + producer/consumer 邻接表 | 一次性构建 | | ScheduleBlock | 调度序列中同 clusterId 的连续 op 段 | 局部窗口操作 | | ScheduleGroup | 组级拓扑排序单元,按 orderIndex 排序 | 用于 EmitScheduleGroups | | ScheduleWindow | scheduleOrder_ 的替换窗口,仅验证受影响区间 | firstPosition ~ lastPosition | ### ID 空间隔离 VF cluster ID 与用户 atomic_scope 编码空间完全隔离: 用户编码空间: scopeId * _ATOMIC_SCOPE_ENCODE_BASE(10000) + iter scopeId ∈ [1, 10000], 最大编码 = 100,009,999 VF cluster ID: [VF_CLUSTER_ID_START(200000000), ...] 间隔: ~100M,确保无重叠 ### 合并安全检查 1. **环路检查**:CanMergeToCluster / CanMergeClusterIntoTarget 通过 AncestorBits::IsAncestor 验证合并不会产生跨 cluster 依赖环 2. **REDUCE producer 拒绝**:若 consumer 的 producer 位于目标 cluster 内且为 REDUCE 类算子,拒绝合并(第二个 commit 修复) 3. **拓扑验证**:VerifyScheduleTopology 在紧凑调度后对完整序列做最终拓扑序校验,作为安全网 4. **窗口验证**:ValidateScheduleWindow 仅验证 ScheduleWindow 范围内的 op 依赖关系,避免全量扫描 ### 紧凑调度策略 CompactScheduleForCluster 通过 ScheduleWindow 将同一簇的算子移到连续位置: 1. GetScheduleWindowRange — 定位候选 op 在 scheduleOrder_ 中的首尾位置 2. BuildScheduleBlock — 将窗口划分为 before/candidate/after 三类 block 3. ClassifyScheduleBlock — 通过 CanPlaceBlockBeforeCandidates / CanPlaceBlockAfterCandidates 验证 block 可安全移动 4. AssembleScheduleWindow — 按 before → candidate → after 顺序组装新窗口 5. ApplyValidatedScheduleWindow — 写回 scheduleOrder_ 并刷新索引 ## 实现细节 ### Commit 列表 1. **feat(pass): Add VFFusionClusterIdentify pass** — 核心 Pass 实现 + 注册 + UT + oooScopeId_→atomicScopeId_ 全局重命名 2. **fix(pass): Reject VF cluster merge when producer is reduce op** — 合并安全修复,新增 4 个 UT 覆盖 expand/elementwise/reduce 组合场景 3. **docs(pass): Update sg_set_atomic_scope description** — 文档与 schema 语义对齐 ### 变更文件 - 新增 vf_fusion_cluster_identify.h / .cpp(~1350 LOC) - pass_type.h / pass_manager.cpp / pass_dependency.cpp 注册 Pass - oooScopeId_ → atomicScopeId_ 跨 C++/Python/文档统一重命名 - 新增 16 个 UT 用例(test_vf_fusion_cluster_identify.cpp) - 适配 test_schedule_ooo.cpp 及配置相关 UT - 更新 sg_set_atomic_scope 文档:VF 融合影响、片上 buffer 与同步指令插入、MixSubgraphSplit/LoopaxesProc 影响 - 更新 tile_fwk_config_schema.json label 为 atomic scope 语义 ### Review 修复已纳入 - VF cluster ID 空间隔离:VF_CLUSTER_ID_START 100001 → 200000000,user scopeId max 100000 → 10000 - 移除 vfFusionClusterOps_ 的 mutable 修饰,相关 const 方法改为 non-const - ProcessLeafFunction 起始处添加 vfFusionClusterOps_.clear() - 失败返回点添加状态契约注释 - AncestorBits::Build 添加复杂度注释(O(N²·D/64), N < 10000) - 提取 _ATOMIC_SCOPE_ENCODE_BASE = 10000 为命名常量 - 为 GraphContext / ReadyNode / ScheduleBlock / ScheduleGroup 添加结构注释 Related Issues: #2815 See merge request: cann/pypto!5669 | 2 months ago | |
feat(pass): Add VFFusionClusterIdentify pass Co-authored-by: Catherie<mayuan33@huawei.com> # message auto-generated for no-merge-commit merge: !5669 merge feat/vf-fusion-cluster-identify-v2 into master feat(pass): Add VFFusionClusterIdentify pass Created-by: Catherie Commit-by: Catherie Merged-by: cann-robot Description: feat(pass): Add VFFusionClusterIdentify pass ## 背景与动机 A5(DAV_3510)硬件支持 Vector Fusion(VF)—— CCE 后端可将相邻的 PIPE_V 指令融合为单条融合指令。此前框架存在两个尝试为 VF 创造融合窗口的 pass: - TuneTileOpSeqForVF(OoO 之后):基于 HasDataDependency 检查相邻 PIPE_V op 可合并性,mergedOps 为局部变量不持久化 - TuneSyncForVF(InsertSync 之后):独立重新识别融合分组,基于时序模型决定是否移除 sync 并合并 **核心问题**:两个 pass 各自局部识别、不持久化 cluster 信息,无法保证编译器认为对 VF 融合友好的 pattern 一定被保留到最终调度。 本 PR 引入 **VFFusionCluster** 机制:在子图切分合图后一次性识别可融合的 PIPE_V op 组,通过 Operation::atomicScopeId_(原 oooScopeId_ 重命名)持久化 cluster 信息,约束 OoO 调度、InsertSync、MixSubgraphSplit、LoopaxesProc 等下游 pass 不破坏 cluster 原子性。新 pass VFFusionClusterIdentify 成为唯一识别源,TuneTileOpSeqForVF 和 TuneSyncForVF 后续将被废弃。 **适用范围**:架构仅 DAV_3510(A5),开关 KEY_ENABLE_VF。 ## 方案设计 ### Pass 管线位置 SubgraphToFunction ★ NEW: VFFusionClusterIdentify ← 本 PR InferParamIndex SrcDstBufferMerge AddAlloc OoOSchedule (增强: 识别 atomicScopeId,cluster 内原子 block issue) × TuneTileOpSeqForVF (废弃) RemoveAlloc CopyOutResolve InsertSync (增强: cluster 内不插 sync) × TuneSyncForVF (废弃) MixSubgraphSplit (增强: 不拆分 cluster) ### 核心算法流程 ProcessLeafFunction ├── 1. BuildGraph 构建 op 列表 + producer/consumer 邻接表 ├── 2. BuildDfsPriorityTopoOrder DFS 优先拓扑排序 ├── 3. AncestorBits::Build 构建传递闭包 bitset(O(1) 祖先查询) ├── 4. BuildScheduledList 基于就绪队列 + 拓扑序的初始调度 ├── 5. ProcessFusableOps 贪心多输入合并 │ ├── 冷启动: inputClusterIds 为空 → 独立成簇 │ ├── 单输入: CanMergeToCluster → 合并或独立成簇 │ ├── 多输入: CanMergeMultiInputClusters → 逐个串行合并 │ └── CompactScheduleForCluster 紧凑调度(ScheduleWindow) ├── 6. DissolveSingletonClusters 解散单 op 簇,重置 atomicScopeId = -1 └── 7. VerifyScheduleTopology 拓扑序一致性校验(安全网) ### 识别与合并策略 每个 PIPE_V compute op **先各自成簇,再贪心合并,最后解散单 op 簇**: - inputClusterIds 为空 → 独立成簇(冷启动) - CanMergeToCluster / CanMergeMultiInputClusters 失败 → 独立成簇(兜底) - DissolveSingletonClusters:单 op 簇重置 atomicScopeId = -1,下游 pass 对这些 op 不做任何 cluster 约束 - GetInputClusterIds 只返回 pass 分配的 cluster(ID ≥ VF_CLUSTER_ID_START),用户 scope(1~10000)封闭,不作为合并目标 多输入合并采用**逐个串行合并**策略:先筛选能与 consumer 合并的 cluster,consumer 与第一个合并并修改 scheduleOrder_,然后逐个尝试剩余 cluster。成环风险由 bitset 检查自然阻止——中间 op 既不能往前移(依赖该 cluster)也不能往后移(被 consumer 依赖),IsAdjustableAdjacent 自然返回 false。 ### 传递闭包 bitset 预构建传递闭包 bitset,所有依赖查询均为 O(1): AncestorBits::Build: N = ops.size() 1. 分配 bitset index(按拓扑序) 2. 填充直接邻接 3. 拓扑序倒序 DP + bitset OR 合并 IsAncestor(a, b) = descendants_[a].test(b) 即 "a 的后代集合包含 b" 等价于 "a 是 b 的祖先" - 构建复杂度:O(N²·D/64),N < 10000(leaf function 内 op 数) - 查询复杂度:O(1) - 只存 descendants_ 一个方向,内存减半 CanMergeToCluster / CanMergeClusterIntoTarget / IsAdjustableAdjacent 中的可调相邻检查全部走 bitset 查询。cluster 自身 op 可以自由重排(CanMoveOp 直接返回 true),内部排序由 OoO 调度器负责。 ### 独立编排容器 引入独立的编排容器 scheduleOrder_(vector<Operation*>)承载当前编排顺序,原始 opList 保留为只读: - 传递闭包 bitset 始终基于原始 opList 的 idx,不受合并操作影响 - schedulePosition_ 维护 op → scheduleOrder_ 位置的映射,支持 O(1) 查找 - ScheduleWindow 抽象限制验证范围:只验证 firstPosition ~ lastPosition 区间内的 op 依赖关系,避免全量扫描 - cluster ops 在 scheduleOrder_ 中保持连续,通过 CompactScheduleForCluster 紧凑化 ### 职责边界 VFFusionClusterIdentify 只负责: - ✅ 识别哪些 PIPE_V op 属于同一 cluster - ✅ 保证 cluster ops 在 scheduleOrder_ 中相邻 - ✅ 分配 atomicScopeId(≥ VF_CLUSTER_ID_START) - ✅ 解散单 op 簇 - ❌ cluster 内部执行序 → OoO pass 负责 VF_CLUSTER_SIZE_LIMIT(32)保留在识别 pass 作为硬性上限。buffer 约束由 OoO 实际分配结果决定,失败时自然回退到普通调度。 ### 关键数据结构 | 结构 | 职责 | 复杂度/约束 | |------|------|------------| | AncestorBits | 传递闭包 bitset,O(1) IsAncestor 查询 | 构建 O(N²·D/64),N < 10000 | | GraphContext | op 列表 + producer/consumer 邻接表 | 一次性构建 | | ScheduleBlock | 调度序列中同 clusterId 的连续 op 段 | 局部窗口操作 | | ScheduleGroup | 组级拓扑排序单元,按 orderIndex 排序 | 用于 EmitScheduleGroups | | ScheduleWindow | scheduleOrder_ 的替换窗口,仅验证受影响区间 | firstPosition ~ lastPosition | ### ID 空间隔离 VF cluster ID 与用户 atomic_scope 编码空间完全隔离: 用户编码空间: scopeId * _ATOMIC_SCOPE_ENCODE_BASE(10000) + iter scopeId ∈ [1, 10000], 最大编码 = 100,009,999 VF cluster ID: [VF_CLUSTER_ID_START(200000000), ...] 间隔: ~100M,确保无重叠 ### 合并安全检查 1. **环路检查**:CanMergeToCluster / CanMergeClusterIntoTarget 通过 AncestorBits::IsAncestor 验证合并不会产生跨 cluster 依赖环 2. **REDUCE producer 拒绝**:若 consumer 的 producer 位于目标 cluster 内且为 REDUCE 类算子,拒绝合并(第二个 commit 修复) 3. **拓扑验证**:VerifyScheduleTopology 在紧凑调度后对完整序列做最终拓扑序校验,作为安全网 4. **窗口验证**:ValidateScheduleWindow 仅验证 ScheduleWindow 范围内的 op 依赖关系,避免全量扫描 ### 紧凑调度策略 CompactScheduleForCluster 通过 ScheduleWindow 将同一簇的算子移到连续位置: 1. GetScheduleWindowRange — 定位候选 op 在 scheduleOrder_ 中的首尾位置 2. BuildScheduleBlock — 将窗口划分为 before/candidate/after 三类 block 3. ClassifyScheduleBlock — 通过 CanPlaceBlockBeforeCandidates / CanPlaceBlockAfterCandidates 验证 block 可安全移动 4. AssembleScheduleWindow — 按 before → candidate → after 顺序组装新窗口 5. ApplyValidatedScheduleWindow — 写回 scheduleOrder_ 并刷新索引 ## 实现细节 ### Commit 列表 1. **feat(pass): Add VFFusionClusterIdentify pass** — 核心 Pass 实现 + 注册 + UT + oooScopeId_→atomicScopeId_ 全局重命名 2. **fix(pass): Reject VF cluster merge when producer is reduce op** — 合并安全修复,新增 4 个 UT 覆盖 expand/elementwise/reduce 组合场景 3. **docs(pass): Update sg_set_atomic_scope description** — 文档与 schema 语义对齐 ### 变更文件 - 新增 vf_fusion_cluster_identify.h / .cpp(~1350 LOC) - pass_type.h / pass_manager.cpp / pass_dependency.cpp 注册 Pass - oooScopeId_ → atomicScopeId_ 跨 C++/Python/文档统一重命名 - 新增 16 个 UT 用例(test_vf_fusion_cluster_identify.cpp) - 适配 test_schedule_ooo.cpp 及配置相关 UT - 更新 sg_set_atomic_scope 文档:VF 融合影响、片上 buffer 与同步指令插入、MixSubgraphSplit/LoopaxesProc 影响 - 更新 tile_fwk_config_schema.json label 为 atomic scope 语义 ### Review 修复已纳入 - VF cluster ID 空间隔离:VF_CLUSTER_ID_START 100001 → 200000000,user scopeId max 100000 → 10000 - 移除 vfFusionClusterOps_ 的 mutable 修饰,相关 const 方法改为 non-const - ProcessLeafFunction 起始处添加 vfFusionClusterOps_.clear() - 失败返回点添加状态契约注释 - AncestorBits::Build 添加复杂度注释(O(N²·D/64), N < 10000) - 提取 _ATOMIC_SCOPE_ENCODE_BASE = 10000 为命名常量 - 为 GraphContext / ReadyNode / ScheduleBlock / ScheduleGroup 添加结构注释 Related Issues: #2815 See merge request: cann/pypto!5669 | 2 months ago | |
feat(operation): Support int64/uint64 for vector operations Co-authored-by: junnyleo<lijun580@huawei.com> # message auto-generated for no-merge-commit merge: !5572 merge feat/dtype into master feat(operation): Support int64/uint64 for vector operations Created-by: junnyleo Commit-by: junnyleo Merged-by: cann-robot Description: 本 PR 旨在为向量(vector)算子补充 int64/uint64 数据类型支持。改动主要为: 1. 通过 GetSupportedDataTypesByArch 在 A5 架构(DAV_3510)的算子支持类型集合中加入 DT_INT64/DT_UINT64; 2. 新增 CheckInt64Broadcast 校验以禁止 int64/uint64 输入的 broadcast;同时修正标量 Element 的构造/转换路径(int64 不经 float、uint64 不经 int64 中转),避免大数值精度丢失或符号翻转; 3. 在 tile-op 内核层为 int64 补齐 FloorDiv、compare、logicalnot、unary 等实现; 4. 配套更新了 Python 侧与测试用例及md文档。 Related Issue: #3141 See merge request: cann/pypto!5572 | 3 months 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 | |
feat(pass): Attach tile-graph tokens from source op during ExpandFunction Co-authored-by: Immutable01<gaoqiancheng@huawei.com> # message auto-generated for no-merge-commit merge: !5755 merge 0828_tokenfinal into master feat(pass): Attach tile-graph tokens from source op during ExpandFunction Created-by: Immutable01 Commit-by: Immutable01 Merged-by: cann-robot Description: token expandfunction代码重构,泛化实现方式 See merge request: cann/pypto!5755 | 3 months ago | |
feat(pass): Attach tile-graph tokens from source op during ExpandFunction Co-authored-by: Immutable01<gaoqiancheng@huawei.com> # message auto-generated for no-merge-commit merge: !5755 merge 0828_tokenfinal into master feat(pass): Attach tile-graph tokens from source op during ExpandFunction Created-by: Immutable01 Commit-by: Immutable01 Merged-by: cann-robot Description: token expandfunction代码重构,泛化实现方式 See merge request: cann/pypto!5755 | 3 months ago | |
feat(Operation): Add pypto.conv_backward_input and its 2D implementation on A2/A3 Co-authored-by: hongyiliu111<liuhongyi1@huawei.com> Co-authored-by: xutianlong1<xutianlong1@huawei.com> Co-authored-by: wangshenhao<wangshenhao1@huawei.com> # message auto-generated for no-merge-commit merge: !5528 merge dev into master feat(Operation): Add pypto.conv_backward_input and its 2D implementation on A2/A3 Created-by: hongyiliu111 Commit-by: wangshenhao;hongyiliu111;xutianlong1 Merged-by: cann-robot Description: feat(Operation): Add pypto.conv_backward_input and its 2D implementation on A2/A3 Add pypto.conv_backward_input interface to compute the gradient of convolution with respect to the input tensor, and implement its 2D support spanning the frontend interface, backend operation implementation and MTE codegen Changes: - Add pypto.conv_backward_input frontend interface with parameter validation - Implement ConvBackwardInput 2D backend operation and codegen - Add UT/ST test cases for the 2D implementation See merge request: cann/pypto!5528 | 3 months 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 | |
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 |
|---|---|---|
| 3 months ago | ||
| 3 months ago | ||
| 2 months ago | ||
| 4 months ago | ||
| 4 months ago | ||
| 3 months ago | ||
| 3 months ago | ||
| 2 months ago | ||
| 3 months ago | ||
| 2 months ago | ||
| 4 months ago | ||
| 2 months ago | ||
| 4 months ago | ||
| 2 months ago | ||
| 3 months ago | ||
| 2 months ago | ||
| 2 months ago | ||
| 3 months ago | ||
| 2 months ago | ||
| 3 months ago | ||
| 3 months ago | ||
| 3 months ago | ||
| 2 months ago | ||
| 4 months ago | ||
| 3 months ago |