已关闭
Fix CleanCode #11170
yayahello创建于 9月3日关闭于 9月4日
Fix CleanCode #11170
已关闭
共 10 个文件变更+59-94
| @@ -24,9 +24,7 @@ | |||
| 24 | 24 | ||
| 25 | using namespace op; | 25 | using namespace op; |
| 26 | 26 | ||
| 27 | -static bool CheckNotNull(const aclTensor *commContext, const aclTensor *indices, const aclTensor *localStorageAddr, | 27 | +static bool CheckNotNull(const aclTensor *commContext, const aclTensor *indices, const aclTensor *fetched) |
| 28 | - aclTensor *fetched, aclTensor *permOut, aclTensor *sendCountsOut, aclTensor *recvCountsOut, | ||
| 29 | - aclTensor *recvLocalEntryOut, aclTensor *numRecvOut) | ||
| 30 | { | 28 | { |
| 31 | OP_CHECK_NULL(commContext, return false); | 29 | OP_CHECK_NULL(commContext, return false); |
| 32 | OP_CHECK_NULL(indices, return false); | 30 | OP_CHECK_NULL(indices, return false); |
| @@ -34,14 +32,9 @@ static bool CheckNotNull(const aclTensor *commContext, const aclTensor *indices, | |||
| 34 | return true; | 32 | return true; |
| 35 | } | 33 | } |
| 36 | 34 | ||
| 37 | -static aclnnStatus CheckParams(const aclTensor *commContext, const aclTensor *indices, | 35 | +static aclnnStatus CheckParams(const aclTensor *commContext, const aclTensor *indices, const aclTensor *fetched) |
| 38 | - const aclTensor *localStorageAddr, aclTensor *fetched, aclTensor *permOut, | ||
| 39 | - aclTensor *sendCountsOut, aclTensor *recvCountsOut, aclTensor *recvLocalEntryOut, | ||
| 40 | - aclTensor *numRecvOut) | ||
| 41 | { | 36 | { |
| 42 | - CHECK_RET(CheckNotNull(commContext, indices, localStorageAddr, fetched, permOut, sendCountsOut, recvCountsOut, | 37 | + CHECK_RET(CheckNotNull(commContext, indices, fetched), ACLNN_ERR_PARAM_NULLPTR); |
| 43 | - recvLocalEntryOut, numRecvOut), | ||
| 44 | - ACLNN_ERR_PARAM_NULLPTR); | ||
| 45 | return ACLNN_SUCCESS; | 38 | return ACLNN_SUCCESS; |
| 46 | } | 39 | } |
| 47 | 40 | ||
| @@ -57,8 +50,7 @@ aclnnStatus aclnnEngramFetchGetWorkspaceSize(const aclTensor *commContext, const | |||
| 57 | int64_t commBufferSize, int64_t withGrad, uint64_t *workspaceSize, | 50 | int64_t commBufferSize, int64_t withGrad, uint64_t *workspaceSize, |
| 58 | aclOpExecutor **executor) | 51 | aclOpExecutor **executor) |
| 59 | { | 52 | { |
| 60 | - auto retParam = CheckParams(commContext, indices, localStorageAddr, fetched, permOut, sendCountsOut, recvCountsOut, | 53 | + auto retParam = CheckParams(commContext, indices, fetched); |
| 61 | - recvLocalEntryOut, numRecvOut); | ||
| 62 | CHECK_RET(retParam == ACLNN_SUCCESS, retParam); | 54 | CHECK_RET(retParam == ACLNN_SUCCESS, retParam); |
| 63 | aclnnStatus ret = aclnnInnerEngramFetchGetWorkspaceSize(commContext, indices, localStorageAddr, hiddenSize, | 55 | aclnnStatus ret = aclnnInnerEngramFetchGetWorkspaceSize(commContext, indices, localStorageAddr, hiddenSize, |
| 64 | numEntriesPerRank, numMaxTokensPerRank, commBufferSize, | 56 | numEntriesPerRank, numMaxTokensPerRank, commBufferSize, |
| @@ -35,7 +35,7 @@ extern "C" { | |||
| 35 | * @param [in] epWorldSize: 计算输入,int。ep通信域size。 | 35 | * @param [in] epWorldSize: 计算输入,int。ep通信域size。 |
| 36 | * @param [in] epRankId: 计算输入,int。ep本卡Id。同一个EP通信域中各卡的epRankId不重复。 | 36 | * @param [in] epRankId: 计算输入,int。ep本卡Id。同一个EP通信域中各卡的epRankId不重复。 |
| 37 | * @param [in] moeExpertNum: 计算输入,int。MOE专家数量。 | 37 | * @param [in] moeExpertNum: 计算输入,int。MOE专家数量。 |
| 38 | - * @param [in] expertSharedType: 计算可选输入,int。共享专家卡分布类型。当前仅支持传0。 | 38 | + * @param [in] expertShardType: 计算可选输入,int。共享专家卡分布类型。当前仅支持传0。 |
| 39 | * @param [in] sharedExpertNum: 计算可选输入,int。共享专家数量。 | 39 | * @param [in] sharedExpertNum: 计算可选输入,int。共享专家数量。 |
| 40 | * @param [in] sharedExpertRankNum: 计算可选输入,int。共享专家卡数量。 | 40 | * @param [in] sharedExpertRankNum: 计算可选输入,int。共享专家卡数量。 |
| 41 | * @param [in] globalBs: 计算可选输入,int。 | 41 | * @param [in] globalBs: 计算可选输入,int。 |
| @@ -51,7 +51,7 @@ extern "C" { | |||
| 51 | */ | 51 | */ |
| 52 | ACLNN_API aclnnStatus aclnnMoeDistributeCombineSetupGetWorkspaceSize( | 52 | ACLNN_API aclnnStatus aclnnMoeDistributeCombineSetupGetWorkspaceSize( |
| 53 | const aclTensor *expandX, const aclTensor *expertIds, const aclTensor *assistInfoForCombine, const char *groupEp, | 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 expertSharedType, int64_t sharedExpertNum, | 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, | 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); | 56 | aclTensor *quantExpandXOut, aclTensor *commCmdInfoOut, uint64_t *workspaceSize, aclOpExecutor **executor); |
| 57 | 57 | ||
| @@ -66,7 +66,7 @@ ACLNN_API aclnnStatus aclnnMoeDistributeCombineSetupGetWorkspaceSize( | |||
| 66 | * @param [in] epWorldSize: 计算输入,int。ep通信域size。 | 66 | * @param [in] epWorldSize: 计算输入,int。ep通信域size。 |
| 67 | * @param [in] epRankId: 计算输入,int。ep本卡Id。同一个EP通信域中各卡的epRankId不重复。 | 67 | * @param [in] epRankId: 计算输入,int。ep本卡Id。同一个EP通信域中各卡的epRankId不重复。 |
| 68 | * @param [in] moeExpertNum: 计算输入,int。MOE专家数量。 | 68 | * @param [in] moeExpertNum: 计算输入,int。MOE专家数量。 |
| 69 | - * @param [in] expertSharedType: 计算可选输入,int。共享专家卡分布类型。当前仅支持传0。 | 69 | + * @param [in] expertShardType: 计算可选输入,int。共享专家卡分布类型。当前仅支持传0。 |
| 70 | * @param [in] sharedExpertNum: 计算可选输入,int。共享专家数量。 | 70 | * @param [in] sharedExpertNum: 计算可选输入,int。共享专家数量。 |
| 71 | * @param [in] sharedExpertRankNum: 计算可选输入,int。共享专家卡数量。 | 71 | * @param [in] sharedExpertRankNum: 计算可选输入,int。共享专家卡数量。 |
| 72 | * @param [in] globalBs: 计算可选输入,int。 | 72 | * @param [in] globalBs: 计算可选输入,int。 |
| @@ -80,7 +80,7 @@ ACLNN_API aclnnStatus aclnnMoeDistributeCombineSetupGetWorkspaceSize( | |||
| 80 | */ | 80 | */ |
| 81 | ACLNN_API aclnnStatus aclnnMoeDistributeCombineSetupTeardownCalcOutputSize( | 81 | ACLNN_API aclnnStatus aclnnMoeDistributeCombineSetupTeardownCalcOutputSize( |
| 82 | const aclTensor *expandX, const aclTensor *expertIds, const aclTensor *assistInfoForCombine, const char *groupEp, | 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 expertSharedType, int64_t sharedExpertNum, | 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, | 84 | int64_t sharedExpertRankNum, int64_t globalBs, int64_t commQuantMode, int64_t commType, const char *commAlg, |
| 85 | uint64_t &tokenMsgSize, uint64_t &commCmdInfoOutSize); | 85 | uint64_t &tokenMsgSize, uint64_t &commCmdInfoOutSize); |
| 86 | 86 | ||
| @@ -36,7 +36,6 @@ enum class NnopbaseHcclServerType : uint32_t { | |||
| 36 | 36 | ||
| 37 | static bool CheckNotNull(const aclTensor *expandX, const aclTensor *quantExpandX, const aclTensor *expertIds, | 37 | static bool CheckNotNull(const aclTensor *expandX, const aclTensor *quantExpandX, const aclTensor *expertIds, |
| 38 | const aclTensor *expandIdx, const aclTensor *expertScales, const aclTensor *commCmdInfo, | 38 | const aclTensor *expandIdx, const aclTensor *expertScales, const aclTensor *commCmdInfo, |
| 39 | - const aclTensor *xActiveMaskOptional, const aclTensor *sharedExpertXOptional, | ||
| 40 | const char *groupEp, aclTensor *xOut) | 39 | const char *groupEp, aclTensor *xOut) |
| 41 | { | 40 | { |
| 42 | OP_LOGD("aclnn_moe_distribute_combine_teardown CheckNotNull start"); | 41 | OP_LOGD("aclnn_moe_distribute_combine_teardown CheckNotNull start"); |
| @@ -57,15 +56,10 @@ static bool CheckNotNull(const aclTensor *expandX, const aclTensor *quantExpandX | |||
| 57 | 56 | ||
| 58 | static aclnnStatus CheckParams(const aclTensor *expandX, const aclTensor *quantExpandX, const aclTensor *expertIds, | 57 | static aclnnStatus CheckParams(const aclTensor *expandX, const aclTensor *quantExpandX, const aclTensor *expertIds, |
| 59 | const aclTensor *expandIdx, const aclTensor *expertScales, const aclTensor *commCmdInfo, | 58 | const aclTensor *expandIdx, const aclTensor *expertScales, const aclTensor *commCmdInfo, |
| 60 | - const aclTensor *xActiveMaskOptional, const aclTensor *sharedExpertXOptional, | 59 | + const char *groupEp, aclTensor *xOut) |
| 61 | - const char *groupEp, int64_t epWorldSize, int64_t epRankId, int64_t moeExpertNum, | ||
| 62 | - int64_t expertShardType, int64_t sharedExpertNum, int64_t sharedExpertRankNum, | ||
| 63 | - int64_t globalBs, int64_t commQuantMode, int64_t commType, const char *commAlg, | ||
| 64 | - aclTensor *xOut) | ||
| 65 | { | 60 | { |
| 66 | OP_LOGD("aclnn_moe_distribute_combine_teardown checkparams start"); | 61 | OP_LOGD("aclnn_moe_distribute_combine_teardown checkparams start"); |
| 67 | - CHECK_RET(CheckNotNull(expandX, quantExpandX, expertIds, expandIdx, expertScales, commCmdInfo, xActiveMaskOptional, | 62 | + CHECK_RET(CheckNotNull(expandX, quantExpandX, expertIds, expandIdx, expertScales, commCmdInfo, groupEp, xOut), |
| 68 | - sharedExpertXOptional, groupEp, xOut), | ||
| 69 | ACLNN_ERR_PARAM_NULLPTR); | 63 | ACLNN_ERR_PARAM_NULLPTR); |
| 70 | if (strnlen(groupEp, HCCL_GROUP_NAME_MAX) >= HCCL_GROUP_NAME_MAX) { | 64 | if (strnlen(groupEp, HCCL_GROUP_NAME_MAX) >= HCCL_GROUP_NAME_MAX) { |
| 71 | OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( | 65 | OP_LOGE_FOR_INVALID_VALUE_WITH_REASON( |
| @@ -105,10 +99,7 @@ extern "C" aclnnStatus aclnnMoeDistributeCombineTeardownGetWorkspaceSize( | |||
| 105 | return ACLNN_ERR_PARAM_INVALID; | 99 | return ACLNN_ERR_PARAM_INVALID; |
| 106 | } | 100 | } |
| 107 | 101 | ||
| 108 | - auto ret_param = | 102 | + auto ret_param = CheckParams(expandX, quantExpandX, expertIds, expandIdx, expertScales, commCmdInfo, groupEp, xOut); |
| 109 | - CheckParams(expandX, quantExpandX, expertIds, expandIdx, expertScales, commCmdInfo, xActiveMaskOptional, | ||
| 110 | - sharedExpertXOptional, groupEp, epWorldSize, epRankId, moeExpertNum, expertShardType, | ||
| 111 | - sharedExpertNum, sharedExpertRankNum, globalBs, commQuantMode, commType, commAlg, xOut); | ||
| 112 | CHECK_RET(ret_param == ACLNN_SUCCESS, ret_param); | 103 | CHECK_RET(ret_param == ACLNN_SUCCESS, ret_param); |
| 113 | 104 | ||
| 114 | aclnnStatus ret = aclnnInnerMoeDistributeCombineTeardownGetWorkspaceSize( | 105 | aclnnStatus ret = aclnnInnerMoeDistributeCombineTeardownGetWorkspaceSize( |
| @@ -65,11 +65,8 @@ static bool CheckNotNull(const aclTensor *x, const aclTensor *expertIds, const c | |||
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | // 入参校验 | 67 | // 入参校验 |
| 68 | -static aclnnStatus CheckParams(const aclTensor *x, const aclTensor *expertIds, const aclTensor *scalesOptional, | 68 | +static aclnnStatus CheckParams(const aclTensor *x, const aclTensor *expertIds, const char *groupEp, aclTensor *yOut, |
| 69 | - const char *groupEp, int64_t epWorldSize, int64_t epRankId, int64_t expertShardType, | 69 | + aclTensor *expandIdxOut, aclTensor *commCmdInfoOut) |
| 70 | - int64_t shareExpertRankNum, int64_t moeExpertNum, int64_t quantMode, int64_t globalBs, | ||
| 71 | - int64_t commType, const char *commAlg, aclTensor *yOut, aclTensor *expandIdxOut, | ||
| 72 | - aclTensor *commCmdInfoOut) | ||
| 73 | { | 70 | { |
| 74 | CHECK_RET(CheckNotNull(x, expertIds, groupEp, yOut, expandIdxOut, commCmdInfoOut), ACLNN_ERR_PARAM_NULLPTR); | 71 | CHECK_RET(CheckNotNull(x, expertIds, groupEp, yOut, expandIdxOut, commCmdInfoOut), ACLNN_ERR_PARAM_NULLPTR); |
| 75 | if (strnlen(groupEp, HCCL_GROUP_NAME_MAX) >= HCCL_GROUP_NAME_MAX) { | 72 | if (strnlen(groupEp, HCCL_GROUP_NAME_MAX) >= HCCL_GROUP_NAME_MAX) { |
| @@ -89,9 +86,7 @@ aclnnStatus aclnnMoeDistributeDispatchSetupGetWorkspaceSize( | |||
| 89 | aclTensor *expandIdxOut, aclTensor *commCmdInfoOut, uint64_t *workspaceSize, aclOpExecutor **executor) | 86 | aclTensor *expandIdxOut, aclTensor *commCmdInfoOut, uint64_t *workspaceSize, aclOpExecutor **executor) |
| 90 | { | 87 | { |
| 91 | OP_LOGD("aclnnMoeDistributeDispatchSetupGetWorkspaceSize start"); | 88 | OP_LOGD("aclnnMoeDistributeDispatchSetupGetWorkspaceSize start"); |
| 92 | - auto ret_param = | 89 | + auto ret_param = CheckParams(x, expertIds, groupEp, yOut, expandIdxOut, commCmdInfoOut); |
| 93 | - CheckParams(x, expertIds, scalesOptional, groupEp, epWorldSize, epRankId, expertShardType, shareExpertRankNum, | ||
| 94 | - moeExpertNum, quantMode, globalBs, commType, commAlg, yOut, expandIdxOut, commCmdInfoOut); | ||
| 95 | CHECK_RET(ret_param == ACLNN_SUCCESS, ret_param); | 90 | CHECK_RET(ret_param == ACLNN_SUCCESS, ret_param); |
| 96 | 91 | ||
| 97 | aclnnStatus ret = aclnnInnerMoeDistributeDispatchSetupGetWorkspaceSize( | 92 | aclnnStatus ret = aclnnInnerMoeDistributeDispatchSetupGetWorkspaceSize( |
| @@ -56,10 +56,9 @@ static bool CheckNotNull(const aclTensor *x, const aclTensor *y, const aclTensor | |||
| 56 | 56 | ||
| 57 | // check invalid parameters | 57 | // check invalid parameters |
| 58 | static aclnnStatus CheckParams(const aclTensor *x, const aclTensor *y, const aclTensor *expertIds, | 58 | static aclnnStatus CheckParams(const aclTensor *x, const aclTensor *y, const aclTensor *expertIds, |
| 59 | - const aclTensor *commCmdInfo, const char *groupEp, int64_t expertShardType, | 59 | + const aclTensor *commCmdInfo, const char *groupEp, int64_t quantMode, |
| 60 | - int64_t sharedExpertRankNum, int64_t moeExpertNum, int64_t quantMode, int64_t globalBs, | 60 | + aclTensor *expandXOut, aclTensor *dynamicScalesOut, aclTensor *assistInfoForCombineOut, |
| 61 | - int64_t commType, char *commAlg, aclTensor *expandXOut, aclTensor *dynamicScalesOut, | 61 | + aclTensor *expertTokenNumsOut) |
| 62 | - aclTensor *assistInfoForCombineOut, aclTensor *expertTokenNumsOut) | ||
| 63 | { | 62 | { |
| 64 | CHECK_RET(CheckNotNull(x, y, expertIds, commCmdInfo, groupEp, expandXOut, dynamicScalesOut, assistInfoForCombineOut, | 63 | CHECK_RET(CheckNotNull(x, y, expertIds, commCmdInfo, groupEp, expandXOut, dynamicScalesOut, assistInfoForCombineOut, |
| 65 | expertTokenNumsOut), | 64 | expertTokenNumsOut), |
| @@ -94,8 +93,7 @@ aclnnStatus aclnnMoeDistributeDispatchTeardownGetWorkspaceSize( | |||
| 94 | "unsupported npuArch"); | 93 | "unsupported npuArch"); |
| 95 | return ACLNN_ERR_PARAM_INVALID; | 94 | return ACLNN_ERR_PARAM_INVALID; |
| 96 | } | 95 | } |
| 97 | - auto ret_param = CheckParams(x, y, expertIds, commCmdInfo, groupEp, expertShardType, sharedExpertRankNum, | 96 | + auto ret_param = CheckParams(x, y, expertIds, commCmdInfo, groupEp, quantMode, expandXOut, dynamicScalesOut, |
| 98 | - moeExpertNum, quantMode, globalBs, commType, commAlg, expandXOut, dynamicScalesOut, | ||
| 99 | assistInfoForCombineOut, expertTokenNumsOut); | 97 | assistInfoForCombineOut, expertTokenNumsOut); |
| 100 | CHECK_RET(ret_param == ACLNN_SUCCESS, ret_param); | 98 | CHECK_RET(ret_param == ACLNN_SUCCESS, ret_param); |
| 101 | 99 | ||
| @@ -86,7 +86,7 @@ bool DispatchCheckNotNull(const aclTensor *x, const aclTensor *expertIds, const | |||
| 86 | aclnnStatus DispatchCheckParams(const aclTensor *x, const aclTensor *expertIds, const aclTensor *scalesOptional, | 86 | aclnnStatus DispatchCheckParams(const aclTensor *x, const aclTensor *expertIds, const aclTensor *scalesOptional, |
| 87 | const char *groupEp, const char *groupTp, int64_t quantMode, aclTensor *expandX, | 87 | const char *groupEp, const char *groupTp, int64_t quantMode, aclTensor *expandX, |
| 88 | aclTensor *dynamicScales, aclTensor *assistInfoForCombine, aclTensor *expertTokensNums, | 88 | aclTensor *dynamicScales, aclTensor *assistInfoForCombine, aclTensor *expertTokensNums, |
| 89 | - aclTensor *epRecvCounts, aclTensor *tpRecvCounts) | 89 | + aclTensor *epRecvCounts) |
| 90 | { | 90 | { |
| 91 | CHECK_RET(DispatchCheckNotNull(x, expertIds, groupEp, groupTp, expandX, dynamicScales, assistInfoForCombine, | 91 | CHECK_RET(DispatchCheckNotNull(x, expertIds, groupEp, groupTp, expandX, dynamicScales, assistInfoForCombine, |
| 92 | expertTokensNums, epRecvCounts), | 92 | expertTokensNums, epRecvCounts), |
| @@ -100,7 +100,7 @@ aclnnStatus DispatchCheckParams(const aclTensor *x, const aclTensor *expertIds, | |||
| 100 | OP_LOGD("quantMode = 2, dynamicScales can't be null"); | 100 | OP_LOGD("quantMode = 2, dynamicScales can't be null"); |
| 101 | CHECK_RET(dynamicScales != nullptr, ACLNN_ERR_PARAM_NULLPTR); | 101 | CHECK_RET(dynamicScales != nullptr, ACLNN_ERR_PARAM_NULLPTR); |
| 102 | } | 102 | } |
| 103 | - if (x->GetDataType() == ACL_INT32) { | 103 | + if (static_cast<int32_t>(x->GetDataType()) == static_cast<int32_t>(ACL_INT32)) { |
| 104 | OP_LOGD("x dtype is INT32, scales and dynamicScales can't be null"); | 104 | OP_LOGD("x dtype is INT32, scales and dynamicScales can't be null"); |
| 105 | CHECK_RET(scalesOptional != nullptr, ACLNN_ERR_PARAM_NULLPTR); | 105 | CHECK_RET(scalesOptional != nullptr, ACLNN_ERR_PARAM_NULLPTR); |
| 106 | CHECK_RET(dynamicScales != nullptr, ACLNN_ERR_PARAM_NULLPTR); | 106 | CHECK_RET(dynamicScales != nullptr, ACLNN_ERR_PARAM_NULLPTR); |
| @@ -164,9 +164,8 @@ aclnnStatus aclnnMoeDistributeDispatchGetWorkspaceSizeBase( | |||
| 164 | OP_LOGD("enter to the aclnnMoeDistributeDispatchGetWorkspaceSizeBase\n"); | 164 | OP_LOGD("enter to the aclnnMoeDistributeDispatchGetWorkspaceSizeBase\n"); |
| 165 | const static bool is910B = GetCurrentPlatformInfo().GetSocVersion() == SocVersion::ASCEND910B; | 165 | const static bool is910B = GetCurrentPlatformInfo().GetSocVersion() == SocVersion::ASCEND910B; |
| 166 | const static bool is950 = GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_3510; | 166 | const static bool is950 = GetCurrentPlatformInfo().GetCurNpuArch() == NpuArch::DAV_3510; |
| 167 | - auto retParam = | 167 | + auto retParam = DispatchCheckParams(x, expertIds, scalesOptional, groupEp, groupTp, quantMode, expandXOut, |
| 168 | - DispatchCheckParams(x, expertIds, scalesOptional, groupEp, groupTp, quantMode, expandXOut, dynamicScalesOut, | 168 | + dynamicScalesOut, assistInfoForCombineOut, expertTokenNumsOut, epRecvCountsOut); |
| 169 | - assistInfoForCombineOut, expertTokenNumsOut, epRecvCountsOut, tpRecvCountsOut); | ||
| 170 | CHECK_RET(retParam == ACLNN_SUCCESS, retParam); | 169 | CHECK_RET(retParam == ACLNN_SUCCESS, retParam); |
| 171 | 170 | ||
| 172 | aclTensor *mc2Context = nullptr; | 171 | aclTensor *mc2Context = nullptr; |
| @@ -45,7 +45,7 @@ ACLNN_API aclnnStatus DispatchCheckParams(const aclTensor *x, const aclTensor *e | |||
| 45 | const aclTensor *scalesOptional, const char *groupEp, const char *groupTp, | 45 | const aclTensor *scalesOptional, const char *groupEp, const char *groupTp, |
| 46 | int64_t quantMode, aclTensor *expandX, aclTensor *dynamicScales, | 46 | int64_t quantMode, aclTensor *expandX, aclTensor *dynamicScales, |
| 47 | aclTensor *assistInfoForCombine, aclTensor *expertTokensNums, | 47 | aclTensor *assistInfoForCombine, aclTensor *expertTokensNums, |
| 48 | - aclTensor *epRecvCounts, aclTensor *tpRecvCounts); | 48 | + aclTensor *epRecvCounts); |
| 49 | 49 | ||
| 50 | ACLNN_API aclnnStatus aclnnMoeDistributeDispatchBase(void *workspace, uint64_t workspaceSize, aclOpExecutor *executor, | 50 | ACLNN_API aclnnStatus aclnnMoeDistributeDispatchBase(void *workspace, uint64_t workspaceSize, aclOpExecutor *executor, |
| 51 | aclrtStream stream); | 51 | aclrtStream stream); |
| @@ -22,7 +22,7 @@ constexpr int64_t NETWORK_DIRECT = 0; | |||
| 22 | constexpr int64_t NETWORK_HYBRID = 1; | 22 | constexpr int64_t NETWORK_HYBRID = 1; |
| 23 | } // namespace | 23 | } // namespace |
| 24 | 24 | ||
| 25 | -static aclnnStatus CheckNotNull(const aclTensor *context, const aclTensor *topkIdx, aclTensor *combinedX) | 25 | +static aclnnStatus CheckNotNull(const aclTensor *context, const aclTensor *topkIdx, const aclTensor *combinedX) |
| 26 | { | 26 | { |
| 27 | CHECK_RET(context != nullptr, ACLNN_ERR_PARAM_NULLPTR); | 27 | CHECK_RET(context != nullptr, ACLNN_ERR_PARAM_NULLPTR); |
| 28 | CHECK_RET(topkIdx != nullptr, ACLNN_ERR_PARAM_NULLPTR); | 28 | CHECK_RET(topkIdx != nullptr, ACLNN_ERR_PARAM_NULLPTR); |
| @@ -23,9 +23,9 @@ constexpr int64_t NETWORK_HYBRID = 1; | |||
| 23 | } // namespace | 23 | } // namespace |
| 24 | 24 | ||
| 25 | static aclnnStatus CheckNotNull(const aclTensor *context, const aclTensor *x, const aclTensor *topkIdx, | 25 | static aclnnStatus CheckNotNull(const aclTensor *context, const aclTensor *x, const aclTensor *topkIdx, |
| 26 | - aclTensor *numRecvTokensPerRank, aclTensor *numRecvTokensPerExpert, | 26 | + const aclTensor *numRecvTokensPerRank, const aclTensor *numRecvTokensPerExpert, |
| 27 | - aclTensor *dstBufferSlotIdx, aclTensor *routeCount, aclTensor *routeDstScaleout, | 27 | + const aclTensor *dstBufferSlotIdx, const aclTensor *routeCount, |
| 28 | - aclTensor *routeScaleoutSlot) | 28 | + const aclTensor *routeDstScaleout, const aclTensor *routeScaleoutSlot) |
| 29 | { | 29 | { |
| 30 | CHECK_RET(context != nullptr, ACLNN_ERR_PARAM_NULLPTR); | 30 | CHECK_RET(context != nullptr, ACLNN_ERR_PARAM_NULLPTR); |
| 31 | CHECK_RET(x != nullptr, ACLNN_ERR_PARAM_NULLPTR); | 31 | CHECK_RET(x != nullptr, ACLNN_ERR_PARAM_NULLPTR); |
| @@ -40,10 +40,9 @@ static aclnnStatus CheckNotNull(const aclTensor *context, const aclTensor *x, co | |||
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | static aclnnStatus CheckParams(int64_t epWorldSize, int64_t epRankId, int64_t numExperts, int64_t numMaxTokensPerRank, | 42 | static aclnnStatus CheckParams(int64_t epWorldSize, int64_t epRankId, int64_t numExperts, int64_t numMaxTokensPerRank, |
| 43 | - int64_t cclBufferSize, int64_t expertAlignment, bool doCpuSync, int64_t topoType, | 43 | + int64_t cclBufferSize, bool doCpuSync, int64_t topoType, int64_t rankNumPerServer, |
| 44 | - int64_t rankNumPerServer, const aclTensor *cachedDstSlotIdx, | 44 | + const aclTensor *cachedDstSlotIdx, const aclTensor *cachedRouteCount, |
| 45 | - const aclTensor *cachedRouteCount, const aclTensor *cachedRouteDstScaleout, | 45 | + const aclTensor *cachedRouteDstScaleout, const aclTensor *cachedRouteScaleoutSlot) |
| 46 | - const aclTensor *cachedRouteScaleoutSlot) | ||
| 47 | { | 46 | { |
| 48 | CHECK_RET(epWorldSize > 1, ACLNN_ERR_PARAM_INVALID); | 47 | CHECK_RET(epWorldSize > 1, ACLNN_ERR_PARAM_INVALID); |
| 49 | CHECK_RET(epRankId >= 0 && epRankId < epWorldSize, ACLNN_ERR_PARAM_INVALID); | 48 | CHECK_RET(epRankId >= 0 && epRankId < epWorldSize, ACLNN_ERR_PARAM_INVALID); |
| @@ -56,13 +55,12 @@ static aclnnStatus CheckParams(int64_t epWorldSize, int64_t epRankId, int64_t nu | |||
| 56 | 55 | ||
| 57 | bool cachedMode = (cachedDstSlotIdx != nullptr); | 56 | bool cachedMode = (cachedDstSlotIdx != nullptr); |
| 58 | CHECK_RET(!(cachedMode && doCpuSync), ACLNN_ERR_PARAM_INVALID); | 57 | CHECK_RET(!(cachedMode && doCpuSync), ACLNN_ERR_PARAM_INVALID); |
| 59 | - bool anyCachedRoute = cachedRouteCount != nullptr || cachedRouteDstScaleout != nullptr || | 58 | + bool anyCachedRoute = |
| 60 | - cachedRouteScaleoutSlot != nullptr; | 59 | + cachedRouteCount != nullptr || cachedRouteDstScaleout != nullptr || cachedRouteScaleoutSlot != nullptr; |
| 61 | - bool allCachedRoute = cachedRouteCount != nullptr && cachedRouteDstScaleout != nullptr && | 60 | + bool allCachedRoute = |
| 62 | - cachedRouteScaleoutSlot != nullptr; | 61 | + cachedRouteCount != nullptr && cachedRouteDstScaleout != nullptr && cachedRouteScaleoutSlot != nullptr; |
| 63 | CHECK_RET(!anyCachedRoute || allCachedRoute, ACLNN_ERR_PARAM_INVALID); | 62 | CHECK_RET(!anyCachedRoute || allCachedRoute, ACLNN_ERR_PARAM_INVALID); |
| 64 | - bool hybridCachedMode = | 63 | + bool hybridCachedMode = cachedMode && topoType == NETWORK_HYBRID && epWorldSize / rankNumPerServer > 1; |
| 65 | - cachedMode && topoType == NETWORK_HYBRID && epWorldSize / rankNumPerServer > 1; | ||
| 66 | CHECK_RET(!hybridCachedMode || allCachedRoute, ACLNN_ERR_PARAM_INVALID); | 64 | CHECK_RET(!hybridCachedMode || allCachedRoute, ACLNN_ERR_PARAM_INVALID); |
| 67 | 65 | ||
| 68 | return ACLNN_SUCCESS; | 66 | return ACLNN_SUCCESS; |
| @@ -81,19 +79,15 @@ enum NnopbaseHcclServerType { | |||
| 81 | 79 | ||
| 82 | extern "C" void __attribute__((weak)) NnopbaseSetHcclServerType(void *executor, NnopbaseHcclServerType sType); | 80 | extern "C" void __attribute__((weak)) NnopbaseSetHcclServerType(void *executor, NnopbaseHcclServerType sType); |
| 83 | 81 | ||
| 84 | -aclnnStatus aclnnMoeEpDispatchGetWorkspaceSize(const aclTensor *context, const aclTensor *x, const aclTensor *topkIdx, | 82 | +aclnnStatus aclnnMoeEpDispatchGetWorkspaceSize( |
| 85 | - const aclTensor *topkWeights, const aclTensor *scales, | 83 | + const aclTensor *context, const aclTensor *x, const aclTensor *topkIdx, const aclTensor *topkWeights, |
| 86 | - const aclTensor *cachedDstSlotIdx, const aclTensor *cachedRouteCount, | 84 | + const aclTensor *scales, const aclTensor *cachedDstSlotIdx, const aclTensor *cachedRouteCount, |
| 87 | - const aclTensor *cachedRouteDstScaleout, | 85 | + const aclTensor *cachedRouteDstScaleout, const aclTensor *cachedRouteScaleoutSlot, int64_t epWorldSize, |
| 88 | - const aclTensor *cachedRouteScaleoutSlot, int64_t epWorldSize, | 86 | + int64_t epRankId, int64_t numExperts, int64_t numMaxTokensPerRank, int64_t cclBufferSize, int64_t expertAlignment, |
| 89 | - int64_t epRankId, int64_t numExperts, int64_t numMaxTokensPerRank, | 87 | + bool doCpuSync, int64_t hostPinnedCounterAddr, int64_t topoType, int64_t rankNumPerServer, |
| 90 | - int64_t cclBufferSize, int64_t expertAlignment, bool doCpuSync, | 88 | + aclTensor *numRecvTokensPerRank, aclTensor *numRecvTokensPerExpert, aclTensor *dstBufferSlotIdx, |
| 91 | - int64_t hostPinnedCounterAddr, int64_t topoType, | 89 | + aclTensor *routeCount, aclTensor *routeDstScaleout, aclTensor *routeScaleoutSlot, uint64_t *workspaceSize, |
| 92 | - int64_t rankNumPerServer, aclTensor *numRecvTokensPerRank, | 90 | + aclOpExecutor **executor) |
| 93 | - aclTensor *numRecvTokensPerExpert, aclTensor *dstBufferSlotIdx, | ||
| 94 | - aclTensor *routeCount, aclTensor *routeDstScaleout, | ||
| 95 | - aclTensor *routeScaleoutSlot, uint64_t *workspaceSize, | ||
| 96 | - aclOpExecutor **executor) | ||
| 97 | { | 91 | { |
| 98 | OP_LOGD("aclnnMoeEpDispatch WorkspaceSize start"); | 92 | OP_LOGD("aclnnMoeEpDispatch WorkspaceSize start"); |
| 99 | 93 | ||
| @@ -101,17 +95,16 @@ aclnnStatus aclnnMoeEpDispatchGetWorkspaceSize(const aclTensor *context, const a | |||
| 101 | routeCount, routeDstScaleout, routeScaleoutSlot); | 95 | routeCount, routeDstScaleout, routeScaleoutSlot); |
| 102 | CHECK_RET(retNotNull == ACLNN_SUCCESS, retNotNull); | 96 | CHECK_RET(retNotNull == ACLNN_SUCCESS, retNotNull); |
| 103 | 97 | ||
| 104 | - auto retParams = CheckParams(epWorldSize, epRankId, numExperts, numMaxTokensPerRank, cclBufferSize, | 98 | + auto retParams = CheckParams(epWorldSize, epRankId, numExperts, numMaxTokensPerRank, cclBufferSize, doCpuSync, |
| 105 | - expertAlignment, doCpuSync, topoType, rankNumPerServer, cachedDstSlotIdx, | 99 | + topoType, rankNumPerServer, cachedDstSlotIdx, cachedRouteCount, cachedRouteDstScaleout, |
| 106 | - cachedRouteCount, cachedRouteDstScaleout, cachedRouteScaleoutSlot); | 100 | + cachedRouteScaleoutSlot); |
| 107 | CHECK_RET(retParams == ACLNN_SUCCESS, retParams); | 101 | CHECK_RET(retParams == ACLNN_SUCCESS, retParams); |
| 108 | 102 | ||
| 109 | aclnnStatus getWorkspaceSizesRes = aclnnInnerMoeEpDispatchGetWorkspaceSize( | 103 | aclnnStatus getWorkspaceSizesRes = aclnnInnerMoeEpDispatchGetWorkspaceSize( |
| 110 | context, x, topkIdx, topkWeights, scales, cachedDstSlotIdx, cachedRouteCount, cachedRouteDstScaleout, | 104 | context, x, topkIdx, topkWeights, scales, cachedDstSlotIdx, cachedRouteCount, cachedRouteDstScaleout, |
| 111 | - cachedRouteScaleoutSlot, epWorldSize, epRankId, numExperts, numMaxTokensPerRank, cclBufferSize, | 105 | + cachedRouteScaleoutSlot, epWorldSize, epRankId, numExperts, numMaxTokensPerRank, cclBufferSize, expertAlignment, |
| 112 | - expertAlignment, doCpuSync, hostPinnedCounterAddr, topoType, rankNumPerServer, numRecvTokensPerRank, | 106 | + doCpuSync, hostPinnedCounterAddr, topoType, rankNumPerServer, numRecvTokensPerRank, numRecvTokensPerExpert, |
| 113 | - numRecvTokensPerExpert, dstBufferSlotIdx, routeCount, routeDstScaleout, routeScaleoutSlot, workspaceSize, | 107 | + dstBufferSlotIdx, routeCount, routeDstScaleout, routeScaleoutSlot, workspaceSize, executor); |
| 114 | - executor); | ||
| 115 | 108 | ||
| 116 | return getWorkspaceSizesRes; | 109 | return getWorkspaceSizesRes; |
| 117 | } | 110 | } |
| @@ -24,8 +24,8 @@ constexpr int64_t NETWORK_HYBRID = 1; | |||
| 24 | 24 | ||
| 25 | static aclnnStatus CheckNotNull(const aclTensor *context, const aclTensor *dstBufferSlotIdx, | 25 | static aclnnStatus CheckNotNull(const aclTensor *context, const aclTensor *dstBufferSlotIdx, |
| 26 | const aclTensor *numRecvTokensPerRank, const aclTensor *numRecvTokensPerExpert, | 26 | const aclTensor *numRecvTokensPerRank, const aclTensor *numRecvTokensPerExpert, |
| 27 | - aclTensor *recvX, aclTensor *recvSrcMetadata, aclTensor *recvTopkWeights, | 27 | + const aclTensor *recvX, const aclTensor *recvSrcMetadata, |
| 28 | - aclTensor *recvScales) | 28 | + const aclTensor *recvTopkWeights, const aclTensor *recvScales) |
| 29 | { | 29 | { |
| 30 | CHECK_RET(context != nullptr, ACLNN_ERR_PARAM_NULLPTR); | 30 | CHECK_RET(context != nullptr, ACLNN_ERR_PARAM_NULLPTR); |
| 31 | CHECK_RET(dstBufferSlotIdx != nullptr, ACLNN_ERR_PARAM_NULLPTR); | 31 | CHECK_RET(dstBufferSlotIdx != nullptr, ACLNN_ERR_PARAM_NULLPTR); |
| @@ -62,14 +62,12 @@ aclnnStatus MoeEpDispatchEpilogueGetWorkspaceSize( | |||
| 62 | aclTensor *recvTopkWeights, aclTensor *recvScales, uint64_t *workspaceSize, aclOpExecutor **executor) | 62 | aclTensor *recvTopkWeights, aclTensor *recvScales, uint64_t *workspaceSize, aclOpExecutor **executor) |
| 63 | { | 63 | { |
| 64 | OP_LOGD("MoeEpDispatchEpilogue", "Begin to do MoeEpDispatchEpilogueGetWorkspaceSize"); | 64 | OP_LOGD("MoeEpDispatchEpilogue", "Begin to do MoeEpDispatchEpilogueGetWorkspaceSize"); |
| 65 | - auto retNotNull = | 65 | + auto retNotNull = CheckNotNull(context, dstBufferSlotIdx, numRecvTokensPerRank, numRecvTokensPerExpert, recvX, |
| 66 | - CheckNotNull(context, dstBufferSlotIdx, numRecvTokensPerRank, numRecvTokensPerExpert, recvX, recvSrcMetadata, | 66 | + recvSrcMetadata, recvTopkWeights, recvScales); |
| 67 | - recvTopkWeights, recvScales); | ||
| 68 | CHECK_RET(retNotNull == ACLNN_SUCCESS, retNotNull); | 67 | CHECK_RET(retNotNull == ACLNN_SUCCESS, retNotNull); |
| 69 | 68 | ||
| 70 | auto retParams = | 69 | auto retParams = |
| 71 | - CheckParams(epWorldSize, epRankId, numExperts, numMaxTokensPerRank, cclBufferSize, topoType, | 70 | + CheckParams(epWorldSize, epRankId, numExperts, numMaxTokensPerRank, cclBufferSize, topoType, rankNumPerServer); |
| 72 | - rankNumPerServer); | ||
| 73 | CHECK_RET(retParams == ACLNN_SUCCESS, retParams); | 71 | CHECK_RET(retParams == ACLNN_SUCCESS, retParams); |
| 74 | 72 | ||
| 75 | return aclnnInnerMoeEpDispatchEpilogueGetWorkspaceSize( | 73 | return aclnnInnerMoeEpDispatchEpilogueGetWorkspaceSize( |
| @@ -85,11 +83,10 @@ aclnnStatus aclnnMoeEpDispatchEpilogueGetWorkspaceSize( | |||
| 85 | int64_t topoType, int64_t rankNumPerServer, aclTensor *recvX, aclTensor *recvSrcMetadata, | 83 | int64_t topoType, int64_t rankNumPerServer, aclTensor *recvX, aclTensor *recvSrcMetadata, |
| 86 | aclTensor *recvTopkWeights, aclTensor *recvScales, uint64_t *workspaceSize, aclOpExecutor **executor) | 84 | aclTensor *recvTopkWeights, aclTensor *recvScales, uint64_t *workspaceSize, aclOpExecutor **executor) |
| 87 | { | 85 | { |
| 88 | - return MoeEpDispatchEpilogueGetWorkspaceSize(context, dstBufferSlotIdx, numRecvTokensPerRank, | 86 | + return MoeEpDispatchEpilogueGetWorkspaceSize( |
| 89 | - numRecvTokensPerExpert, cachedRecvSrcMetadata, epWorldSize, epRankId, | 87 | + context, dstBufferSlotIdx, numRecvTokensPerRank, numRecvTokensPerExpert, cachedRecvSrcMetadata, epWorldSize, |
| 90 | - numExperts, numMaxTokensPerRank, cclBufferSize, hasTopkWeights, | 88 | + epRankId, numExperts, numMaxTokensPerRank, cclBufferSize, hasTopkWeights, topoType, rankNumPerServer, recvX, |
| 91 | - topoType, rankNumPerServer, recvX, recvSrcMetadata, recvTopkWeights, | 89 | + recvSrcMetadata, recvTopkWeights, recvScales, workspaceSize, executor); |
| 92 | - recvScales, workspaceSize, executor); | ||
| 93 | } | 90 | } |
| 94 | 91 | ||
| 95 | enum NnopbaseHcclServerType { | 92 | enum NnopbaseHcclServerType { |