| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
清理 3rdparty 下冗余 tensor_api 文件,已迁移至三方仓 ops-tensor Co-authored-by: luobaiqing<luobaiqing1@huawei.com> # message auto-generated for no-merge-commit merge: !7037 merge remove_tensor_api into master 清理 3rdparty 下冗余 tensor_api 文件,已迁移至三方仓 ops-tensor Created-by: luobaiqing Commit-by: luobaiqing Merged-by: cann-robot Description: ## 描述 删除 3rdparty 下的内部 tensor_api 头文件和实现(共 129 个文件),涵盖 compute/mmad 及 gm_to_l1/gm_to_ub/l0c_to_gm/l0c_to_ub/l1_to_bt/l1_to_fb/l1_to_l0a/l1_to_l0b/l1_to_ub/ub_to_gm/ub_to_l1 等全部数据搬运原语。 这些 tensor_api 已迁移至三方仓 ops-tensor,通过 TENSOR_API_IMPL_INCLUDE_ROOT 引用,3rdparty 下副本为冗余代码。 ## 关联的Issue 无 ## 测试 - [x] ops-transformer CI 编译通过 ## 文档更新 无 ## 类型标签 - [x] 🧹 代码清理 See merge request: cann/ops-transformer!7037 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
新增engram_fetch 核函数 && engram_fetch_wait算子 Co-authored-by: wuchenhao123<wuchenhao6@huawei.com> # message auto-generated for no-merge-commit merge: !7749 merge master_engram into master 新增engram_fetch 核函数 && engram_fetch_wait算子 Created-by: wuchenhao123 Commit-by: wuchenhao123 Merged-by: cann-robot Description: ## 描述 EngramFetch算子工程代码 ## 关联的Issue https://gitcode.com/cann/ops-transformer/issues/3385 ## 测试 本地验证 ## 文档更新 不涉及 ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug修复 - [X] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [ ] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [ ] 🧹 代码清理 - [ ] ❓ 其他,请描述: See merge request: cann/ops-transformer!7749 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
fix: mc2日志宏向前兼容旧版 log.h Co-authored-by: hello_simida<wangyi206@huawei.com> # message auto-generated for no-merge-commit merge: !6737 merge master into master fix: mc2日志宏向前兼容旧版 log.h Created-by: hello_simida Commit-by: hello_simida Merged-by: cann-robot Description: ## 描述 新增 mc2_log_compat.h 提供 OP_LOGE_LIBOPAPI_REPORT 和 OP_LOGE_FOR_* (EZ0008-EZ0034) fallback 定义,支持与仅有 EZ0001-EZ0007 的旧版 log.h 配套编译。 主要修改: - 新建 mc2/common/utils/mc2_log_compat.h,包含 28 个 fallback 宏定义(含 #ifndef 守卫) - opapi 构建 (OP_LOG_LIBOPAPI_ONLY) 使用 opdev 原生 DlogRecordInner,避免旧版 GetOpInfo 模板类型冲突 - ophost 构建使用旧版 D_OP_LOGE + GetOpInfo - mc2_common_log.h 替换内联 fallback 为 include - 48 个 mc2 源文件添加兼容引用 ## 关联的Issue Closes #3039 ## 测试 - 旧版 log.h + bash build.sh --pkg --soc=ascend910b --ops=allto_all_matmul ✅ 0 errors - 新版 log.h + bash build.sh --pkg --soc=ascend910b --ops=allto_all_matmul ✅ 0 errors(无回归) ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] 🐛 Bug 修复 - [ ] ✨ 新特性 - [ ] ⚡ 性能优化 - [ ] ♻️ 重构 - [ ] 🧪 测试 - [ ] 📦 构建/CI - [ ] 🔧 配置变更 - [ ] 📝 文档更新 - [ ] ⬆️ 依赖升级 - [ ] 🔒 安全修复 - [x] 🧹 代码清理 - [ ] ❓ 其他,请描述: <!-- CODE_REVIEW_REPORT --> ## 🤖 自动代码检视报告 **检视状态:** 完成 ✅ **摘要:** - 检视文件数:52 个(核心逻辑 3 个,单行 include 新增 49 个) - 发现风险点:0 个(CRITICAL: 0, HIGH: 0, MEDIUM: 0) ### 逐项检查 1. ✅ 宏包装安全 — 所有 28 个宏均使用 do { } while (0) 包裹 2. ✅ 重复定义防护 — 使用 #ifndef 守卫 3. ✅ 参数防多次求值 — _safe_ 前缀局部变量 4. ✅ 类型安全 — EZ0022 使用 static_cast<int64_t> 5. ✅ 格式字符串匹配 — 27 个宏的格式串正确 6. ✅ 条件编译隔离 — OP_LOG_LIBOPAPI_ONLY 正确隔离 7. ✅ include guard — MC2_LOG_COMPAT_H 正确 ### 结论 **整体评价:** ✅ 代码质量良好,符合 CANN 编码规范。 - 无红线规范违反,无安全风险 - 新旧 log.h 双编译验证通过(0 errors) **检视信息:** - Agent: Claude Code CLI - Model: deepseek-v4-flash - Skill: ascendc-code-review 💡 此报告由 ascendc-code-review skill 自动生成,仅供参考。 <!-- /CODE_REVIEW_REPORT --> See merge request: cann/ops-transformer!6737 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 | |
移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Co-authored-by: gitcode_lijd<lijiandong20@huawei.com> # message auto-generated for no-merge-commit merge: !7544 merge compile into master 移除 mc2 op_kernel 摊平机制,统一编译框架与 include 风格 Created-by: gitcode_lijd Commit-by: gitcode_lijd Merged-by: cann-robot Description: ## 背景 ops-transformer 出包时 op_kernel/ 目录被扁平化展开:mc2/common/op_kernel/xxx.h → ascendc/common/xxx.h。对于 static_true(JIT 在线编译)算子,kernel 代码需兼容两种环境: 1. **本地预编译**:源码树,op_kernel/ 层级存在 2. **CANN 包 JIT 编译**:扁平化,op_kernel/ 层级消失 ## 治理原则 ### 核心规则 - **static_true 算子**:需要 __has_include 守卫,兼容两种路径 - **static_false 算子**:不需要守卫,直接用本地 op_kernel/ 路径 - **同目录引用**:不需要守卫 ### 三种标准模式 // 1. op_kernel 层 → common #if __has_include("../common/xxx.h") // CANN(无 op_kernel) #include "../common/xxx.h" #else #include "../../common/op_kernel/xxx.h" // 本地(有 op_kernel) #endif // 2. arch 层 → common #if __has_include("../../common/xxx.h") #include "../../common/xxx.h" #else #include "../../../common/op_kernel/xxx.h" #endif // 3. op_kernel 层 → 兄弟算子 #if __has_include("../sibling_op/xxx.h") #include "../sibling_op/xxx.h" #else #include "../../sibling_op/op_kernel/xxx.h" #endif ### 合并原则 同深度、紧邻的 __has_include 块可合并为一个。**不可合并**的情况: - 两个块之间有其他 #include(依赖排序) - 第一个块在 #if defined(__NPU_ARCH__) 条件编译内 - quantize_functions.h 等特殊依赖 ## 已完成工作清单 ### 1. cmake 出包扁平化 - common/: install 目标去掉 op_kernel 中间层 - 3rd/: install 加尾 /(op_kernel → op_kernel/),展开内容 ### 2. __CCE_KT_TEST__ 守卫还原(4 个文件) matmul_all_reduce 下 common.h + 3 个 *_tiling_data.h,被误删的守卫恢复,并修正 else 分支路径(combined.h 的 ../common/ → ../../common/) ### 3. __has_include 路径纠正 - op_kernel 层:../../common/ → ../common/ - arch 层:../../../common/ → ../../common/ - 覆盖全部 static_true 算子(14 个 → 20 个) ### 4. 同级块合并(8 个文件) 相邻同深度的 __has_include 块合并 ### 5. setup/teardown 预加守卫(4 个算子,8 个文件 → 已纳入守护范围) 已加 __has_include 守卫,后续切 static_true 无需修改 .h 文件: - moe_distribute_combine_setup - moe_distribute_dispatch_setup - moe_distribute_combine_teardown - moe_distribute_dispatch_teardown ### 6. 高风险拆分 moe_distribute_combine_v2_quant.h:quantize_functions.h 从合并块拆出,单独守卫 ### 7. 无效守卫清理 - engram_fetch_wait(纯 static_false):移除守卫,直接用本地路径 ### 8. 新增 EP 算子守护(3 个算子) 新增 3 个 static_true 算子: - moe_ep_dispatch(守卫已正确) - moe_ep_combine(修正 __has_include 路径中多余 op_kernel/ 层级) - moe_ep_dispatch_epilogue(同上) ### 9. MegaMoe 跨算子引用加守卫(2 个文件,4 处) mega_moe/op_kernel/arch35/ 下 mega_moe.h + mega_moe_combine_send.h: - quantize_functions.h 加 __has_include 双路径守卫 - 原裸 "moe_distribute_dispatch_v2/op_kernel/..." 路径(依赖 -Imc2/)改为相对路径 ### 10. MegaMoe CMake 清理 - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../(-Imc2/,仅 mega_moe 使用) - 删除 -I${CMAKE_CURRENT_SOURCE_DIR}/../../3rd(目录不存在,无引用) - 新增 mega_moe_apt_depends,声明 apt 编译依赖 mc2/moe_distribute_dispatch_v2 mc2/moe_distribute_dispatch_v3,确保 opc 编译时跨算子头文件可解析 ## 当前 static_true 算子清单(共 17 个已启用 + 3 个守卫待启用 = 20 个) | 算子 | 目录 | 守卫状态 | |------|------|---------| | AttentionToFFN | mc2/attention_to_ffn/ | ✓ | | DistributeBarrier | mc2/distribute_barrier/ | ✓ | | DistributeBarrierExtend | mc2/distribute_barrier_extend/ | ✓(*) | | FFNToAttention | mc2/ffn_to_attention/ | ✓ | | MegaMoe | mc2/mega_moe/ | ✓ | | MoeDistributeCombine | mc2/moe_distribute_combine/ | ✓ | | MoeDistributeCombineAddRmsNorm | mc2/moe_distribute_combine_add_rms_norm/ | ✓(*) | | MoeDistributeCombineSetup | mc2/moe_distribute_combine_setup/ | ✓(†) | | MoeDistributeCombineTeardown | mc2/moe_distribute_combine_teardown/ | ✓ | | MoeDistributeCombineV2 | mc2/moe_distribute_combine_v2/ | ✓ | | MoeDistributeCombineV3 | mc2/moe_distribute_combine_v3/ | ✓(*) | | MoeDistributeDispatch | mc2/moe_distribute_dispatch/ | ✓ | | MoeDistributeDispatchSetup | mc2/moe_distribute_dispatch_setup/ | ✓(†) | | MoeDistributeDispatchTeardown | mc2/moe_distribute_dispatch_teardown/ | ✓(†) | | MoeDistributeDispatchV2 | mc2/moe_distribute_dispatch_v2/ | ✓ | | MoeDistributeDispatchV3 | mc2/moe_distribute_dispatch_v3/ | ✓(*) | | MoeEpCombine | mc2/moe_ep_combine/ | ✓ | | MoeEpDispatch | mc2/moe_ep_dispatch/ | ✓ | | MoeEpDispatchEpilogue | mc2/moe_ep_dispatch_epilogue/ | ✓ | | MoeUpdateExpert | mc2/moe_update_expert/ | ✓ | > (\*) 守卫仅存在于 .cpp 文件,.h 文件无跨目录引用,无需守卫 > (†) 守卫已就位,当前 jitCompile.flag 为 static_false,后续切换不需改 .h 文件 ## 后续开发注意事项 ### 新增算子 1. 确认 jitCompile.flag(在 op_host/*_def.cpp) 2. static_true → 所有跨 common/兄弟算子的 include 加守卫 3. 同目录引用、系统头文件不需要守卫 ### 切换 static_false → static_true 1. 改 jitCompile.flag 为 "static_true" 2. 扫描全部跨算子 include,加 __has_include 守卫 3. 参照已有 setup/teardown 做法 ### 代码审查要点 - op_kernel 层引用 common:是否用了 ../common/(非 ../../common/) - arch 层引用 common:是否用了 ../../common/(非 ../../../) - #else 分支路径是否包含 op_kernel/ - 同目录引用是否被误加了守卫 See merge request: cann/ops-transformer!7544 | 2 个月前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 | ||
| 2 个月前 |