Merged
删除dispatch/combine_setup/teardown aclnn接口,graph文件 #12568
删除dispatch/combine_setup/teardown aclnn接口,graph文件 #12568
Merged
jiangxiuhanAdd on Sep 21
Total: 54 files changed+25-8004
@@ -755,14 +755,10 @@ mc2_moe_advanced@ops-transformer:
755 - ops/ops-transformer/mc2/moe_distribute_combine_add_rms_norm/CMakeLists.txt755 - ops/ops-transformer/mc2/moe_distribute_combine_add_rms_norm/CMakeLists.txt
756 - ops/ops-transformer/mc2/moe_distribute_combine_add_rms_norm/README.md756 - ops/ops-transformer/mc2/moe_distribute_combine_add_rms_norm/README.md
757 - ops/ops-transformer/mc2/moe_distribute_combine_setup/op_host/op_tiling/arch35/757 - ops/ops-transformer/mc2/moe_distribute_combine_setup/op_host/op_tiling/arch35/
758- - ops/ops-transformer/mc2/moe_distribute_combine_setup/op_api/
759- - ops/ops-transformer/mc2/moe_distribute_combine_setup/op_graph/
760 - ops/ops-transformer/mc2/moe_distribute_combine_setup/op_kernel/arch35/758 - ops/ops-transformer/mc2/moe_distribute_combine_setup/op_kernel/arch35/
761 - ops/ops-transformer/mc2/moe_distribute_combine_setup/README.md759 - ops/ops-transformer/mc2/moe_distribute_combine_setup/README.md
762 - ops/ops-transformer/mc2/moe_distribute_combine_setup/CMakeLists.txt760 - ops/ops-transformer/mc2/moe_distribute_combine_setup/CMakeLists.txt
763 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/op_host/op_tiling/arch35/761 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/op_host/op_tiling/arch35/
764- - ops/ops-transformer/mc2/moe_distribute_combine_teardown/op_api/
765- - ops/ops-transformer/mc2/moe_distribute_combine_teardown/op_graph/
766 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/op_kernel/arch35/762 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/op_kernel/arch35/
767 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/CMakeLists.txt763 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/CMakeLists.txt
768 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/README.md764 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/README.md
@@ -809,14 +805,10 @@ mc2_moe_advanced@ops-transformer:
809 - ops/ops-transformer/mc2/moe_distribute_dispatch/CMakeLists.txt805 - ops/ops-transformer/mc2/moe_distribute_dispatch/CMakeLists.txt
810 - ops/ops-transformer/mc2/moe_distribute_dispatch/README.md806 - ops/ops-transformer/mc2/moe_distribute_dispatch/README.md
811 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/op_host/op_tiling/arch35/807 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/op_host/op_tiling/arch35/
812- - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/op_api/
813- - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/op_graph/
814 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/op_kernel/arch35/808 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/op_kernel/arch35/
815 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/CMakeLists.txt809 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/CMakeLists.txt
816 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/README.md810 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/README.md
817 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/op_host/op_tiling/arch35/811 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/op_host/op_tiling/arch35/
818- - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/op_api/
819- - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/op_graph/
820 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/op_kernel/arch35/812 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/op_kernel/arch35/
821 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/CMakeLists.txt813 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/CMakeLists.txt
822 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/README.md814 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/README.md
@@ -897,10 +889,7 @@ mc2_moe_advanced@ops-transformer:
897 - ops/ops-transformer/mc2/moe_distribute_combine_add_rms_norm/examples/889 - ops/ops-transformer/mc2/moe_distribute_combine_add_rms_norm/examples/
898 - ops/ops-transformer/mc2/moe_distribute_combine_add_rms_norm/docs/890 - ops/ops-transformer/mc2/moe_distribute_combine_add_rms_norm/docs/
899 - ops/ops-transformer/mc2/moe_distribute_combine_setup/tests/891 - ops/ops-transformer/mc2/moe_distribute_combine_setup/tests/
Z

后面删除了combine_setup的tests,这里还需要保留吗

likedislike
jiangxiuhan
jiangxiuhan
Sep 23 Comments:
900- - ops/ops-transformer/mc2/moe_distribute_combine_setup/examples/
901- - ops/ops-transformer/mc2/moe_distribute_combine_setup/docs/
902 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/tests/892 - ops/ops-transformer/mc2/moe_distribute_combine_teardown/tests/
903- - ops/ops-transformer/mc2/moe_distribute_combine_teardown/docs/
904 - ops/ops-transformer/mc2/moe_distribute_combine_v2/tests/893 - ops/ops-transformer/mc2/moe_distribute_combine_v2/tests/
905 - ops/ops-transformer/mc2/moe_distribute_combine_v2/examples/894 - ops/ops-transformer/mc2/moe_distribute_combine_v2/examples/
906 - ops/ops-transformer/mc2/moe_distribute_combine_v2/docs/895 - ops/ops-transformer/mc2/moe_distribute_combine_v2/docs/
@@ -909,10 +898,7 @@ mc2_moe_advanced@ops-transformer:
909 - ops/ops-transformer/mc2/moe_distribute_dispatch/examples/898 - ops/ops-transformer/mc2/moe_distribute_dispatch/examples/
910 - ops/ops-transformer/mc2/moe_distribute_dispatch/docs/899 - ops/ops-transformer/mc2/moe_distribute_dispatch/docs/
911 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/tests/900 - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/tests/
912- - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/examples/
913- - ops/ops-transformer/mc2/moe_distribute_dispatch_setup/docs/
914 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/tests/901 - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/tests/
915- - ops/ops-transformer/mc2/moe_distribute_dispatch_teardown/docs/
916 - ops/ops-transformer/mc2/moe_distribute_dispatch_v2/tests/902 - ops/ops-transformer/mc2/moe_distribute_dispatch_v2/tests/
917 - ops/ops-transformer/mc2/moe_distribute_dispatch_v2/examples/903 - ops/ops-transformer/mc2/moe_distribute_dispatch_v2/examples/
918 - ops/ops-transformer/mc2/moe_distribute_dispatch_v2/docs/904 - ops/ops-transformer/mc2/moe_distribute_dispatch_v2/docs/
@@ -961,8 +961,8 @@ Ascend 950支持的算子分类和算子列表如下:
961 <td><a href="../../mc2/moe_distribute_combine_setup/README.md">moe_distribute_combine_setup</a></td>961 <td><a href="../../mc2/moe_distribute_combine_setup/README.md">moe_distribute_combine_setup</a></td>
962 <td>✓</td>962 <td>✓</td>
963 <td>✓</td>963 <td>✓</td>
964- <td>✓</td>964+ <td>✗</td>
965- <td>✓</td>965+ <td>✗</td>
966 <td>AI Core</td>966 <td>AI Core</td>
967 <td>MoeDistributeCombine的setup阶段,用于初始化通信资源。</td>967 <td>MoeDistributeCombine的setup阶段,用于初始化通信资源。</td>
968 </tr>968 </tr>
@@ -971,8 +971,8 @@ Ascend 950支持的算子分类和算子列表如下:
971 <td><a href="../../mc2/moe_distribute_combine_teardown/README.md">moe_distribute_combine_teardown</a></td>971 <td><a href="../../mc2/moe_distribute_combine_teardown/README.md">moe_distribute_combine_teardown</a></td>
972 <td>✓</td>972 <td>✓</td>
973 <td>✓</td>973 <td>✓</td>
974- <td>✓</td>974+ <td>✗</td>
975- <td>✓</td>975+ <td>✗</td>
976 <td>AI Core</td>976 <td>AI Core</td>
977 <td>MoeDistributeCombine的teardown阶段,用于释放通信资源。</td>977 <td>MoeDistributeCombine的teardown阶段,用于释放通信资源。</td>
978 </tr>978 </tr>
@@ -1011,8 +1011,8 @@ Ascend 950支持的算子分类和算子列表如下:
1011 <td><a href="../../mc2/moe_distribute_dispatch_setup/README.md">moe_distribute_dispatch_setup</a></td>1011 <td><a href="../../mc2/moe_distribute_dispatch_setup/README.md">moe_distribute_dispatch_setup</a></td>
1012 <td>✓</td>1012 <td>✓</td>
1013 <td>✓</td>1013 <td>✓</td>
1014- <td>✓</td>1014+ <td>✗</td>
1015- <td>✓</td>1015+ <td>✗</td>
1016 <td>AI Core</td>1016 <td>AI Core</td>
1017 <td>MoeDistributeDispatch的setup阶段,用于初始化通信资源。</td>1017 <td>MoeDistributeDispatch的setup阶段,用于初始化通信资源。</td>
1018 </tr>1018 </tr>
@@ -1021,8 +1021,8 @@ Ascend 950支持的算子分类和算子列表如下:
1021 <td><a href="../../mc2/moe_distribute_dispatch_teardown/README.md">moe_distribute_dispatch_teardown</a></td>1021 <td><a href="../../mc2/moe_distribute_dispatch_teardown/README.md">moe_distribute_dispatch_teardown</a></td>
1022 <td>✓</td>1022 <td>✓</td>
1023 <td>✓</td>1023 <td>✓</td>
1024- <td>✓</td>1024+ <td>✗</td>
1025- <td>✓</td>1025+ <td>✗</td>
1026 <td>AI Core</td>1026 <td>AI Core</td>
1027 <td>MoeDistributeDispatch的teardown阶段,用于释放通信资源。</td>1027 <td>MoeDistributeDispatch的teardown阶段,用于释放通信资源。</td>
1028 </tr>1028 </tr>
@@ -162,14 +162,10 @@
162- [aclnnMoeDistributeCombine](../../mc2/moe_distribute_combine/docs/aclnnMoeDistributeCombine.md)162- [aclnnMoeDistributeCombine](../../mc2/moe_distribute_combine/docs/aclnnMoeDistributeCombine.md)
163- [aclnnMoeDistributeCombineAddRmsNorm](../../mc2/moe_distribute_combine_add_rms_norm/docs/aclnnMoeDistributeCombineAddRmsNorm.md)163- [aclnnMoeDistributeCombineAddRmsNorm](../../mc2/moe_distribute_combine_add_rms_norm/docs/aclnnMoeDistributeCombineAddRmsNorm.md)
164- [aclnnMoeDistributeCombineAddRmsNormV2](../../mc2/moe_distribute_combine_add_rms_norm/docs/aclnnMoeDistributeCombineAddRmsNormV2.md)164- [aclnnMoeDistributeCombineAddRmsNormV2](../../mc2/moe_distribute_combine_add_rms_norm/docs/aclnnMoeDistributeCombineAddRmsNormV2.md)
165-- [aclnnMoeDistributeCombineSetup](../../mc2/moe_distribute_combine_setup/docs/aclnnMoeDistributeCombineSetup.md)
166-- [aclnnMoeDistributeCombineTeardown](../../mc2/moe_distribute_combine_teardown/docs/aclnnMoeDistributeCombineTeardown.md)
167- [aclnnMoeDistributeCombineV2](../../mc2/moe_distribute_combine_v2/docs/aclnnMoeDistributeCombineV2.md)165- [aclnnMoeDistributeCombineV2](../../mc2/moe_distribute_combine_v2/docs/aclnnMoeDistributeCombineV2.md)
168- [aclnnMoeDistributeCombineV3](../../mc2/moe_distribute_combine_v2/docs/aclnnMoeDistributeCombineV3.md)166- [aclnnMoeDistributeCombineV3](../../mc2/moe_distribute_combine_v2/docs/aclnnMoeDistributeCombineV3.md)
169- [aclnnMoeDistributeCombineV4](../../mc2/moe_distribute_combine_v2/docs/aclnnMoeDistributeCombineV4.md)167- [aclnnMoeDistributeCombineV4](../../mc2/moe_distribute_combine_v2/docs/aclnnMoeDistributeCombineV4.md)
170- [aclnnMoeDistributeDispatch](../../mc2/moe_distribute_dispatch/docs/aclnnMoeDistributeDispatch.md)168- [aclnnMoeDistributeDispatch](../../mc2/moe_distribute_dispatch/docs/aclnnMoeDistributeDispatch.md)
171-- [aclnnMoeDistributeDispatchSetup](../../mc2/moe_distribute_dispatch_setup/docs/aclnnMoeDistributeDispatchSetup.md)
172-- [aclnnMoeDistributeDispatchTeardown](../../mc2/moe_distribute_dispatch_teardown/docs/aclnnMoeDistributeDispatchTeardown.md)
173- [aclnnMoeDistributeDispatchV2](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV2.md)169- [aclnnMoeDistributeDispatchV2](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV2.md)
174- [aclnnMoeDistributeDispatchV3](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV3.md)170- [aclnnMoeDistributeDispatchV3](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV3.md)
175- [aclnnMoeDistributeDispatchV4](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV4.md)171- [aclnnMoeDistributeDispatchV4](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV4.md)
@@ -158,14 +158,10 @@
158|[aclnnMoeDistributeCombineV4](../../mc2/moe_distribute_combine_v2/docs/aclnnMoeDistributeCombineV4.md)|当存在TP域通信时,先进行ReduceScatterV通信,再进行AllToAllV通信,最后将接收的数据整合;当不存在TP域通信时,进行AllToAllV通信,最后将接收的数据整合。expertScales非空时乘权重再相加,为空Tensor时直接相加。|默认确定性实现|默认确定性实现|默认确定性实现|158|[aclnnMoeDistributeCombineV4](../../mc2/moe_distribute_combine_v2/docs/aclnnMoeDistributeCombineV4.md)|当存在TP域通信时,先进行ReduceScatterV通信,再进行AllToAllV通信,最后将接收的数据整合;当不存在TP域通信时,进行AllToAllV通信,最后将接收的数据整合。expertScales非空时乘权重再相加,为空Tensor时直接相加。|默认确定性实现|默认确定性实现|默认确定性实现|
159|[aclnnMoeDistributeCombineAddRmsNorm](../../mc2/moe_distribute_combine_add_rms_norm/docs/aclnnMoeDistributeCombineAddRmsNorm.md)|当存在TP域通信时,先进行ReduceScatterV通信,再进行AlltoAllV通信,最后将接收的数据整合;当不存在TP域通信时,进行AlltoAllV通信,最后将接收的数据整合,之后完成Add + RmsNorm融合。|-|默认确定性实现|默认确定性实现|159|[aclnnMoeDistributeCombineAddRmsNorm](../../mc2/moe_distribute_combine_add_rms_norm/docs/aclnnMoeDistributeCombineAddRmsNorm.md)|当存在TP域通信时,先进行ReduceScatterV通信,再进行AlltoAllV通信,最后将接收的数据整合;当不存在TP域通信时,进行AlltoAllV通信,最后将接收的数据整合,之后完成Add + RmsNorm融合。|-|默认确定性实现|默认确定性实现|
160|[aclnnMoeDistributeCombineAddRmsNormV2](../../mc2/moe_distribute_combine_add_rms_norm/docs/aclnnMoeDistributeCombineAddRmsNormV2.md)|当存在TP域通信时,先进行ReduceScatterV通信,再进行AlltoAllV通信,最后将接收的数据整合;当不存在TP域通信时,进行AlltoAllV通信,最后将接收的数据整合,之后完成Add + RmsNorm融合。|-|默认确定性实现|默认确定性实现|160|[aclnnMoeDistributeCombineAddRmsNormV2](../../mc2/moe_distribute_combine_add_rms_norm/docs/aclnnMoeDistributeCombineAddRmsNormV2.md)|当存在TP域通信时,先进行ReduceScatterV通信,再进行AlltoAllV通信,最后将接收的数据整合;当不存在TP域通信时,进行AlltoAllV通信,最后将接收的数据整合,之后完成Add + RmsNorm融合。|-|默认确定性实现|默认确定性实现|
161-|[aclnnMoeDistributeCombineSetup](../../mc2/moe_distribute_combine_setup/docs/aclnnMoeDistributeCombineSetup.md)|进行AlltoAllV通信,将数据写入对端GM。|-|-|默认确定性实现|
162-|[aclnnMoeDistributeCombineTeardown](../../mc2/moe_distribute_combine_teardown/docs/aclnnMoeDistributeCombineTeardown.md)|接收aclnnMoeDistributeCombineSetup发来的数据并整合数据(乘权重再相加)。|-|-|默认确定性实现|
163|[aclnnMoeDistributeDispatch](../../mc2/moe_distribute_dispatch/docs/aclnnMoeDistributeDispatch.md)|对Token数据进行量化,当存在TP域通信时,先进行EP域的AllToAllV通信,再进行TP域的AllGatherV通信;当不存在TP域通信时,进行EP域的AllToAllV通信。|默认确定性实现|默认确定性实现|默认确定性实现|161|[aclnnMoeDistributeDispatch](../../mc2/moe_distribute_dispatch/docs/aclnnMoeDistributeDispatch.md)|对Token数据进行量化,当存在TP域通信时,先进行EP域的AllToAllV通信,再进行TP域的AllGatherV通信;当不存在TP域通信时,进行EP域的AllToAllV通信。|默认确定性实现|默认确定性实现|默认确定性实现|
164|[aclnnMoeDistributeDispatchV2](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV2.md)|对token数据进行量化,当存在TP域通信时,先进行EP域的AllToAllV通信,再进行TP域的AllGatherV通信;当不存在TP域通信时,进行EP域的AllToAllV通信。|默认确定性实现|默认确定性实现|默认确定性实现|162|[aclnnMoeDistributeDispatchV2](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV2.md)|对token数据进行量化,当存在TP域通信时,先进行EP域的AllToAllV通信,再进行TP域的AllGatherV通信;当不存在TP域通信时,进行EP域的AllToAllV通信。|默认确定性实现|默认确定性实现|默认确定性实现|
165|[aclnnMoeDistributeDispatchV3](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV3.md)|对token数据进行量化,当存在TP域通信时,先进行EP域的AllToAllV通信,再进行TP域的AllGatherV通信;当不存在TP域通信时,进行EP域的AllToAllV通信。|默认确定性实现|默认确定性实现|默认确定性实现|163|[aclnnMoeDistributeDispatchV3](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV3.md)|对token数据进行量化,当存在TP域通信时,先进行EP域的AllToAllV通信,再进行TP域的AllGatherV通信;当不存在TP域通信时,进行EP域的AllToAllV通信。|默认确定性实现|默认确定性实现|默认确定性实现|
166|[aclnnMoeDistributeDispatchV4](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV4.md)|对token数据进行量化,当存在TP域通信时,先进行EP域的AllToAllV通信,再进行TP域的AllGatherV通信;当不存在TP域通信时,进行EP域的AllToAllV通信。|默认确定性实现|默认确定性实现|默认确定性实现|164|[aclnnMoeDistributeDispatchV4](../../mc2/moe_distribute_dispatch_v2/docs/aclnnMoeDistributeDispatchV4.md)|对token数据进行量化,当存在TP域通信时,先进行EP域的AllToAllV通信,再进行TP域的AllGatherV通信;当不存在TP域通信时,进行EP域的AllToAllV通信。|默认确定性实现|默认确定性实现|默认确定性实现|
167-|[aclnnMoeDistributeDispatchSetup](../../mc2/moe_distribute_dispatch_setup/docs/aclnnMoeDistributeDispatchSetup.md)|对Token数据进行量化(可选),根据token选择的topK专家在EP(Expert Parallelism)域的AllToAllV通信,只进行数据发送和通信状态发送,通信指令发出后算子即刻退出,无需等待通信完成。数据的接收和后处理由aclnnMoeDistributeDispatchTeardown接口完成。|-|-|默认确定性实现|
168-|[aclnnMoeDistributeDispatchTeardown](../../mc2/moe_distribute_dispatch_teardown/docs/aclnnMoeDistributeDispatchTeardown.md)|接收MoE层EP(Expert Parallelism)域的AllToAllV通信发过来的数据,数据发送端由aclnnMoeDistributeDispatchSetup完成,本接口内完成通信状态确认和数据整理。|-|-|默认确定性实现|
169|[aclnnMoeFinalizeRouting](../../moe/moe_finalize_routing/docs/aclnnMoeFinalizeRouting.md)|MoE计算中,最后处理合并MoE FFN的输出结果。|默认确定性实现|默认确定性实现|-|165|[aclnnMoeFinalizeRouting](../../moe/moe_finalize_routing/docs/aclnnMoeFinalizeRouting.md)|MoE计算中,最后处理合并MoE FFN的输出结果。|默认确定性实现|默认确定性实现|-|
170|[aclnnMoeFinalizeRoutingV2](../../moe/moe_finalize_routing_v2/docs/aclnnMoeFinalizeRoutingV2.md)|MoE计算中,最后处理合并MoE FFN的输出结果,支持配置dropPadMode。|默认确定性实现|默认确定性实现|默认确定性实现|166|[aclnnMoeFinalizeRoutingV2](../../moe/moe_finalize_routing_v2/docs/aclnnMoeFinalizeRoutingV2.md)|MoE计算中,最后处理合并MoE FFN的输出结果,支持配置dropPadMode。|默认确定性实现|默认确定性实现|默认确定性实现|
171|[aclnnMoeFinalizeRoutingV2Grad](../../moe/moe_finalize_routing_v2_grad/docs/aclnnMoeFinalizeRoutingV2Grad.md)|aclnnMoeFinalizeRoutingV2的反向传播。|默认确定性实现|默认确定性实现|默认确定性实现|167|[aclnnMoeFinalizeRoutingV2Grad](../../moe/moe_finalize_routing_v2_grad/docs/aclnnMoeFinalizeRoutingV2Grad.md)|aclnnMoeFinalizeRoutingV2的反向传播。|默认确定性实现|默认确定性实现|默认确定性实现|
@@ -36,10 +36,6 @@ const std::string DISTRIBUTE_BARRIER_OP_TYPE = "DistributeBarrier";
36const std::string MOE_DISTRIBUTE_DISPATCH_V2_OP_TYPE = "MoeDistributeDispatchV2";36const std::string MOE_DISTRIBUTE_DISPATCH_V2_OP_TYPE = "MoeDistributeDispatchV2";
37const std::string MOE_DISTRIBUTE_COMBINE_V2_OP_TYPE = "MoeDistributeCombineV2";37const std::string MOE_DISTRIBUTE_COMBINE_V2_OP_TYPE = "MoeDistributeCombineV2";
38const std::string MOE_DISTRIBUTE_COMBINE_ADD_RMS_NORM_OP_TYPE = "MoeDistributeCombineAddRmsNorm";38const std::string MOE_DISTRIBUTE_COMBINE_ADD_RMS_NORM_OP_TYPE = "MoeDistributeCombineAddRmsNorm";
39-const std::string MOE_DISTRIBUTE_COMBINE_SETUP_OP_TYPE = "MoeDistributeCombineSetup";
40-const std::string MOE_DISTRIBUTE_COMBINE_TEARDOWN_OP_TYPE = "MoeDistributeCombineTeardown";
41-const std::string MOE_DISTRIBUTE_DISPATCH_SETUP_OP_TYPE = "MoeDistributeDispatchSetup";
42-const std::string MOE_DISTRIBUTE_DISPATCH_TEARDOWN_OP_TYPE = "MoeDistributeDispatchTeardown";
43const std::string ALLTO_ALLV_GROUPED_MAT_MUL_OP_TYPE = "AlltoAllvGroupedMatMul";39const std::string ALLTO_ALLV_GROUPED_MAT_MUL_OP_TYPE = "AlltoAllvGroupedMatMul";
44const std::string GROUPED_MAT_MUL_ALLTO_ALLV_OP_TYPE = "GroupedMatMulAlltoAllv";40const std::string GROUPED_MAT_MUL_ALLTO_ALLV_OP_TYPE = "GroupedMatMulAlltoAllv";
45const std::string ALL_TO_ALLV_QUANT_GROUPED_MM_OP_TYPE = "AlltoAllvQuantGroupedMatMul";41const std::string ALL_TO_ALLV_QUANT_GROUPED_MM_OP_TYPE = "AlltoAllvQuantGroupedMatMul";
@@ -48,7 +44,6 @@ const std::string ATTENTION_TO_FFN_OP_TYPE = "AttentionToFFN";
48const std::string FFN_TO_ATTENTION_OP_TYPE = "FFNToAttention";44const std::string FFN_TO_ATTENTION_OP_TYPE = "FFNToAttention";
49const int32_t GROUP_CNT_OF_DS_TRAINING = 1;45const int32_t GROUP_CNT_OF_DS_TRAINING = 1;
50const int32_t GROUP_CNT_OF_MOE_DISTRIBUTE = 2;46const int32_t GROUP_CNT_OF_MOE_DISTRIBUTE = 2;
51-const int32_t ONE_GROUP_CNT_OF_MOE_DISTRIBUTE = 1;
52const int32_t GROUP_CNT_OF_DISTRIBUTE_BARRIER = 1;47const int32_t GROUP_CNT_OF_DISTRIBUTE_BARRIER = 1;
53const int32_t GROUP_CNT_OF_ATTENTION_FFN = 1;48const int32_t GROUP_CNT_OF_ATTENTION_FFN = 1;
54const int32_t GROUP_CNT = 2;49const int32_t GROUP_CNT = 2;
@@ -70,10 +65,6 @@ static const std::map<const std::string, int32_t> GROUP_CNT_MAP{
70 {MOE_DISTRIBUTE_DISPATCH_V2_OP_TYPE, GROUP_CNT_OF_MOE_DISTRIBUTE},65 {MOE_DISTRIBUTE_DISPATCH_V2_OP_TYPE, GROUP_CNT_OF_MOE_DISTRIBUTE},
71 {MOE_DISTRIBUTE_COMBINE_V2_OP_TYPE, GROUP_CNT_OF_MOE_DISTRIBUTE},66 {MOE_DISTRIBUTE_COMBINE_V2_OP_TYPE, GROUP_CNT_OF_MOE_DISTRIBUTE},
72 {MOE_DISTRIBUTE_COMBINE_ADD_RMS_NORM_OP_TYPE, GROUP_CNT_OF_MOE_DISTRIBUTE},67 {MOE_DISTRIBUTE_COMBINE_ADD_RMS_NORM_OP_TYPE, GROUP_CNT_OF_MOE_DISTRIBUTE},
73- {MOE_DISTRIBUTE_COMBINE_SETUP_OP_TYPE, ONE_GROUP_CNT_OF_MOE_DISTRIBUTE},
74- {MOE_DISTRIBUTE_COMBINE_TEARDOWN_OP_TYPE, ONE_GROUP_CNT_OF_MOE_DISTRIBUTE},
75- {MOE_DISTRIBUTE_DISPATCH_SETUP_OP_TYPE, ONE_GROUP_CNT_OF_MOE_DISTRIBUTE},
76- {MOE_DISTRIBUTE_DISPATCH_TEARDOWN_OP_TYPE, ONE_GROUP_CNT_OF_MOE_DISTRIBUTE},
77 {ALLTO_ALLV_GROUPED_MAT_MUL_OP_TYPE, GROUP_CNT_OF_DS_TRAINING},68 {ALLTO_ALLV_GROUPED_MAT_MUL_OP_TYPE, GROUP_CNT_OF_DS_TRAINING},
78 {GROUPED_MAT_MUL_ALLTO_ALLV_OP_TYPE, GROUP_CNT_OF_DS_TRAINING},69 {GROUPED_MAT_MUL_ALLTO_ALLV_OP_TYPE, GROUP_CNT_OF_DS_TRAINING},
79 {ALL_TO_ALLV_QUANT_GROUPED_MM_OP_TYPE, GROUP_CNT_OF_DS_TRAINING},70 {ALL_TO_ALLV_QUANT_GROUPED_MM_OP_TYPE, GROUP_CNT_OF_DS_TRAINING},
@@ -85,8 +76,6 @@ static const std::unordered_set<std::string> NO_AI_CPU_SET{MOE_DISTRIBUTE_DISPAT
85 MOE_DISTRIBUTE_COMBINE_OP_TYPE,76 MOE_DISTRIBUTE_COMBINE_OP_TYPE,
86 MOE_DISTRIBUTE_DISPATCH_V2_OP_TYPE,77 MOE_DISTRIBUTE_DISPATCH_V2_OP_TYPE,
87 MOE_DISTRIBUTE_COMBINE_V2_OP_TYPE,78 MOE_DISTRIBUTE_COMBINE_V2_OP_TYPE,
88- MOE_DISTRIBUTE_DISPATCH_TEARDOWN_OP_TYPE,
89- MOE_DISTRIBUTE_COMBINE_TEARDOWN_OP_TYPE,
90 MOE_DISTRIBUTE_COMBINE_ADD_RMS_NORM_OP_TYPE,79 MOE_DISTRIBUTE_COMBINE_ADD_RMS_NORM_OP_TYPE,
91 DISTRIBUTE_BARRIER_OP_TYPE,80 DISTRIBUTE_BARRIER_OP_TYPE,
92 ATTENTION_TO_FFN_OP_TYPE,81 ATTENTION_TO_FFN_OP_TYPE,
@@ -300,10 +289,6 @@ ge::Status Mc2MoeGenTaskOpsUtils::Mc2MoeGenTaskCallback(const gert::ExeResGenera
300 return ge::GRAPH_SUCCESS;289 return ge::GRAPH_SUCCESS;
301 }290 }
302 291 
303- const std::string opTypeStr = opType; // 和V2的差异点,待确认,应该可以整合为一,用V2的if逻辑即可
304- if (opTypeStr == MOE_DISTRIBUTE_COMBINE_TEARDOWN_OP_TYPE || opTypeStr == MOE_DISTRIBUTE_DISPATCH_TEARDOWN_OP_TYPE) {
305- return ge::GRAPH_SUCCESS;
306- }
307 return Mc2MoeInsertTask(context, tasks, groupCnt);292 return Mc2MoeInsertTask(context, tasks, groupCnt);
308}293}
309 294 
@@ -82,14 +82,13 @@ TEST_F(GroupedMatMulAllReduceInfershape, Runtime0)
82 outputShapeRef[3] = &yShape3;82 outputShapeRef[3] = &yShape3;
83 auto contextHolder = gert::InferShapeContextFaker()83 auto contextHolder = gert::InferShapeContextFaker()
84 .SetOpType("GroupedMatMulAllReduce")84 .SetOpType("GroupedMatMulAllReduce")
85- .NodeIoNum(8, 4)85+ .IrInstanceNum({4, 4, 0}, {4})
86 .InputTensors(inputShapeRef)86 .InputTensors(inputShapeRef)
87 .OutputShapes(outputShapeRef)87 .OutputShapes(outputShapeRef)
88 .Attr("splitItem", int64_t(0))88 .Attr("splitItem", int64_t(0))
89 .Attr("group", AscendString("group"))89 .Attr("group", AscendString("group"))
90 .Attr("reduceOp", AscendString("sum"))90 .Attr("reduceOp", AscendString("sum"))
91 .Attr("commTurn", int64_t(0))91 .Attr("commTurn", int64_t(0))
92- .IrInstanceNum({4, 4, 0}, {4})
93 .Build();92 .Build();
94 auto context = contextHolder.GetContext();93 auto context = contextHolder.GetContext();
95 ASSERT_NE(context, nullptr);94 ASSERT_NE(context, nullptr);
@@ -141,7 +140,6 @@ TEST_F(GroupedMatMulAllReduceInfershape, Runtime0MultiDim)
141 140 
142 auto contextHolder = gert::InferShapeContextFaker()141 auto contextHolder = gert::InferShapeContextFaker()
143 .SetOpType("GroupedMatMulAllReduce")142 .SetOpType("GroupedMatMulAllReduce")
144- .NodeIoNum(8, 4)
145 .IrInstanceNum({4, 4, 0}, {4})143 .IrInstanceNum({4, 4, 0}, {4})
146 .InputTensors(inputShapeRef)144 .InputTensors(inputShapeRef)
147 .OutputShapes(outputShapeRef)145 .OutputShapes(outputShapeRef)
@@ -220,7 +218,6 @@ TEST_F(GroupedMatMulAllReduceInfershape, Runtime1)
220 218 
221 auto contextHolder = gert::InferShapeContextFaker()219 auto contextHolder = gert::InferShapeContextFaker()
222 .SetOpType("GroupedMatMulAllReduce")220 .SetOpType("GroupedMatMulAllReduce")
223- .NodeIoNum(6, 4)
224 .IrInstanceNum({1, 4, 0}, {4})221 .IrInstanceNum({1, 4, 0}, {4})
225 .InputTensors(inputShapeRef)222 .InputTensors(inputShapeRef)
226 .OutputShapes(outputShapeRef)223 .OutputShapes(outputShapeRef)
@@ -302,7 +299,6 @@ TEST_F(GroupedMatMulAllReduceInfershape, Runtime1NonIncreasingGroupList)
302 299 
303 auto contextHolder = gert::InferShapeContextFaker()300 auto contextHolder = gert::InferShapeContextFaker()
304 .SetOpType("GroupedMatMulAllReduce")301 .SetOpType("GroupedMatMulAllReduce")
305- .NodeIoNum(6, 4)
306 .IrInstanceNum({1, 4, 0}, {4})302 .IrInstanceNum({1, 4, 0}, {4})
307 .InputTensors(inputShapeRef)303 .InputTensors(inputShapeRef)
308 .OutputShapes(outputShapeRef)304 .OutputShapes(outputShapeRef)
@@ -351,7 +347,6 @@ TEST_F(GroupedMatMulAllReduceInfershape, Runtime2)
351 347 
352 auto contextHolder = gert::InferShapeContextFaker()348 auto contextHolder = gert::InferShapeContextFaker()
353 .SetOpType("GroupedMatMulAllReduce")349 .SetOpType("GroupedMatMulAllReduce")
354- .NodeIoNum(8, 1)
355 .IrInstanceNum({4, 4, 0}, {1})350 .IrInstanceNum({4, 4, 0}, {1})
356 .InputTensors(inputShapeRef)351 .InputTensors(inputShapeRef)
357 .OutputShapes(outputShapeRef)352 .OutputShapes(outputShapeRef)
@@ -414,7 +409,6 @@ TEST_F(GroupedMatMulAllReduceInfershape, Runtime3)
414 409 
415 auto contextHolder = gert::InferShapeContextFaker()410 auto contextHolder = gert::InferShapeContextFaker()
416 .SetOpType("GroupedMatMulAllReduce")411 .SetOpType("GroupedMatMulAllReduce")
417- .NodeIoNum(6, 1)
418 .IrInstanceNum({1, 4, 0}, {1})412 .IrInstanceNum({1, 4, 0}, {1})
419 .InputTensors(inputShapeRef)413 .InputTensors(inputShapeRef)
420 .OutputShapes(outputShapeRef)414 .OutputShapes(outputShapeRef)
@@ -453,8 +447,7 @@ TEST_F(GroupedMatMulAllReduceInfershape, InferShapeFor2dim)
453 inputShapeRef[3] = (gert::Tensor*)&groupListShape;447 inputShapeRef[3] = (gert::Tensor*)&groupListShape;
454 auto contextHolder = gert::InferShapeContextFaker()448 auto contextHolder = gert::InferShapeContextFaker()
455 .SetOpType("GroupedMatMulAllReduce")449 .SetOpType("GroupedMatMulAllReduce")
456- .NodeIoNum(4, 1)450+ .IrInstanceNum({1, 1, 1, 1}, {1})
457- .IrInstanceNum({1, 1, 1}, {1})
458 .InputTensors(inputShapeRef)451 .InputTensors(inputShapeRef)
459 .OutputShapes({&outputShape})452 .OutputShapes({&outputShape})
460 .Attr("splitItem", int64_t(0))453 .Attr("splitItem", int64_t(0))
@@ -488,8 +481,7 @@ TEST_F(GroupedMatMulAllReduceInfershape, InferShapeFor3dim)
488 481 
489 auto contextHolder = gert::InferShapeContextFaker()482 auto contextHolder = gert::InferShapeContextFaker()
490 .SetOpType("GroupedMatMulAllReduce")483 .SetOpType("GroupedMatMulAllReduce")
491- .NodeIoNum(4, 1)484+ .IrInstanceNum({1, 1, 1, 1}, {1})
492- .IrInstanceNum({1, 1, 1}, {1})
493 .InputTensors(inputShapeRef)485 .InputTensors(inputShapeRef)
494 .OutputShapes({&outputShape})486 .OutputShapes({&outputShape})
495 .Attr("splitItem", int64_t(0))487 .Attr("splitItem", int64_t(0))
@@ -522,8 +514,7 @@ TEST_F(GroupedMatMulAllReduceInfershape, InferShapeForinvalidK)
522 inputShapeRef[3] = (gert::Tensor*)&groupListShape;514 inputShapeRef[3] = (gert::Tensor*)&groupListShape;
523 auto contextHolder = gert::InferShapeContextFaker()515 auto contextHolder = gert::InferShapeContextFaker()
524 .SetOpType("GroupedMatMulAllReduce")516 .SetOpType("GroupedMatMulAllReduce")
525- .NodeIoNum(4, 1)517+ .IrInstanceNum({1, 1, 1, 1}, {1})
526- .IrInstanceNum({1, 1, 1}, {1})
527 .InputTensors(inputShapeRef)518 .InputTensors(inputShapeRef)
528 .OutputShapes({&outputShape})519 .OutputShapes({&outputShape})
529 .Attr("splitItem", int64_t(0))520 .Attr("splitItem", int64_t(0))
@@ -555,8 +546,7 @@ TEST_F(GroupedMatMulAllReduceInfershape, InferShapeForzeroK)
555 inputShapeRef[3] = (gert::Tensor*)&groupListShape;546 inputShapeRef[3] = (gert::Tensor*)&groupListShape;
556 auto contextHolder = gert::InferShapeContextFaker()547 auto contextHolder = gert::InferShapeContextFaker()
557 .SetOpType("GroupedMatMulAllReduce")548 .SetOpType("GroupedMatMulAllReduce")
558- .NodeIoNum(4, 1)549+ .IrInstanceNum({1, 1, 1, 1}, {1})
559- .IrInstanceNum({1, 1, 1}, {1})
560 .InputTensors(inputShapeRef)550 .InputTensors(inputShapeRef)
561 .OutputShapes({&outputShape})551 .OutputShapes({&outputShape})
562 .Attr("splitItem", int64_t(0))552 .Attr("splitItem", int64_t(0))
@@ -579,7 +569,6 @@ TEST_F(GroupedMatMulAllReduceInfershape, InferDtype)
579 569 
580 auto contextHolder = gert::InferDataTypeContextFaker()570 auto contextHolder = gert::InferDataTypeContextFaker()
581 .SetOpType("GroupedMatMulAllReduce")571 .SetOpType("GroupedMatMulAllReduce")
582- .NodeIoNum(2, 1)
583 .IrInstanceNum({1, 1}, {1})572 .IrInstanceNum({1, 1}, {1})
584 .NodeInputTd(0, x1Dtype, ge::FORMAT_ND, ge::FORMAT_ND)573 .NodeInputTd(0, x1Dtype, ge::FORMAT_ND, ge::FORMAT_ND)
585 .NodeInputTd(1, x2Dtype, ge::FORMAT_ND, ge::FORMAT_ND)574 .NodeInputTd(1, x2Dtype, ge::FORMAT_ND, ge::FORMAT_ND)
@@ -622,7 +611,6 @@ TEST_F(GroupedMatMulAllReduceInfershape, InferDtypeTestRuntime2)
622 611 
623 auto contextHolder = gert::InferDataTypeContextFaker()612 auto contextHolder = gert::InferDataTypeContextFaker()
624 .SetOpType("GroupedMatMulAllReduce")613 .SetOpType("GroupedMatMulAllReduce")
625- .NodeIoNum(2, 1)
626 .IrInstanceNum({1, 1}, {1})614 .IrInstanceNum({1, 1}, {1})
627 .NodeInputTd(0, xDtype0, ge::FORMAT_ND, ge::FORMAT_ND)615 .NodeInputTd(0, xDtype0, ge::FORMAT_ND, ge::FORMAT_ND)
628 .NodeInputTd(1, xDtype1, ge::FORMAT_ND, ge::FORMAT_ND)616 .NodeInputTd(1, xDtype1, ge::FORMAT_ND, ge::FORMAT_ND)
@@ -1,3 +1,3 @@
1# MoeDistributeCombineSetup1# MoeDistributeCombineSetup
2 2 
3-本目录仅包含MoeDistributeCombineSetup算子对应的aclnn接口;如您想要贡献该算子的Ascend C实现,请参考[贡献流程](../../CONTRIBUTING.md)。3+本目录包含MoeDistributeCombineSetup算子的实现,不提供公开的aclnn接口;如您想要为该算子贡献代码,请参考[贡献流程](../../CONTRIBUTING.md)。
@@ -1,356 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file test_aclnn_moe_distribute_combine_setup.cpp
13- * \brief aclnn直调测试脚本
14- */
15- 
16-#include <thread>
17-#include <iostream>
18-#include <string>
19-#include <vector>
20-#include <cstring>
21-#include "acl/acl.h"
22-#include "hccl/hccl.h"
23-#include "aclnnop/aclnn_moe_distribute_combine_setup.h"
24-#include "aclnnop/aclnn_moe_distribute_combine_teardown.h"
25- 
26-#define CHECK_RET(cond, return_expr) \
27- do { \
28- if (!(cond)) { \
29- return_expr; \
30- } \
31- } while (0)
32- 
33-#define LOG_PRINT(message, ...) \
34- do { \
35- printf(message, ##__VA_ARGS__); \
36- } while (0)
37- 
38-constexpr int DEV_NUM = 2;
39- 
40-template <typename Func>
41-class Guard {
42-public:
43- explicit Guard(Func& func)
44- : func_(func)
45- {}
46- ~Guard()
47- {
48- func_();
49- }
50- 
51-private:
52- Func& func_;
53-};
54- 
55-int64_t AlignN(int64_t x, int64_t n)
56-{
57- return (x + n - 1) / n * n;
58-}
59- 
60-int64_t GetShapeSize(const std::vector<int64_t>& shape)
61-{
62- int64_t shape_size = 1;
63- for (auto i : shape) {
64- shape_size *= i;
65- }
66- return shape_size;
67-}
68- 
69-struct Args {
70- uint32_t rankId;
71- uint32_t epRankId;
72- HcclComm hcclEpComm;
73- aclrtStream combinesetupstream;
74- aclrtStream combineteardownstream;
75- aclrtContext context;
76-};
77- 
78-template <typename T>
79-int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr,
80- aclDataType dataType, aclTensor** tensor)
81-{
82- auto size = GetShapeSize(shape) * sizeof(T);
83- auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
84- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtMalloc failed. ret: %d\n", ret); return ret);
85- 
86- ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
87- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtMemcpy failed. ret: %d\n", ret); return ret);
88- std::vector<int64_t> strides(shape.size(), 1);
89- for (int64_t i = shape.size() - 2; i >= 0; i--) {
90- strides[i] = shape[i + 1] * strides[i + 1];
91- }
92- *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND,
93- shape.data(), shape.size(), *deviceAddr);
94- return 0;
95-}
96- 
97-void DestroyTensor(aclTensor* tensor)
98-{
99- if (tensor != nullptr) {
100- aclDestroyTensor(tensor);
101- }
102-}
103- 
104-void FreeDeviceAddr(void* deviceAddr)
105-{
106- if (deviceAddr != nullptr) {
107- aclrtFree(deviceAddr);
108- }
109-}
110- 
111-int LaunchOneProcess(Args& args)
112-{
113- int ret = aclrtSetCurrentContext(args.context);
114- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtSetCurrentContext failed. ret: %d\n", ret); return ret);
115- 
116- char hcomEpName[128] = {0};
117- ret = HcclGetCommName(args.hcclEpComm, hcomEpName);
118- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] HcclGetCommName failed. ret: %d\n", ret); return ret);
119- 
120- auto destroyFunc = [&args]() {
121- std::cout << "== begin to destroy " << std::endl;
122- HcclCommDestroy(args.hcclEpComm);
123- aclrtDestroyStream(args.combinesetupstream);
124- aclrtDestroyStream(args.combineteardownstream);
125- aclrtDestroyContext(args.context);
126- aclrtResetDevice(args.rankId);
127- };
128- auto guard = Guard<decltype(destroyFunc)>(destroyFunc);
129- 
130- // 场景参数
131- int64_t bs = 16;
132- int64_t h = 4096;
133- int64_t k = 6;
134- int64_t expertShardType = 0;
135- int64_t sharedExpertNum = 0;
136- int64_t sharedExpertRankNum = 0;
137- int64_t moeExpertNum = 32;
138- int64_t commQuantMode = 0;
139- int64_t tpWorldSize = 1;
140- int64_t epWorldSize = DEV_NUM;
141- int64_t commType = 2;
142- int64_t timeOut = 100000000;
143- 
144- int64_t globalBS = bs * epWorldSize;
145- int64_t localExpertNum;
146- int64_t localToken;
147- 
148- if (args.epRankId < sharedExpertRankNum) {
149- localExpertNum = 1;
150- localToken = globalBS / sharedExpertRankNum;
151- } else {
152- localExpertNum = moeExpertNum / (epWorldSize - sharedExpertRankNum);
153- localToken = globalBS * (localExpertNum < k ? localExpertNum : k);
154- }
155- 
156- uint64_t assistInfoForCombineOutSize = localToken * 128;
157- 
158- // 定义 shape
159- std::vector<int64_t> expandXShape{tpWorldSize * localToken, h};
160- std::vector<int64_t> expertIdsShape{bs, k};
161- std::vector<int64_t> expertScalesShape{bs, k};
162- std::vector<int64_t> expandIdxShape{bs * k};
163- std::vector<int64_t> assistInfoForCombineOutShape{assistInfoForCombineOutSize};
164- std::vector<int64_t> quantExpandXOutShape{tpWorldSize * localToken,
165- AlignN(AlignN(h, 32) + AlignN(h, 8) / 8 * sizeof(float), 512)};
166- std::vector<int64_t> commCmdInfoOutShapeforcombine{(localToken + epWorldSize) * 16};
167- std::vector<int64_t> xOutShape{bs, h};
168- 
169- int64_t expandXShapeSize = GetShapeSize(expandXShape);
170- int64_t expertIdsShapeSize = GetShapeSize(expertIdsShape);
171- int64_t expertScalesShapeSize = GetShapeSize(expertScalesShape);
172- int64_t expandIdxShapeSize = GetShapeSize(expandIdxShape);
173- int64_t assistInfoForCombineOutShapeSize = GetShapeSize(assistInfoForCombineOutShape);
174- int64_t quantExpandXOutShapeSize = GetShapeSize(quantExpandXOutShape);
175- int64_t commCmdInfoOutShapeSizeforcombine = GetShapeSize(commCmdInfoOutShapeforcombine);
176- int64_t xOutShapeSize = GetShapeSize(xOutShape);
177- 
178- // 构造 host 数据
179- std::vector<int16_t> expandXHostData(expandXShapeSize, 0);
180- std::vector<int32_t> expertIdsHostData;
181- for (int32_t token_id = 0; token_id < expertIdsShape[0]; token_id++) {
182- for (int32_t k_id = 0; k_id < expertIdsShape[1]; k_id++) {
183- expertIdsHostData.push_back(k_id);
184- }
185- }
186- std::vector<float> expertScalesHostData(expertScalesShapeSize, 0);
187- std::vector<int32_t> expandIdxHostData(expandIdxShapeSize, 0);
188- std::vector<int32_t> assistInfoForCombineOutHostData(assistInfoForCombineOutShapeSize, 0);
189- std::vector<int8_t> quantExpandXOutHostData(quantExpandXOutShapeSize, 0);
190- std::vector<int32_t> commCmdInfoOutforCombineHostData(commCmdInfoOutShapeSizeforcombine, 0);
191- std::vector<float> xOutHostData(xOutShapeSize, 0);
192- 
193- // 声明 device 地址和 tensor
194- void* expandXDeviceAddr = nullptr;
195- void* expertIdsDeviceAddr = nullptr;
196- void* expertScalesDeviceAddr = nullptr;
197- void* expandIdxDeviceAddr = nullptr;
198- void* assistInfoForCombineOutDeviceAddr = nullptr;
199- void* quantExpandXOutDeviceAddr = nullptr;
200- void* commCmdInfoOutforCombineDeviceAddr = nullptr;
201- void* xOutDeviceAddr = nullptr;
202- 
203- aclTensor* expandX = nullptr;
204- aclTensor* expertIds = nullptr;
205- aclTensor* expertScales = nullptr;
206- aclTensor* expandIdx = nullptr;
207- aclTensor* assistInfoForCombineOut = nullptr;
208- aclTensor* quantExpandXOut = nullptr;
209- aclTensor* commCmdInfoOutforCombine = nullptr;
210- aclTensor* xOut = nullptr;
211- 
212- // 创建 tensor
213- ret = CreateAclTensor(expandXHostData, expandXShape, &expandXDeviceAddr, aclDataType::ACL_FLOAT16, &expandX);
214- CHECK_RET(ret == ACL_SUCCESS, return ret);
215- ret = CreateAclTensor(expertIdsHostData, expertIdsShape, &expertIdsDeviceAddr, aclDataType::ACL_INT32, &expertIds);
216- CHECK_RET(ret == ACL_SUCCESS, return ret);
217- ret = CreateAclTensor(expertScalesHostData, expertScalesShape, &expertScalesDeviceAddr, aclDataType::ACL_FLOAT,
218- &expertScales);
219- CHECK_RET(ret == ACL_SUCCESS, return ret);
220- ret = CreateAclTensor(expandIdxHostData, expandIdxShape, &expandIdxDeviceAddr, aclDataType::ACL_INT32, &expandIdx);
221- CHECK_RET(ret == ACL_SUCCESS, return ret);
222- ret = CreateAclTensor(assistInfoForCombineOutHostData, assistInfoForCombineOutShape,
223- &assistInfoForCombineOutDeviceAddr, aclDataType::ACL_INT32, &assistInfoForCombineOut);
224- CHECK_RET(ret == ACL_SUCCESS, return ret);
225- ret = CreateAclTensor(quantExpandXOutHostData, quantExpandXOutShape, &quantExpandXOutDeviceAddr,
226- aclDataType::ACL_INT8, &quantExpandXOut);
227- CHECK_RET(ret == ACL_SUCCESS, return ret);
228- ret = CreateAclTensor(commCmdInfoOutforCombineHostData, commCmdInfoOutShapeforcombine,
229- &commCmdInfoOutforCombineDeviceAddr, aclDataType::ACL_INT32, &commCmdInfoOutforCombine);
230- CHECK_RET(ret == ACL_SUCCESS, return ret);
231- ret = CreateAclTensor(xOutHostData, xOutShape, &xOutDeviceAddr, aclDataType::ACL_FLOAT16, &xOut);
232- CHECK_RET(ret == ACL_SUCCESS, return ret);
233- 
234- // 声明算子执行必需变量
235- uint64_t workspaceSize = 0;
236- aclOpExecutor* executor = nullptr;
237- void* workspaceAddr = nullptr;
238- 
239- /******************************调用combine_setup********************************************/
240- ret = aclnnMoeDistributeCombineSetupGetWorkspaceSize(
241- expandX, expertIds, assistInfoForCombineOut, hcomEpName, epWorldSize, args.epRankId, moeExpertNum,
242- expertShardType, sharedExpertNum, sharedExpertRankNum, globalBS, commQuantMode, commType, nullptr,
243- quantExpandXOut, commCmdInfoOutforCombine, &workspaceSize, &executor);
244- CHECK_RET(ret == ACL_SUCCESS,
245- LOG_PRINT("[ERROR] aclnnMoeDistributeCombineSetupGetWorkspaceSize failed. ret = %d \n", ret);
246- return ret);
247- 
248- if (workspaceSize > 0) {
249- ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
250- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] CombineSetup aclrtMalloc failed. ret = %d\n", ret);
251- return ret);
252- }
253- 
254- ret = aclnnMoeDistributeCombineSetup(workspaceAddr, workspaceSize, executor, args.combinesetupstream);
255- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclnnMoeDistributeCombineSetup failed. ret = %d \n", ret);
256- return ret);
257- 
258- ret = aclrtSynchronizeStreamWithTimeout(args.combinesetupstream, timeOut);
259- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtSynchronizeStreamWithTimeout failed. ret = %d \n", ret);
260- return ret);
261- LOG_PRINT("[INFO] device_%d aclnnMoeDistributeCombineSetup execute successfully.\n", args.rankId);
262- 
263- /******************************调用combine_teardown********************************************/
264- ret = aclnnMoeDistributeCombineTeardownGetWorkspaceSize(
265- expandX, quantExpandXOut, expertIds, expandIdx, expertScales, commCmdInfoOutforCombine, nullptr, nullptr,
266- hcomEpName, epWorldSize, args.epRankId, moeExpertNum, expertShardType, sharedExpertNum, sharedExpertRankNum,
267- globalBS, commQuantMode, commType, nullptr, xOut, &workspaceSize, &executor);
268- CHECK_RET(ret == ACL_SUCCESS,
269- LOG_PRINT("[ERROR] aclnnMoeDistributeCombineTeardownGetWorkspaceSize failed. ret = %d \n", ret);
270- return ret);
271- 
272- if (workspaceSize > 0) {
273- ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
274- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] CombineTeardown aclrtMalloc failed. ret = %d\n", ret);
275- return ret);
276- }
277- 
278- ret = aclnnMoeDistributeCombineTeardown(workspaceAddr, workspaceSize, executor, args.combineteardownstream);
279- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclnnMoeDistributeCombineTeardown failed. ret = %d \n", ret);
280- return ret);
281- 
282- ret = aclrtSynchronizeStreamWithTimeout(args.combineteardownstream, timeOut);
283- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtSynchronizeStreamWithTimeout failed. ret = %d \n", ret);
284- return ret);
285- LOG_PRINT("[INFO] device_%d aclnnMoeDistributeCombineTeardown execute successfully.\n", args.rankId);
286- 
287- // 释放资源
288- if (workspaceSize > 0) {
289- aclrtFree(workspaceAddr);
290- }
291- DestroyTensor(expandX);
292- DestroyTensor(expertIds);
293- DestroyTensor(expertScales);
294- DestroyTensor(expandIdx);
295- DestroyTensor(assistInfoForCombineOut);
296- DestroyTensor(quantExpandXOut);
297- DestroyTensor(commCmdInfoOutforCombine);
298- DestroyTensor(xOut);
299- 
300- FreeDeviceAddr(expandXDeviceAddr);
301- FreeDeviceAddr(expertIdsDeviceAddr);
302- FreeDeviceAddr(expertScalesDeviceAddr);
303- FreeDeviceAddr(expandIdxDeviceAddr);
304- FreeDeviceAddr(assistInfoForCombineOutDeviceAddr);
305- FreeDeviceAddr(quantExpandXOutDeviceAddr);
306- FreeDeviceAddr(commCmdInfoOutforCombineDeviceAddr);
307- FreeDeviceAddr(xOutDeviceAddr);
308- 
309- return 0;
310-}
311- 
312-int main(int argc, char* argv[])
313-{
314- int ret = aclInit(nullptr);
315- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclInit failed. ret = %d \n", ret); return ret);
316- 
317- aclrtStream combineSetupStream[DEV_NUM];
318- aclrtStream combineTeardownStream[DEV_NUM];
319- aclrtContext context[DEV_NUM];
320- for (uint32_t rankId = 0; rankId < DEV_NUM; rankId++) {
321- ret = aclrtSetDevice(rankId);
322- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtSetDevice failed. ret = %d \n", ret); return ret);
323- ret = aclrtCreateContext(&context[rankId], rankId);
324- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtCreateContext failed. ret = %d \n", ret); return ret);
325- ret = aclrtCreateStream(&combineSetupStream[rankId]);
326- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtCreateStream failed. ret = %d \n", ret); return ret);
327- ret = aclrtCreateStream(&combineTeardownStream[rankId]);
328- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtCreateStream failed. ret = %d \n", ret); return ret);
329- }
330- 
331- int32_t devices[DEV_NUM];
332- for (int i = 0; i < DEV_NUM; i++) {
333- devices[i] = i;
334- }
335- 
336- HcclComm comms[DEV_NUM];
337- ret = HcclCommInitAll(DEV_NUM, devices, comms);
338- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] HcclCommInitAll failed. ret = %d \n", ret); return ret);
339- 
340- Args args[DEV_NUM];
341- std::vector<std::unique_ptr<std::thread>> threads(DEV_NUM);
342- for (uint32_t rankId = 0; rankId < DEV_NUM; rankId++) {
343- args[rankId].rankId = rankId;
344- args[rankId].epRankId = rankId;
345- args[rankId].hcclEpComm = comms[rankId];
346- args[rankId].combinesetupstream = combineSetupStream[rankId];
347- args[rankId].combineteardownstream = combineTeardownStream[rankId];
348- args[rankId].context = context[rankId];
349- threads[rankId].reset(new (std::nothrow) std::thread(&LaunchOneProcess, std::ref(args[rankId])));
350- }
351- for (uint32_t rankId = 0; rankId < DEV_NUM; rankId++) {
352- threads[rankId]->join();
353- }
354- aclFinalize();
355- return 0;
356-}
@@ -1,224 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file aclnn_moe_distribute_combine_setup.cpp
13- * \brief
14- */
15-#include "aclnn_moe_distribute_combine_setup.h"
16-#include <algorithm>
17-#include "common/utils/op_mc2.h"
18-#include "common/op_host/op_api/mc2_3rd_matmul_util.h"
19-#include "common/utils/op_mc2_def.h"
20-#include "aclnn_kernels/common/op_error_check.h"
21- 
22-#include "aclnnInner_moe_distribute_combine_setup.h"
23-#include "common/op_api/mc2_context.h"
24- 
25-#include "opdev/op_log.h"
26-#include "opdev/common_types.h"
27-#include "opdev/platform.h"
28-#include "op_host/util/op_const_def.h"
29-#include "mc2_log_compat.h"
30- 
31-namespace {
32- 
33-using namespace Mc2Aclnn;
34-using namespace op;
35- 
36-static inline bool CheckEmptyTensor(const aclTensor* tensor, const char* name)
37-{
38- const auto& shape = tensor->GetViewShape();
39- if (shape.GetDimNum() == 0) {
40- OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON("aclnnMoeDistributeCombineSetup", name, "[]",
41- (std::string("The shape of ") + name + " cannot be empty.").c_str());
42- return false;
43- }
44- for (size_t i = 0; i < shape.GetDimNum(); ++i) {
45- if (shape.GetDim(i) <= 0) {
46- OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON("aclnnMoeDistributeCombineSetup", name,
47- std::to_string(shape.GetDim(i)).c_str(),
48- "dimension must be positive");
49- return false;
50- }
51- }
52- return true;
53-}
54- 
55-#define OP_CHECK_EMPTY_TENSOR(tensor, retExpr) \
56- if (!CheckEmptyTensor(tensor, #tensor)) { \
57- retExpr; \
58- }
59- 
60-static constexpr size_t TWO_DIM = 2;
61-static constexpr int64_t ALIGN_8 = 8;
62-static constexpr int64_t ALIGN_32 = 32;
63-static constexpr int64_t ALIGN_512 = 512;
64-static constexpr int64_t COMM_CMD_INFO_BASE = 16;
65- 
66-enum class NnopbaseHcclServerType : uint32_t {
67- NNOPBASE_HCCL_SERVER_TYPE_AICPU = 0,
68- NNOPBASE_HCCL_SERVER_TYPE_MTE,
69- NNOPBASE_HCCL_SERVER_TYPE_CCU,
70- NNOPBASE_HCCL_SERVER_TYPE_END
71-};
72- 
73-static inline int64_t AlignUp(int64_t x, int64_t base)
74-{
75- if (base == 0) {
76- OP_LOGD("AlignUp: base cannot be zero");
77- return 0;
78- }
79- return ((x + base - 1) / base) * base;
80-}
81- 
82-// check nullptr
83-static bool CheckNotNull(const aclTensor* expandX, const aclTensor* expertIds, const aclTensor* assistInfoForCombine,
84- const char* groupEp, aclTensor* quantExpandXOut, aclTensor* commCmdInfoOut)
85-{
86- OP_LOGD("aclnn_moe_distribute_combine_setup CheckNotNull start");
87- OP_CHECK_NULL(expandX, return false);
88- OP_CHECK_NULL(expertIds, return false);
89- OP_CHECK_NULL(assistInfoForCombine, return false);
90- OP_CHECK_NULL(quantExpandXOut, return false);
91- OP_CHECK_NULL(commCmdInfoOut, return false);
92- if ((groupEp == nullptr) || (strnlen(groupEp, HCCL_GROUP_NAME_MAX) == 0)) {
93- OP_LOGE_WITH_INVALID_INPUT("aclnnMoeDistributeCombineSetup", "groupEp");
94- return false;
95- }
96- OP_LOGD("aclnn_moe_distribute_combine_setup CheckNotNull success");
97- return true;
98-}
99- 
100-// 入参校验
101-static aclnnStatus CheckParams(const aclTensor* expandX, const aclTensor* expertIds,
102- const aclTensor* assistInfoForCombine, const char* groupEp, int64_t epWorldSize,
103- int64_t epRankId, int64_t moeExpertNum, int64_t expertShardType, int64_t sharedExpertNum,
104- int64_t sharedExpertRankNum, int64_t globalBs, int64_t commQuantMode, int64_t commType,
105- const char* commAlg, aclTensor* quantExpandXOut, aclTensor* commCmdInfoOut)
106-{
107- (void)epWorldSize;
108- (void)epRankId;
109- (void)moeExpertNum;
110- (void)expertShardType;
111- (void)sharedExpertNum;
112- (void)sharedExpertRankNum;
113- (void)globalBs;
114- (void)commQuantMode;
115- (void)commType;
116- (void)commAlg;
117- OP_LOGD("aclnn_moe_distribute_combine_setup CheckParams start");
118- CHECK_RET(CheckNotNull(expandX, expertIds, assistInfoForCombine, groupEp, quantExpandXOut, commCmdInfoOut),
119- ACLNN_ERR_PARAM_NULLPTR);
120- OP_CHECK_EMPTY_TENSOR(expandX, return ACLNN_ERR_PARAM_INVALID);
121- OP_CHECK_EMPTY_TENSOR(expertIds, return ACLNN_ERR_PARAM_INVALID);
122- OP_CHECK_EMPTY_TENSOR(assistInfoForCombine, return ACLNN_ERR_PARAM_INVALID);
123- OP_CHECK_EMPTY_TENSOR(quantExpandXOut, return ACLNN_ERR_PARAM_INVALID);
124- OP_CHECK_EMPTY_TENSOR(commCmdInfoOut, return ACLNN_ERR_PARAM_INVALID);
125- if (strnlen(groupEp, HCCL_GROUP_NAME_MAX) >= HCCL_GROUP_NAME_MAX) {
126- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON("aclnnMoeDistributeCombineSetup", "groupEp",
127- "length exceeds " + std::to_string(HCCL_GROUP_NAME_MAX),
128- "groupEp name too long");
129- return ACLNN_ERR_PARAM_INVALID;
130- }
131- OP_LOGD("aclnn_moe_distribute_combine_setup CheckParams success");
132- return ACLNN_SUCCESS;
133-}
134- 
135-} // namespace
136- 
137-extern "C" void __attribute__((weak)) NnopbaseSetHcclServerType(void* executor, NnopbaseHcclServerType sType);
138- 
139-extern "C" aclnnStatus aclnnMoeDistributeCombineSetupGetWorkspaceSize(
140- const aclTensor* expandX, const aclTensor* expertIds, const aclTensor* assistInfoForCombine, const char* groupEp,
141- int64_t epWorldSize, int64_t epRankId, int64_t moeExpertNum, int64_t expertShardType, int64_t sharedExpertNum,
142- int64_t sharedExpertRankNum, int64_t globalBs, int64_t commQuantMode, int64_t commType, const char* commAlg,
143- aclTensor* quantExpandXOut, aclTensor* commCmdInfoOut, uint64_t* workspaceSize, aclOpExecutor** executor)
144-{
145- OP_LOGD("aclnnMoeDistributeCombineSetupGetWorkspaceSize start.");
146- if (GetCurrentPlatformInfo().GetCurNpuArch() != Ops::Base::DAV_3510) {
147- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
148- "aclnnMoeDistributeCombineSetup", "npuArch",
149- std::to_string(static_cast<int64_t>(GetCurrentPlatformInfo().GetCurNpuArch())).c_str(),
150- "only support Ops::Base::DAV_3510");
151- return ACLNN_ERR_PARAM_INVALID;
152- }
153- 
154- auto retParam = CheckParams(expandX, expertIds, assistInfoForCombine, groupEp, epWorldSize, epRankId, moeExpertNum,
155- expertShardType, sharedExpertNum, sharedExpertRankNum, globalBs, commQuantMode,
156- commType, commAlg, quantExpandXOut, commCmdInfoOut);
157- CHECK_RET(retParam == ACLNN_SUCCESS, retParam);
158- 
159- aclnnStatus retStatus;
160- uint64_t hcclBuffSize = 0;
161- aclTensor* mc2Context = nullptr;
162- const char* opName = "moe_distribute_a2av_setup_teardown";
163- retStatus = Mc2Aclnn::Mc2Context::GetMc2ContextTensor(groupEp, opName, hcclBuffSize, mc2Context,
164- CommProtocol::COMM_PROTOCOL_UBC_CTP);
165- CHECK_RET(retStatus == ACLNN_SUCCESS, retStatus);
166- retStatus = aclnnInnerMoeDistributeCombineSetupGetWorkspaceSize(
167- mc2Context, expandX, expertIds, assistInfoForCombine, epWorldSize, epRankId, moeExpertNum, hcclBuffSize,
168- expertShardType, sharedExpertNum, sharedExpertRankNum, globalBs, commQuantMode, commType,
169- const_cast<char*>(commAlg), quantExpandXOut, commCmdInfoOut, workspaceSize, executor);
170- return retStatus;
171-}
172- 
173-extern "C" aclnnStatus aclnnMoeDistributeCombineSetupTeardownCalcOutputSize(
174- const aclTensor* expandX, const aclTensor* expertIds, const aclTensor* assistInfoForCombine, const char* groupEp,
175- int64_t epWorldSize, int64_t epRankId, int64_t moeExpertNum, int64_t expertShardType, int64_t sharedExpertNum,
176- int64_t sharedExpertRankNum, int64_t globalBs, int64_t commQuantMode, int64_t commType, const char* commAlg,
177- uint64_t& tokenMsgSize, uint64_t& commCmdInfoOutSize)
178-{
179- (void)expertIds;
180- (void)assistInfoForCombine;
181- (void)groupEp;
182- (void)epRankId;
183- (void)moeExpertNum;
184- (void)expertShardType;
185- (void)sharedExpertNum;
186- (void)sharedExpertRankNum;
187- (void)globalBs;
188- (void)commQuantMode;
189- (void)commType;
190- (void)commAlg;
191- OP_CHECK_NULL(expandX, return ACLNN_ERR_PARAM_NULLPTR);
192- OP_CHECK_EMPTY_TENSOR(expandX, return ACLNN_ERR_PARAM_INVALID);
193- if (expandX->GetViewShape().GetDimNum() != TWO_DIM) {
194- OP_LOGE_FOR_INVALID_SHAPEDIM_WITH_REASON("aclnnMoeDistributeCombineSetup", "expandX",
195- "dim=" + std::to_string(expandX->GetViewShape().GetDimNum()),
196- "The shape dim of expandX must be 2D.");
197- return ACLNN_ERR_PARAM_INVALID;
198- }
199- int64_t a = expandX->GetViewShape().GetDim(0);
200- int64_t h = expandX->GetViewShape().GetDim(1);
201- if (a <= 0 || h <= 0) {
202- OP_LOGE_FOR_INVALID_SHAPE_WITH_REASON("aclnnMoeDistributeCombineSetup", "expandX",
203- "[" + std::to_string(a) + "," + std::to_string(h) + "]",
204- "dimensions must be greater than zero");
205- return ACLNN_ERR_PARAM_INVALID;
206- }
207- 
208- tokenMsgSize =
209- static_cast<uint64_t>(AlignUp(AlignUp(h, ALIGN_32) + AlignUp(h, ALIGN_8) / ALIGN_8 * sizeof(float), ALIGN_512));
210- commCmdInfoOutSize = static_cast<uint64_t>((a + epWorldSize) * COMM_CMD_INFO_BASE);
211- return ACLNN_SUCCESS;
212-}
213- 
214-extern "C" aclnnStatus aclnnMoeDistributeCombineSetup(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor,
215- aclrtStream stream)
216-{
217- OP_LOGD("aclnnMoeDistributeCombineSetup start");
218- if (NnopbaseSetHcclServerType) {
219- NnopbaseSetHcclServerType(executor, NnopbaseHcclServerType::NNOPBASE_HCCL_SERVER_TYPE_MTE);
220- }
221- aclnnStatus ret = aclnnInnerMoeDistributeCombineSetup(workspace, workspaceSize, executor, stream);
222- OP_LOGD("aclnnMoeDistributeCombineSetup success");
223- return ret;
224-}
@@ -1,103 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file aclnn_moe_distribute_combine_setup.h
13- * \brief
14- */
15-#ifndef OP_API_INC_MOE_DISTRIBUTE_COMBINE_SETUP
16-#define OP_API_INC_MOE_DISTRIBUTE_COMBINE_SETUP
17- 
18-#include <string>
19- 
20-#include "aclnn/aclnn_base.h"
21-#include "aclnn_util.h"
22- 
23-#ifdef __cplusplus
24-extern "C" {
25-#endif
26- 
27-/**
28- * 算子功能:进行AlltoAllv通信,将数据写入对端GM。
29- * @brief aclnnMoeDistributeCombineSetup的第一段接口,根据具体的计算流程,计算workspace大小。
30- * @domain aclnn_ops_infer
31- * @param [in] expandX: 计算输入,Tensor,数据类型float16,bfloat16,必须为2维,数据格式支持ND。
32- * @param [in] expertIds: 计算输入,Tensor,数据类型int32,必须为2维,数据格式支持ND。
33- * @param [in] assistInfoForCombine: 计算输入,Tensor,数据类型int32,必须为1维,数据格式支持ND。
34- * @param [in] groupEp: 计算输入,str。ep通信域名称,专家并行的通信域。不能和groupTp相同。
35- * @param [in] epWorldSize: 计算输入,int。ep通信域size。
36- * @param [in] epRankId: 计算输入,int。ep本卡Id。同一个EP通信域中各卡的epRankId不重复。
37- * @param [in] moeExpertNum: 计算输入,int。MOE专家数量。
38- * @param [in] expertShardType: 计算可选输入,int。共享专家卡分布类型。当前仅支持传0。
39- * @param [in] sharedExpertNum: 计算可选输入,int。共享专家数量。
40- * @param [in] sharedExpertRankNum: 计算可选输入,int。共享专家卡数量。
41- * @param [in] globalBs: 计算可选输入,int。
42- * @param [in] commQuantMode: 计算可选输入,int。通信量化类型。预留参数,暂未使用,传0即可。
43- * @param [in] commType: 计算可选输入,int。通信方案选择。预留参数,暂未使用,传0即可。
44- * @param [in] commAlg: 计算可选输入,str。通信算法选择。预留参数,暂未使用。
45- * @param [out] quantExpandXOut: 计算输出,Tensor,数据类型支持int8,仅支持2维,数据格式支持ND。表示量化处理后的token。
46- * @param [out] commCmdInfoOut: 计算输出,Tensor,数据类型支持int32,仅支持1维,数据格式支持ND。表示通信的cmd信息。
47- * @param [out] workspaceSize: 出参,返回需要在npu device侧申请的workspace大小。
48- * @param [out] executor: 出参,返回op执行器,包含了算子计算流程。
49- * @return aclnnStatus: 返回值,返回状态码.
50- *
51- */
52-ACLNN_API aclnnStatus aclnnMoeDistributeCombineSetupGetWorkspaceSize(
53- const aclTensor* expandX, const aclTensor* expertIds, const aclTensor* assistInfoForCombine, const char* groupEp,
54- int64_t epWorldSize, int64_t epRankId, int64_t moeExpertNum, int64_t expertShardType, int64_t sharedExpertNum,
55- int64_t sharedExpertRankNum, int64_t globalBs, int64_t commQuantMode, int64_t commType, const char* commAlg,
56- aclTensor* quantExpandXOut, aclTensor* commCmdInfoOut, uint64_t* workspaceSize, aclOpExecutor** executor);
57- 
58-/**
59- * 算子功能:进行AlltoAllv通信,将数据写入对端GM。
60- * @brief 计算aclnnMoeDistributeCombineSetup部分输出的size大小
61- * @domain aclnn_ops_infer
62- * @param [in] expandX: 计算输入,Tensor,数据类型float16,bfloat16,必须为2维,数据格式支持ND。
63- * @param [in] expertIds: 计算输入,Tensor,数据类型int32,必须为2维,数据格式支持ND。
64- * @param [in] assistInfoForCombine: 计算输入,Tensor,数据类型int32,必须为1维,数据格式支持ND。
65- * @param [in] groupEp: 计算输入,str。ep通信域名称,专家并行的通信域。不能和groupTp相同。
66- * @param [in] epWorldSize: 计算输入,int。ep通信域size。
67- * @param [in] epRankId: 计算输入,int。ep本卡Id。同一个EP通信域中各卡的epRankId不重复。
68- * @param [in] moeExpertNum: 计算输入,int。MOE专家数量。
69- * @param [in] expertShardType: 计算可选输入,int。共享专家卡分布类型。当前仅支持传0。
70- * @param [in] sharedExpertNum: 计算可选输入,int。共享专家数量。
71- * @param [in] sharedExpertRankNum: 计算可选输入,int。共享专家卡数量。
72- * @param [in] globalBs: 计算可选输入,int。
73- * @param [in] commQuantMode: 计算可选输入,int。通信量化类型。预留参数,暂未使用,传0即可。
74- * @param [in] commType: 计算可选输入,int。通信方案选择。预留参数,暂未使用,传0即可。
75- * @param [in] commAlg: 计算可选输入,str。通信算法选择。预留参数,暂未使用。
76- * @param [out] tokenMsgSize: 计算输出,int。aclnnMoeDistributeCombineSetup接口quantExpandXOut第二维的大小。
77- * @param [out] commCmdInfoOutSize: 计算输出,int。aclnnMoeDistributeCombineSetup接口commCmdInfoOut的大小。
78- * @return aclnnStatus: 返回值,返回状态码
79- *
80- */
81-ACLNN_API aclnnStatus aclnnMoeDistributeCombineSetupTeardownCalcOutputSize(
82- const aclTensor* expandX, const aclTensor* expertIds, const aclTensor* assistInfoForCombine, const char* groupEp,
83- int64_t epWorldSize, int64_t epRankId, int64_t moeExpertNum, int64_t expertShardType, int64_t sharedExpertNum,
84- int64_t sharedExpertRankNum, int64_t globalBs, int64_t commQuantMode, int64_t commType, const char* commAlg,
85- uint64_t& tokenMsgSize, uint64_t& commCmdInfoOutSize);
86- 
87-/**
88- * @brief aclnnMoeDistributeCombineSetup的第二段接口,用于执行计算。
89- * @param [in] workspace: 在npu device侧申请的workspace内存起址。
90- * @param [in] workspaceSize: 在npu device侧申请的workspace大小,
91- * 由第一段接口aclnnMoeDistributeCombineSetupGetWorkspaceSize获取。
92- * @param [in] executor: op执行器,包含了算子计算流程。
93- * @param [in] stream: acl stream流。
94- * @return aclnnStatus: 返回状态码。
95- */
96-ACLNN_API aclnnStatus aclnnMoeDistributeCombineSetup(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor,
97- aclrtStream stream);
98- 
99-#ifdef __cplusplus
100-}
101-#endif
102- 
103-#endif // OP_API_INC_MOE_DISTRIBUTE_COMBINE_SETUP
@@ -1,13 +0,0 @@
1-# -----------------------------------------------------------------------------------------------------------
2-# Copyright (c) 2026 Huawei Technologies Co., Ltd.
3-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4-# CANN Open Software License Agreement Version 2.0 (the "License").
5-# Please refer to the License for details. You may not use this file except in compliance with the License.
6-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7-# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8-# See LICENSE in the root of the software repository for the full text of the License.
9-# -----------------------------------------------------------------------------------------------------------
10- 
11-if (BUILD_OPEN_PROJECT)
12- add_graph_plugin_sources()
13-endif()
@@ -1,45 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file moe_distribute_combine_setup_gen_task.cpp
13- * \brief
14- */
15-#include <vector>
16- 
17-#include "common/utils/op_mc2.h"
18-#include "platform/platform_info.h"
19- 
20-#include "op_graph/mc2_gen_task_ops_utils.h"
21-#include "op_graph/mc2_moe_gen_task_ops_utils.h"
22-#include "register/op_impl_registry.h"
23-#include "mc2_log.h"
24-namespace ops {
25- 
26-ge::Status MoeDistributeCombineSetupCalcParamFunc(gert::ExeResGenerationContext* context)
27-{
28- const ge::AscendString name = "aicpu kfc server";
29- const ge::AscendString reuseKey = "kfc_stream";
30- OPS_LOG_D(context->GetNodeName(), "Do A3 aicpu CalcParam.");
31- return Mc2GenTaskOpsUtils::CommonKFCMc2CalcParamFunc(context, name, reuseKey);
32-}
33- 
34-ge::Status MoeDistributeCombineSetupGenTaskFunc(const gert::ExeResGenerationContext* context,
35- std::vector<std::vector<uint8_t>>& tasks)
36-{
37- OPS_LOG_I(context->GetNodeName(), "Do A3 aicpu GenTask.");
38- return Mc2MoeGenTaskOpsUtils::Mc2MoeGenTaskCallbackV2(context, tasks);
39-}
40- 
41-// new ver
42-IMPL_OP(MoeDistributeCombineSetup)
43- .CalcOpParam(MoeDistributeCombineSetupCalcParamFunc)
44- .GenerateTask(MoeDistributeCombineSetupGenTaskFunc);
45-} // namespace ops
@@ -1,79 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file moe_distribute_combine_setup_proto.h
13- * \brief 图模式原型定义
14- */
15- 
16-#ifndef MOE_DISTRIBUTE_COMBINE_SETUP_PROTO_H_
17-#define MOE_DISTRIBUTE_COMBINE_SETUP_PROTO_H_
18- 
19-#include "graph/operator_reg.h"
20- 
21-namespace ge {
22- 
23-/**
24- * @brief MoeDistributeCombineSetup operator interface implementation.
25- * @par Inputs
26- * Three inputs, including:
27- * @li context: A tensor. Support dtype: int32, dimension must be 1. Shape supports (2052, ), support format: ND.
28- * @li expand_x: A tensor. Support dtype: float16, bfloat16, dimension must be 2. Shape supports (A, H), support format:
29- * ND.
30- * @li expert_ids: A tensor. Support dtype: int32, indicates top k experts of each token, dimension must be 2. Shape
31- * supports (BS, K), support format: ND.
32- * @li assist_info_for_combine: A tensor. Support dtype: int32, dimension must be 1. Shape supports (N, ), support
33- * format: ND.
34- *
35- * @par Attributes
36- * @li ep_world_size: Required. Input ep comm world size, dtype: int64.
37- * @li ep_rank_id: Required. Input ep comm rank Id, dtype: int64.
38- * @li moe_expert_num: Required. Input moe expert num, dtype: int64.
39- * @li ccl_buffer_size: Required, Input ccl buffer size, Support Range: [0, MAX_INT32),MAX_INT32 = 2^31 - 1, dtype:
40- * Int64.
41- * @li expert_shard_type: Input moe shard type, dtype: int64. Default: 0.
42- * @li shared_expert_num: Input shared expert num, dtype: int64. Default: 1.
43- * @li shared_expert_rank_num: Input shared expert rank num, dtype: int64. Default: 0.
44- * @li comm_quant_mode: Input quant mode. The options are 0 (non-quantization), 1 (static quantization), and 2 (dynamic
45- * quantization). dtype: int64. Default: 0.
46- * @li global_bs: Input global batch size, dtype: int64. Default: 0.
47- * @li comm_type: Input comm type, dtype: int64. Default: 0.
48- * @li comm_alg: Input comm algorithm, dtype: String. Default: "".
49- *
50- * @par Outputs
51- * Two outputs, including:
52- * @li quant_expand_x: A tensor. Result of quantized expand_x. Support dtype: int8, dimension must be 2. Shape supports
53- * (A, H), support format: ND.
54- * @li comm_cmd_info: A tensor. Communication command info. Support dtype: int32, dimension must be 1. Shape supports
55- * (N, ), support format: ND.
56- */
57-REG_OP(MoeDistributeCombineSetup)
58- .INPUT(context, TensorType({DT_INT32}))
59- .INPUT(expand_x, TensorType({DT_BF16, DT_FLOAT16}))
60- .INPUT(expert_ids, TensorType({DT_INT32}))
61- .INPUT(assist_info_for_combine, TensorType({DT_INT32}))
62- .OUTPUT(quant_expand_x, TensorType({DT_INT8}))
63- .OUTPUT(comm_cmd_info, TensorType({DT_INT32}))
64- .REQUIRED_ATTR(ep_world_size, Int)
65- .REQUIRED_ATTR(ep_rank_id, Int)
66- .REQUIRED_ATTR(moe_expert_num, Int)
67- .REQUIRED_ATTR(ccl_buffer_size, Int)
68- .ATTR(expert_shard_type, Int, 0)
69- .ATTR(shared_expert_num, Int, 1)
70- .ATTR(shared_expert_rank_num, Int, 0)
71- .ATTR(global_bs, Int, 0)
72- .ATTR(comm_quant_mode, Int, 0)
73- .ATTR(comm_type, Int, 0)
74- .ATTR(comm_alg, String, "")
75- .OP_END_FACTORY_REG(MoeDistributeCombineSetup)
76- 
77-} // namespace ge
78- 
79-#endif // MOE_DISTRIBUTE_COMBINE_SETUP_PROTO_H_
@@ -13,14 +13,12 @@ if (BUILD_OPEN_PROJECT) # custom
13 moe_distribute_combine_setup_def.cpp13 moe_distribute_combine_setup_def.cpp
14 )14 )
15 add_modules_sources_with_soc(15 add_modules_sources_with_soc(
16- OP_API_INDEPENDENT ON
17- OP_API_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../op_api
18 OP_MC2_ENABLE ON16 OP_MC2_ENABLE ON
19- OPTYPE moe_distribute_combine_setup moe_distribute_combine_setup ACLNNTYPE aclnn aclnn_inner)17+ OPTYPE moe_distribute_combine_setup ACLNNTYPE aclnn_inner)
20 set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)18 set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)
21 set(MC2_OPT ON PARENT_SCOPE)19 set(MC2_OPT ON PARENT_SCOPE)
22 set(moe_distribute_combine_setup_depends mc2/common mc2/3rd PARENT_SCOPE)20 set(moe_distribute_combine_setup_depends mc2/common mc2/3rd PARENT_SCOPE)
23else() # 回黄host21else() # 回黄host
24- add_mc2_modules_sources(OPTYPE moe_distribute_combine_setup moe_distribute_combine_setup ACLNNTYPE aclnn aclnn_inner)22+ add_mc2_modules_sources(OPTYPE moe_distribute_combine_setup ACLNNTYPE aclnn_inner)
25 set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)23 set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)
26endif()24endif()
@@ -1,13 +0,0 @@
1-# -----------------------------------------------------------------------------------------------------------
2-# Copyright (c) 2026 Huawei Technologies Co., Ltd.
3-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4-# CANN Open Software License Agreement Version 2.0 (the "License").
5-# Please refer to the License for details. You may not use this file except in compliance with the License.
6-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7-# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8-# See LICENSE in the root of the software repository for the full text of the License.
9-# -----------------------------------------------------------------------------------------------------------
10- 
11-if(UT_TEST_ALL OR OP_API_UT)
12- add_modules_ut_sources(UT_NAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
13-endif()
@@ -1,697 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file test_aclnn_moe_distribute_combine_setup.cpp
13- * \brief aclnn ut
14- */
15- 
16-#include <float.h>
17-#include <array>
18-#include <vector>
19-#include <string>
20-#include <gtest/gtest.h>
21-#include <gmock/gmock.h>
22-#include "../../../op_api/aclnn_moe_distribute_combine_setup.h"
23-#include "op_api_ut_common/tensor_desc.h"
24-#include "op_api_ut_common/op_api_ut.h"
25-#include "opdev/platform.h"
26- 
27-using namespace op;
28- 
29-namespace MoeDistributeCombineSetupUT {
30-static aclTensor* CreateAclTensor(const std::vector<int64_t> shape, aclDataType dataType, aclFormat format)
31-{
32- void* storage_data = nullptr;
33- std::vector<int64_t> strides(shape.size(), 1);
34- for (int64_t i = shape.size() - 2; i >= 0; i--) {
35- strides[i] = shape[i + 1] * strides[i + 1];
36- }
37- aclTensor* tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, format, shape.data(),
38- shape.size(), storage_data);
39- assert(tensor != nullptr);
40- return tensor;
41-}
42- 
43-static aclTensor* CreateAclTensorOrNull(const std::vector<int64_t> shape, aclDataType dataType, aclFormat format)
44-{
45- if (shape.empty()) {
46- return nullptr;
47- }
48- return CreateAclTensor(shape, dataType, format);
49-}
50- 
51-class TestAclnnMoeDistributeCombineSetup : public testing::Test {
52-protected:
53- static void SetUpTestCase()
54- {
55- op::SetPlatformNpuArch(Ops::Base::DAV_3510);
56- std::cout << "TestAclnnMoeDistributeCombineSetup SetUp" << std::endl;
57- }
58- static void TearDownTestCase()
59- {
60- op::SetPlatformSocVersion(op::SocVersion::ASCEND910B);
61- std::cout << "TestAclnnMoeDistributeCombineSetup TearDown" << std::endl;
62- }
63-};
64- 
65-struct MoeDistributeCombineSetupAclnnTestParam {
66- string caseName;
67- 
68- // shape
69- std::vector<int64_t> expandXShape;
70- std::vector<int64_t> expertIdsShape;
71- std::vector<int64_t> assistInfoForCombineShape;
72- std::vector<int64_t> quantExpandXOutShape;
73- std::vector<int64_t> commCmdInfoOutShape;
74- 
75- // 通信域标识
76- char* groupEp;
77- int64_t epWorldSize;
78- int64_t epRankId;
79- int64_t moeExpertNum;
80- int64_t expertShardType;
81- int64_t sharedExpertNum;
82- int64_t sharedExpertRankNum;
83- int64_t globalBs;
84- int64_t commQuantMode;
85- int64_t commType;
86- char* commAlg;
87- 
88- // dtype
89- aclDataType expandXDtype;
90- aclDataType expertIdsDtype;
91- aclDataType assistInfoForCombineDtype;
92- aclDataType quantExpandXOutDtype;
93- aclDataType commCmdInfoOutDtype;
94- 
95- // format
96- aclFormat expandXFormat;
97- aclFormat expertIdsFormat;
98- aclFormat assistInfoForCombineFormat;
99- aclFormat quantExpandXOutFormat;
100- aclFormat commCmdInfoOutFormat;
@@ -1,3 +1,3 @@
1# MoeDistributeCombineTeardown1# MoeDistributeCombineTeardown
2 2 
3-本目录仅包含MoeDistributeCombineTeardown算子对应的aclnn接口;如您想要贡献该算子的Ascend C实现,请参考[贡献流程](../../CONTRIBUTING.md)。3+本目录包含MoeDistributeCombineTeardown算子的实现,不提供公开的aclnn接口;如您想要为该算子贡献代码,请参考[贡献流程](../../CONTRIBUTING.md)。
@@ -1,476 +0,0 @@
1-# aclnnMoeDistributeCombineTeardown
2- 
3-## 产品支持情况
4- 
5-<!-- npu="950" id1 -->
6-- <term>Ascend 950DT系列产品</term>:支持
7-<!-- end id1 -->
8-<!-- npu="A3" id2 -->
9-- <term>Atlas A3系列产品</term>:不支持
10-<!-- end id2 -->
11-<!-- npu="910b" id3 -->
12-- <term>Atlas A2系列产品</term>:不支持
13-<!-- end id3 -->
14-<!-- npu="310b" id4 -->
15-- <term>Atlas 200I/500 A2推理产品</term>:不支持
16-<!-- end id4 -->
17-<!-- npu="310p" id5 -->
18-- <term>Atlas推理系列产品</term>:不支持
19-<!-- end id5 -->
20-<!-- npu="910" id6 -->
21-- <term>Atlas训练系列产品</term>:不支持
22-<!-- end id6 -->
23- 
24-## 功能说明
25- 
26-- **接口功能**:接收aclnnMoeDistributeCombineSetup发来的数据并整合数据(乘权重再相加)。
27-- **计算公式**:
28- 
29- $$
30- ataOut = AllToAllV(expandX)\\
31- xOut = Sum(expertScales * ataOut + expertScales * sharedExpertX)
32- $$
33- 
34- 按MoeDistributeDispatchSetup和MoeDistributeDispatchTeardown算子收集数据的路径原路返还,本算子只做通信状态确认和数据整理,对aclnnMoeDistributeCombineSetup接口发送的数据做通信状态确认,并按照专家的scale权重做加权求和。
35- 
36-- **注意**:该接口必须与aclnnMoeDistributeDispatchSetup、aclnnMoeDistributeDispatchTeardown及aclnnMoeDistributeCombineSetup配套使用。
37- 
38-## 函数原型
39- 
40-每个算子分为两段式接口,必须先调用“`aclnnMoeDistributeCombineTeardownGetWorkspaceSize`”接口获取入参并根据计算流程获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“`aclnnMoeDistributeCombineTeardown`”接口执行计算。
41- 
42-```cpp
43-aclnnStatus aclnnMoeDistributeCombineTeardownGetWorkspaceSize(
44- const aclTensor* expandX,
45- const aclTensor* quantExpandX,
46- const aclTensor* expertIds,
47- const aclTensor* expandIdx,
48- const aclTensor* expertScales,
49- const aclTensor* commCmdInfo,
50- const aclTensor* xActiveMaskOptional,
51- const aclTensor* sharedExpertXOptional,
52- const char* groupEp,
53- int64_t epWorldSize,
54- int64_t epRankId,
55- int64_t moeExpertNum,
56- int64_t expertShardType,
57- int64_t sharedExpertNum,
58- int64_t sharedExpertRankNum,
59- int64_t globalBs,
60- int64_t commQuantMode,
61- int64_t commType,
62- const char* commAlg,
63- aclTensor* xOut,
64- uint64_t* workspaceSize,
65- aclOpExecutor** executor)
66-```
67- 
68-```cpp
69-aclnnStatus aclnnMoeDistributeCombineTeardown(
70- void* workspace,
71- uint64_t workspaceSize,
72- aclOpExecutor* executor,
73- aclrtStream stream)
74-```
75- 
76-## aclnnMoeDistributeCombineTeardownGetWorkspaceSize
77- 
78-- **参数说明**
79- 
80- <table style="undefined;table-layout: fixed; width: 1548px"><colgroup>
81- <col style="width: 162px">
82- <col style="width: 94px">
83- <col style="width: 485px">
84- <col style="width: 458px">
85- <col style="width: 84px">
86- <col style="width: 78px">
87- <col style="width: 76px">
88- <col style="width: 111px">
89- </colgroup>
90- <thead>
91- <tr>
92- <th>参数名</th>
93- <th>输入/输出</th>
94- <th>描述</th>
95- <th>使用说明</th>
96- <th>数据类型</th>
97- <th>数据格式</th>
98- <th>维度</th>
99- <th>非连续Tensor</th>
100- </tr></thead>
101- <tbody>
102- <tr>
103- <td>expandX(aclTensor*)</td>
104- <td>输入</td>
105- <td>根据expertIds进行扩展过的token特征</td>
106- <td>不支持空Tensor。</td>
107- <td>FLOAT16、BFLOAT16</td>
108- <td>ND</td>
109- <td>(A, H)</td>
110- <td>√</td>
111- </tr>
112- <tr>
113- <td>quantExpandX(aclTensor*)</td>
114- <td>输入</td>
115- <td>对应aclnnMoeDistributeCombineSetup中的quantExpandX输出</td>
116- <td>不支持空Tensor。</td>
117- <td>INT8</td>
118- <td>ND</td>
119- <td>(A, tokenMsgSize)</td>
120- <td>√</td>
121- </tr>
122- <tr>
123- <td>expertIds(aclTensor*)</td>
124- <td>输入</td>
125- <td>每个token的topK个专家索引</td>
126- <td>不支持空Tensor。</td>
127- <td>INT32</td>
128- <td>ND</td>
129- <td>(Bs, K)</td>
130- <td>√</td>
131- </tr>
132- <tr>
133- <td>expandIdx(aclTensor*)</td>
134- <td>输入</td>
135- <td>对应aclnnMoeDistributeDispatchSetup中的expandIdx输出</td>
136- <td>不支持空Tensor。</td>
137- <td>INT32</td>
138- <td>ND</td>
139- <td>(BS * K, )</td>
140- <td>√</td>
141- </tr>
142- <tr>
143- <td>expertScales(aclTensor*)</td>
144- <td>输入</td>
145- <td>每个token的topK个专家的权重</td>
146- <td>不支持空Tensor。</td>
147- <td>FLOAT32</td>
148- <td>ND</td>
149- <td>(BS, K)</td>
150- <td>√</td>
151- </tr>
152- <tr>
153- <td>commCmdInfo(aclTensor*)</td>
154- <td>输入</td>
155- <td>aclnnMoeDistributeCombineSetup的输出,通信的cmd信息</td>
156- <td>不支持空Tensor。</td>
157- <td>INT32</td>
158- <td>ND</td>
159- <td>((A + epWorldSize) * 16, )</td>
160- <td>√</td>
161- </tr>
162- <tr>
163- <td>xActiveMaskOptional(aclTensor*)</td>
164- <td>可选输入</td>
165- <td>表示token是否参与通信</td>
166- <td>可选择传入有效数据或填空指针,传空指针时表示所有token都参与通信。</td>
167- <td>BOOL</td>
168- <td>ND</td>
169- <td>(BS, )</td>
170- <td>√</td>
171- </tr>
172- <tr>
173- <td>sharedExpertXOptional(aclTensor*)</td>
174- <td>可选输入</td>
175- <td>表示共享专家计算后的Token</td>
176- <td>不支持空Tensor。要求是一个2D或3D的Tensor,当Tensor为2D时,shape为(BS,H);当Tensor为3D时,前两位的乘积需等于BS,第三维需等于H。数据类型需跟expandX保持一致。可选择传入有效数据或填空指针,传入有效数据时,sharedExpertNum需为0。</td>
177- <td>FLOAT16、BFLOAT16</td>
178- <td>ND</td>
179- <td>(BS, H)或(a, b, H)</td>
180- <td>√</td>
181- </tr>
182- <tr>
183- <td>groupEp</td>
184- <td>输入</td>
185- <td>EP通信域名称</td>
186- <td>字符串长度范围为[1, 128)</td>
187- <td>-</td>
188- <td>-</td>
189- <td>-</td>
190- <td>-</td>
191- </tr>
192- <tr>
193- <td>epWorldSize</td>
194- <td>输入</td>
195- <td>EP通信域size</td>
196- <td>取值支持[2, 384]</td>
197- <td>-</td>
198- <td>-</td>
199- <td>-</td>
200- <td>-</td>
201- </tr>
202- <tr>
203- <td>epRankId</td>
204- <td>输入</td>
205- <td>EP域本卡Id</td>
206- <td>取值范围[0, epWorldSize)。<br>同一个EP通信域中各卡的epRankId不重复。</td>
207- <td>-</td>
208- <td>-</td>
209- <td>-</td>
210- <td>-</td>
211- </tr>
212- <tr>
213- <td>moeExpertNum</td>
214- <td>输入</td>
215- <td>MoE专家数量</td>
216- <td>取值范围(0, 512]。<br>满足moeExpertNum % (epWorldSize - sharedExpertRankNum) = 0。</td>
217- <td>-</td>
218- <td>-</td>
219- <td>-</td>
220- <td>-</td>
221- </tr>
222- <tr>
223- <td>expertShardType</td>
224- <td>输入</td>
225- <td>共享专家卡分布类型</td>
226- <td>当前仅支持传0,表示共享专家卡排在MoE专家卡前面。</td>
227- <td>-</td>
228- <td>-</td>
229- <td>-</td>
230- <td>-</td>
231- </tr>
232- <tr>
233- <td>sharedExpertNum</td>
234- <td>输入</td>
235- <td>共享专家数量</td>
236- <td>当前取值范围[0, 4]。0表示无共享专家。当前仅支持无共享专家。</td>
237- <td>-</td>
238- <td>-</td>
239- <td>-</td>
240- <td>-</td>
241- </tr>
242- <tr>
243- <td>sharedExpertRankNum</td>
244- <td>输入</td>
245- <td>共享专家卡数量</td>
246- <td>当前取值范围[0, epWorldSize / 2]。</td>
247- <td>-</td>
248- <td>-</td>
249- <td>-</td>
250- <td>-</td>
251- </tr>
252- <tr>
253- <td>globalBs</td>
254- <td>输入</td>
255- <td>EP域全局的batch size大小</td>
256- <td>当每个rank的Bs数一致场景下,globalBs = Bs * epWorldSize或globalBs = 0;当每个rank的Bs数不一致场景下,globalBs = maxBs * epWorldSize,其中maxBs表示单卡Bs最大值。</td>
257- <td>-</td>
258- <td>-</td>
259- <td>-</td>
260- <td>-</td>
261- </tr>
262- <tr>
263- <td>commQuantMode</td>
264- <td>输入</td>
265- <td>通信量化类型</td>
266- <td>取值范围[0, 2],0表示通信时不进行量化,当前仅支持0。</td>
267- <td>-</td>
268- <td>-</td>
269- <td>-</td>
270- <td>-</td>
271- </tr>
272- <tr>
273- <td>commType</td>
274- <td>输入</td>
275- <td>通信方案选择</td>
276- <td>取值范围[0, 2],0表示AICPU-SDMA方案,1表示CCU方案,2表示URMA方案,当前仅支持2。</td>
277- <td>-</td>
278- <td>-</td>
279- <td>-</td>
280- <td>-</td>
281- </tr>
282- <tr>
283- <td>commAlg</td>
284- <td>输入</td>
285- <td>通信算法选择</td>
286- <td>仅支持传入空指针或空字符串</td>
287- <td>-</td>
288- <td>-</td>
289- <td>-</td>
290- <td>-</td>
291- </tr>
292- <tr>
293- <td>xOut(aclTensor*)</td>
294- <td>输出</td>
295- <td>表示处理后的token</td>
296- <td>不支持空Tensor。数据类型与expandX保持一致。</td>
297- <td>FLOAT16、BFLOAT16</td>
298- <td>ND</td>
299- <td>(BS, H)</td>
300- <td>√</td>
301- </tr>
302- <tr>
303- <td>workspaceSize</td>
304- <td>输出</td>
305- <td>返回需要在Device侧申请的workspace大小。</td>
306- <td>-</td>
307- <td>-</td>
308- <td>-</td>
309- <td>-</td>
310- <td>-</td>
311- </tr>
312- <tr>
313- <td>executor</td>
314- <td>输出</td>
315- <td>返回op执行器,包含了算子计算流程。</td>
316- <td>-</td>
317- <td>-</td>
318- <td>-</td>
319- <td>-</td>
320- <td>-</td>
321- </tr>
322- <tr>
323- <td>stream</td>
324- <td>输入</td>
325- <td>指定执行任务的stream流。</td>
326- </tr>
327- </tbody></table>
328- 
329- <!-- npu="950" id7 -->
330- - Ascend 950DT系列产品:
331- - 不支持共享专家场景。
332- - epWorldSize当前取值仅支持2、8。
333- - moeExpertNum表示MoE专家数量,当前仅能传入32。
334- - expertShardType当前仅支持传0,表示共享专家卡排在MoE专家卡前面。
335- - sharedExpertNum表示共享专家数量,当前不支持共享专家,仅能传入0。
336- - sharedExpertRankNum表示共享专家卡数,当前不支持共享专家,仅能传入0。
337- - commQuantMode当前仅支持传入0,表示不进行量化。
338- - commType取值范围[0, 2],当前仅支持2,表示URMA通路。
339- - commAlg当前版本不支持,传空指针即可。
340- 
341- <!-- end id7 -->
342- - Atlas A3训练系列产品/Atlas A3推理系列产品:
343- - 不支持共享专家场景。
344- - epWorldSize当前取值仅支持2、8。
345- - moeExpertNum表示MoE专家数量,当前仅能传入32。
346- - expertShardType当前仅支持传0,表示共享专家卡排在MoE专家卡前面。
347- - sharedExpertNum表示共享专家数量,当前不支持共享专家,仅能传入0。
348- - sharedExpertRankNum表示共享专家卡数,当前不支持共享专家,仅能传入0。
349- - commQuantMode当前仅支持传入0,表示不进行量化。
350- - commType取值范围[0, 2],当前仅支持2,表示URMA通路。
351- - commAlg当前版本不支持,传空指针即可。
352- 
353-- **返回值**
354- 
355- aclnnStatus:返回状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。
356- 
357- 第一段接口完成入参校验,出现以下场景时报错:
358- 
359- <table style="undefined;table-layout: fixed; width: 1000px"><colgroup>
360- <col style="width: 300px">
361- <col style="width: 150px">
362- <col style="width: 550px">
363- </colgroup>
364- <thead>
365- <tr>
366- <th>返回值</th>
367- <th>错误码</th>
368- <th>描述</th>
369- </tr></thead>
370- <tbody>
371- <tr>
372- <td>ACLNN_ERR_PARAM_NULLPTR </td>
373- <td>161001</td>
374- <td>输入和输出的必选参数Tensor是空指针。</td>
375- </tr>
376- <tr>
377- <td>ACLNN_ERR_PARAM_INVALID </td>
378- <td>161002</td>
379- <td>输入和输出的数据类型不在支持的范围内。</td>
380- </tr>
381- <tr>
382- <td rowspan="2">ACLNN_ERR_INNER_TILING_ERROR</td>
383- <td rowspan="2">561002</td>
384- <td>输入和输出的shape不在支持的范围内。</td>
385- </tr>
386- <tr>
387- <td>参数的取值不在支持的范围内。</td>
388- </tr>
389- </tbody>
390- </table>
391- 
392-## aclnnMoeDistributeCombineTeardown
393- 
394-- **参数说明:**
395- 
396- <table style="undefined;table-layout: fixed; width: 1000px"><colgroup>
397- <col style="width: 200px">
398- <col style="width: 130px">
399- <col style="width: 670px">
400- </colgroup>
401- <thead>
402- <tr>
403- <th>参数名</th>
404- <th>输入/输出</th>
405- <th>描述</th>
406- </tr></thead>
407- <tbody>
408- <tr>
409- <td>workspace</td>
410- <td>输入</td>
411- <td>在Device侧申请的workspace内存地址。</td>
412- </tr>
413- <tr>
414- <td>workspaceSize</td>
415- <td>输入</td>
416- <td>在Device侧申请的workspace大小,由第一段接口aclnnMoeDistributeCombineTeardownGetWorkspaceSize获取。</td>
417- </tr>
418- <tr>
419- <td rowspan="2">executor</td>
420- <td rowspan="2">输入</td>
421- <td>op执行器,包含了算子计算流程。</td>
422- </tr>
423- <tr>
424- <td>指定执行任务的stream流。</td>
425- </tr>
426- </tbody>
427- </table>
428- 
429-- **返回值:**
430- 
431- 返回aclnnStatus状态码,具体参见[aclnn返回码](../../../docs/zh/context/aclnn_return_code.md)。
432- 
433-## 约束说明
434- 
435-- 确定性计算:
436- - aclnnMoeDistributeCombineTeardown默认确定性实现。
437-- aclnnMoeDistributeDispatchSetup接口,aclnnMoeDistributeDispatchTeardown接口,aclnnMoeDistributeCombineSetup接口,aclnnMoeDistributeCombineTeardown接口必须配套使用。
438-- 调用接口过程中使用的`groupEp`、`epWorldSize`、`moeExpertNum`、`expertShardType`、`sharedExpertNum`、`sharedExpertRankNum`、`globalBs`、`commQuantMode`、`commType`、`commAlg`参数取值所有卡需保持一致,`groupEp`、`epWorldSize`、`expertShardType`、`sharedExpertNum`、`sharedExpertRankNum`、`globalBs`、`commQuantMode`、`commType`、`commAlg`参数取值在网络中不同层中也需保持一致,且和aclnnMoeDistributeDispatchSetup接口,aclnnMoeDistributeDispatchTeardown接口,aclnnMoeDistributeCombineSetup接口对应参数也保持一致。
439-- 参数说明里shape格式说明:
440- 
441- - A:表示本卡需要分发的最大token数量,取值范围如下:
442- - 对于共享专家,要满足A = BS \* epWorldSize \* sharedExpertNum / sharedExpertRankNum;当globalBs非0时,要满足A = globalBs\* sharedExpertNum / sharedExpertRankNum。
443- - 对于MoE专家,当globalBs为0时,要满足A >= BS \* epWorldSize \* min(localExpertNum, K);当globalBs非0时,要满足A >= globalBs \* min(localExpertNum, K)。
444- - H:表示hidden size隐藏层大小。取值为[1024, 8192]。当前仅支持4096、7168。
445- - HS:表示通信时的数据大小,Align512( Align32(H) + Align8(H) / 8 *sizeof(float) ),其中Align512(x) = ((x + 512 - 1) / 512) \* 512,Align32(x) = ((x + 32 - 1) / 32) \* 32,Align8(x) = ((x + 8 - 1) / 8) \* 8。
446- - BS:表示batch sequence size,即本卡最终输出的token数量。取值范围为0 < BS ≤ 512。当前仅支持8、16、256。
447- - K:表示选取topK个专家,取值范围为0 < K ≤ 16同时满足0 < K ≤ moeExpertNum。当前仅支持6、8。
448- - localExpertNum:表示本卡专家数量。
449- - 对于共享专家卡,localExpertNum = 1
450- - 对于MoE专家卡,localExpertNum = moeExpertNum / (epWorldSize - sharedExpertRankNum)。moeExpertNum当前仅支持32。
451- - tokenMsgSize:表示每个token在数据通信时的维度信息,计算公式为Align512(Align32(H)+Align8(H)/8\*sizeof(float)),其中AlignN(x)=((x+N-1)/N*N)。
452- - 当前不支持共享专家。sharedExpertNum和sharedExpertRankNum当前仅支持0。
453-- HCCL_BUFFSIZE:
454- 调用本接口前需检查HCCL_BUFFSIZE环境变量取值是否合理,该环境变量表示单个通信域占用内存大小,单位MB,不配置时默认为200MB。
455- 
456- <!-- npu="950" id8 -->
457- - Ascend 950DT系列产品:
458- - 要求 >= 2且满足>= 4 \* (localExpertNum \* maxBs \* epWorldSize \* Align512(Align32(2 \* H) + 44) + (K + sharedExpertNum) \* maxBs \* Align512(2 \* H)),localExpertNum需使用MoE专家卡的本卡专家数,其中Align512(x) = ((x + 512 - 1) / 512) \* 512,Align32(x) = ((x + 32 - 1) / 32) \* 32
459- <!-- end id8 -->
460- - Atlas A3训练系列产品/Atlas A3推理系列产品:
461- - 要求 >= 2且满足>= 2 \* (localExpertNum \* maxBs \* epWorldSize \* Align512(Align32(2 \* H) + 44) + (K + sharedExpertNum) \* maxBs \* Align512(2 \* H)),localExpertNum需使用MoE专家卡的本卡专家数,其中Align512(x) = ((x + 512 - 1) / 512) \* 512,Align32(x) = ((x + 32 - 1) / 32) \* 32
462-- 通信域使用约束:
463- - 一个模型中的aclnnMoeDistributeDispatchSetup接口,aclnnMoeDistributeDispatchTeardown接口,aclnnMoeDistributeCombineSetup接口,aclnnMoeDistributeCombineTeardown接口仅支持相同EP通信域,且该通信域中不允许有其他算子。
464-- 通信方式约束:
465- 
466- <!-- npu="950" id9 -->
467- - <term>Ascend 950DT系列产品</term>:仅支持URMA通信。
468- 
469- <!-- end id9 -->
470- 
471-## 调用示例
472- 
473-<!-- npu="950" id10 -->
474-- Ascend 950DT系列产品:aclnnMoeDistributeCombineTeardown必须在aclnnMoeDistributeCombineSetup调用之后调用,请参考[aclnnMoeDistributeCombineSetup](../../moe_distribute_combine_setup/docs/aclnnMoeDistributeCombineSetup.md)中的调用示例。
475- 
476-<!-- end id10 -->
@@ -1,356 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file test_aclnn_moe_distribute_combine_teardown.cpp
13- * \brief aclnn直调测试脚本
14- */
15- 
16-#include <thread>
17-#include <iostream>
18-#include <string>
19-#include <vector>
20-#include <cstring>
21-#include "acl/acl.h"
22-#include "hccl/hccl.h"
23-#include "aclnnop/aclnn_moe_distribute_combine_teardown.h"
24-#include "aclnnop/aclnn_moe_distribute_combine_setup.h"
25- 
26-#define CHECK_RET(cond, return_expr) \
27- do { \
28- if (!(cond)) { \
29- return_expr; \
30- } \
31- } while (0)
32- 
33-#define LOG_PRINT(message, ...) \
34- do { \
35- printf(message, ##__VA_ARGS__); \
36- } while (0)
37- 
38-constexpr int DEV_NUM = 2;
39- 
40-template <typename Func>
41-class Guard {
42-public:
43- explicit Guard(Func& func)
44- : func_(func)
45- {}
46- ~Guard()
47- {
48- func_();
49- }
50- 
51-private:
52- Func& func_;
53-};
54- 
55-int64_t AlignN(int64_t x, int64_t n)
56-{
57- return (x + n - 1) / n * n;
58-}
59- 
60-int64_t GetShapeSize(const std::vector<int64_t>& shape)
61-{
62- int64_t shape_size = 1;
63- for (auto i : shape) {
64- shape_size *= i;
65- }
66- return shape_size;
67-}
68- 
69-struct Args {
70- uint32_t rankId;
71- uint32_t epRankId;
72- HcclComm hcclEpComm;
73- aclrtStream combinesetupstream;
74- aclrtStream combineteardownstream;
75- aclrtContext context;
76-};
77- 
78-template <typename T>
79-int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr,
80- aclDataType dataType, aclTensor** tensor)
81-{
82- auto size = GetShapeSize(shape) * sizeof(T);
83- auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
84- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtMalloc failed. ret: %d\n", ret); return ret);
85- 
86- ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
87- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtMemcpy failed. ret: %d\n", ret); return ret);
88- std::vector<int64_t> strides(shape.size(), 1);
89- for (int64_t i = shape.size() - 2; i >= 0; i--) {
90- strides[i] = shape[i + 1] * strides[i + 1];
91- }
92- *tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND,
93- shape.data(), shape.size(), *deviceAddr);
94- return 0;
95-}
96- 
97-void DestroyTensor(aclTensor* tensor)
98-{
99- if (tensor != nullptr) {
100- aclDestroyTensor(tensor);
101- }
102-}
103- 
104-void FreeDeviceAddr(void* deviceAddr)
105-{
106- if (deviceAddr != nullptr) {
107- aclrtFree(deviceAddr);
108- }
109-}
110- 
111-int LaunchOneProcess(Args& args)
112-{
113- int ret = aclrtSetCurrentContext(args.context);
114- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtSetCurrentContext failed. ret: %d\n", ret); return ret);
115- 
116- char hcomEpName[128] = {0};
117- ret = HcclGetCommName(args.hcclEpComm, hcomEpName);
118- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] HcclGetCommName failed. ret: %d\n", ret); return ret);
119- 
120- auto destroyFunc = [&args]() {
121- std::cout << "== begin to destroy " << std::endl;
122- HcclCommDestroy(args.hcclEpComm);
123- aclrtDestroyStream(args.combinesetupstream);
124- aclrtDestroyStream(args.combineteardownstream);
125- aclrtDestroyContext(args.context);
126- aclrtResetDevice(args.rankId);
127- };
128- auto guard = Guard<decltype(destroyFunc)>(destroyFunc);
129- 
130- // 场景参数
131- int64_t bs = 16;
132- int64_t h = 4096;
133- int64_t k = 6;
134- int64_t expertSharedType = 0;
135- int64_t sharedExpertNum = 0;
136- int64_t sharedExpertRankNum = 0;
137- int64_t moeExpertNum = 32;
138- int64_t commQuantMode = 0;
139- int64_t tpWorldSize = 1;
140- int64_t epWorldSize = DEV_NUM;
141- int64_t commType = 2;
142- int64_t timeOut = 100000000;
143- 
144- int64_t globalBS = bs * epWorldSize;
145- int64_t localExpertNum;
146- int64_t localToken;
147- 
148- if (args.epRankId < sharedExpertRankNum) {
149- localExpertNum = 1;
150- localToken = globalBS / sharedExpertRankNum;
151- } else {
152- localExpertNum = moeExpertNum / (epWorldSize - sharedExpertRankNum);
153- localToken = globalBS * (localExpertNum < k ? localExpertNum : k);
154- }
155- 
156- int64_t assistInfoForCombineOutSize = localToken * 128;
157- 
158- // 定义 shape
159- std::vector<int64_t> expandXShape{tpWorldSize * localToken, h};
160- std::vector<int64_t> expertIdsShape{bs, k};
161- std::vector<int64_t> expertScalesShape{bs, k};
162- std::vector<int64_t> expandIdxShape{bs * k};
163- std::vector<int64_t> assistInfoForCombineOutShape{assistInfoForCombineOutSize};
164- std::vector<int64_t> quantExpandXOutShape{tpWorldSize * localToken,
165- AlignN(AlignN(h, 32) + AlignN(h, 8) / 8 * sizeof(float), 512)};
166- std::vector<int64_t> commCmdInfoOutShapeforcombine{(localToken + epWorldSize) * 16};
167- std::vector<int64_t> xOutShape{bs, h};
168- 
169- int64_t expandXShapeSize = GetShapeSize(expandXShape);
170- int64_t expertIdsShapeSize = GetShapeSize(expertIdsShape);
171- int64_t expertScalesShapeSize = GetShapeSize(expertScalesShape);
172- int64_t expandIdxShapeSize = GetShapeSize(expandIdxShape);
173- int64_t assistInfoForCombineOutShapeSize = GetShapeSize(assistInfoForCombineOutShape);
174- int64_t quantExpandXOutShapeSize = GetShapeSize(quantExpandXOutShape);
175- int64_t commCmdInfoOutShapeSizeforcombine = GetShapeSize(commCmdInfoOutShapeforcombine);
176- int64_t xOutShapeSize = GetShapeSize(xOutShape);
177- 
178- // 构造 host 数据
179- std::vector<int16_t> expandXHostData(expandXShapeSize, 0);
180- std::vector<int32_t> expertIdsHostData;
181- for (int32_t token_id = 0; token_id < expertIdsShape[0]; token_id++) {
182- for (int32_t k_id = 0; k_id < expertIdsShape[1]; k_id++) {
183- expertIdsHostData.push_back(k_id);
184- }
185- }
186- std::vector<float> expertScalesHostData(expertScalesShapeSize, 0);
187- std::vector<int32_t> expandIdxHostData(expandIdxShapeSize, 0);
188- std::vector<int32_t> assistInfoForCombineOutHostData(assistInfoForCombineOutShapeSize, 0);
189- std::vector<int8_t> quantExpandXOutHostData(quantExpandXOutShapeSize, 0);
190- std::vector<int32_t> commCmdInfoOutforCombineHostData(commCmdInfoOutShapeSizeforcombine, 0);
191- std::vector<float> xOutHostData(xOutShapeSize, 0);
192- 
193- // 声明 device 地址和 tensor
194- void* expandXDeviceAddr = nullptr;
195- void* expertIdsDeviceAddr = nullptr;
196- void* expertScalesDeviceAddr = nullptr;
197- void* expandIdxDeviceAddr = nullptr;
198- void* assistInfoForCombineOutDeviceAddr = nullptr;
199- void* quantExpandXOutDeviceAddr = nullptr;
200- void* commCmdInfoOutforCombineDeviceAddr = nullptr;
201- void* xOutDeviceAddr = nullptr;
202- 
203- aclTensor* expandX = nullptr;
204- aclTensor* expertIds = nullptr;
205- aclTensor* expertScales = nullptr;
206- aclTensor* expandIdx = nullptr;
207- aclTensor* assistInfoForCombineOut = nullptr;
208- aclTensor* quantExpandXOut = nullptr;
209- aclTensor* commCmdInfoOutforCombine = nullptr;
210- aclTensor* xOut = nullptr;
211- 
212- // 创建 tensor
213- ret = CreateAclTensor(expandXHostData, expandXShape, &expandXDeviceAddr, aclDataType::ACL_FLOAT16, &expandX);
214- CHECK_RET(ret == ACL_SUCCESS, return ret);
215- ret = CreateAclTensor(expertIdsHostData, expertIdsShape, &expertIdsDeviceAddr, aclDataType::ACL_INT32, &expertIds);
216- CHECK_RET(ret == ACL_SUCCESS, return ret);
217- ret = CreateAclTensor(expertScalesHostData, expertScalesShape, &expertScalesDeviceAddr, aclDataType::ACL_FLOAT,
218- &expertScales);
219- CHECK_RET(ret == ACL_SUCCESS, return ret);
220- ret = CreateAclTensor(expandIdxHostData, expandIdxShape, &expandIdxDeviceAddr, aclDataType::ACL_INT32, &expandIdx);
221- CHECK_RET(ret == ACL_SUCCESS, return ret);
222- ret = CreateAclTensor(assistInfoForCombineOutHostData, assistInfoForCombineOutShape,
223- &assistInfoForCombineOutDeviceAddr, aclDataType::ACL_INT32, &assistInfoForCombineOut);
224- CHECK_RET(ret == ACL_SUCCESS, return ret);
225- ret = CreateAclTensor(quantExpandXOutHostData, quantExpandXOutShape, &quantExpandXOutDeviceAddr,
226- aclDataType::ACL_INT8, &quantExpandXOut);
227- CHECK_RET(ret == ACL_SUCCESS, return ret);
228- ret = CreateAclTensor(commCmdInfoOutforCombineHostData, commCmdInfoOutShapeforcombine,
229- &commCmdInfoOutforCombineDeviceAddr, aclDataType::ACL_INT32, &commCmdInfoOutforCombine);
230- CHECK_RET(ret == ACL_SUCCESS, return ret);
231- ret = CreateAclTensor(xOutHostData, xOutShape, &xOutDeviceAddr, aclDataType::ACL_FLOAT16, &xOut);
232- CHECK_RET(ret == ACL_SUCCESS, return ret);
233- 
234- // 声明算子执行必需变量
235- uint64_t workspaceSize = 0;
236- aclOpExecutor* executor = nullptr;
237- void* workspaceAddr = nullptr;
238- 
239- /******************************调用combine_setup********************************************/
240- ret = aclnnMoeDistributeCombineSetupGetWorkspaceSize(
241- expandX, expertIds, assistInfoForCombineOut, hcomEpName, epWorldSize, args.epRankId, moeExpertNum,
242- expertSharedType, sharedExpertNum, sharedExpertRankNum, globalBS, commQuantMode, commType, nullptr,
243- quantExpandXOut, commCmdInfoOutforCombine, &workspaceSize, &executor);
244- CHECK_RET(ret == ACL_SUCCESS,
245- LOG_PRINT("[ERROR] aclnnMoeDistributeCombineSetupGetWorkspaceSize failed. ret = %d \n", ret);
246- return ret);
247- 
248- if (workspaceSize > 0) {
249- ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
250- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] CombineSetup aclrtMalloc failed. ret = %d\n", ret);
251- return ret);
252- }
253- 
254- ret = aclnnMoeDistributeCombineSetup(workspaceAddr, workspaceSize, executor, args.combinesetupstream);
255- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclnnMoeDistributeCombineSetup failed. ret = %d \n", ret);
256- return ret);
257- 
258- ret = aclrtSynchronizeStreamWithTimeout(args.combinesetupstream, timeOut);
259- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtSynchronizeStreamWithTimeout failed. ret = %d \n", ret);
260- return ret);
261- LOG_PRINT("[INFO] device_%d aclnnMoeDistributeCombineSetup execute successfully.\n", args.rankId);
262- 
263- /******************************调用combine_teardown********************************************/
264- ret = aclnnMoeDistributeCombineTeardownGetWorkspaceSize(
265- expandX, quantExpandXOut, expertIds, expandIdx, expertScales, commCmdInfoOutforCombine, nullptr, nullptr,
266- hcomEpName, epWorldSize, args.epRankId, moeExpertNum, expertSharedType, sharedExpertNum, sharedExpertRankNum,
267- globalBS, commQuantMode, commType, nullptr, xOut, &workspaceSize, &executor);
268- CHECK_RET(ret == ACL_SUCCESS,
269- LOG_PRINT("[ERROR] aclnnMoeDistributeCombineTeardownGetWorkspaceSize failed. ret = %d \n", ret);
270- return ret);
271- 
272- if (workspaceSize > 0) {
273- ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
274- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] CombineTeardown aclrtMalloc failed. ret = %d\n", ret);
275- return ret);
276- }
277- 
278- ret = aclnnMoeDistributeCombineTeardown(workspaceAddr, workspaceSize, executor, args.combineteardownstream);
279- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclnnMoeDistributeCombineTeardown failed. ret = %d \n", ret);
280- return ret);
281- 
282- ret = aclrtSynchronizeStreamWithTimeout(args.combineteardownstream, timeOut);
283- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtSynchronizeStreamWithTimeout failed. ret = %d \n", ret);
284- return ret);
285- LOG_PRINT("[INFO] device_%d aclnnMoeDistributeCombineTeardown execute successfully.\n", args.rankId);
286- 
287- // 释放资源
288- if (workspaceSize > 0) {
289- aclrtFree(workspaceAddr);
290- }
291- DestroyTensor(expandX);
292- DestroyTensor(expertIds);
293- DestroyTensor(expertScales);
294- DestroyTensor(expandIdx);
295- DestroyTensor(assistInfoForCombineOut);
296- DestroyTensor(quantExpandXOut);
297- DestroyTensor(commCmdInfoOutforCombine);
298- DestroyTensor(xOut);
299- 
300- FreeDeviceAddr(expandXDeviceAddr);
301- FreeDeviceAddr(expertIdsDeviceAddr);
302- FreeDeviceAddr(expertScalesDeviceAddr);
303- FreeDeviceAddr(expandIdxDeviceAddr);
304- FreeDeviceAddr(assistInfoForCombineOutDeviceAddr);
305- FreeDeviceAddr(quantExpandXOutDeviceAddr);
306- FreeDeviceAddr(commCmdInfoOutforCombineDeviceAddr);
307- FreeDeviceAddr(xOutDeviceAddr);
308- 
309- return 0;
310-}
311- 
312-int main(int argc, char* argv[])
313-{
314- int ret = aclInit(nullptr);
315- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclInit failed. ret = %d \n", ret); return ret);
316- 
317- aclrtStream combineSetupStream[DEV_NUM];
318- aclrtStream combineTeardownStream[DEV_NUM];
319- aclrtContext context[DEV_NUM];
320- for (uint32_t rankId = 0; rankId < DEV_NUM; rankId++) {
321- ret = aclrtSetDevice(rankId);
322- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtSetDevice failed. ret = %d \n", ret); return ret);
323- ret = aclrtCreateContext(&context[rankId], rankId);
324- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtCreateContext failed. ret = %d \n", ret); return ret);
325- ret = aclrtCreateStream(&combineSetupStream[rankId]);
326- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtCreateStream failed. ret = %d \n", ret); return ret);
327- ret = aclrtCreateStream(&combineTeardownStream[rankId]);
328- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] aclrtCreateStream failed. ret = %d \n", ret); return ret);
329- }
330- 
331- int32_t devices[DEV_NUM];
332- for (int i = 0; i < DEV_NUM; i++) {
333- devices[i] = i;
334- }
335- 
336- HcclComm comms[DEV_NUM];
337- ret = HcclCommInitAll(DEV_NUM, devices, comms);
338- CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("[ERROR] HcclCommInitAll failed. ret = %d \n", ret); return ret);
339- 
340- Args args[DEV_NUM];
341- std::vector<std::unique_ptr<std::thread>> threads(DEV_NUM);
342- for (uint32_t rankId = 0; rankId < DEV_NUM; rankId++) {
343- args[rankId].rankId = rankId;
344- args[rankId].epRankId = rankId;
345- args[rankId].hcclEpComm = comms[rankId];
346- args[rankId].combinesetupstream = combineSetupStream[rankId];
347- args[rankId].combineteardownstream = combineTeardownStream[rankId];
348- args[rankId].context = context[rankId];
349- threads[rankId].reset(new (std::nothrow) std::thread(&LaunchOneProcess, std::ref(args[rankId])));
350- }
351- for (uint32_t rankId = 0; rankId < DEV_NUM; rankId++) {
352- threads[rankId]->join();
353- }
354- aclFinalize();
355- return 0;
356-}
@@ -1,135 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file aclnn_moe_distribute_combine_teardown.cpp
13- * \brief
14- */
15-#include "aclnn_moe_distribute_combine_teardown.h"
16-#include <algorithm>
17-#include "common/utils/op_mc2.h"
18-#include "common/utils/matmul_util.h"
19-#include "common/utils/op_mc2_def.h"
20-#include "aclnn_kernels/common/op_error_check.h"
21-#include "opdev/op_log.h"
22-#include "mc2_log_compat.h"
23-#include "opdev/common_types.h"
24-#include "opdev/platform.h"
25-#include "op_host/util/op_const_def.h"
26-#include "common/op_api/mc2_context.h"
27- 
28-namespace {
29- 
30-using namespace Mc2Aclnn;
31-using namespace op;
32- 
33-enum class NnopbaseHcclServerType : uint32_t {
34- NNOPBASE_HCCL_SERVER_TYPE_AICPU = 0,
35- NNOPBASE_HCCL_SERVER_TYPE_MTE,
36- NNOPBASE_HCCL_SERVER_TYPE_CCU,
37- NNOPBASE_HCCL_SERVER_TYPE_END
38-};
39- 
40-static bool CheckNotNull(const aclTensor* expandX, const aclTensor* quantExpandX, const aclTensor* expertIds,
41- const aclTensor* expandIdx, const aclTensor* expertScales, const aclTensor* commCmdInfo,
42- const char* groupEp, aclTensor* xOut)
43-{
44- OP_LOGD("aclnn_moe_distribute_combine_teardown CheckNotNull start");
45- OP_CHECK_NULL(expandX, return false);
46- OP_CHECK_NULL(quantExpandX, return false);
47- OP_CHECK_NULL(expertIds, return false);
48- OP_CHECK_NULL(expandIdx, return false);
49- OP_CHECK_NULL(expertScales, return false);
50- OP_CHECK_NULL(commCmdInfo, return false);
51- OP_CHECK_NULL(xOut, return false);
52- if ((groupEp == nullptr) || (strnlen(groupEp, HCCL_GROUP_NAME_MAX) == 0)) {
53- OP_LOGE_WITH_INVALID_INPUT("aclnnMoeDistributeCombineTeardown", "groupEp");
54- return false;
55- }
56- OP_LOGD("aclnn_moe_distribute_combine_teardown CheckNotNull success");
57- return true;
58-}
59- 
60-static aclnnStatus CheckParams(const aclTensor* expandX, const aclTensor* quantExpandX, const aclTensor* expertIds,
61- const aclTensor* expandIdx, const aclTensor* expertScales, const aclTensor* commCmdInfo,
62- const char* groupEp, aclTensor* xOut)
63-{
64- OP_LOGD("aclnn_moe_distribute_combine_teardown checkparams start");
65- CHECK_RET(CheckNotNull(expandX, quantExpandX, expertIds, expandIdx, expertScales, commCmdInfo, groupEp, xOut),
66- ACLNN_ERR_PARAM_NULLPTR);
67- if (strnlen(groupEp, HCCL_GROUP_NAME_MAX) >= HCCL_GROUP_NAME_MAX) {
68- OP_LOGE_FOR_INVALID_VALUE_WITH_REASON(
69- "aclnnMoeDistributeCombineTeardown", "groupEp",
70- std::to_string(strnlen(groupEp, HCCL_GROUP_NAME_MAX)).c_str(),
71- std::string("groupEp name exceeds ").append(std::to_string(HCCL_GROUP_NAME_MAX)).c_str());
72- return ACLNN_ERR_PARAM_INVALID;
73- }
74- OP_LOGD("aclnn_moe_distribute_combine_teardown checkparams success");
75- return ACLNN_SUCCESS;
76-}
77- 
78-} // namespace
79- 
80-extern "C" aclnnStatus aclnnInnerMoeDistributeCombineTeardownGetWorkspaceSize(
81- aclTensor* mc2Context, const aclTensor* expandX, const aclTensor* quantExpandX, const aclTensor* expertIds,
82- const aclTensor* expandIdx, const aclTensor* expertScales, const aclTensor* commCmdInfo,
83- const aclTensor* xActiveMaskOptional, const aclTensor* sharedExpertXOptional, int64_t epWorldSize, int64_t epRankId,
84- int64_t moeExpertNum, int64_t cclBuffSize, int64_t expertShardType, int64_t sharedExpertNum,
85- int64_t sharedExpertRankNum, int64_t globalBs, int64_t commQuantMode, int64_t commType, const char* commAlg,
86- aclTensor* xOut, uint64_t* workspaceSize, aclOpExecutor** executor);
87- 
88-extern "C" aclnnStatus aclnnInnerMoeDistributeCombineTeardown(void* workspace, uint64_t workspaceSize,
89- aclOpExecutor* executor, aclrtStream stream);
90-extern "C" void __attribute__((weak)) NnopbaseSetHcclServerType(void* executor, NnopbaseHcclServerType sType);
91- 
92-extern "C" aclnnStatus aclnnMoeDistributeCombineTeardownGetWorkspaceSize(
93- const aclTensor* expandX, const aclTensor* quantExpandX, const aclTensor* expertIds, const aclTensor* expandIdx,
94- const aclTensor* expertScales, const aclTensor* commCmdInfo, const aclTensor* xActiveMaskOptional,
95- const aclTensor* sharedExpertXOptional, const char* groupEp, int64_t epWorldSize, int64_t epRankId,
96- int64_t moeExpertNum, int64_t expertShardType, int64_t sharedExpertNum, int64_t sharedExpertRankNum,
97- int64_t globalBs, int64_t commQuantMode, int64_t commType, const char* commAlg, aclTensor* xOut,
98- uint64_t* workspaceSize, aclOpExecutor** executor)
99-{
100- OP_LOGD("aclnn_moe_distribute_combine_teardown get_workspace_size start");
101- if (GetCurrentPlatformInfo().GetCurNpuArch() != Ops::Base::DAV_3510) {
102- OP_LOGE_LIBOPAPI_REPORT("aclnnMoeDistributeCombineTeardown", "Unsupported npuArch");
103- return ACLNN_ERR_PARAM_INVALID;
104- }
105- 
106- auto ret_param = CheckParams(expandX, quantExpandX, expertIds, expandIdx, expertScales, commCmdInfo, groupEp, xOut);
107- CHECK_RET(ret_param == ACLNN_SUCCESS, ret_param);
108- 
109- aclnnStatus retStatus;
110- uint64_t hcclBuffSize = 0;
111- aclTensor* mc2Context = nullptr;
112- const char* opName = "moe_distribute_a2av_setup_teardown";
113- retStatus = Mc2Aclnn::Mc2Context::GetMc2ContextTensor(groupEp, opName, hcclBuffSize, mc2Context,
114- CommProtocol::COMM_PROTOCOL_UBC_CTP);
115- CHECK_RET(retStatus == ACLNN_SUCCESS, retStatus);
116- retStatus = aclnnInnerMoeDistributeCombineTeardownGetWorkspaceSize(
117- mc2Context, expandX, quantExpandX, expertIds, expandIdx, expertScales, commCmdInfo, xActiveMaskOptional,
118- sharedExpertXOptional, epWorldSize, epRankId, moeExpertNum, hcclBuffSize, expertShardType, sharedExpertNum,
119- sharedExpertRankNum, globalBs, commQuantMode, commType, const_cast<char*>(commAlg), xOut, workspaceSize,
120- executor);
121- OP_LOGD("aclnn_moe_distribute_combine_teardown get_workspace_size success");
122- return retStatus;
123-}
124- 
125-extern "C" aclnnStatus aclnnMoeDistributeCombineTeardown(void* workspace, uint64_t workspaceSize,
126- aclOpExecutor* executor, aclrtStream stream)
127-{
128- OP_LOGD("aclnnMoeDistributeCombineTeardown start");
129- if (NnopbaseSetHcclServerType) {
130- NnopbaseSetHcclServerType(executor, NnopbaseHcclServerType::NNOPBASE_HCCL_SERVER_TYPE_MTE);
131- }
132- aclnnStatus ret = aclnnInnerMoeDistributeCombineTeardown(workspace, workspaceSize, executor, stream);
133- OP_LOGD("aclnnMoeDistributeCombineTeardown success");
134- return ret;
135-}
@@ -1,82 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file aclnn_moe_distribute_combine_teardown.h
13- * \brief
14- */
15-#ifndef OP_API_INC_MOE_DISTRIBUTE_COMBINE_TEARDOWN_
16-#define OP_API_INC_MOE_DISTRIBUTE_COMBINE_TEARDOWN_
17- 
18-#include <string>
19- 
20-#include "aclnn/aclnn_base.h"
21-#include "aclnn_util.h"
22- 
23-#ifdef __cplusplus
24-extern "C" {
25-#endif
26- 
27-/**
28- * 算子功能:实现MoeDistributeCombineTeardown功能
29- * @brief aclnnMoeDistributeCombineTeardown的第一段接口,根据具体的计算流程,计算workspace大小。
30- * @domain aclnn_ops_infer
31- * @param [in] expandX: 计算输入,Tensor,数据类型float16, bfloat16,必须为2维,数据格式支持ND。
32- * @param [in] quantExpandX: 计算输入,Tensor,数据类型int8,必须为2维,数据格式支持ND。
33- * @param [in] expertIds: 计算输入,Tensor,数据类型int32,必须为2维,数据格式支持ND。
34- * @param [in] expandIdx: 计算输入,Tensor,数据类型int32,必须为2维,数据格式支持ND。
35- * @param [in] expertScales: 计算输入,Tensor,数据类型float32,必须为2维,数据格式支持ND。
36- * @param [in] commCmdInfo:
37- * 计算输入,Tensor,数据类型int32,必须为1维,数据格式支持ND,aclnnMoeDistributeCombineSetUp的输出。
38- * @param [in] xActiveMaskOptional:
39- * 计算输入,Tensor,数据类型bool,必须为1维,数据格式支持ND。预留参数,暂未使用,传空即可。
40- * @param [in] sharedExpertXOptional:
41- * 计算输入,Tensor,数据类型与expandX保持一致,必须为2维,数据格式支持ND。预留参数,暂未使用,传空即可。
42- * @param [in] groupEp: 计算输入,str。ep通信域名称,专家并行的通信域。不能和groupTp相同。
43- * @param [in] epWorldSize: 计算输入,int。ep通信域size。
44- * @param [in] epRankId: 计算输入,int。ep本卡Id。同一个EP通信域中各卡的epRankId不能重复。
45- * @param [in] moeExpertNum: 计算输入,int。MOE专家数量。
46- * @param [in] expertShardType: 计算可选输入,int。共享专家卡分布类型。当前仅支持传0。
47- * @param [in] sharedExpertNum: 计算可选输入,int。共享专家数量。当前仅支持传0。
48- * @param [in] sharedExpertRankNum: 计算可选输入,int。共享专家卡数量。当前仅支持传0。
49- * @param [in] globalBs: 计算可选输入,int。
50- * @param [in] commQuantMode: 计算可选输入,int。通信量化类型。预留参数,暂未使用,传0即可。
51- * @param [in] commType: 计算可选输入,int。通信方案选择。预留参数,暂未使用,传0即可。
52- * @param [in] commAlg: 计算可选输入,str。通信算法类型。预留参数,暂未使用。
53- * @param [out] xOut: 计算输出,Tensor,必选输出,数据类型支持float16,bfloat16,仅支持2维,数据格式支持ND。
54- * @param [out] workspaceSize: 出参,返回需要在npu device侧申请的workspace大小。
55- * @param [out] executor: 出参,返回op执行器,包含了算子计算流程。
56- * @return aclnnStatus: 返回值,返回状态码。
57- */
58-ACLNN_API aclnnStatus aclnnMoeDistributeCombineTeardownGetWorkspaceSize(
59- const aclTensor* expandX, const aclTensor* quantExpandX, const aclTensor* expertIds, const aclTensor* expandIdx,
60- const aclTensor* expertScales, const aclTensor* commCmdInfo, const aclTensor* xActiveMaskOptional,
61- const aclTensor* sharedExpertXOptional, const char* groupEp, int64_t epWorldSize, int64_t epRankId,
62- int64_t moeExpertNum, int64_t expertShardType, int64_t sharedExpertNum, int64_t sharedExpertRankNum,
63- int64_t globalBs, int64_t commQuantMode, int64_t commType, const char* commAlg, aclTensor* xOut,
64- uint64_t* workspaceSize, aclOpExecutor** executor);
65- 
66-/**
67- * @brief aclnnMoeDistributeCombineTeardown的第二段接口,用于执行计算。
68- * @param [in] workspace: 在npu device侧申请的workspace内存地址。
69- * @param [in] workspace_size: 在npu device侧申请的workspace大小,
70- * 由第一段接口aclnnMoeDistributeCombineTeardownGetWorkspaceSize获取。
71- * @param [in] executor: op执行器,包含了算子计算流程。
72- * @param [in] stream: acl stream流。
73- * @return aclnnStatus: 返回状态码。
74- */
75-ACLNN_API aclnnStatus aclnnMoeDistributeCombineTeardown(void* workspace, uint64_t workspaceSize,
76- aclOpExecutor* executor, aclrtStream stream);
77- 
78-#ifdef __cplusplus
79-}
80-#endif
81- 
82-#endif // OP_API_INC_MOE_DISTRIBUTE_COMBINE_TEARDOWN_
@@ -1,13 +0,0 @@
1-# -----------------------------------------------------------------------------------------------------------
2-# Copyright (c) 2026 Huawei Technologies Co., Ltd.
3-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4-# CANN Open Software License Agreement Version 2.0 (the "License").
5-# Please refer to the License for details. You may not use this file except in compliance with the License.
6-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7-# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8-# See LICENSE in the root of the software repository for the full text of the License.
9-# -----------------------------------------------------------------------------------------------------------
10- 
11-if (BUILD_OPEN_PROJECT)
12- add_graph_plugin_sources()
13-endif()
@@ -1,86 +0,0 @@
1-/**
2- * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.
9- */
10- 
11-/*!
12- * \file moe_distribute_combine_teardown_proto.h
13- * \brief 图模式原型定义
14- */
15-#ifndef MOE_DISTRIBUTE_COMBINE_TEARDOWN_PROTO_H
16-#define MOE_DISTRIBUTE_COMBINE_TEARDOWN_PROTO_H
17- 
18-#include <graph/operator_reg.h>
19- 
20-namespace ge {
21-/**
22- * @brief MoeDistributeCombineTeardown operator interface implementation.
23- 
24- * @par Inputs
25- * Eight inputs, including:
26- * @li context: A tensor. Support dtype: int32, dimension must be 1. Shape supports (2052, ), support format: ND.
27- * @li expand_x: A tensor. Support dtype: float16, bfloat16, dimension must be 2, Support Shape: (A, H),
28- * support format: ND.
29- * @li quant_expand_x: A tensor. Support dtype: int8, dimension must be 2, Support Shape: (A, tokenMsgSize), support
30- * format: ND.
31- * @li expert_ids: A tensor. Support dtype: int32, dimension must be 2, Support Shape: (BS, K), support format: ND.
32- * @li expand_idx: A tensor. Support dtype: int32, dimension must be 1, Support Shape: (BS * K, ), support format: ND.
33- * @li expert_scales: A tensor. Support dtype: float32, dimension must be 2, Support Shape: (BS, K),
34- * support format: ND.
35- * @li comm_cmd_info: A tensor. Support dtype: int32, dimension must be 1, Call the
36- * `aclnnMoeDistributeCombineSetupTeardownCalcOutputSize` API to obtain the Shape, support format: ND.
37- * @li x_active_mask: An optional tensor. Support dtype: bool, dimension must be 1, Support Shape: (BS, ) support
38- * format: ND.
39- * @li shared_expert_x: An optional tensor. Dtype should be same with expand_x, dimension must be 2 or 3,
40- * Support Shape: (BS, H) or (a, b, H), where a * b = BS, support format: ND.
41- 
42- * @par Attributes
43- * @li ep_world_size: Input ep comm world size, dtype: Int64.
44- * @li ep_rank_id: Input ep comm rank Id, dtype: Int64.
45- * @li moe_expert_num: Input moe expert num, dtype: Int64.
46- * @li ccl_buffer_size: Required, Input ccl buffer size, Support Range: [0, MAX_INT32),MAX_INT32 = 2^31 - 1,
47- * dtype: Int64.
48- * @li expert_shard_type: Input moe shard type, dtype: Int64. Default: 0.
49- * @li shared_expert_num: Input shared expert num, dtype: Int64. Default: 1.
50- * @li shared_expert_rank_num: Input shared expert rank num, dtype: Int64. Default: 0.
51- * @li global_bs: Input global batch size, dtype: Int64. Default: 0.
52- * @li comm_quant_mode: communication quantization mode, 1 for enable, 0 for disable, dtype: Int64. Default: 0.
53- * @li comm_type: type of communication, dtype: Int64. Default: 0.
54- * @li comm_alg: Input comm alg type, dtype: String. Default: "".
55- 
56- * @par Outputs
57- * One outputs, including:
58- * @li x_out: A tensor. Result of combine. Dtype should be same with expand_x, Support Shape: (BS, H), support format:
59- * ND.
60- */
61-REG_OP(MoeDistributeCombineTeardown)
62- .INPUT(context, TensorType({DT_INT32}))
63- .INPUT(expand_x, TensorType({DT_FLOAT16, DT_BF16}))
64- .INPUT(quant_expand_x, TensorType({DT_INT8}))
65- .INPUT(expert_ids, TensorType({DT_INT32}))
66- .INPUT(expand_idx, TensorType({DT_INT32}))
67- .INPUT(expert_scales, TensorType({DT_FLOAT}))
68- .INPUT(comm_cmd_info, TensorType({DT_INT32}))
69- .OPTIONAL_INPUT(x_active_mask, TensorType({DT_BOOL}))
70- .OPTIONAL_INPUT(shared_expert_x, TensorType({DT_FLOAT16, DT_BF16}))
71- .OUTPUT(x_out, TensorType({DT_FLOAT16, DT_BF16}))
72- .REQUIRED_ATTR(ep_world_size, Int)
73- .REQUIRED_ATTR(ep_rank_id, Int)
74- .REQUIRED_ATTR(moe_expert_num, Int)
75- .REQUIRED_ATTR(ccl_buffer_size, Int)
76- .ATTR(expert_shard_type, Int, 0)
77- .ATTR(shared_expert_num, Int, 1)
78- .ATTR(shared_expert_rank_num, Int, 0)
79- .ATTR(global_bs, Int, 0)
80- .ATTR(comm_quant_mode, Int, 0)
81- .ATTR(comm_type, Int, 0)
82- .ATTR(comm_alg, String, "")
83- .OP_END_FACTORY_REG(MoeDistributeCombineTeardown)
84-} // namespace ge
85- 
86-#endif // MOE_DISTRIBUTE_COMBINE_TEARDOWN_PROTO_H
@@ -13,14 +13,12 @@ if (BUILD_OPEN_PROJECT) # custom
13 moe_distribute_combine_teardown_def.cpp13 moe_distribute_combine_teardown_def.cpp
14 )14 )
15 add_modules_sources_with_soc(15 add_modules_sources_with_soc(
16- OP_API_INDEPENDENT ON
17- OP_API_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../op_api
18 OP_MC2_ENABLE ON16 OP_MC2_ENABLE ON
19- OPTYPE moe_distribute_combine_teardown moe_distribute_combine_teardown ACLNNTYPE aclnn aclnn_inner)17+ OPTYPE moe_distribute_combine_teardown ACLNNTYPE aclnn_inner)
20 set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)18 set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)
21 set(MC2_OPT ON PARENT_SCOPE)19 set(MC2_OPT ON PARENT_SCOPE)
22 set(moe_distribute_combine_teardown_depends mc2/common mc2/3rd mc2/moe_distribute_combine_setup PARENT_SCOPE)20 set(moe_distribute_combine_teardown_depends mc2/common mc2/3rd mc2/moe_distribute_combine_setup PARENT_SCOPE)
23else() # 回黄host21else() # 回黄host
24- add_mc2_modules_sources(OPTYPE moe_distribute_combine_teardown moe_distribute_combine_teardown ACLNNTYPE aclnn aclnn_inner)22+ add_mc2_modules_sources(OPTYPE moe_distribute_combine_teardown ACLNNTYPE aclnn_inner)
25 set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)23 set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)
26endif()24endif()
@@ -1,13 +0,0 @@
1-# -----------------------------------------------------------------------------------------------------------
2-# Copyright (c) 2026 Huawei Technologies Co., Ltd.
3-# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4-# CANN Open Software License Agreement Version 2.0 (the "License").
5-# Please refer to the License for details. You may not use this file except in compliance with the License.
6-# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7-# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8-# See LICENSE in the root of the software repository for the full text of the License.
9-# -----------------------------------------------------------------------------------------------------------
10- 
11-if(UT_TEST_ALL OR OP_API_UT)
12- add_modules_ut_sources(UT_NAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
13-endif()
Mtests/test_config.yaml+0-10File content is under review, please try again later