Merged
add new op moe_ep_dispatch #7807
add new op moe_ep_dispatch #7807
Merged
z1017iAdd on Jun 29
Total: 10 files changed+1861-0
@@ -24,6 +24,7 @@ struct Mc2MoeContext {
24 uint32_t rankSizePerServer;24 uint32_t rankSizePerServer;
25 uint64_t kfcContextAddr; // host kfc方案中,需要传递通信API所需的地址25 uint64_t kfcContextAddr; // host kfc方案中,需要传递通信API所需的地址
26 uint64_t epHcclBuffer_[HCCL_MAX_RANK_SIZE];26 uint64_t epHcclBuffer_[HCCL_MAX_RANK_SIZE];
27+ uint64_t hcommHandle_[HCCL_MAX_RANK_SIZE]; // 支持ROCE或者URMA
27};28};
28}29}
29 30 
@@ -0,0 +1,21 @@
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+file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
12+if(NOT ENABLE_TEST)
13+ list(REMOVE_ITEM CURRENT_DIRS tests)
14+endif()
15+foreach(SUB_DIR ${CURRENT_DIRS})
16+ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
17+ add_subdirectory(${SUB_DIR})
18+ endif()
19+endforeach()
20+ 
21+set(MC2_COMPILE ${SUB_MC2_COMPILE} PARENT_SCOPE)
@@ -0,0 +1,103 @@
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+#include "common/utils/op_mc2.h"
12+#include "common/utils/op_mc2_def.h"
13+#include "aclnn_kernels/common/op_error_check.h"
14+#include "opdev/op_log.h"
15+#include "opdev/common_types.h"
16+#include "aclnnInner_moe_ep_dispatch.h"
17+ 
18+using namespace op;
19+ 
20+#ifdef __cplusplus
21+extern "C" {
22+#endif
23+ 
24+enum NnopbaseHcclServerType {
25+ NNOPBASE_HCCL_SERVER_TYPE_AICPU = 0,
26+ NNOPBASE_HCCL_SERVER_TYPE_MTE,
27+ NNOPBASE_HCCL_SERVER_TYPE_CCU,
28+ NNOPBASE_HCCL_SERVER_TYPE_END
29+};
30+ 
31+extern "C" void __attribute__((weak)) NnopbaseSetHcclServerType(void *executor, NnopbaseHcclServerType sType);
32+ 
33+static aclnnStatus CheckNotNull(const aclTensor* context, const aclTensor* x, const aclTensor* topkIdx,
chenjianjun11

不需要被外面调用的函数,放到 extern "C"范围外面

likedislike
34+ aclTensor* numRecvTokensPerRank, aclTensor* numRecvTokensPerExpert,
35+ aclTensor* dstBufferSlotIdx)
36+{
37+ CHECK_RET(context != nullptr, ACLNN_ERR_PARAM_NULLPTR);
38+ CHECK_RET(x != nullptr, ACLNN_ERR_PARAM_NULLPTR);
39+ CHECK_RET(topkIdx != nullptr, ACLNN_ERR_PARAM_NULLPTR);
40+ CHECK_RET(numRecvTokensPerRank != nullptr, ACLNN_ERR_PARAM_NULLPTR);
41+ CHECK_RET(numRecvTokensPerExpert != nullptr, ACLNN_ERR_PARAM_NULLPTR);
42+ CHECK_RET(dstBufferSlotIdx != nullptr, ACLNN_ERR_PARAM_NULLPTR);
43+ return ACLNN_SUCCESS;
44+}
45+ 
46+static aclnnStatus CheckParams(int64_t epWorldSize, int64_t epRankId, int64_t numExperts,
wangyongguang

补充PR描述和issue关联

likedislike
47+ int64_t numMaxTokensPerRank, int64_t cclBufferSize,
48+ int64_t expertAlignment, bool doCpuSync,
49+ const aclTensor* cachedHandleDstBufferSlotIdx)
50+{
51+ CHECK_RET(epWorldSize > 1, ACLNN_ERR_PARAM_INVALID);
52+ CHECK_RET(epRankId >= 0 && epRankId < epWorldSize, ACLNN_ERR_PARAM_INVALID);
53+ CHECK_RET(numExperts % epWorldSize == 0, ACLNN_ERR_PARAM_INVALID);
54+ CHECK_RET(numMaxTokensPerRank > 0, ACLNN_ERR_PARAM_INVALID);
55+ CHECK_RET(cclBufferSize > 0, ACLNN_ERR_PARAM_INVALID);
56+ CHECK_RET(expertAlignment == 1, ACLNN_ERR_PARAM_INVALID);
57+ 
58+ bool cachedMode = (cachedHandleDstBufferSlotIdx != nullptr);
59+ CHECK_RET(!(cachedMode && doCpuSync), ACLNN_ERR_PARAM_INVALID);
60+ 
61+ return ACLNN_SUCCESS;
62+}
63+ 
64+aclnnStatus aclnnMoeEpDispatchGetWorkspaceSize(
65+ const aclTensor* context, const aclTensor* x, const aclTensor* topkIdx, const aclTensor* topkWeights,
66+ const aclTensor* scales, const aclTensor* cachedHandleDstBufferSlotIdx, int64_t epWorldSize,
67+ int64_t epRankId, int64_t numExperts, int64_t numMaxTokensPerRank, int64_t cclBufferSize,
68+ int64_t expertAlignment, bool doCpuSync, int64_t hostPinnedCounterAddr,
69+ aclTensor* numRecvTokensPerRank, aclTensor* numRecvTokensPerExpert, aclTensor* dstBufferSlotIdx,
70+ uint64_t* workspaceSize, aclOpExecutor** executor)
71+{
72+ OP_LOGD("aclnnMoeEpDispatch WorkspaceSize start");
73+ 
74+ auto retNotNull = CheckNotNull(context, x, topkIdx, numRecvTokensPerRank, numRecvTokensPerExpert,
75+ dstBufferSlotIdx);
76+ CHECK_RET(retNotNull == ACLNN_SUCCESS, retNotNull);
77+ 
78+ auto retParams = CheckParams(epWorldSize, epRankId, numExperts, numMaxTokensPerRank, cclBufferSize,
79+ expertAlignment, doCpuSync, cachedHandleDstBufferSlotIdx);
80+ CHECK_RET(retParams == ACLNN_SUCCESS, retParams);
81+ 
82+ aclnnStatus getWorkspaceSizesRes = aclnnInnerMoeEpDispatchGetWorkspaceSize(
83+ context, x, topkIdx, topkWeights, scales, cachedHandleDstBufferSlotIdx, epWorldSize, epRankId,
84+ numExperts, numMaxTokensPerRank, cclBufferSize, expertAlignment, doCpuSync, hostPinnedCounterAddr,
85+ numRecvTokensPerRank, numRecvTokensPerExpert, dstBufferSlotIdx, workspaceSize, executor);
86+
87+ return getWorkspaceSizesRes;
88+}
89+ 
90+aclnnStatus aclnnMoeEpDispatch(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, aclrtStream stream)
91+{
92+ OP_LOGD("aclnnMoeEpDispatch start");
93+ if (NnopbaseSetHcclServerType) {
94+ NnopbaseSetHcclServerType(executor, NnopbaseHcclServerType::NNOPBASE_HCCL_SERVER_TYPE_MTE);
95+ }
96+ aclnnStatus ret = aclnnInnerMoeEpDispatch(workspace, workspaceSize, executor, stream);
97+ OP_LOGD("aclnnMoeEpDispatch success");
98+ return ret;
99+}
100+ 
101+#ifdef __cplusplus
102+}
103+#endif // extern "C"
@@ -0,0 +1,33 @@
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+ target_sources(op_host_aclnnInner PRIVATE
13+ moe_ep_dispatch_def.cpp
14+ )
15+ add_modules_sources(
16+ OP_API_INDEPENDENT ON
17+ OP_API_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../op_api
18+ OP_MC2_ENABLE ON
19+ OPTYPE moe_ep_dispatch ACLNNTYPE aclnn_inner)
20+ set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)
21+ set(MC2_OPT ON PARENT_SCOPE)
22+ set(moe_ep_dispatch_depends mc2/common mc2/3rd PARENT_SCOPE)
23+ 
24+ set(CONDITION_UNIT ${ASCEND_COMPUTE_UNIT})
25+ add_ops_compile_options(
26+ OP_NAME MoeEpDispatch
27+ OPTIONS --cce-auto-sync=off
28+ )
29+ 
30+else()
31+ add_mc2_modules_sources(OPTYPE moe_ep_dispatch ACLNNTYPE aclnn_inner)
32+ set(SUB_MC2_COMPILE TRUE PARENT_SCOPE)
33+endif()
@@ -0,0 +1,94 @@
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_ep_dispatch_def.cpp
13+ * \brief
14+ */
15+ 
16+#include "register/op_def_registry.h"
17+ 
18+namespace ops {
19+ 
20+class MoeEpDispatch : public OpDef {
21+public:
22+ explicit MoeEpDispatch(const char* name) : OpDef(name) {
23+ this->Input("context")
24+ .ParamType(REQUIRED)
25+ .DataTypeList({ge::DT_INT32})
26+ .FormatList({ge::FORMAT_ND})
27+ .AutoContiguous();
28+ this->Input("x")
29+ .ParamType(REQUIRED)
30+ .DataTypeList({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT8_E5M2, ge::DT_FLOAT8_E4M3FN})
31+ .FormatList({ge::FORMAT_ND})
32+ .AutoContiguous();
33+ this->Input("topk_idx")
34+ .ParamType(REQUIRED)
35+ .DataTypeList({ge::DT_INT32})
36+ .FormatList({ge::FORMAT_ND})
37+ .AutoContiguous();
38+ this->Input("topk_weights")
39+ .ParamType(OPTIONAL)
40+ .DataTypeList({ge::DT_FLOAT})
41+ .FormatList({ge::FORMAT_ND})
42+ .AutoContiguous();
43+ this->Input("scales")
44+ .ParamType(OPTIONAL)
45+ .DataTypeList({ge::DT_FLOAT, ge::DT_FLOAT8_E8M0})
46+ .FormatList({ge::FORMAT_ND})
47+ .AutoContiguous();
48+ this->Input("cached_handle_dst_buffer_slot_idx")
49+ .ParamType(OPTIONAL)
50+ .DataTypeList({ge::DT_INT32})
51+ .FormatList({ge::FORMAT_ND})
52+ .AutoContiguous();
53+ 
54+ this->Output("num_recv_tokens_per_rank")
55+ .ParamType(REQUIRED)
56+ .DataTypeList({ge::DT_INT32})
57+ .FormatList({ge::FORMAT_ND});
58+ this->Output("num_recv_tokens_per_expert")
59+ .ParamType(REQUIRED)
60+ .DataTypeList({ge::DT_INT64})
61+ .FormatList({ge::FORMAT_ND});
62+ this->Output("dst_buffer_slot_idx")
63+ .ParamType(REQUIRED)
64+ .DataTypeList({ge::DT_INT32})
65+ .FormatList({ge::FORMAT_ND});
66+ 
67+ this->Attr("ep_world_size").AttrType(REQUIRED).Int();
68+ this->Attr("ep_rank_id").AttrType(REQUIRED).Int();
69+ this->Attr("num_experts").AttrType(REQUIRED).Int();
70+ this->Attr("num_max_tokens_per_rank").AttrType(REQUIRED).Int();
71+ this->Attr("ccl_buffer_size").AttrType(REQUIRED).Int();
72+ this->Attr("expert_alignment").AttrType(OPTIONAL).Int(1);
73+ this->Attr("do_cpu_sync").AttrType(OPTIONAL).Bool(true);
74+ this->Attr("host_pinned_counter_addr").AttrType(OPTIONAL).Int(0);
75+ 
76+ OpAICoreConfig aicore_config;
77+ aicore_config.DynamicCompileStaticFlag(true)
78+ .DynamicFormatFlag(true)
79+ .DynamicRankSupportFlag(true)
80+ .DynamicShapeSupportFlag(true)
81+ .NeedCheckSupportFlag(false)
82+ .PrecisionReduceFlag(true)
83+ .ExtendCfgInfo("aclnnSupport.value", "support_aclnn")
84+ .ExtendCfgInfo("prebuildPattern.value", "Opaque")
85+ .ExtendCfgInfo("jitCompile.flag", "static_true")
86+ .ExtendCfgInfo("multiKernelSupportDynamicGraph.value", "multi_kernel");
87+ 
88+ this->AICore().AddConfig("ascend950", aicore_config);
89+ }
90+};
91+ 
92+OP_ADD(MoeEpDispatch);
93+ 
94+} // namespace ops
@@ -0,0 +1,631 @@
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_ep_dispatch_tiling.cpp
13+ * \brief
14+ */
15+ 
16+#include <cmath>
17+#include <cstdint>
18+#include <cstdio>
19+#include <cstdlib>
20+#include <cstring>
21+#include <vector>
22+ 
23+#include "mc2_log.h"
24+#include "graph/utils/type_utils.h"
25+#include "mc2_tiling_utils.h"
26+#include "register/op_def_registry.h"
27+#include "register/tilingdata_base.h"
28+#include "tiling/tiling_api.h"
29+#include "../../op_kernel/moe_ep_dispatch_tiling.h"
30+#include "../../op_kernel/moe_ep_dispatch_tiling_key.h"
31+ 
32+using namespace AscendC;
33+using namespace ge;
34+using namespace Mc2Tiling;
35+ 
36+namespace optiling {
chenjianjun11

namespace Mc2Tiling

likedislike
37+ 
38+constexpr uint32_t CONTEXT_INDEX = 0U;
39+constexpr uint32_t X_INDEX = 1U;
40+constexpr uint32_t TOPK_IDX_INDEX = 2U;
41+constexpr uint32_t TOPK_WEIGHTS_INDEX = 3U;
42+constexpr uint32_t SCALES_INDEX = 4U;
43+constexpr uint32_t CACHED_SLOT_IDX_INDEX = 5U;
44+ 
45+constexpr uint32_t NUM_RECV_PER_RANK_INDEX = 0U;
46+constexpr uint32_t NUM_RECV_PER_EXPERT_INDEX = 1U;
47+constexpr uint32_t DST_BUFFER_SLOT_IDX_INDEX = 2U;
48+ 
49+constexpr uint32_t ATTR_EP_WORLD_SIZE_INDEX = 0;
50+constexpr uint32_t ATTR_EP_RANK_ID_INDEX = 1;
51+constexpr uint32_t ATTR_NUM_EXPERTS_INDEX = 2;
52+constexpr uint32_t ATTR_NUM_MAX_TPR_INDEX = 3;
53+constexpr uint32_t ATTR_CCL_BUFFER_SIZE_INDEX = 4;
54+constexpr uint32_t ATTR_EXPERT_ALIGNMENT_INDEX = 5;
55+constexpr uint32_t ATTR_DO_CPU_SYNC_INDEX = 6;
56+constexpr uint32_t ATTR_HOST_PINNED_COUNTER_ADDR_INDEX = 7;
57+ 
58+constexpr uint32_t ONE_DIM = 1U;
59+constexpr uint32_t TWO_DIMS = 2U;
60+constexpr int64_t H_MAX = 8192;
61+constexpr int64_t K_MAX = 32;
62+constexpr int64_t MAX_EP_WORLD_SIZE = 128;
63+constexpr int64_t MIN_EP_WORLD_SIZE = 2;
64+constexpr uint64_t MAX_OUT_DTYPE_SIZE = 2UL;
65+constexpr uint64_t FP8_DTYPE_SIZE = 1UL;
66+constexpr uint64_t METADATA_DTYPE_SIZE = 4UL; // sizeof(int32)=sizeof(float)=4
67+constexpr int64_t SCALES_GROUP_SIZE_MXFP = 32;
68+constexpr int64_t SCALES_GROUP_SIZE_PERGROUP = 128;
69+constexpr int64_t SCALES_ALIGN_EVEN = 2; // fp8 align 2
70+ 
71+constexpr uint32_t SYSTEM_NEED_WORKSPACE = 16U * 1024U * 1024U;
72+constexpr uint64_t MB_SIZE = 1024UL * 1024UL;
73+constexpr uint64_t WIN_ADDR_ALIGN = 512UL;
74+constexpr uint64_t UB_ALIGN = 32UL;
75+ 
76+constexpr uint32_t DIRECT_MODE = 0;
77+constexpr uint32_t HYBRID_MODE = 1;
78+ 
79+static void PrintTilingDataInfo(const char *nodeName, const MoeEpDispatchInfo &info)
80+{
81+ OP_LOGD(nodeName, "epWorldSize is %u.", info.cfg.epWorldSize);
82+ OP_LOGD(nodeName, "epRankId is %u.", info.cfg.epRankId);
83+ OP_LOGD(nodeName, "numExperts is %u.", info.cfg.numExperts);
84+ OP_LOGD(nodeName, "numLocalExperts is %u.", info.cfg.numLocalExperts);
85+ OP_LOGD(nodeName, "numTokens is %u.", info.cfg.numTokens);
86+ OP_LOGD(nodeName, "hidden is %u.", info.cfg.hidden);
87+ OP_LOGD(nodeName, "topK is %u.", info.cfg.topK);
88+ OP_LOGD(nodeName, "numMaxTokensPerRank is %u.", info.cfg.numMaxTokensPerRank);
89+ OP_LOGD(nodeName, "perSlotBytes is %u.", info.cfg.perSlotBytes);
90+ OP_LOGD(nodeName, "expertAlignment is %u.", info.cfg.expertAlignment);
91+ OP_LOGD(nodeName, "doCpuSync is %u.", info.doCpuSync);
92+ OP_LOGD(nodeName, "isCached is %u.", info.isCached);
93+ OP_LOGD(nodeName, "isTopkWeights is %u.", info.isTopkWeights);
94+ OP_LOGD(nodeName, "networkMode is %u.", info.networkMode);
95+ OP_LOGD(nodeName, "numScaleupRanks is %u.", info.numScaleupRanks);
96+ OP_LOGD(nodeName, "numScaleoutRanks is %u.", info.numScaleoutRanks);
97+ OP_LOGD(nodeName, "numAivStage1 is %u.", info.numAivStage1);
98+ OP_LOGD(nodeName, "numAivStage2 is %u.", info.numAivStage2);
99+ OP_LOGD(nodeName, "aivNum is %u.", info.aivNum);
100+ OP_LOGD(nodeName, "hostPinnedCounterAddr is %lu.", info.hostPinnedCounterAddr);
@@ -0,0 +1,46 @@
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_ep_dispatch.cpp
13+ * \brief
14+ */
15+ 
16+#if ASC_DEVKIT_MAJOR >= 9
17+#include "basic_api/kernel_basic_intf.h"
18+#else
19+#include "kernel_operator.h"
20+#endif
21+ 
22+#include "moe_ep_dispatch_tiling_key.h"
23+#include "moe_ep_dispatch_tiling.h"
24+#include "moe_ep_dispatch.h"
25+ 
26+using namespace MoeEpDispatchImpl;
27+using namespace Mc2Tiling;
28+using namespace AscendC;
29+ 
30+template<bool DoCpuSync, bool IsCached, bool IsTopkWeights, bool IsMxQuant, uint8_t NetworkMode>
31+__global__ __aicore__ void moe_ep_dispatch(
32+ GM_ADDR context, GM_ADDR x, GM_ADDR topkIdx, GM_ADDR topkWeights, GM_ADDR scales,
33+ GM_ADDR cachedSlotIdx, GM_ADDR numRecvPerRank, GM_ADDR numRecvPerExpert,
34+ GM_ADDR dstBufferSlotIdx, GM_ADDR workspaceGM, GM_ADDR tilingGM)
35+{
36+ REGISTER_TILING_DEFAULT(MoeEpDispatchTilingData);
37+ 
38+ TPipe pipe;
39+ GET_TILING_DATA_WITH_STRUCT(MoeEpDispatchTilingData, tilingData, tilingGM);
40+ using ScalesType = typename std::conditional<IsMxQuant, fp8_e8m0_t, float>::type;
41+ 
42+ MoeEpDispatch<DTYPE_X, ScalesType, DoCpuSync, IsCached, IsTopkWeights, NetworkMode> op;
43+ op.Init(context, x, topkIdx, topkWeights, scales, cachedSlotIdx, numRecvPerRank,
44+ numRecvPerExpert, dstBufferSlotIdx, workspaceGM, &pipe, &tilingData);
45+ op.Process();
46+}
@@ -0,0 +1,60 @@
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_ep_dispatch_tiling.h
13+ * \brief
14+ */
15+ 
16+#ifndef MOE_EP_DISPATCH_TILING_H
17+#define MOE_EP_DISPATCH_TILING_H
18+ 
19+#include <cstdint>
20+#include "kernel_tiling/kernel_tiling.h"
21+ 
22+struct MoeEpCommonTilingData {
23+ uint32_t epWorldSize;
24+ uint32_t epRankId;
25+ uint32_t numExperts;
26+ uint32_t numLocalExperts;
27+ uint32_t numTokens;
28+ uint32_t hidden;
tu_song
tu_songtu_songJun 29

hiddenSize?

likedislike
29+ uint32_t topK;
30+ uint32_t numMaxTokensPerRank;
31+ uint32_t scalesBytes;
32+ uint32_t perSlotBytes;
33+ uint32_t expertAlignment;
34+};
35+ 
36+struct MoeEpDispatchInfo {
37+ MoeEpCommonTilingData cfg;
38+ uint32_t doCpuSync;
39+ uint32_t isCached;
40+ uint32_t isTopkWeights;
41+ uint32_t isMxQuant;
42+ uint32_t networkMode;
43+ uint32_t numScaleupRanks;
44+ uint32_t numScaleoutRanks;
45+ uint32_t numAivStage1;
46+ uint32_t numAivStage2;
47+ uint32_t aivNum;
48+ uint64_t hostPinnedCounterAddr;
49+ uint64_t cntWinStateOffset;
50+ uint64_t slotWinStateOffset;
51+ uint64_t winDataOffset;
52+ uint64_t totalWinSizeEp;
53+ uint64_t totalUbSize;
54+};
55+ 
56+struct MoeEpDispatchTilingData {
57+ MoeEpDispatchInfo moeEpDispatchInfo;
tu_song
tu_songtu_songJun 29

MoeEpDispatchInfo 这个结构体是不是多余

likedislike
58+};
59+ 
60+#endif // MOE_EP_DISPATCH_TILING_H
@@ -0,0 +1,46 @@
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_ep_dispatch_tiling_key.h
13+ * \brief
14+ */
15+ 
16+#ifndef MOE_EP_DISPATCH_TILING_KEY_H
17+#define MOE_EP_DISPATCH_TILING_KEY_H
18+ 
19+#include "ascendc/host_api/tiling/template_argument.h"
20+ 
21+namespace Mc2Tiling {
22+ 
23+#define TILINGKEY_DIRECT 0
24+#define TILINGKEY_HYBRID 1
25+ 
26+ASCENDC_TPL_ARGS_DECL(MoeEpDispatch,
27+ ASCENDC_TPL_BOOL_DECL(TILINGKEY_DO_CPU_SYNC, 0, 1),
28+ ASCENDC_TPL_BOOL_DECL(TILINGKEY_IS_CACHED, 0, 1),
29+ ASCENDC_TPL_BOOL_DECL(TILINGKEY_IS_TOPK_WEIGHTS, 0, 1),
30+ ASCENDC_TPL_BOOL_DECL(TILINGKEY_IS_MXQUANT, 0, 1),
31+ ASCENDC_TPL_UINT_DECL(TILINGKEY_NETWORK_MODE, ASCENDC_TPL_2_BW, ASCENDC_TPL_UI_LIST,
32+ TILINGKEY_DIRECT, TILINGKEY_HYBRID));
33+ 
34+ASCENDC_TPL_SEL(
35+ ASCENDC_TPL_ARGS_SEL(
36+ ASCENDC_TPL_BOOL_SEL(TILINGKEY_DO_CPU_SYNC, 0, 1),
37+ ASCENDC_TPL_BOOL_SEL(TILINGKEY_IS_CACHED, 0, 1),
38+ ASCENDC_TPL_BOOL_SEL(TILINGKEY_IS_TOPK_WEIGHTS, 0, 1),
39+ ASCENDC_TPL_BOOL_SEL(TILINGKEY_IS_MXQUANT, 0, 1),
40+ ASCENDC_TPL_UINT_SEL(TILINGKEY_NETWORK_MODE, ASCENDC_TPL_UI_LIST, TILINGKEY_DIRECT, TILINGKEY_HYBRID),
41+ ASCENDC_TPL_TILING_STRUCT_SEL(MoeEpDispatchTilingData)
42+ ),
43+);
44+ 
45+} // namespace Mc2Tiling
46+#endif // MOE_EP_DISPATCH_TILING_KEY_H