Merged
ccu适配multitiling #7440
jiachengtangAdd on 12 days ago
ccu适配multitiling #7440
Merged
Total: 17 files changed+739-144
| @@ -14,6 +14,7 @@ | |||
| 14 | #include "kfc_server_protocol.h" | 14 | #include "kfc_server_protocol.h" |
| 15 | #include "mc2_comm_info_reporter.h" | 15 | #include "mc2_comm_info_reporter.h" |
| 16 | #include "hccl_res.h" | 16 | #include "hccl_res.h" |
| 17 | +#include "../ops/kfc_server/template/ccu/kernel/ccu_kernel_kfc_server.h" | ||
| 17 | 18 | ||
| 18 | #include <limits> | 19 | #include <limits> |
| 19 | 20 | ||
| @@ -170,7 +171,6 @@ HcclResult CheckCcuKfcFlow(const void* mc2Tiling, const void* ccTilingList[], ui | |||
| 170 | HCCL_ERROR("Invalid CCU KFC tiling number %u, init tiling number %u.", tilingNum, initTiling->mc2HcommCnt); | 171 | HCCL_ERROR("Invalid CCU KFC tiling number %u, init tiling number %u.", tilingNum, initTiling->mc2HcommCnt); |
| 171 | return HCCL_E_NOT_SUPPORT; | 172 | return HCCL_E_NOT_SUPPORT; |
| 172 | } | 173 | } |
| 173 | - uint32_t expectedOpType = static_cast<uint32_t>(HcclCMDType::HCCL_CMD_INVALID); | ||
| 174 | for (uint32_t i = 0U; i < tilingNum; ++i) { | 174 | for (uint32_t i = 0U; i < tilingNum; ++i) { |
| 175 | const auto* ccTiling = static_cast<const Mc2CcTilingInner*>(ccTilingList[i]); | 175 | const auto* ccTiling = static_cast<const Mc2CcTilingInner*>(ccTilingList[i]); |
| 176 | CHK_PTR_NULL(ccTiling); | 176 | CHK_PTR_NULL(ccTiling); |
| @@ -179,12 +179,8 @@ HcclResult CheckCcuKfcFlow(const void* mc2Tiling, const void* ccTilingList[], ui | |||
| 179 | "Peer-only ReduceScatter requires rankSize 2, but got rankSize %u at tiling index %u.", rankSize, i); | 179 | "Peer-only ReduceScatter requires rankSize 2, but got rankSize %u at tiling index %u.", rankSize, i); |
| 180 | return HCCL_E_NOT_SUPPORT; | 180 | return HCCL_E_NOT_SUPPORT; |
| 181 | } | 181 | } |
| 182 | - if (expectedOpType == static_cast<uint32_t>(HcclCMDType::HCCL_CMD_INVALID)) { | ||
| 183 | - expectedOpType = ccTiling->opType; | ||
| 184 | - } | ||
| 185 | if (!IsCcuKfcSupportedOp(ccTiling->opType) || | 182 | if (!IsCcuKfcSupportedOp(ccTiling->opType) || |
| 186 | - ccTiling->commEngine != static_cast<uint8_t>(OpExecuteConfig::CCU_SCHED) || | 183 | + ccTiling->commEngine != static_cast<uint8_t>(OpExecuteConfig::CCU_SCHED)) { |
| 187 | - ccTiling->opType != expectedOpType) { | ||
| 188 | HCCL_ERROR( | 184 | HCCL_ERROR( |
| 189 | "Unsupported CCU KFC tiling at index %u, opType %u, commEngine %u.", i, ccTiling->opType, | 185 | "Unsupported CCU KFC tiling at index %u, opType %u, commEngine %u.", i, ccTiling->opType, |
| 190 | ccTiling->commEngine); | 186 | ccTiling->commEngine); |
| @@ -939,7 +935,8 @@ HcclResult HandleSingleRankAndCommMode(HcclComm comm, OpParam& opParam, bool& sk | |||
| 939 | 935 | ||
| 940 | static HcclResult AcquireAlgResources( | 936 | static HcclResult AcquireAlgResources( |
| 941 | HcclComm comm, OpParam& opParam, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, | 937 | HcclComm comm, OpParam& opParam, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, |
| 942 | - std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, OpResCtx& opResCtx, void** resCtxOut) | 938 | + std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, OpResCtx& opResCtx, void** resCtxOut, |
| 939 | + AlgResourceRequest* request, const std::string& resourceTag) | ||
| 943 | { | 940 | { |
| 944 | HCCL_INFO("[AcquireAlgResources]start AcquireAlgResources!"); | 941 | HCCL_INFO("[AcquireAlgResources]start AcquireAlgResources!"); |
| 945 | bool isResourceReused = false; | 942 | bool isResourceReused = false; |
| @@ -963,7 +960,8 @@ static HcclResult AcquireAlgResources( | |||
| 963 | "ckeAddr[0x%llx]", | 960 | "ckeAddr[0x%llx]", |
| 964 | missionNum, resCtxHost->kfcServerArgSize, static_cast<unsigned long long>(opResCtx.xnAddr), | 961 | missionNum, resCtxHost->kfcServerArgSize, static_cast<unsigned long long>(opResCtx.xnAddr), |
| 965 | static_cast<unsigned long long>(opResCtx.ckeAddr)); | 962 | static_cast<unsigned long long>(opResCtx.ckeAddr)); |
| 966 | - auto resRet = HcclGetAlgRes(comm, opParam, executor, topoInfo, resCtxHost, resCtxOut, isResourceReused); | 963 | + HcclResult resRet = HcclGetAlgRes( |
| 964 | + comm, opParam, executor, topoInfo, resCtxHost, resCtxOut, isResourceReused, request, resourceTag); | ||
| 967 | if (opParam.checkRes && resRet == HCCL_E_UNAVAIL) { | 965 | if (opParam.checkRes && resRet == HCCL_E_UNAVAIL) { |
| 968 | HCCL_WARNING("[%s] HCCL_E_UNAVAIL, resource unavailable.", __func__); | 966 | HCCL_WARNING("[%s] HCCL_E_UNAVAIL, resource unavailable.", __func__); |
| 969 | return HCCL_E_RES_NOT_SUFFICIENT; | 967 | return HCCL_E_RES_NOT_SUFFICIENT; |
| @@ -1021,7 +1019,7 @@ HcclResult GetOpParamResCtx( | |||
| 1021 | 1019 | ||
| 1022 | HcclResult GetCcuOpParamResCtx( | 1020 | HcclResult GetCcuOpParamResCtx( |
| 1023 | HcclComm comm, const std::string& algName, OpParam& opParam, TopoInfoWithNetLayerDetails* topoInfo, | 1021 | HcclComm comm, const std::string& algName, OpParam& opParam, TopoInfoWithNetLayerDetails* topoInfo, |
| 1024 | - OpResCtx& opResCtx, void** resCtxOut) | 1022 | + OpResCtx& opResCtx, void** resCtxOut, AlgResourceRequest* request, const std::string& resourceTag) |
| 1025 | { | 1023 | { |
| 1026 | CHK_PTR_NULL(topoInfo); | 1024 | CHK_PTR_NULL(topoInfo); |
| 1027 | CHK_PTR_NULL(resCtxOut); | 1025 | CHK_PTR_NULL(resCtxOut); |
| @@ -1035,7 +1033,8 @@ HcclResult GetCcuOpParamResCtx( | |||
| 1035 | CHK_PRT_RET( | 1033 | CHK_PRT_RET( |
| 1036 | executor.get() == nullptr, HCCL_ERROR("Fail to find executor for algName[%s]", algName.c_str()), HCCL_E_PARA); | 1034 | executor.get() == nullptr, HCCL_ERROR("Fail to find executor for algName[%s]", algName.c_str()), HCCL_E_PARA); |
| 1037 | std::unique_ptr<AlgResourceCtxSerializable> resCtxHost = std::make_unique<AlgResourceCtxSerializable>(); | 1035 | std::unique_ptr<AlgResourceCtxSerializable> resCtxHost = std::make_unique<AlgResourceCtxSerializable>(); |
| 1038 | - CHK_RET(AcquireAlgResources(comm, opParam, executor, topoInfo, resCtxHost, opResCtx, resCtxOut)); | 1036 | + CHK_RET( |
| 1037 | + AcquireAlgResources(comm, opParam, executor, topoInfo, resCtxHost, opResCtx, resCtxOut, request, resourceTag)); | ||
| 1039 | // die 切分比例走 res[1] 预留槽(不动 OpResCtx 布局:新旧 op 包/host lib 混搭时旧侧读 0=不切分,安全降级) | 1038 | // die 切分比例走 res[1] 预留槽(不动 OpResCtx 布局:新旧 op 包/host lib 混搭时旧侧读 0=不切分,安全降级) |
| 1040 | opResCtx.res[1] = DieSplitRatioToPermille(resCtxHost->dieSplitRatio); | 1039 | opResCtx.res[1] = DieSplitRatioToPermille(resCtxHost->dieSplitRatio); |
| 1041 | // KFC mission 数(2die 为动态 dieNum)经 res[2] 下发,AIV 逐 mission commit/wait 消费;非 KFC 为 0(AIV 回退 1) | 1040 | // KFC mission 数(2die 为动态 dieNum)经 res[2] 下发,AIV 逐 mission commit/wait 消费;非 KFC 为 0(AIV 回退 1) |
| @@ -1219,7 +1218,7 @@ void FillCcuAlgorithmInfo( | |||
| 1219 | 1218 | ||
| 1220 | HcclResult PrepareCcuAlgorithmResource( | 1219 | HcclResult PrepareCcuAlgorithmResource( |
| 1221 | HcclComm comm, uint32_t tilingIndex, const std::string& algName, OpParam& opParam, | 1220 | HcclComm comm, uint32_t tilingIndex, const std::string& algName, OpParam& opParam, |
| 1222 | - TopoInfoWithNetLayerDetails* topoInfo, OpResCtx& opResCtx, bool& skipGetRes) | 1221 | + TopoInfoWithNetLayerDetails* topoInfo, bool& skipGetRes, AlgResourceRequest& request) |
| 1223 | { | 1222 | { |
| 1224 | uint32_t userRank = 0; | 1223 | uint32_t userRank = 0; |
| 1225 | HcclGetRankId(comm, &userRank); | 1224 | HcclGetRankId(comm, &userRank); |
| @@ -1229,16 +1228,14 @@ HcclResult PrepareCcuAlgorithmResource( | |||
| 1229 | return HCCL_SUCCESS; | 1228 | return HCCL_SUCCESS; |
| 1230 | } | 1229 | } |
| 1231 | HCCL_INFO("[CcuSelectAlg]HandleSingleRankAndCommMode[%u] successfully! rank[%u]", tilingIndex, userRank); | 1230 | HCCL_INFO("[CcuSelectAlg]HandleSingleRankAndCommMode[%u] successfully! rank[%u]", tilingIndex, userRank); |
| 1232 | - | 1231 | + auto executor = CollAlgExecRegistryV2::Instance().GetAlgExec(opParam.opType, algName); |
| 1233 | - void* resCtxSequence = nullptr; | 1232 | + CHK_PTR_NULL(executor); |
| 1234 | - HcclResult ret = GetCcuOpParamResCtx(comm, algName, opParam, topoInfo, opResCtx, &resCtxSequence); | 1233 | + AlgHierarchyInfoForAllLevel hierarchy; |
| 1235 | - if (ret != HCCL_SUCCESS) { | 1234 | + const size_t kernelNum = request.ccuKernelInfos.size(); |
| 1236 | - HCCL_ERROR( | 1235 | + CHK_RET(CalcAlgResourceRequest(comm, opParam, executor, topoInfo, hierarchy, request)); |
| 1237 | - "[CcuSelectAlg] rank[%u] GetCcuOpParamResCtx FAILED, ret[%d], algName[%s]", userRank, static_cast<int>(ret), | 1236 | + CHK_PRT_RET( |
| 1238 | - algName.c_str()); | 1237 | + opParam.isMultiTiling && request.ccuKernelInfos.size() != kernelNum + 1U, |
| 1239 | - return ret; | 1238 | + HCCL_ERROR("Multi-tiling KFC requires one mission per tiling, tiling[%u].", tilingIndex), HCCL_E_NOT_SUPPORT); |
| 1240 | - } | ||
| 1241 | - HCCL_INFO("[CcuSelectAlg]GetCcuOpParamResCtx[%u] successfully! rank[%u]", tilingIndex, userRank); | ||
| 1242 | return HCCL_SUCCESS; | 1239 | return HCCL_SUCCESS; |
| 1243 | } | 1240 | } |
| 1244 | 1241 | ||
| @@ -1260,10 +1257,11 @@ HcclResult CopyCcuOpParamToDevice( | |||
| 1260 | return HCCL_SUCCESS; | 1257 | return HCCL_SUCCESS; |
| 1261 | } | 1258 | } |
| 1262 | 1259 | ||
| 1263 | -// 逐tiling处理:checkOnly时走真实资源链探测资源是否充足(UNAVAIL映射为HCCL_E_RES_NOT_SUFFICIENT) | 1260 | +// 逐tiling准备算法参数和资源需求,最终资源申请及预检查统一在PrepareCcuTilingResources完成。 |
| 1264 | HcclResult ProcessCcuTiling( | 1261 | HcclResult ProcessCcuTiling( |
| 1265 | HcclComm comm, void* stream, const std::string& topoTag, const Mc2CcTilingInner* ccTiling, uint32_t tilingIndex, | 1262 | HcclComm comm, void* stream, const std::string& topoTag, const Mc2CcTilingInner* ccTiling, uint32_t tilingIndex, |
| 1266 | - const Mc2InitTilingInner* initTiling, OpResCtx& opResCtx, bool checkOnly = false) | 1263 | + OpResCtx& opResCtx, OpParam& opParam, AlgResourceRequest& request, uint32_t tilingNum, bool checkOnly, |
| 1264 | + bool& skipGetRes, std::unique_ptr<TopoInfoWithNetLayerDetails>& topoInfo) | ||
| 1267 | { | 1265 | { |
| 1268 | uint32_t userRank = 0; | 1266 | uint32_t userRank = 0; |
| 1269 | HcclGetRankId(comm, &userRank); | 1267 | HcclGetRankId(comm, &userRank); |
| @@ -1272,29 +1270,75 @@ HcclResult ProcessCcuTiling( | |||
| 1272 | 1270 | ||
| 1273 | RunCcuSelectAlgCheck(ccTiling, tilingIndex); | 1271 | RunCcuSelectAlgCheck(ccTiling, tilingIndex); |
| 1274 | 1272 | ||
| 1275 | - OpParam opParam{}; | ||
| 1276 | opParam.checkRes = checkOnly; | 1273 | opParam.checkRes = checkOnly; |
| 1277 | std::string algName; | 1274 | std::string algName; |
| 1278 | - auto topoInfo = std::make_unique<TopoInfoWithNetLayerDetails>(); | 1275 | + topoInfo = std::make_unique<TopoInfoWithNetLayerDetails>(); |
| 1279 | AlgorithmType algorithmType; | 1276 | AlgorithmType algorithmType; |
| 1280 | CHK_RET(SelectCcuAlgorithm( | 1277 | CHK_RET(SelectCcuAlgorithm( |
| 1281 | comm, stream, topoTag, ccTiling, tilingIndex, opParam, algName, topoInfo, algorithmType, checkOnly)); | 1278 | comm, stream, topoTag, ccTiling, tilingIndex, opParam, algName, topoInfo, algorithmType, checkOnly)); |
| 1279 | + opParam.isMultiTiling = tilingNum > 1U; | ||
| 1280 | + | ||
| 1281 | + const std::string tag = std::string(opParam.algTag) + "_tiling_" + std::to_string(tilingNum) + "_" + | ||
| 1282 | + std::to_string(ccTiling->srcDataType) + "_" + std::to_string(ccTiling->dstDataType) + "_" + | ||
| 1283 | + std::to_string(ccTiling->reduceType); | ||
| 1284 | + CHK_SAFETY_FUNC_RET(strcpy_s(opParam.algTag, sizeof(opParam.algTag), tag.c_str())); | ||
| 1282 | 1285 | ||
| 1283 | FillCcuAlgorithmInfo(tilingIndex, ccTiling, algName, algorithmType, opParam, opResCtx); | 1286 | FillCcuAlgorithmInfo(tilingIndex, ccTiling, algName, algorithmType, opParam, opResCtx); |
| 1284 | 1287 | ||
| 1285 | - bool skipGetRes = false; | 1288 | + const size_t kernelNum = request.ccuKernelInfos.size(); |
| 1286 | - CHK_RET(PrepareCcuAlgorithmResource(comm, tilingIndex, algName, opParam, topoInfo.get(), opResCtx, skipGetRes)); | 1289 | + CHK_RET(PrepareCcuAlgorithmResource(comm, tilingIndex, algName, opParam, topoInfo.get(), skipGetRes, request)); |
| 1287 | - if (skipGetRes || checkOnly) { | 1290 | + constexpr uint64_t fieldMask = 0x7fU; |
| 1288 | - HCCL_INFO( | 1291 | + constexpr uint32_t dataTypeShift = 8U; |
| 1289 | - "[CcuSelectAlg] rank[%u] ProcessCcuTiling[%u] DONE (skipGetRes), opType[%u]", userRank, tilingIndex, | 1292 | + constexpr uint32_t reduceTypeShift = 16U; |
| 1290 | - ccTiling->opType); | 1293 | + constexpr uint32_t outputTypeShift = 24U; |
| 1294 | + const bool isReduceType = opParam.opType == HcclCMDType::HCCL_CMD_REDUCE || | ||
| 1295 | + opParam.opType == HcclCMDType::HCCL_CMD_REDUCE_SCATTER || | ||
| 1296 | + opParam.opType == HcclCMDType::HCCL_CMD_ALLREDUCE; | ||
| 1297 | + const uint64_t reduceType = isReduceType ? ccTiling->reduceType : 0U; | ||
| 1298 | + const uint64_t opId = (static_cast<uint64_t>(ccTiling->opType) & fieldMask) | | ||
| 1299 | + ((static_cast<uint64_t>(ccTiling->srcDataType) & fieldMask) << dataTypeShift) | | ||
| 1300 | + ((reduceType & fieldMask) << reduceTypeShift) | | ||
| 1301 | + ((static_cast<uint64_t>(ccTiling->dstDataType) & fieldMask) << outputTypeShift); | ||
| 1302 | + for (size_t i = kernelNum; i < request.ccuKernelInfos.size(); ++i) { | ||
| 1303 | + auto* arg = static_cast<CcuKernelArgKfcServer*>(request.ccuKernelInfos[i].kernelArg); | ||
| 1304 | + arg->opId = opId; | ||
| 1305 | + } | ||
| 1306 | + return HCCL_SUCCESS; | ||
| 1307 | +} | ||
| 1308 | +HcclResult PrepareCcuTilingResources( | ||
| 1309 | + HcclComm comm, const Mc2InitTilingInner* initTiling, std::vector<OpParam>& opParamVec, AlgResourceRequest& request, | ||
| 1310 | + OpResCtx& opResCtx, bool checkOnly, bool skipGetRes, std::unique_ptr<TopoInfoWithNetLayerDetails>& topoInfo) | ||
| 1311 | +{ | ||
| 1312 | + if (skipGetRes) { | ||
| 1291 | return HCCL_SUCCESS; | 1313 | return HCCL_SUCCESS; |
| 1292 | } | 1314 | } |
| 1293 | - HcclResult copyRet = CopyCcuOpParamToDevice(comm, tilingIndex, initTiling, opParam, opResCtx); | 1315 | + void* ctx = nullptr; |
| 1316 | + topoInfo = std::make_unique<TopoInfoWithNetLayerDetails>(); | ||
| 1317 | + CHK_RET(HcclCalcTopoInfo(comm, opParamVec[0], topoInfo)); | ||
| 1318 | + std::string resourceTag = opParamVec[0].algTag; | ||
| 1319 | + if (!checkOnly) { | ||
| 1320 | + for (uint32_t i = 0U; i < opParamVec.size(); ++i) { | ||
| 1321 | + const std::string tagParam = std::to_string(i) + "_" + std::string(opParamVec[i].algTag); | ||
| 1322 | + void* opParamPtr = nullptr; | ||
| 1323 | + CHK_RET(GetOrCreateCcuCtx(comm, tagParam, sizeof(OpParam), &opParamPtr)); | ||
| 1324 | + resourceTag += "_" + std::to_string(reinterpret_cast<uint64_t>(opParamPtr)); | ||
| 1325 | + } | ||
| 1326 | + } | ||
| 1327 | + CHK_RET(GetCcuOpParamResCtx( | ||
| 1328 | + comm, opParamVec[0].algName, opParamVec[0], topoInfo.get(), opResCtx, &ctx, &request, resourceTag)); | ||
| 1294 | HCCL_INFO( | 1329 | HCCL_INFO( |
| 1295 | - "[CcuSelectAlg] rank[%u] ProcessCcuTiling[%u] DONE, opType[%u], ret[%d]", userRank, tilingIndex, | 1330 | + "[PrepareCcuTilingResources] resource preparation completed, tilingNum[%zu], checkOnly[%u], " |
| 1296 | - ccTiling->opType, static_cast<int>(copyRet)); | 1331 | + "kernelNum[%zu], resCtx[%p]", |
| 1297 | - return copyRet; | 1332 | + opParamVec.size(), static_cast<uint32_t>(checkOnly), request.ccuKernelInfos.size(), ctx); |
| 1333 | + if (checkOnly) { | ||
| 1334 | + return HCCL_SUCCESS; | ||
| 1335 | + } | ||
| 1336 | + for (uint32_t i = 0U; i < opParamVec.size(); ++i) { | ||
| 1337 | + opParamVec[i].resCtx = ctx; | ||
| 1338 | + opParamVec[i].ctxSize = opParamVec[0].ctxSize; | ||
| 1339 | + CHK_RET(CopyCcuOpParamToDevice(comm, i, initTiling, opParamVec[i], opResCtx)); | ||
| 1340 | + } | ||
| 1341 | + return HCCL_SUCCESS; | ||
| 1298 | } | 1342 | } |
| 1299 | } // namespace | 1343 | } // namespace |
| 1300 | 1344 | ||
| @@ -1308,17 +1352,17 @@ HcclResult CcuSelectAlg( | |||
| 1308 | "[CcuSelectAlg]received: workspace[%p], size[%llu]", reinterpret_cast<void*>(opResCtx.workSpace), | 1352 | "[CcuSelectAlg]received: workspace[%p], size[%llu]", reinterpret_cast<void*>(opResCtx.workSpace), |
| 1309 | opResCtx.workSpaceSize); | 1353 | opResCtx.workSpaceSize); |
| 1310 | Mc2InitTilingInner* initTiling = static_cast<Mc2InitTilingInner*>(mc2Tiling); | 1354 | Mc2InitTilingInner* initTiling = static_cast<Mc2InitTilingInner*>(mc2Tiling); |
| 1355 | + std::vector<OpParam> opParamVec(tilingNum); | ||
| 1356 | + AlgResourceRequest request; | ||
| 1357 | + bool skipGetRes = false; | ||
| 1358 | + std::unique_ptr<TopoInfoWithNetLayerDetails> topoInfo; | ||
| 1311 | for (uint32_t i = 0U; i < tilingNum; ++i) { | 1359 | for (uint32_t i = 0U; i < tilingNum; ++i) { |
| 1312 | const Mc2CcTilingInner* ccTiling = static_cast<const Mc2CcTilingInner*>(ccTilingList[i]); | 1360 | const Mc2CcTilingInner* ccTiling = static_cast<const Mc2CcTilingInner*>(ccTilingList[i]); |
| 1313 | - CHK_RET(ProcessCcuTiling(comm, stream, topoTag[i], ccTiling, i, initTiling, opResCtx, checkOnly)); | 1361 | + CHK_RET(ProcessCcuTiling( |
| 1314 | - if (i > 0U && opResCtx.algorithmType[i] != opResCtx.algorithmType[0]) { | 1362 | + comm, stream, topoTag[i], ccTiling, i, opResCtx, opParamVec[i], request, tilingNum, checkOnly, skipGetRes, |
| 1315 | - HCCL_ERROR( | 1363 | + topoInfo)); |
| 1316 | - "[CcuSelectAlg] all tilings in one KFC context must use the same static server algorithm, " | ||
| 1317 | - "algorithmType[0]=[%u], tiling[%u] algorithmType=[%u], opType[%u], algConfig[%s].", | ||
| 1318 | - opResCtx.algorithmType[0], i, opResCtx.algorithmType[i], ccTiling->opType, ccTiling->algConfig); | ||
| 1319 | - return HCCL_E_NOT_SUPPORT; | ||
| 1320 | - } | ||
| 1321 | } | 1364 | } |
| 1322 | - | 1365 | + CHK_RET( |
| 1366 | + PrepareCcuTilingResources(comm, initTiling, opParamVec, request, opResCtx, checkOnly, skipGetRes, topoInfo)); | ||
| 1323 | return HCCL_SUCCESS; | 1367 | return HCCL_SUCCESS; |
| 1324 | } | 1368 | } |
| @@ -229,7 +229,7 @@ HcclResult GetOpParamResCtx( | |||
| 229 | 229 | ||
| 230 | HcclResult GetCcuOpParamResCtx( | 230 | HcclResult GetCcuOpParamResCtx( |
| 231 | HcclComm comm, const std::string& algName, OpParam& opParam, TopoInfoWithNetLayerDetails* topoInfo, | 231 | HcclComm comm, const std::string& algName, OpParam& opParam, TopoInfoWithNetLayerDetails* topoInfo, |
| 232 | - OpResCtx& opResCtx, void** resCtxOut); | 232 | + OpResCtx& opResCtx, void** resCtxOut, AlgResourceRequest* request, const std::string& resourceTag = ""); |
| 233 | 233 | ||
| 234 | HcclResult GetOpParam( | 234 | HcclResult GetOpParam( |
| 235 | HcclComm comm, void* stream, const std::string& tag, const Mc2CcTilingInner* ccTiling, OpParam& opParam); | 235 | HcclComm comm, void* stream, const std::string& tag, const Mc2CcTilingInner* ccTiling, OpParam& opParam); |
| @@ -321,6 +321,50 @@ HcclResult CcuTempKfcServer::CalcRes( | |||
| 321 | return HcclResult::HCCL_SUCCESS; | 321 | return HcclResult::HCCL_SUCCESS; |
| 322 | } | 322 | } |
| 323 | 323 | ||
| 324 | +HcclResult BuildKfcServer( | ||
| 325 | + AlgResourceRequest& resRequest, std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, const OpParam& param) | ||
| 326 | +{ | ||
| 327 | + auto arg = std::make_shared<CcuKernelArgKfcServer>(); | ||
| 328 | + CHK_PRT_RET( | ||
| 329 | + param.isMultiTiling && | ||
| 330 | + (resRequest.ccuKernelInfos.empty() || resCtxHost->kfcServerArgs.size() < KFC_SERVER_ARG_NUM), | ||
| 331 | + HCCL_ERROR("Invalid multi-tiling KFC resource request."), HCCL_E_PARA); | ||
| 332 | + CcuKernelInfo server{}; | ||
| 333 | + CHK_SAFETY_FUNC_RET(strcpy_s(server.kernelFuncName, sizeof(server.kernelFuncName), "CcuKernelKfcServer")); | ||
| 334 | + server.kernelFunc = reinterpret_cast<void*>(CcuKfcServerKernel); | ||
| 335 | + if (param.isMultiTiling) { | ||
| 336 | + server.dieId = resRequest.ccuKernelInfos.front().dieId; | ||
| 337 | + } | ||
| 338 | + for (const auto& source : resRequest.ccuKernelInfos) { | ||
| 339 | + CHK_PRT_RET( | ||
| 340 | + source.kernelArg == nullptr || std::strcmp(source.kernelFuncName, "CcuKernelKfcServer") != 0, | ||
| 341 | + HCCL_ERROR("Invalid multi-tiling KFC source kernel."), HCCL_E_PARA); | ||
| 342 | + CHK_PRT_RET( | ||
| 343 | + param.isMultiTiling && source.dieId != server.dieId, | ||
| 344 | + HCCL_ERROR("Multi-tiling KFC requires all tilings on the same die."), HCCL_E_NOT_SUPPORT); | ||
| 345 | + auto* sourceArg = static_cast<CcuKernelArgKfcServer*>(source.kernelArg); | ||
| 346 | + auto& tilingArgs = param.isMultiTiling ? arg->tilingArgs : sourceArg->tilingArgs; | ||
| 347 | + tilingArgs.push_back(std::make_shared<CcuKernelArgKfcServer>(*sourceArg)); | ||
| 348 | + } | ||
| 349 | + HCCL_INFO( | ||
| 350 | + "[BuildKfcServer] tilingArgs prepared, isMultiTiling[%u], sourceKernelNum[%zu]", | ||
| 351 | + static_cast<uint32_t>(param.isMultiTiling), resRequest.ccuKernelInfos.size()); | ||
| 352 | + if (!param.isMultiTiling) { | ||
| 353 | + return HCCL_SUCCESS; | ||
| 354 | + } | ||
| 355 | + server.setKernelArg(arg); | ||
| 356 | + resRequest.ccuKernelInfos.clear(); | ||
| 357 | + resRequest.ccuKernelInfos.push_back(std::move(server)); | ||
| 358 | + resRequest.ccuKernelNum.assign(1U, 1U); | ||
| 359 | + resRequest.slaveThreadNum = 0U; | ||
| 360 | + resRequest.notifyNumPerThread.clear(); | ||
| 361 | + resCtxHost->notifyNumPerThread.clear(); | ||
| 362 | + resCtxHost->kfcServerArgs.resize(KFC_SERVER_ARG_NUM); | ||
| 363 | + resCtxHost->kfcServerArgs[KFC_SERVER_MISSION_NUM_ARG_INDEX] = 1U; | ||
| 364 | + resCtxHost->kfcServerArgs[KFC_SERVER_MISSION_INDEX_ARG_INDEX] = 0U; | ||
| 365 | + return HCCL_SUCCESS; | ||
| 366 | +} | ||
| 367 | + | ||
| 324 | HcclResult CcuTempKfcServer::KernelRun( | 368 | HcclResult CcuTempKfcServer::KernelRun( |
| 325 | const OpParam& param, const TemplateDataParams& templateDataParams, TemplateResource& templateResource) | 369 | const OpParam& param, const TemplateDataParams& templateDataParams, TemplateResource& templateResource) |
| 326 | { | 370 | { |
| @@ -528,13 +528,20 @@ CcuResult KfcServerGenCircularQueue(KfcServerContext& ctx) | |||
| 528 | CCU_IF(param[HBM_PARAM_IDX_0] == INVALID_U64) { repeatCond = 1; } | 528 | CCU_IF(param[HBM_PARAM_IDX_0] == INVALID_U64) { repeatCond = 1; } |
| 529 | CCU_IF(param[HBM_PARAM_IDX_0] != INVALID_U64) | 529 | CCU_IF(param[HBM_PARAM_IDX_0] != INVALID_U64) |
| 530 | { | 530 | { |
| 531 | - CCU_CHK_RET(MissionPreSync(param[HBM_PARAM_IDX_0], ctx)); | 531 | + const auto* serverArg = ctx.arg; |
| 532 | - DispatchKfcSubKernel(param, ctx, recordAddr); | 532 | + for (const auto& arg : serverArg->tilingArgs) { |
| 533 | - CCU_CHK_RET(MissionPostSync(ctx)); | 533 | + CCU_IF(param[HBM_PARAM_IDX_0] == arg->opId) |
| 534 | - // D3:SoleNHR AG kernel 已在末步同步后、PostSync 前写 turn-end(AIV 提前返回), | 534 | + { |
| 535 | - // 其余角色维持 dispatch 后统一发放。条件为宿主侧常量,不产生运行时分支指令。 | 535 | + ctx.arg = arg.get(); |
| 536 | - if (!KernelEmitsEarlyTurnEnd(ctx)) { | 536 | + CCU_CHK_RET(MissionPreSync(param[HBM_PARAM_IDX_0], ctx)); |
| 537 | - CCU_CHK_RET(SetTurnEndSig(recordAddr, turnEndSig, ctx)); | 537 | + DispatchKfcSubKernel(param, ctx, recordAddr); |
| 538 | + CCU_CHK_RET(MissionPostSync(ctx)); | ||
| 539 | + // SoleNHR AG may emit turn-end inside its subkernel. | ||
| 540 | + if (!KernelEmitsEarlyTurnEnd(ctx)) { | ||
| 541 | + CCU_CHK_RET(SetTurnEndSig(recordAddr, turnEndSig, ctx)); | ||
| 542 | + } | ||
| 543 | + ctx.arg = serverArg; | ||
| 544 | + } | ||
| 538 | } | 545 | } |
| 539 | } | 546 | } |
| 540 | waitAddr += ckeSize; | 547 | waitAddr += ckeSize; |
| @@ -47,6 +47,9 @@ struct CcuKernelArgKfcServer : CcuKernelArgBase { | |||
| 47 | // 会导致双 mission 两个 kernel 各自 export 同一对 tag,注册期 ProcessInterCtxRes | 47 | // 会导致双 mission 两个 kernel 各自 export 同一对 tag,注册期 ProcessInterCtxRes |
| 48 | // 合并 exported sharedNotifies 时同名冲突(HCCL_E_PARA)。 | 48 | // 合并 exported sharedNotifies 时同名冲突(HCCL_E_PARA)。 |
| 49 | uint32_t hostMissionIndex = 0; | 49 | uint32_t hostMissionIndex = 0; |
| 50 | + uint64_t opId = 0U; | ||
| 51 | + // Multi-tiling subgraphs have distinct opTypes and one mission each on the same die. | ||
| 52 | + std::vector<std::shared_ptr<CcuKernelArgKfcServer>> tilingArgs; | ||
| 50 | }; | 53 | }; |
| 51 | 54 | ||
| 52 | class CcuTaskArgKfcServer : public hcomm::CcuTaskArg { | 55 | class CcuTaskArgKfcServer : public hcomm::CcuTaskArg { |
| @@ -720,9 +720,10 @@ struct OpParam { // 不申请ctx,每个算子单独下发 | |||
| 720 | ThreadHandle deviceOrderThread = 0; // device侧保序流 | 720 | ThreadHandle deviceOrderThread = 0; // device侧保序流 |
| 721 | u64 varMemSize{0}; | 721 | u64 varMemSize{0}; |
| 722 | u8 varData[0]; | 722 | u8 varData[0]; |
| 723 | - u64 ccuKfcArgs[4]; // 测试,ccu-kfc作为通信算子 | 723 | + u64 ccuKfcArgs[4]; // 测试,ccu-kfc作为通信算子 |
| 724 | - bool isKfc = false; // 标记是否使用KFC Server kernel | 724 | + bool isKfc = false; // 标记是否使用KFC Server kernel |
| 725 | - bool checkRes = false; // 仅校验资源是否充足,不实际下发 | 725 | + bool checkRes = false; // 仅校验资源是否充足,不实际下发 |
| 726 | + bool isMultiTiling = false; // 标记是否属于多 tiling 资源申请 | ||
| 726 | }; | 727 | }; |
| 727 | 728 | ||
| 728 | struct AlgDesc { | 729 | struct AlgDesc { |
| @@ -816,63 +816,11 @@ void CompReqChannelWithExistChannel( | |||
| 816 | return; | 816 | return; |
| 817 | } | 817 | } |
| 818 | 818 | ||
| 819 | -HcclResult HcclGetAlgRes( | 819 | +HcclResult CalcAlgResourceRequest( |
| 820 | HcclComm comm, OpParam& param, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, | 820 | HcclComm comm, OpParam& param, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, |
| 821 | - std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, void** resCtxSequence, bool& isResourceReused) | 821 | + AlgHierarchyInfoForAllLevel& algHierarchyInfo, AlgResourceRequest& resRequest) |
| 822 | { | 822 | { |
| 823 | - CHK_PTR_NULL(topoInfo); | ||
| 824 | - CHK_PTR_NULL(resCtxSequence); | ||
| 825 | - *resCtxSequence = nullptr; | ||
| 826 | - HCCL_INFO( | ||
| 827 | - "[asc][AlgoResource][HcclGetAlgRes] start, opType[%d], algName[%s], algTag[%s], engine[%d], opMode[%d].", | ||
| 828 | - param.opType, param.algName, param.algTag, param.engine, param.opMode); | ||
| 829 | - | ||
| 830 | - void* ctx = nullptr; | ||
| 831 | - bool increCreateChannelFlag = false; | ||
| 832 | - if (param.opType == HcclCMDType::HCCL_CMD_BATCH_SEND_RECV && param.opMode == OpMode::OPBASE) { | ||
| 833 | - // 增量建链模式 | ||
| 834 | - increCreateChannelFlag = true; | ||
| 835 | - } | ||
| 836 | - uint64_t size = 0; | ||
| 837 | - // 图模式不支持资源复用,且不存在增量建链场景 | ||
| 838 | - if (!increCreateChannelFlag && param.opMode == OpMode::OPBASE) { | ||
| 839 | - void* ctx = nullptr; | ||
| 840 | - // 这种情况下资源已经有了 | ||
| 841 | - CommEngine ctxEngine = param.engine; | ||
| 842 | - if (param.engine == COMM_ENGINE_CPU) { | ||
| 843 | - // host dpu申请device内存用于存放resctx | ||
| 844 | - ctxEngine = COMM_ENGINE_AICPU_TS; | ||
| 845 | - } else if (param.engine == COMM_ENGINE_CCU) { | ||
| 846 | - // ccu申请aiv内存用于存放resctx | ||
| 847 | - ctxEngine = COMM_ENGINE_AIV; | ||
| 848 | - } | ||
| 849 | - HCCL_INFO( | ||
| 850 | - "[asc][AlgoResource][HcclGetAlgRes] before HcclEngineCtxGet, algTag[%s], engine[%d], ctxEngine[%d].", | ||
| 851 | - param.algTag, param.engine, ctxEngine); | ||
| 852 | - if (HcclEngineCtxGet(comm, param.algTag, ctxEngine, &ctx, &size) == HCCL_SUCCESS) { | ||
| 853 | - HCCL_INFO( | ||
| 854 | - "[asc][AlgoResource][HcclGetAlgRes] HcclEngineCtxGet HIT cache, algTag[%s], engine[%d], ctxEngine[%d], " | ||
| 855 | - "ctxSize[%llu].", | ||
| 856 | - param.algTag, param.engine, ctxEngine, static_cast<unsigned long long>(size)); | ||
| 857 | - HCCL_DEBUG("Already have context, skip create, ctxSize is %u", param.ctxSize); | ||
| 858 | - isResourceReused = true; | ||
| 859 | - *resCtxSequence = ctx; | ||
| 860 | - param.ctxSize = size; | ||
| 861 | - | ||
| 862 | - if (param.engine == COMM_ENGINE_CCU) { | ||
| 863 | - CHK_RET(UpdateCcuCtxTokenOnReuse(comm, ctx, size, resCtxHost)); | ||
| 864 | - } | ||
| 865 | - | ||
| 866 | - return HCCL_SUCCESS; | ||
| 867 | - } | ||
| 868 | - HCCL_INFO( | ||
| 869 | - "[asc][AlgoResource][HcclGetAlgRes] HcclEngineCtxGet MISS cache, algTag[%s], engine[%d], ctxEngine[%d], " | ||
| 870 | - "will alloc new resource.", | ||
| 871 | - param.algTag, param.engine, ctxEngine); | ||
| 872 | - } | ||
| 873 | - | ||
| 874 | // 计算AlgHierarchyInfo | 823 | // 计算AlgHierarchyInfo |
| 875 | - AlgHierarchyInfoForAllLevel algHierarchyInfo; // 分级通信域信息{localRankId, localRankSize} | ||
| 876 | HCCL_INFO( | 824 | HCCL_INFO( |
| 877 | "[asc][AlgoResource][HcclGetAlgRes] before CalcAlgHierarchyInfo, opType[%d], algTag[%s].", param.opType, | 825 | "[asc][AlgoResource][HcclGetAlgRes] before CalcAlgHierarchyInfo, opType[%d], algTag[%s].", param.opType, |
| 878 | param.algTag); | 826 | param.algTag); |
| @@ -892,7 +840,6 @@ HcclResult HcclGetAlgRes( | |||
| 892 | CHK_RET(calcHierarchyRet); | 840 | CHK_RET(calcHierarchyRet); |
| 893 | } | 841 | } |
| 894 | // 资源计算 | 842 | // 资源计算 |
| 895 | - AlgResourceRequest resRequest; | ||
| 896 | HCCL_INFO( | 843 | HCCL_INFO( |
| 897 | "[asc][AlgoResource][HcclGetAlgRes] before CalcRes, opType[%d], algTag[%s], engine[%d].", param.opType, | 844 | "[asc][AlgoResource][HcclGetAlgRes] before CalcRes, opType[%d], algTag[%s], engine[%d].", param.opType, |
| 898 | param.algTag, param.engine); | 845 | param.algTag, param.engine); |
| @@ -919,6 +866,77 @@ HcclResult HcclGetAlgRes( | |||
| 919 | "[asc][AlgoResource][HcclGetAlgRes] after CcuKfcServer CalcRes, " | 866 | "[asc][AlgoResource][HcclGetAlgRes] after CcuKfcServer CalcRes, " |
| 920 | "ccuKernelInfos.size()[%zu], ccuKernelNum.size()[%zu]", | 867 | "ccuKernelInfos.size()[%zu], ccuKernelNum.size()[%zu]", |
| 921 | resRequest.ccuKernelInfos.size(), resRequest.ccuKernelNum.size()); | 868 | resRequest.ccuKernelInfos.size(), resRequest.ccuKernelNum.size()); |
| 869 | + } | ||
| 870 | + return HCCL_SUCCESS; | ||
| 871 | +} | ||
| 872 | + | ||
| 873 | +HcclResult HcclGetAlgRes( | ||
| 874 | + HcclComm comm, OpParam& param, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, | ||
| 875 | + std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, void** resCtxSequence, bool& isResourceReused, | ||
| 876 | + AlgResourceRequest* request, const std::string& resourceTag) | ||
| 877 | +{ | ||
| 878 | + CHK_PTR_NULL(topoInfo); | ||
| 879 | + CHK_PTR_NULL(resCtxSequence); | ||
| 880 | + *resCtxSequence = nullptr; | ||
| 881 | + HCCL_INFO( | ||
| 882 | + "[asc][AlgoResource][HcclGetAlgRes] start, opType[%d], algName[%s], algTag[%s], engine[%d], opMode[%d].", | ||
| 883 | + param.opType, param.algName, param.algTag, param.engine, param.opMode); | ||
| 884 | + | ||
| 885 | + void* ctx = nullptr; | ||
| 886 | + bool increCreateChannelFlag = false; | ||
| 887 | + if (param.opType == HcclCMDType::HCCL_CMD_BATCH_SEND_RECV && param.opMode == OpMode::OPBASE) { | ||
| 888 | + // 增量建链模式 | ||
| 889 | + increCreateChannelFlag = true; | ||
| 890 | + } | ||
| 891 | + uint64_t size = 0; | ||
| 892 | + const std::string contextTag = resourceTag.empty() ? std::string(param.algTag) : resourceTag; | ||
| 893 | + // 图模式不支持资源复用,且不存在增量建链场景 | ||
| 894 | + if (!increCreateChannelFlag && !param.isMultiTiling && param.opMode == OpMode::OPBASE) { | ||
| 895 | + void* ctx = nullptr; | ||
| 896 | + // 这种情况下资源已经有了 | ||
| 897 | + CommEngine ctxEngine = param.engine; | ||
| 898 | + if (param.engine == COMM_ENGINE_CPU) { | ||
| 899 | + // host dpu申请device内存用于存放resctx | ||
| 900 | + ctxEngine = COMM_ENGINE_AICPU_TS; | ||
| 901 | + } else if (param.engine == COMM_ENGINE_CCU) { | ||
| 902 | + // ccu申请aiv内存用于存放resctx | ||
| 903 | + ctxEngine = COMM_ENGINE_AIV; | ||
| 904 | + } | ||
| 905 | + HCCL_INFO( | ||
| 906 | + "[asc][AlgoResource][HcclGetAlgRes] before HcclEngineCtxGet, algTag[%s], engine[%d], ctxEngine[%d].", | ||
| 907 | + contextTag.c_str(), param.engine, ctxEngine); | ||
| 908 | + if (HcclEngineCtxGet(comm, contextTag.c_str(), ctxEngine, &ctx, &size) == HCCL_SUCCESS) { | ||
| 909 | + HCCL_INFO( | ||
| 910 | + "[asc][AlgoResource][HcclGetAlgRes] HcclEngineCtxGet HIT cache, algTag[%s], engine[%d], ctxEngine[%d], " | ||
| 911 | + "ctxSize[%llu].", | ||
| 912 | + contextTag.c_str(), param.engine, ctxEngine, static_cast<unsigned long long>(size)); | ||
| 913 | + HCCL_DEBUG("Already have context, skip create, ctxSize is %u", param.ctxSize); | ||
| 914 | + isResourceReused = true; | ||
| 915 | + *resCtxSequence = ctx; | ||
| 916 | + param.ctxSize = size; | ||
| 917 | + | ||
| 918 | + if (param.engine == COMM_ENGINE_CCU) { | ||
| 919 | + CHK_RET(UpdateCcuCtxTokenOnReuse(comm, ctx, size, resCtxHost)); | ||
| 920 | + } | ||
| 921 | + | ||
| 922 | + return HCCL_SUCCESS; | ||
| 923 | + } | ||
| 924 | + HCCL_INFO( | ||
| 925 | + "[asc][AlgoResource][HcclGetAlgRes] HcclEngineCtxGet MISS cache, algTag[%s], engine[%d], ctxEngine[%d], " | ||
| 926 | + "will alloc new resource.", | ||
| 927 | + contextTag.c_str(), param.engine, ctxEngine); | ||
| 928 | + } | ||
| 929 | + | ||
| 930 | + AlgHierarchyInfoForAllLevel algHierarchyInfo; | ||
| 931 | + AlgResourceRequest localRequest; | ||
| 932 | + AlgResourceRequest& resRequest = request != nullptr ? *request : localRequest; | ||
| 933 | + if (request == nullptr) { | ||
| 934 | + CHK_RET(CalcAlgResourceRequest(comm, param, executor, topoInfo, algHierarchyInfo, resRequest)); | ||
| 935 | + } else { | ||
| 936 | + CHK_RET(executor->CalcAlgHierarchyInfo(comm, topoInfo, algHierarchyInfo)); | ||
| 937 | + } | ||
| 938 | + | ||
| 939 | + if (param.isKfc && param.engine == COMM_ENGINE_CCU) { | ||
| 922 | // SoleNHR 动态 mission(RS 2Die / AG SoleNHR D4):mission 数由 dieNum(模板 CalcRes 通道探测) | 940 | // SoleNHR 动态 mission(RS 2Die / AG SoleNHR D4):mission 数由 dieNum(模板 CalcRes 通道探测) |
| 923 | // 决定,AcquireAlgResources 构造 kfcServerArgs 时按静态 GetKfcServerMissionNum(=1)生成—— | 941 | // 决定,AcquireAlgResources 构造 kfcServerArgs 时按静态 GetKfcServerMissionNum(=1)生成—— |
| 924 | // 双 die 时此处按源 kernel 数修正 missionNum 与 dieNum(ccuKernelNum 尾值即模板 push 的 | 942 | // 双 die 时此处按源 kernel 数修正 missionNum 与 dieNum(ccuKernelNum 尾值即模板 push 的 |
| @@ -984,8 +1002,8 @@ HcclResult HcclGetAlgRes( | |||
| 984 | HCCL_INFO( | 1002 | HCCL_INFO( |
| 985 | "[asc][AlgoResource][HcclGetAlgRes] before GetAlgResCcu, opType[%d], algTag[%s].", param.opType, | 1003 | "[asc][AlgoResource][HcclGetAlgRes] before GetAlgResCcu, opType[%d], algTag[%s].", param.opType, |
| 986 | param.algTag); | 1004 | param.algTag); |
| 987 | - HcclResult ccuRet = | 1005 | + HcclResult ccuRet = GetAlgResCcu( |
| 988 | - GetAlgResCcu(comm, param, resRequest, resCtxHost, topoInfo, algHierarchyInfo, resCtxSequence, size); | 1006 | + comm, param, resRequest, resCtxHost, topoInfo, algHierarchyInfo, resCtxSequence, size, resourceTag); |
| 989 | HCCL_INFO( | 1007 | HCCL_INFO( |
| 990 | "[asc][AlgoResource][HcclGetAlgRes] after GetAlgResCcu, ret[%d], ctxSize[%llu], " | 1008 | "[asc][AlgoResource][HcclGetAlgRes] after GetAlgResCcu, ret[%d], ctxSize[%llu], " |
| 991 | "resCtxSequence[%p].", | 1009 | "resCtxSequence[%p].", |
| @@ -1427,7 +1445,8 @@ HcclResult GetGraphModeBuffers( | |||
| 1427 | HcclResult GetAlgResCcu( | 1445 | HcclResult GetAlgResCcu( |
| 1428 | HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest, | 1446 | HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest, |
| 1429 | std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, TopoInfoWithNetLayerDetails* topoInfo, | 1447 | std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, TopoInfoWithNetLayerDetails* topoInfo, |
| 1430 | - AlgHierarchyInfoForAllLevel& algHierarchyInfo, void** resCtxSequence, uint64_t& ctxSize) | 1448 | + AlgHierarchyInfoForAllLevel& algHierarchyInfo, void** resCtxSequence, uint64_t& ctxSize, |
| 1449 | + const std::string& resourceTag) | ||
| 1431 | { | 1450 | { |
| 1432 | #if !MC2_CLIENT_ENABLE_CCU | 1451 | #if !MC2_CLIENT_ENABLE_CCU |
| 1433 | (void)comm; | 1452 | (void)comm; |
| @@ -1438,6 +1457,7 @@ HcclResult GetAlgResCcu( | |||
| 1438 | (void)algHierarchyInfo; | 1457 | (void)algHierarchyInfo; |
| 1439 | (void)resCtxSequence; | 1458 | (void)resCtxSequence; |
| 1440 | (void)ctxSize; | 1459 | (void)ctxSize; |
| 1460 | + (void)resourceTag; | ||
| 1441 | HCCL_ERROR("[GetAlgResCcu] CCU resource is not supported by mc2_client."); | 1461 | HCCL_ERROR("[GetAlgResCcu] CCU resource is not supported by mc2_client."); |
| 1442 | return HCCL_E_NOT_SUPPORT; | 1462 | return HCCL_E_NOT_SUPPORT; |
| 1443 | #else | 1463 | #else |
| @@ -1447,6 +1467,7 @@ HcclResult GetAlgResCcu( | |||
| 1447 | HCCL_INFO("[GetAlgResCcu]start GetAlgResCcu!"); | 1467 | HCCL_INFO("[GetAlgResCcu]start GetAlgResCcu!"); |
| 1448 | resCtxHost->topoInfo = *topoInfo; | 1468 | resCtxHost->topoInfo = *topoInfo; |
| 1449 | resCtxHost->algHierarchyInfo = algHierarchyInfo; | 1469 | resCtxHost->algHierarchyInfo = algHierarchyInfo; |
| 1470 | + std::string contextTag = resourceTag.empty() ? std::string(param.algTag) : resourceTag; | ||
| 1450 | 1471 | ||
| 1451 | // 创建资源,并填充到Host内存上 | 1472 | // 创建资源,并填充到Host内存上 |
| 1452 | HcclResult ret = HcclAllocAlgResourceCcu(comm, param, resRequest, resCtxHost); | 1473 | HcclResult ret = HcclAllocAlgResourceCcu(comm, param, resRequest, resCtxHost); |
| @@ -1467,7 +1488,7 @@ HcclResult GetAlgResCcu( | |||
| 1467 | uint64_t size = seq.size(); | 1488 | uint64_t size = seq.size(); |
| 1468 | 1489 | ||
| 1469 | void* ctx = nullptr; | 1490 | void* ctx = nullptr; |
| 1470 | - CHK_RET(GetOrCreateCcuCtx(comm, param.algTag, size, &ctx)); | 1491 | + CHK_RET(GetOrCreateCcuCtx(comm, contextTag, size, &ctx)); |
| 1471 | const size_t copySize = static_cast<size_t>(size); | 1492 | const size_t copySize = static_cast<size_t>(size); |
| 1472 | HcclResult copyRet = haclrtMemcpy(ctx, copySize, seq.data(), copySize, ACL_MEMCPY_HOST_TO_DEVICE); | 1493 | HcclResult copyRet = haclrtMemcpy(ctx, copySize, seq.data(), copySize, ACL_MEMCPY_HOST_TO_DEVICE); |
| 1473 | if (copyRet != HCCL_SUCCESS) { | 1494 | if (copyRet != HCCL_SUCCESS) { |
| @@ -1542,12 +1563,23 @@ HcclResult HcclAllocAlgResourceCcu( | |||
| 1542 | resCtxHost->parallelPortInfo = resRequest.parallelPortInfo; | 1563 | resCtxHost->parallelPortInfo = resRequest.parallelPortInfo; |
| 1543 | resCtxHost->dieSplitRatio = resRequest.dieSplitRatio; | 1564 | resCtxHost->dieSplitRatio = resRequest.dieSplitRatio; |
| 1544 | if (!param.checkRes) { | 1565 | if (!param.checkRes) { |
| 1545 | - CHK_RET(HcclGetThread(comm, param, resRequest, resCtxHost)); | ||
| 1546 | CHK_RET(HcclGetChannelForCcu(comm, param, resRequest)); | 1566 | CHK_RET(HcclGetChannelForCcu(comm, param, resRequest)); |
| 1567 | + if (param.isKfc) { | ||
| 1568 | + const HcclResult buildRet = BuildKfcServer(resRequest, resCtxHost, param); | ||
| 1569 | + if (buildRet != HCCL_SUCCESS) { | ||
| 1570 | + ReleaseCcuAcquiredChannels(comm, resRequest); | ||
| 1571 | + return buildRet; | ||
| 1572 | + } | ||
| 1573 | + } | ||
| 1574 | + resCtxHost->slaveThreadNum = resRequest.slaveThreadNum; | ||
| 1575 | + CHK_RET(HcclGetThread(comm, param, resRequest, resCtxHost)); | ||
| 1547 | CHK_RET(HcclGetCcuKernel(comm, param, resRequest, resCtxHost)); | 1576 | CHK_RET(HcclGetCcuKernel(comm, param, resRequest, resCtxHost)); |
| 1548 | return HCCL_SUCCESS; | 1577 | return HCCL_SUCCESS; |
| 1549 | } | 1578 | } |
| 1550 | HcclResult ret = HcclGetChannelForCcu(comm, param, resRequest); | 1579 | HcclResult ret = HcclGetChannelForCcu(comm, param, resRequest); |
| 1580 | + if (ret == HCCL_SUCCESS && param.isKfc) { | ||
| 1581 | + ret = BuildKfcServer(resRequest, resCtxHost, param); | ||
| 1582 | + } | ||
| 1551 | if (ret == HCCL_SUCCESS) { | 1583 | if (ret == HCCL_SUCCESS) { |
| 1552 | ret = HcclGetCcuKernel(comm, param, resRequest, resCtxHost); | 1584 | ret = HcclGetCcuKernel(comm, param, resRequest, resCtxHost); |
| 1553 | } | 1585 | } |
| @@ -37,9 +37,14 @@ HcclResult HcclExecOp( | |||
| 37 | 37 | ||
| 38 | HcclResult HcclCalcTopoInfo(HcclComm comm, OpParam& param, std::unique_ptr<TopoInfoWithNetLayerDetails>& topoInfo); | 38 | HcclResult HcclCalcTopoInfo(HcclComm comm, OpParam& param, std::unique_ptr<TopoInfoWithNetLayerDetails>& topoInfo); |
| 39 | 39 | ||
| 40 | +HcclResult CalcAlgResourceRequest( | ||
| 41 | + HcclComm comm, OpParam& param, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, | ||
| 42 | + AlgHierarchyInfoForAllLevel& algHierarchyInfo, AlgResourceRequest& resRequest); | ||
| 43 | + | ||
| 40 | HcclResult HcclGetAlgRes( | 44 | HcclResult HcclGetAlgRes( |
| 41 | HcclComm comm, OpParam& param, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, | 45 | HcclComm comm, OpParam& param, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, |
| 42 | - std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, void** resCtxSequence, bool& isResourceReused); | 46 | + std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, void** resCtxSequence, bool& isResourceReused, |
| 47 | + AlgResourceRequest* request = nullptr, const std::string& resourceTag = ""); | ||
| 43 | 48 | ||
| 44 | HcclResult GetAlgResAICPU( | 49 | HcclResult GetAlgResAICPU( |
| 45 | HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest, | 50 | HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest, |
| @@ -73,13 +78,17 @@ HcclResult HcclGetCcuKernel( | |||
| 73 | 78 | ||
| 74 | HcclResult HcclGetChannelForCcu(HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest); | 79 | HcclResult HcclGetChannelForCcu(HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest); |
| 75 | 80 | ||
| 81 | +HcclResult BuildKfcServer( | ||
| 82 | + AlgResourceRequest& resRequest, std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, const OpParam& param); | ||
| 83 | + | ||
| 76 | HcclResult HcclAllocAlgResourceCcu( | 84 | HcclResult HcclAllocAlgResourceCcu( |
| 77 | HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest, | 85 | HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest, |
| 78 | std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost); | 86 | std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost); |
| 79 | HcclResult GetAlgResCcu( | 87 | HcclResult GetAlgResCcu( |
| 80 | HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest, | 88 | HcclComm comm, const OpParam& param, AlgResourceRequest& resRequest, |
| 81 | std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, TopoInfoWithNetLayerDetails* topoInfo, | 89 | std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, TopoInfoWithNetLayerDetails* topoInfo, |
| 82 | - AlgHierarchyInfoForAllLevel& algHierarchyInfo, void** resCtxSequence, uint64_t& ctxSize); | 90 | + AlgHierarchyInfoForAllLevel& algHierarchyInfo, void** resCtxSequence, uint64_t& ctxSize, |
| 91 | + const std::string& resourceTag = ""); | ||
| 83 | 92 | ||
| 84 | HcclResult SetOpParamFastLaunchTag(OpParam& param); | 93 | HcclResult SetOpParamFastLaunchTag(OpParam& param); |
| 85 | 94 | ||
| @@ -20,11 +20,20 @@ | |||
| 20 | #include "external_alg_resolver.h" | 20 | #include "external_alg_resolver.h" |
| 21 | #include "external_alg_rules.h" | 21 | #include "external_alg_rules.h" |
| 22 | #include "gtest/gtest.h" | 22 | #include "gtest/gtest.h" |
| 23 | +#include "op_common.h" | ||
| 23 | #include "sim_communicator.h" | 24 | #include "sim_communicator.h" |
| 24 | #include "sim_world.h" | 25 | #include "sim_world.h" |
| 25 | 26 | ||
| 26 | #include "acl/acl_rt.h" | 27 | #include "acl/acl_rt.h" |
| 27 | 28 | ||
| 29 | +namespace mc2_ops_hccl { | ||
| 30 | +// 本目标不链接 KFC server,实现桩仅用于补齐 op_common.cc 的链接依赖。 | ||
| 31 | +HcclResult BuildKfcServer(AlgResourceRequest&, std::unique_ptr<AlgResourceCtxSerializable>&, const OpParam&) | ||
| 32 | +{ | ||
| 33 | + return HCCL_E_NOT_SUPPORT; | ||
| 34 | +} | ||
| 35 | +} // namespace mc2_ops_hccl | ||
| 36 | + | ||
| 28 | using namespace mc2_ops_hccl; | 37 | using namespace mc2_ops_hccl; |
| 29 | 38 | ||
| 30 | namespace { | 39 | namespace { |
| @@ -17,6 +17,7 @@ | |||
| 17 | #include "kfc_server_protocol.h" | 17 | #include "kfc_server_protocol.h" |
| 18 | 18 | ||
| 19 | #include <limits> | 19 | #include <limits> |
| 20 | +#include <memory> | ||
| 20 | #include <vector> | 21 | #include <vector> |
| 21 | 22 | ||
| 22 | namespace HcclSim { | 23 | namespace HcclSim { |
| @@ -33,6 +34,7 @@ constexpr uint32_t KFC_PARAMETER_WORDS = KFC_CKE_WORD_OFFSET + 2 * KFC_CKE_REGIO | |||
| 33 | constexpr uint64_t SOURCE_BASE_OFFSET = 7; | 34 | constexpr uint64_t SOURCE_BASE_OFFSET = 7; |
| 34 | constexpr uint64_t DESTINATION_BASE_OFFSET = 11; | 35 | constexpr uint64_t DESTINATION_BASE_OFFSET = 11; |
| 35 | constexpr uint64_t GUARD_SIZE = 32; | 36 | constexpr uint64_t GUARD_SIZE = 32; |
| 37 | +constexpr uint64_t KFC_OP_ID = 1U; | ||
| 36 | 38 | ||
| 37 | struct AllGatherKfcServerConfig { | 39 | struct AllGatherKfcServerConfig { |
| 38 | mc2_ops_hccl::CcuKernelArgKfcServer kernelArg; | 40 | mc2_ops_hccl::CcuKernelArgKfcServer kernelArg; |
| @@ -49,6 +51,9 @@ void* ConvertAllGatherKfcServerArg(const void* productArg, uint32_t argNum) | |||
| 49 | } | 51 | } |
| 50 | auto* config = new AllGatherKfcServerConfig(); | 52 | auto* config = new AllGatherKfcServerConfig(); |
| 51 | config->kernelArg = *source; | 53 | config->kernelArg = *source; |
| 54 | + config->kernelArg.opId = KFC_OP_ID; | ||
| 55 | + config->kernelArg.tilingArgs.clear(); | ||
| 56 | + config->kernelArg.tilingArgs.push_back(std::make_shared<mc2_ops_hccl::CcuKernelArgKfcServer>(config->kernelArg)); | ||
| 52 | return config; | 57 | return config; |
| 53 | } | 58 | } |
| 54 | 59 | ||
| @@ -90,7 +95,7 @@ void FillKfcQueue(RankMemory& memory, uint32_t rank, uint64_t sliceSize, uint64_ | |||
| 90 | } | 95 | } |
| 91 | 96 | ||
| 92 | // Keep this payload in lockstep with CcuTempKfcAllGatherMesh1DMem2Mem::KernelRun. | 97 | // Keep this payload in lockstep with CcuTempKfcAllGatherMesh1DMem2Mem::KernelRun. |
| 93 | - memory.parameter[HcclKfcProtocol::KFC_CONCURRENT_AG_OP_ID] = 1U; | 98 | + memory.parameter[HcclKfcProtocol::KFC_CONCURRENT_AG_OP_ID] = KFC_OP_ID; |
| 94 | memory.parameter[HcclKfcProtocol::KFC_CONCURRENT_AG_MESH_INPUT] = inputAddress; | 99 | memory.parameter[HcclKfcProtocol::KFC_CONCURRENT_AG_MESH_INPUT] = inputAddress; |
| 95 | memory.parameter[HcclKfcProtocol::KFC_CONCURRENT_AG_MESH_OUTPUT] = outputAddress; | 100 | memory.parameter[HcclKfcProtocol::KFC_CONCURRENT_AG_MESH_OUTPUT] = outputAddress; |
| 96 | memory.parameter[HcclKfcProtocol::KFC_CONCURRENT_AG_MESH_OUTPUT_OFFSET] = | 101 | memory.parameter[HcclKfcProtocol::KFC_CONCURRENT_AG_MESH_OUTPUT_OFFSET] = |
Mtests/api/adv_api/hccl/cc/st/algorithm/testcase/mc2_ccu/all_gather/parallel_migration_testcase.cpp+178-1
| @@ -13,9 +13,12 @@ | |||
| 13 | #include "ccu_temp_kfc_all_gather_nhr_1D_multi_jetty_mem2mem.h" | 13 | #include "ccu_temp_kfc_all_gather_nhr_1D_multi_jetty_mem2mem.h" |
| 14 | #include "sim_world.h" | 14 | #include "sim_world.h" |
| 15 | #include "acl/acl_rt.h" | 15 | #include "acl/acl_rt.h" |
| 16 | +#include "op_common.h" | ||
| 17 | +#include <cstring> | ||
| 16 | 18 | ||
| 17 | #include <algorithm> | 19 | #include <algorithm> |
| 18 | #include <functional> | 20 | #include <functional> |
| 21 | +#include <memory> | ||
| 19 | #include <numeric> | 22 | #include <numeric> |
| 20 | 23 | ||
| 21 | namespace HcclSim { | 24 | namespace HcclSim { |
| @@ -67,6 +70,7 @@ protected: | |||
| 67 | // 覆盖双 mission 的真实并发、GM 可见性或硬件资源容量。 | 70 | // 覆盖双 mission 的真实并发、GM 可见性或硬件资源容量。 |
| 68 | void VerifyMission(uint32_t meshSize, uint32_t nhrSize, uint64_t count, uint64_t elementSize, bool mesh) | 71 | void VerifyMission(uint32_t meshSize, uint32_t nhrSize, uint64_t count, uint64_t elementSize, bool mesh) |
| 69 | { | 72 | { |
| 73 | + constexpr uint64_t opId = 1U; | ||
| 70 | const uint32_t ranks = meshSize * nhrSize; | 74 | const uint32_t ranks = meshSize * nhrSize; |
| 71 | const uint64_t bytes = count * elementSize; | 75 | const uint64_t bytes = count * elementSize; |
| 72 | const uint64_t part0 = count / 2 * elementSize; | 76 | const uint64_t part0 = count / 2 * elementSize; |
| @@ -133,7 +137,7 @@ protected: | |||
| 133 | } | 137 | } |
| 134 | for (uint32_t entry = 0; entry < 2; ++entry) { | 138 | for (uint32_t entry = 0; entry < 2; ++entry) { |
| 135 | auto* p = memory.parameter.data() + entry * QUEUE_WORDS; | 139 | auto* p = memory.parameter.data() + entry * QUEUE_WORDS; |
| 136 | - p[KFC_PARALLEL_AG_OP_ID] = 1; | 140 | + p[KFC_PARALLEL_AG_OP_ID] = opId; |
| 137 | p[KFC_PARALLEL_AG_INPUT] = memory.InputAddress() + GUARD + entry * bytes; | 141 | p[KFC_PARALLEL_AG_INPUT] = memory.InputAddress() + GUARD + entry * bytes; |
| 138 | p[KFC_PARALLEL_AG_OUTPUT] = memory.OutputAddress() + GUARD + entry * bytes; | 142 | p[KFC_PARALLEL_AG_OUTPUT] = memory.OutputAddress() + GUARD + entry * bytes; |
| 139 | p[KFC_PARALLEL_AG_TOTAL_SIZE] = bytes; | 143 | p[KFC_PARALLEL_AG_TOTAL_SIZE] = bytes; |
| @@ -166,6 +170,7 @@ protected: | |||
| 166 | } | 170 | } |
| 167 | 171 | ||
| 168 | CcuKernelArgKfcServer arg; | 172 | CcuKernelArgKfcServer arg; |
| 173 | + arg.opId = opId; | ||
| 169 | arg.algSubType = mc2_ops_hccl::KFC_PARALLEL_ALL_GATHER_SUB_TYPE; | 174 | arg.algSubType = mc2_ops_hccl::KFC_PARALLEL_ALL_GATHER_SUB_TYPE; |
| 170 | auto parallel = std::make_shared<mc2_ops_hccl::KfcParallelAllGatherArg>(); | 175 | auto parallel = std::make_shared<mc2_ops_hccl::KfcParallelAllGatherArg>(); |
| 171 | arg.algArg = parallel; | 176 | arg.algArg = parallel; |
| @@ -191,6 +196,7 @@ protected: | |||
| 191 | ASSERT_LE(channels.size(), sizeof(arg.channels) / sizeof(arg.channels[0])); | 196 | ASSERT_LE(channels.size(), sizeof(arg.channels) / sizeof(arg.channels[0])); |
| 192 | std::copy(channels.begin(), channels.end(), arg.channels); | 197 | std::copy(channels.begin(), channels.end(), arg.channels); |
| 193 | arg.channelCount = channels.size(); | 198 | arg.channelCount = channels.size(); |
| 199 | + arg.tilingArgs.push_back(std::make_shared<CcuKernelArgKfcServer>(arg)); | ||
| 194 | auto& registry = RegisterManager::Global(); | 200 | auto& registry = RegisterManager::Global(); |
| 195 | // Register 在调用线程同步执行 kernel lambda,GetCcuVersion() 经 | 201 | // Register 在调用线程同步执行 kernel lambda,GetCcuVersion() 经 |
| 196 | // thread_local 的 curr_dev_id 查 SimNpu,须先绑定当前 rank 的设备 | 202 | // thread_local 的 curr_dev_id 查 SimNpu,须先绑定当前 rank 的设备 |
| @@ -248,6 +254,177 @@ TEST_F(ParallelAllGatherMigrationTest, NonPowerOfTwoNhr) | |||
| 248 | VerifyMission(4, 3, 67, 1, false); | 254 | VerifyMission(4, 3, 67, 1, false); |
| 249 | } | 255 | } |
| 250 | 256 | ||
| 257 | +TEST_F(ParallelAllGatherMigrationTest, SharedQueueSelectsOpIdsAndDifferentSubgraphs) | ||
| 258 | +{ | ||
| 259 | + constexpr uint32_t ranks = 2; | ||
| 260 | + constexpr uint32_t count = 16; | ||
| 261 | + constexpr uint64_t bytes = count * sizeof(int32_t); | ||
| 262 | + constexpr uint32_t signalBase = mc2_ops_hccl::CCU_TASK_NUM_MAX * QUEUE_WORDS; | ||
| 263 | + constexpr uint32_t scratchBase = signalBase + 4 * CKE_REGION; | ||
| 264 | + struct SimGuard { | ||
| 265 | + ~SimGuard() { HcclSim::SimWorld::Global()->Deinit(); } | ||
| 266 | + } guard; | ||
| 267 | + SuperPodMeta pod{ServerMeta(ranks)}; | ||
| 268 | + std::iota(pod[0].begin(), pod[0].end(), 0U); | ||
| 269 | + HcclSim::SimWorld::Global()->Init(TopoMeta{pod}, DevType::DEV_TYPE_950); | ||
| 270 | + std::vector<RankMemory> memories(ranks); | ||
| 271 | + std::vector<RankLaunch> launches(ranks); | ||
| 272 | + for (uint32_t rank = 0; rank < ranks; ++rank) { | ||
| 273 | + auto& memory = memories[rank]; | ||
| 274 | + memory.input.assign(GUARD + bytes + GUARD, 0x5a); | ||
| 275 | + memory.output.assign(GUARD + 3 * bytes + GUARD, 0xa5); | ||
| 276 | + memory.parameter.assign(scratchBase + bytes / sizeof(uint64_t), 0); | ||
| 277 | + for (uint32_t i = 0; i < count; ++i) { | ||
| 278 | + const int32_t value = (rank + 1) * 10 + i; | ||
| 279 | + std::memcpy(memory.input.data() + GUARD + i * sizeof(value), &value, sizeof(value)); | ||
| 280 | + } | ||
| 281 | + std::vector<ChannelHandle> channels{MakeChannel(rank, 1U - rank)}; | ||
| 282 | + CcuKernelArgKfcServer server; | ||
| 283 | + for (uint32_t i = 0; i < 2; ++i) { | ||
| 284 | + auto arg = std::make_shared<CcuKernelArgKfcServer>(); | ||
| 285 | + arg->rankSize = ranks; | ||
| 286 | + arg->rankId = rank; | ||
| 287 | + arg->channels[0] = channels[0]; | ||
| 288 | + arg->channelCount = channels.size(); | ||
| 289 | + arg->opParam.opType = i == 1 ? HCCL_CMD_ALLGATHER : HCCL_CMD_ALLREDUCE; | ||
| 290 | + arg->opParam.DataDes.dataType = HCCL_DATA_TYPE_INT32; | ||
| 291 | + arg->opParam.DataDes.outputType = HCCL_DATA_TYPE_INT32; | ||
| 292 | + arg->opParam.reduceType = i == 0 ? HCCL_REDUCE_SUM : HCCL_REDUCE_MAX; | ||
| 293 | + constexpr uint32_t dataTypeShift = 8U; | ||
| 294 | + constexpr uint32_t outputTypeShift = 24U; | ||
| 295 | + arg->opId = static_cast<uint64_t>(arg->opParam.opType) | | ||
| 296 | + (static_cast<uint64_t>(HCCL_DATA_TYPE_INT32) << dataTypeShift) | | ||
| 297 | + (static_cast<uint64_t>(HCCL_DATA_TYPE_INT32) << outputTypeShift); | ||
| 298 | + server.tilingArgs.push_back(arg); | ||
| 299 | + } | ||
| 300 | + // AllGather -> AllReduce differs from host registration order. | ||
| 301 | + for (uint32_t entry = 0; entry < 2; ++entry) { | ||
| 302 | + auto* frame = memory.parameter.data() + entry * QUEUE_WORDS; | ||
| 303 | + constexpr uint32_t dataTypeShift = 8U; | ||
| 304 | + constexpr uint32_t outputTypeShift = 24U; | ||
| 305 | + frame[0] = static_cast<uint64_t>(entry == 0 ? HCCL_CMD_ALLGATHER : HCCL_CMD_ALLREDUCE) | | ||
| 306 | + (static_cast<uint64_t>(HCCL_DATA_TYPE_INT32) << dataTypeShift) | | ||
| 307 | + (static_cast<uint64_t>(HCCL_DATA_TYPE_INT32) << outputTypeShift); | ||
| 308 | + frame[1] = memory.InputAddress() + GUARD; | ||
| 309 | + frame[2] = memory.OutputAddress() + GUARD + entry * 2 * bytes; | ||
| 310 | + mc2_ops_hccl::LoopGroupConfig config{}; | ||
| 311 | + config.msInterleave = mc2_ops_hccl::CCU_MS_INTERLEAVE; | ||
| 312 | + config.loopCount = | ||
| 313 | + entry == 0 ? mc2_ops_hccl::CCU_MS_LOCAL_COPY_LOOP_COUNT : mc2_ops_hccl::CCU_M2M_LOCAL_COPY_LOOP_COUNT; | ||
| 314 | + config.memSlice = mc2_ops_hccl::CCU_MS_SIZE * (entry == 0 ? mc2_ops_hccl::LOCAL_COPY_MS_PER_LOOP : 1U); | ||
| 315 | + const auto go = mc2_ops_hccl::CalGoSize(entry == 0 ? bytes : bytes / ranks, config); | ||
| 316 | + if (entry == 0) { | ||
| 317 | + frame[3] = rank * bytes; | ||
| 318 | + frame[4] = bytes; | ||
| 319 | + std::copy(go.begin(), go.end(), frame + 5); | ||
| 320 | + frame[10] = UINT64_MAX - 1; | ||
| 321 | + frame[13] = bytes; | ||
| 322 | + } else { | ||
| 323 | + frame[3] = memory.ParameterAddress() + scratchBase * sizeof(uint64_t); | ||
| 324 | + frame[6] = frame[7] = frame[8] = bytes / ranks; | ||
| 325 | + frame[9] = rank * bytes / ranks; | ||
| 326 | + std::copy(go.begin(), go.end(), frame + 11); | ||
| 327 | + frame[15] = frame[16] = bytes / ranks; | ||
| 328 | + frame[17] = UINT64_MAX - 1; | ||
| 329 | + std::copy(go.begin(), go.end(), frame + 18); | ||
| 330 | + std::copy(go.begin(), go.end(), frame + 22); | ||
| 331 | + } | ||
| 332 | + memory.parameter[signalBase + entry] = 1; | ||
| 333 | + } | ||
| 334 | + memory.parameter[2 * QUEUE_WORDS] = UINT64_MAX; | ||
| 335 | + memory.parameter[signalBase + 2] = 1; | ||
| 336 | + ASSERT_EQ(aclrtSetDevice(rank), ACL_SUCCESS); | ||
| 337 | + auto& registry = RegisterManager::Global(); | ||
| 338 | + ASSERT_EQ(registry.RegisterStart(rank + 1), Result::SUCCESS); | ||
| 339 | + KernelHandle handle = 0; | ||
| 340 | + ASSERT_EQ( | ||
| 341 | + registry.Register( | ||
| 342 | + rank + 1, "shared-kfc", | ||
| 343 | + [&](void*) { | ||
| 344 | + CompilerContext::Current().ConfigureProgram(rank, ranks, channels); | ||
| 345 | + return mc2_ops_hccl::CcuKfcServerKernel(&server) == CCU_SUCCESS ? Result::SUCCESS : | ||
| 346 | + Result::CONTRACT_ERROR; | ||
| 347 | + }, | ||
| 348 | + nullptr, handle), | ||
| 349 | + Result::SUCCESS); | ||
| 350 | + ASSERT_EQ(registry.RegisterEnd(rank + 1), Result::SUCCESS); | ||
| 351 | + launches[rank] = { | ||
| 352 | + handle, | ||
| 353 | + {memory.ParameterAddress(), memory.ParameterAddress() + signalBase * sizeof(uint64_t), 1, 1, 0, | ||
| 354 | + 0x1000U + rank}, | ||
| 355 | + &memory}; | ||
| 356 | + } | ||
| 357 | + RuntimeWorld runtime; | ||
| 358 | + ASSERT_EQ(runtime.Launch(launches), Result::SUCCESS) << runtime.LastError(); | ||
| 359 | + for (const auto& memory : memories) { | ||
| 360 | + for (uint32_t i = 0; i < 3 * count; ++i) { | ||
| 361 | + int32_t actual; | ||
| 362 | + std::memcpy(&actual, memory.output.data() + GUARD + i * sizeof(actual), sizeof(actual)); | ||
| 363 | + const int32_t expected = i < count ? 10 + i : i < 2 * count ? 20 + i - count : 30 + 2 * (i - 2 * count); | ||
| 364 | + EXPECT_EQ(actual, expected) << "element " << i; | ||
| 365 | + } | ||
| 366 | + EXPECT_TRUE(std::all_of( | ||
| 367 | + memory.output.begin(), memory.output.begin() + GUARD, [](uint8_t value) { return value == 0xa5; })); | ||
| 368 | + EXPECT_TRUE( | ||
| 369 | + std::all_of(memory.output.end() - GUARD, memory.output.end(), [](uint8_t value) { return value == 0xa5; })); | ||
| 370 | + for (uint32_t entry = 0; entry < 2; ++entry) { | ||
| 371 | + EXPECT_EQ(memory.parameter[signalBase + CKE_REGION + entry], 1U); | ||
| 372 | + } | ||
| 373 | + EXPECT_EQ(memory.parameter[signalBase + CKE_REGION + 2], 0U); | ||
| 374 | + } | ||
| 375 | +} | ||
| 376 | + | ||
| 377 | +TEST_F(ParallelAllGatherMigrationTest, BuildPreservesPerTilingResourcesOnSameDie) | ||
| 378 | +{ | ||
| 379 | + mc2_ops_hccl::OpParam param; | ||
| 380 | + param.isMultiTiling = true; | ||
| 381 | + mc2_ops_hccl::AlgResourceRequest request; | ||
| 382 | + auto resources = std::make_unique<mc2_ops_hccl::AlgResourceCtxSerializable>(); | ||
| 383 | + resources->kfcServerArgSize = 6; | ||
| 384 | + resources->kfcServerArgs = {0x1000, 0x2000, 1, 1, 0, 0x3000}; | ||
| 385 | + constexpr uint64_t opIdBase = 0x1000U; | ||
| 386 | + // Three single-mission tilings share die 1 and one persistent server. | ||
| 387 | + for (uint32_t i = 0; i < 3; ++i) { | ||
| 388 | + mc2_ops_hccl::CcuKernelInfo info{}; | ||
| 389 | + std::strcpy(info.kernelFuncName, "CcuKernelKfcServer"); | ||
| 390 | + auto arg = std::make_shared<CcuKernelArgKfcServer>(); | ||
| 391 | + arg->channels[0] = 100 + i; | ||
| 392 | + arg->channelCount = 1; | ||
| 393 | + arg->opParam.opType = i == 0 ? HCCL_CMD_ALLREDUCE : (i == 1 ? HCCL_CMD_ALLGATHER : HCCL_CMD_REDUCE_SCATTER); | ||
| 394 | + arg->opParam.reduceType = HCCL_REDUCE_MAX; | ||
| 395 | + arg->opId = opIdBase + i; | ||
| 396 | + info.dieId = 1; | ||
| 397 | + info.setKernelArg(arg); | ||
| 398 | + request.ccuKernelInfos.push_back(info); | ||
| 399 | + } | ||
| 400 | + auto crossDieRequest = request; | ||
| 401 | + crossDieRequest.ccuKernelInfos.back().dieId = 0; | ||
| 402 | + ASSERT_EQ(mc2_ops_hccl::BuildKfcServer(request, resources, param), HCCL_SUCCESS); | ||
| 403 | + ASSERT_EQ(request.ccuKernelInfos.size(), 1U); | ||
| 404 | + EXPECT_EQ(request.ccuKernelInfos[0].dieId, 1U); | ||
| 405 | + EXPECT_EQ(request.ccuKernelNum, std::vector<uint32_t>({1U})); | ||
| 406 | + EXPECT_EQ(request.slaveThreadNum, 0U); | ||
| 407 | + EXPECT_TRUE(request.notifyNumPerThread.empty()); | ||
| 408 | + EXPECT_TRUE(resources->notifyNumPerThread.empty()); | ||
| 409 | + EXPECT_EQ(resources->kfcServerArgs, std::vector<uint64_t>({0x1000, 0x2000, 1, 1, 0, 0x3000})); | ||
| 410 | + const auto* first = static_cast<const CcuKernelArgKfcServer*>(request.ccuKernelInfos[0].kernelArg); | ||
| 411 | + EXPECT_STREQ(request.ccuKernelInfos[0].kernelFuncName, "CcuKernelKfcServer"); | ||
| 412 | + EXPECT_EQ(first->hostMissionIndex, 0U); | ||
| 413 | + ASSERT_EQ(first->tilingArgs.size(), 3U); | ||
| 414 | + ASSERT_NE(first->tilingArgs[0], nullptr); | ||
| 415 | + EXPECT_EQ(first->tilingArgs[0]->channels[0], 100U); | ||
| 416 | + EXPECT_EQ(first->tilingArgs[0]->opParam.reduceType, HCCL_REDUCE_MAX); | ||
| 417 | + EXPECT_EQ(first->tilingArgs[0]->opId, opIdBase); | ||
| 418 | + ASSERT_NE(first->tilingArgs[1], nullptr); | ||
| 419 | + EXPECT_EQ(first->tilingArgs[1]->channels[0], 101U); | ||
| 420 | + EXPECT_EQ(first->tilingArgs[1]->opId, opIdBase + 1U); | ||
| 421 | + ASSERT_NE(first->tilingArgs[2], nullptr); | ||
| 422 | + EXPECT_EQ(first->tilingArgs[2]->channels[0], 102U); | ||
| 423 | + EXPECT_EQ(first->tilingArgs[2]->opId, opIdBase + 2U); | ||
| 424 | + EXPECT_EQ(first->tilingArgs[2]->hostMissionIndex, 0U); | ||
| 425 | + EXPECT_EQ(mc2_ops_hccl::BuildKfcServer(crossDieRequest, resources, param), HCCL_E_NOT_SUPPORT); | ||
| 426 | +} | ||
| 427 | + | ||
| 251 | TEST_F(ParallelAllGatherMigrationTest, NhrRankBeyondEventMaskWidth) { VerifyMission(2, 17, 9, 1, false); } | 428 | TEST_F(ParallelAllGatherMigrationTest, NhrRankBeyondEventMaskWidth) { VerifyMission(2, 17, 9, 1, false); } |
| 252 | 429 | ||
| 253 | TEST_F(ParallelAllGatherMigrationTest, EmptyFirstHalf) | 430 | TEST_F(ParallelAllGatherMigrationTest, EmptyFirstHalf) |
| @@ -13,6 +13,7 @@ | |||
| 13 | 13 | ||
| 14 | #include <algorithm> | 14 | #include <algorithm> |
| 15 | #include <cstring> | 15 | #include <cstring> |
| 16 | +#include <memory> | ||
| 16 | 17 | ||
| 17 | namespace HcclSim { | 18 | namespace HcclSim { |
| 18 | namespace CcuSt { | 19 | namespace CcuSt { |
| @@ -37,6 +38,7 @@ protected: | |||
| 37 | template <typename T> | 38 | template <typename T> |
| 38 | void Verify(HcclDataType type, HcclReduceOp op, uint64_t count, bool paddedStride) | 39 | void Verify(HcclDataType type, HcclReduceOp op, uint64_t count, bool paddedStride) |
| 39 | { | 40 | { |
| 41 | + constexpr uint64_t opId = 1U; | ||
| 40 | const uint64_t bytes = count * sizeof(T); | 42 | const uint64_t bytes = count * sizeof(T); |
| 41 | const uint64_t stride = bytes + (paddedStride ? 128 : 0); | 43 | const uint64_t stride = bytes + (paddedStride ? 128 : 0); |
| 42 | const uint64_t requestSpan = 2 * stride + GUARD; | 44 | const uint64_t requestSpan = 2 * stride + GUARD; |
| @@ -81,7 +83,7 @@ protected: | |||
| 81 | std::fill_n(memory.input.data() + inBase + rank * stride, bytes, 0x7f); | 83 | std::fill_n(memory.input.data() + inBase + rank * stride, bytes, 0x7f); |
| 82 | } | 84 | } |
| 83 | auto* p = memory.parameter.data() + request * QUEUE_WORDS; | 85 | auto* p = memory.parameter.data() + request * QUEUE_WORDS; |
| 84 | - p[0] = 1; | 86 | + p[0] = opId; |
| 85 | p[1] = memory.InputAddress() + inBase; | 87 | p[1] = memory.InputAddress() + inBase; |
| 86 | p[2] = memory.OutputAddress() + outBase; | 88 | p[2] = memory.OutputAddress() + outBase; |
| 87 | p[4] = rank * stride; | 89 | p[4] = rank * stride; |
| @@ -95,6 +97,7 @@ protected: | |||
| 95 | memory.parameter[CKE_WORD + REQUESTS] = 1; | 97 | memory.parameter[CKE_WORD + REQUESTS] = 1; |
| 96 | 98 | ||
| 97 | mc2_ops_hccl::CcuKernelArgKfcServer arg; | 99 | mc2_ops_hccl::CcuKernelArgKfcServer arg; |
| 100 | + arg.opId = opId; | ||
| 98 | arg.opParam.opType = HCCL_CMD_REDUCE_SCATTER; | 101 | arg.opParam.opType = HCCL_CMD_REDUCE_SCATTER; |
| 99 | arg.opParam.DataDes.dataType = type; | 102 | arg.opParam.DataDes.dataType = type; |
| 100 | arg.opParam.reduceType = op; | 103 | arg.opParam.reduceType = op; |
| @@ -103,6 +106,7 @@ protected: | |||
| 103 | arg.rankId = rank; | 106 | arg.rankId = rank; |
| 104 | arg.channelCount = 1; | 107 | arg.channelCount = 1; |
| 105 | arg.channels[0] = MakeChannel(rank, rank ^ 1U); | 108 | arg.channels[0] = MakeChannel(rank, rank ^ 1U); |
| 109 | + arg.tilingArgs.push_back(std::make_shared<mc2_ops_hccl::CcuKernelArgKfcServer>(arg)); | ||
| 106 | std::vector<ChannelHandle> channels{arg.channels[0]}; | 110 | std::vector<ChannelHandle> channels{arg.channels[0]}; |
| 107 | auto& registry = RegisterManager::Global(); | 111 | auto& registry = RegisterManager::Global(); |
| 108 | ASSERT_EQ(registry.RegisterStart(rank + 1), Result::SUCCESS); | 112 | ASSERT_EQ(registry.RegisterStart(rank + 1), Result::SUCCESS); |
| @@ -178,7 +178,15 @@ KernelHandle CcuStFixture::RegisterKernelForRank( | |||
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | void* resCtxOut = nullptr; | 180 | void* resCtxOut = nullptr; |
| 181 | - if (GetCcuOpParamResCtx(comm, algName, opParam, topoInfo.get(), resCtx, &resCtxOut) != HCCL_SUCCESS) { | 181 | + auto executor = CollAlgExecRegistryV2::Instance().GetAlgExec(opParam.opType, algName); |
| 182 | + AlgHierarchyInfoForAllLevel hierarchy; | ||
| 183 | + AlgResourceRequest request; | ||
| 184 | + if (executor == nullptr || | ||
| 185 | + CalcAlgResourceRequest(comm, opParam, executor, topoInfo.get(), hierarchy, request) != HCCL_SUCCESS) { | ||
| 186 | + CleanupHostEnv(comm); | ||
| 187 | + return 0; | ||
| 188 | + } | ||
| 189 | + if (GetCcuOpParamResCtx(comm, algName, opParam, topoInfo.get(), resCtx, &resCtxOut, &request) != HCCL_SUCCESS) { | ||
| 182 | CleanupHostEnv(comm); | 190 | CleanupHostEnv(comm); |
| 183 | return 0; | 191 | return 0; |
| 184 | } | 192 | } |
| @@ -16,6 +16,7 @@ | |||
| 16 | #include "coll_alg_v2_exec_registry.h" | 16 | #include "coll_alg_v2_exec_registry.h" |
| 17 | #include "executor_base.h" | 17 | #include "executor_base.h" |
| 18 | #include "executor_v2_base.h" | 18 | #include "executor_v2_base.h" |
| 19 | +#include "ops/kfc_server/template/ccu/kernel/ccu_kernel_kfc_server.h" | ||
| 19 | #include "alg_env_config.h" | 20 | #include "alg_env_config.h" |
| 20 | #include "param_check.h" | 21 | #include "param_check.h" |
| 21 | #include "sal.h" | 22 | #include "sal.h" |
| @@ -104,7 +105,8 @@ AlgAttrs InsCollAlgBase::GetAlgoMeta(const std::string& algName) const | |||
| 104 | 105 | ||
| 105 | class MockInsCollAlgBase : public InsCollAlgBase { | 106 | class MockInsCollAlgBase : public InsCollAlgBase { |
| 106 | public: | 107 | public: |
| 107 | - MockInsCollAlgBase() = default; | 108 | + explicit MockInsCollAlgBase(bool server = false) : server_(server) {} |
| 109 | + bool server_; | ||
| 108 | ~MockInsCollAlgBase() override = default; | 110 | ~MockInsCollAlgBase() override = default; |
| 109 | 111 | ||
| 110 | std::string Describe() const override { return "MockInsCollAlgBase"; } | 112 | std::string Describe() const override { return "MockInsCollAlgBase"; } |
| @@ -121,6 +123,14 @@ public: | |||
| 121 | HcclComm comm, const OpParam& param, const TopoInfoWithNetLayerDetails* topoInfo, | 123 | HcclComm comm, const OpParam& param, const TopoInfoWithNetLayerDetails* topoInfo, |
| 122 | const AlgHierarchyInfoForAllLevel& algHierarchyInfo, AlgResourceRequest& resourceRequest) override | 124 | const AlgHierarchyInfoForAllLevel& algHierarchyInfo, AlgResourceRequest& resourceRequest) override |
| 123 | { | 125 | { |
| 126 | + if (!server_) { | ||
| 127 | + resourceRequest.ccuKernelInfos.emplace_back(); | ||
| 128 | + resourceRequest.ccuKernelNum.push_back(1U); | ||
| 129 | + } else { | ||
| 130 | + auto arg = std::make_shared<CcuKernelArgKfcServer>(); | ||
| 131 | + arg->opParam = param; | ||
| 132 | + resourceRequest.ccuKernelInfos.back().setKernelArg(arg); | ||
| 133 | + } | ||
| 124 | return HCCL_SUCCESS; | 134 | return HCCL_SUCCESS; |
| 125 | } | 135 | } |
| 126 | 136 | ||
| @@ -385,12 +395,27 @@ std::unique_ptr<InsCollAlgBase> CollAlgExecRegistryV2::GetAlgExec(HcclCMDType op | |||
| 385 | if (g_stubCcuAlgExecNull && (g_stubCcuAlgExecNullName.empty() || algTag == g_stubCcuAlgExecNullName)) { | 395 | if (g_stubCcuAlgExecNull && (g_stubCcuAlgExecNullName.empty() || algTag == g_stubCcuAlgExecNullName)) { |
| 386 | return nullptr; | 396 | return nullptr; |
| 387 | } | 397 | } |
| 388 | - return std::make_unique<MockInsCollAlgBase>(); | 398 | + return std::make_unique<MockInsCollAlgBase>(opType == HcclCMDType::HCCL_CMD_KFC_SERVER); |
| 399 | +} | ||
| 400 | + | ||
| 401 | +HcclResult CalcAlgResourceRequest( | ||
| 402 | + HcclComm comm, OpParam& param, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, | ||
| 403 | + AlgHierarchyInfoForAllLevel& algHierarchyInfo, AlgResourceRequest& resRequest) | ||
| 404 | +{ | ||
| 405 | + CHK_RET(executor->CalcAlgHierarchyInfo(comm, topoInfo, algHierarchyInfo)); | ||
| 406 | + CHK_RET(executor->CalcRes(comm, param, topoInfo, algHierarchyInfo, resRequest)); | ||
| 407 | + if (param.isKfc && param.engine == COMM_ENGINE_CCU) { | ||
| 408 | + auto server = CollAlgExecRegistryV2::Instance().GetAlgExec(HcclCMDType::HCCL_CMD_KFC_SERVER, "CcuKfcServer"); | ||
| 409 | + CHK_PTR_NULL(server); | ||
| 410 | + CHK_RET(server->CalcRes(comm, param, topoInfo, algHierarchyInfo, resRequest)); | ||
| 411 | + } | ||
| 412 | + return HCCL_SUCCESS; | ||
| 389 | } | 413 | } |
| 390 | 414 | ||
| 391 | HcclResult HcclGetAlgRes( | 415 | HcclResult HcclGetAlgRes( |
| 392 | HcclComm comm, OpParam& param, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, | 416 | HcclComm comm, OpParam& param, std::unique_ptr<InsCollAlgBase>& executor, TopoInfoWithNetLayerDetails* topoInfo, |
| 393 | - std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, void** resCtxDevice, bool& isResourceReused) | 417 | + std::unique_ptr<AlgResourceCtxSerializable>& resCtxHost, void** resCtxDevice, bool& isResourceReused, |
| 418 | + AlgResourceRequest*, const std::string&) | ||
| 394 | { | 419 | { |
| 395 | if (resCtxDevice == nullptr) { | 420 | if (resCtxDevice == nullptr) { |
| 396 | return HCCL_E_PTR; | 421 | return HCCL_E_PTR; |
| @@ -452,4 +477,16 @@ HcclResult HcclGetAlgRes( | |||
| 452 | 477 | ||
| 453 | return HCCL_SUCCESS; | 478 | return HCCL_SUCCESS; |
| 454 | } | 479 | } |
| 480 | +HcclResult GetAlgResCcu( | ||
| 481 | + HcclComm comm, const OpParam& param, AlgResourceRequest& request, | ||
| 482 | + std::unique_ptr<AlgResourceCtxSerializable>& resources, TopoInfoWithNetLayerDetails* topo, | ||
| 483 | + AlgHierarchyInfoForAllLevel&, void** ctx, uint64_t& size, const std::string&) | ||
| 484 | +{ | ||
| 485 | + OpParam copy = param; | ||
| 486 | + std::unique_ptr<InsCollAlgBase> executor; | ||
| 487 | + bool reused = false; | ||
| 488 | + const HcclResult ret = HcclGetAlgRes(comm, copy, executor, topo, resources, ctx, reused, nullptr, ""); | ||
| 489 | + size = copy.ctxSize; | ||
| 490 | + return ret; | ||
| 491 | +} | ||
| 455 | } // namespace mc2_ops_hccl | 492 | } // namespace mc2_ops_hccl |
| @@ -349,6 +349,7 @@ uint16_t CcuBuf::Id() const { return 0; } | |||
| 349 | namespace mc2_ops_hccl { | 349 | namespace mc2_ops_hccl { |
| 350 | bool g_stubHcommCcuKernelLaunchFail = false; | 350 | bool g_stubHcommCcuKernelLaunchFail = false; |
| 351 | uint32_t g_stubHcommCcuKernelLaunchCallCount = 0U; | 351 | uint32_t g_stubHcommCcuKernelLaunchCallCount = 0U; |
| 352 | +std::vector<std::vector<uint64_t>> g_stubHcommCcuKernelLaunchArgs; | ||
| 352 | bool g_stubHcommIsSupportCcuV2 = true; | 353 | bool g_stubHcommIsSupportCcuV2 = true; |
| 353 | } // namespace mc2_ops_hccl | 354 | } // namespace mc2_ops_hccl |
| 354 | 355 | ||
| @@ -413,6 +414,8 @@ extern ccu_result asccomm_ccu_kernel_launch( | |||
| 413 | (void)task_args; | 414 | (void)task_args; |
| 414 | (void)arg_num; | 415 | (void)arg_num; |
| 415 | ++mc2_ops_hccl::g_stubHcommCcuKernelLaunchCallCount; | 416 | ++mc2_ops_hccl::g_stubHcommCcuKernelLaunchCallCount; |
| 417 | + const auto* args = static_cast<const uint64_t*>(task_args); | ||
| 418 | + mc2_ops_hccl::g_stubHcommCcuKernelLaunchArgs.emplace_back(args, args + arg_num); | ||
| 416 | if (mc2_ops_hccl::g_stubHcommCcuKernelLaunchFail) { | 419 | if (mc2_ops_hccl::g_stubHcommCcuKernelLaunchFail) { |
| 417 | return ccu_result::CCU_E_INTERNAL; | 420 | return ccu_result::CCU_E_INTERNAL; |
| 418 | } | 421 | } |
| @@ -43,15 +43,13 @@ extern HcclResult g_stubHcomCheckReductionOpResult; | |||
| 43 | extern HcclResult g_stubCalcTopoInfoResult; | 43 | extern HcclResult g_stubCalcTopoInfoResult; |
| 44 | extern bool g_stubHcommCcuKernelLaunchFail; | 44 | extern bool g_stubHcommCcuKernelLaunchFail; |
| 45 | extern uint32_t g_stubHcommCcuKernelLaunchCallCount; | 45 | extern uint32_t g_stubHcommCcuKernelLaunchCallCount; |
| 46 | +extern std::vector<std::vector<uint64_t>> g_stubHcommCcuKernelLaunchArgs; | ||
| 46 | extern std::string g_stubCcuAlgNotRegisteredName; | 47 | extern std::string g_stubCcuAlgNotRegisteredName; |
| 47 | extern bool g_stubHcommIsSupportCcuV2; | 48 | extern bool g_stubHcommIsSupportCcuV2; |
| 48 | } // namespace mc2_ops_hccl | 49 | } // namespace mc2_ops_hccl |
| 49 | 50 | ||
| 50 | // 夹具:本目标不编 executor 文件(-DAICPU_COMPILE 裁掉产品 CCU sidecar 注册行), | 51 | // 夹具:本目标不编 executor 文件(-DAICPU_COMPILE 裁掉产品 CCU sidecar 注册行), |
| 51 | // 按产品现场同款注册供 EXTERNAL 用例使用。 | 52 | // 按产品现场同款注册供 EXTERNAL 用例使用。 |
| 52 | -// (AR, sole[mesh]) 键两条 CCU 候选;闸门 B 全量校验用例 | ||
| 53 | -// (GateBRejectsDriftedExternalCandidate)以按名桩把其中一条打成双名单不过, | ||
| 54 | -// 验证"任一候选未过即整体拒绝"(D8)。 | ||
| 55 | namespace mc2_ops_hccl { | 53 | namespace mc2_ops_hccl { |
| 56 | REGISTER_ALG_META( | 54 | REGISTER_ALG_META( |
| 57 | HcclCMDType::HCCL_CMD_ALLGATHER, CcuSchedAllGatherSoleMesh, AlgEngine::CCU, "sole[mesh]", COND_NONE, FLAG_NONE, 0); | 55 | HcclCMDType::HCCL_CMD_ALLGATHER, CcuSchedAllGatherSoleMesh, AlgEngine::CCU, "sole[mesh]", COND_NONE, FLAG_NONE, 0); |
| @@ -59,8 +57,6 @@ REGISTER_ALG_META( | |||
| 59 | HcclCMDType::HCCL_CMD_ALLGATHER, InsAllGatherMesh1D, AlgEngine::AICPU, "sole[mesh]", COND_NONE, FLAG_NONE, 0); | 57 | HcclCMDType::HCCL_CMD_ALLGATHER, InsAllGatherMesh1D, AlgEngine::AICPU, "sole[mesh]", COND_NONE, FLAG_NONE, 0); |
| 60 | REGISTER_ALG_META( | 58 | REGISTER_ALG_META( |
| 61 | HcclCMDType::HCCL_CMD_ALLREDUCE, CcuSchedAllReduceSoleMesh, AlgEngine::CCU, "sole[mesh]", COND_NONE, FLAG_NONE, 0); | 59 | HcclCMDType::HCCL_CMD_ALLREDUCE, CcuSchedAllReduceSoleMesh, AlgEngine::CCU, "sole[mesh]", COND_NONE, FLAG_NONE, 0); |
| 62 | -REGISTER_ALG_META( | ||
| 63 | - HcclCMDType::HCCL_CMD_ALLREDUCE, CcuSchedAllGatherSoleMesh, AlgEngine::CCU, "sole[mesh]", COND_NONE, FLAG_NONE, 0); | ||
| 64 | REGISTER_ALG_META( | 60 | REGISTER_ALG_META( |
| 65 | HcclCMDType::HCCL_CMD_ALLREDUCE, InsAllReduceMesh1D, AlgEngine::AICPU, "sole[mesh]", COND_NONE, FLAG_NONE, 0); | 61 | HcclCMDType::HCCL_CMD_ALLREDUCE, InsAllReduceMesh1D, AlgEngine::AICPU, "sole[mesh]", COND_NONE, FLAG_NONE, 0); |
| 66 | REGISTER_ALG_META( | 62 | REGISTER_ALG_META( |
| @@ -108,6 +104,7 @@ static void StubCleanup() | |||
| 108 | mc2_ops_hccl::g_stubCcuAlgNotRegisteredName.clear(); | 104 | mc2_ops_hccl::g_stubCcuAlgNotRegisteredName.clear(); |
| 109 | mc2_ops_hccl::g_stubHcommCcuKernelLaunchFail = false; | 105 | mc2_ops_hccl::g_stubHcommCcuKernelLaunchFail = false; |
| 110 | mc2_ops_hccl::g_stubHcommCcuKernelLaunchCallCount = 0U; | 106 | mc2_ops_hccl::g_stubHcommCcuKernelLaunchCallCount = 0U; |
| 107 | + mc2_ops_hccl::g_stubHcommCcuKernelLaunchArgs.clear(); | ||
| 111 | mc2_ops_hccl::g_stubHcommIsSupportCcuV2 = true; | 108 | mc2_ops_hccl::g_stubHcommIsSupportCcuV2 = true; |
| 112 | unsetenv("HCCL_OP_EXPANSION_MODE"); | 109 | unsetenv("HCCL_OP_EXPANSION_MODE"); |
| 113 | } | 110 | } |
| @@ -485,7 +482,7 @@ TEST_F(CcuMc2TestSuite, CcuSelectAlg_ReduceScatterRejectsProd) | |||
| 485 | EXPECT_EQ(RunCcuSelectAlg(comm_, stream_, topoTag, ccTilingList, 1, resCtx), HCCL_E_NOT_SUPPORT); | 482 | EXPECT_EQ(RunCcuSelectAlg(comm_, stream_, topoTag, ccTilingList, 1, resCtx), HCCL_E_NOT_SUPPORT); |
| 486 | } | 483 | } |
| 487 | 484 | ||
| 488 | -TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_RejectsMixedOps) | 485 | +TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_AcceptsMixedOps) |
| 489 | { | 486 | { |
| 490 | Mc2InitTilingInner initTiling{}; | 487 | Mc2InitTilingInner initTiling{}; |
| 491 | initTiling.version = INIT_TILING_CCU_NEW_VERSION; | 488 | initTiling.version = INIT_TILING_CCU_NEW_VERSION; |
| @@ -497,7 +494,10 @@ TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_RejectsMixedOps) | |||
| 497 | allReduce.opType = static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLREDUCE); | 494 | allReduce.opType = static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLREDUCE); |
| 498 | const void* ccTilingList[] = {&allGather, &allReduce}; | 495 | const void* ccTilingList[] = {&allGather, &allReduce}; |
| 499 | 496 | ||
| 500 | - EXPECT_EQ(CheckCcuKfcFlow(&initTiling, ccTilingList, 2U, g_stubRankSize), HCCL_E_NOT_SUPPORT); | 497 | + EXPECT_EQ(CheckCcuKfcFlow(&initTiling, ccTilingList, 2U, g_stubRankSize), HCCL_SUCCESS); |
| 498 | + EXPECT_EQ(CheckCcuKfcFlow(&initTiling, ccTilingList, 1U, g_stubRankSize), HCCL_E_NOT_SUPPORT); | ||
| 499 | + initTiling.mc2HcommCnt = 0U; | ||
| 500 | + EXPECT_EQ(CheckCcuKfcFlow(&initTiling, ccTilingList, 0U, g_stubRankSize), HCCL_E_NOT_SUPPORT); | ||
| 501 | } | 501 | } |
| 502 | 502 | ||
| 503 | TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_AcceptsReduceScatter) | 503 | TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_AcceptsReduceScatter) |
| @@ -514,7 +514,7 @@ TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_AcceptsReduceScatter) | |||
| 514 | EXPECT_EQ(CheckCcuKfcFlow(&initTiling, ccTilingList, 2U, g_stubRankSize), HCCL_SUCCESS); | 514 | EXPECT_EQ(CheckCcuKfcFlow(&initTiling, ccTilingList, 2U, g_stubRankSize), HCCL_SUCCESS); |
| 515 | } | 515 | } |
| 516 | 516 | ||
| 517 | -TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_RejectsAllGatherReduceScatterMix) | 517 | +TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_AcceptsAllGatherReduceScatterMix) |
| 518 | { | 518 | { |
| 519 | Mc2InitTilingInner initTiling{}; | 519 | Mc2InitTilingInner initTiling{}; |
| 520 | initTiling.version = INIT_TILING_CCU_NEW_VERSION; | 520 | initTiling.version = INIT_TILING_CCU_NEW_VERSION; |
| @@ -526,7 +526,7 @@ TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_RejectsAllGatherReduceScatterMix) | |||
| 526 | reduceScatter.opType = static_cast<uint32_t>(HcclCMDType::HCCL_CMD_REDUCE_SCATTER); | 526 | reduceScatter.opType = static_cast<uint32_t>(HcclCMDType::HCCL_CMD_REDUCE_SCATTER); |
| 527 | const void* ccTilingList[] = {&allGather, &reduceScatter}; | 527 | const void* ccTilingList[] = {&allGather, &reduceScatter}; |
| 528 | 528 | ||
| 529 | - EXPECT_EQ(CheckCcuKfcFlow(&initTiling, ccTilingList, 2U, g_stubRankSize), HCCL_E_NOT_SUPPORT); | 529 | + EXPECT_EQ(CheckCcuKfcFlow(&initTiling, ccTilingList, 2U, g_stubRankSize), HCCL_SUCCESS); |
| 530 | } | 530 | } |
| 531 | 531 | ||
| 532 | TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_RejectsPeerOnlyOutsideTp2) | 532 | TEST_F(CcuMc2TestSuite, CheckCcuKfcFlow_RejectsPeerOnlyOutsideTp2) |
| @@ -972,13 +972,53 @@ TEST_F(CcuMc2TestSuite, InitOpParamByTiling_SetsExpansionMode) | |||
| 972 | EXPECT_EQ(ccuOpParam.commOpExpansionMode, HcclOpExpansionMode::HCCL_OP_EXPANSION_CCU_SCHED); | 972 | EXPECT_EQ(ccuOpParam.commOpExpansionMode, HcclOpExpansionMode::HCCL_OP_EXPANSION_CCU_SCHED); |
| 973 | } | 973 | } |
| 974 | 974 | ||
| 975 | -TEST_F(CcuMc2TestSuite, HcclAllocComResourceByTiling_MixedOpsRejected) | 975 | +TEST_F(CcuMc2TestSuite, HcclAllocComResourceByTiling_SingleAndMultiTiling) |
| 976 | { | 976 | { |
| 977 | uint32_t opTypes[] = { | 977 | uint32_t opTypes[] = { |
| 978 | static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLGATHER), static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLREDUCE)}; | 978 | static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLGATHER), static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLREDUCE)}; |
| 979 | - Mc2TilingTestData tiling = BuildMc2Tiling(2, static_cast<uint8_t>(OpExecuteConfig::CCU_SCHED), opTypes, nullptr); | 979 | + const OpParam* singleParam = nullptr; |
| 980 | - void* opResCtx = nullptr; | 980 | + void* singleResCtx = nullptr; |
| 981 | - EXPECT_EQ(HcclAllocComResourceByTiling(comm_, stream_, &tiling, &opResCtx), HCCL_E_ALG_NOT_SUPPORTED); | 981 | + for (uint32_t tilingNum : {1U, 2U}) { |
| 982 | + SCOPED_TRACE(::testing::Message() << "tilingNum=" << tilingNum); | ||
| 983 | + auto tiling = BuildMc2Tiling(tilingNum, static_cast<uint8_t>(OpExecuteConfig::CCU_SCHED), opTypes, nullptr); | ||
| 984 | + for (auto& cc : tiling.ccTiling) { | ||
| 985 | + strcpy(cc.algConfig, "sole[mesh]"); | ||
| 986 | + } | ||
| 987 | + void* opResCtx = nullptr; | ||
| 988 | + const HcclResult ret = HcclAllocComResourceByTiling(comm_, stream_, &tiling, &opResCtx); | ||
| 989 | + if (tilingNum > 1U) { | ||
| 990 | + EXPECT_EQ(ret, HCCL_E_ALG_NOT_SUPPORTED); | ||
| 991 | + EXPECT_EQ(opResCtx, nullptr); | ||
| 992 | + ASSERT_NE(singleParam, nullptr); | ||
| 993 | + EXPECT_EQ(singleParam->resCtx, singleResCtx); | ||
| 994 | + continue; | ||
| 995 | + } | ||
| 996 | + ASSERT_EQ(ret, HCCL_SUCCESS); | ||
| 997 | + ASSERT_NE(opResCtx, nullptr); | ||
| 998 | + const auto& ctx = *static_cast<OpResCtx*>(opResCtx); | ||
| 999 | + EXPECT_EQ(ctx.resCtx, 0U); | ||
| 1000 | + const auto& first = *reinterpret_cast<const OpParam*>(ctx.algInfo[0].opParam); | ||
| 1001 | + singleParam = &first; | ||
| 1002 | + singleResCtx = first.resCtx; | ||
| 1003 | + for (uint32_t i = 0; i < tilingNum; ++i) { | ||
| 1004 | + const auto& param = *reinterpret_cast<const OpParam*>(ctx.algInfo[i].opParam); | ||
| 1005 | + EXPECT_EQ(ctx.algInfo[i].offset, tiling.offset[i]); | ||
| 1006 | + EXPECT_EQ(param.resCtx, first.resCtx); | ||
| 1007 | + std::vector<char> seq( | ||
| 1008 | + static_cast<const char*>(param.resCtx), static_cast<const char*>(param.resCtx) + param.ctxSize); | ||
| 1009 | + AlgResourceCtxSerializable resources; | ||
| 1010 | + resources.DeSerialize(seq); | ||
| 1011 | + EXPECT_EQ(resources.kfcServerArgs[0], ctx.xnAddr); | ||
| 1012 | + EXPECT_EQ(resources.kfcServerArgs[1], ctx.ckeAddr); | ||
| 1013 | + } | ||
| 1014 | + EXPECT_EQ(ctx.res[1], 1000U); | ||
| 1015 | + const uint32_t launches = mc2_ops_hccl::g_stubHcommCcuKernelLaunchCallCount; | ||
| 1016 | + ASSERT_EQ(CcuKernelLaunch(comm_, opResCtx), CCU_SUCCESS); | ||
| 1017 | + EXPECT_EQ(mc2_ops_hccl::g_stubHcommCcuKernelLaunchCallCount, launches + 1U); | ||
| 1018 | + ASSERT_EQ(mc2_ops_hccl::g_stubHcommCcuKernelLaunchArgs.size(), launches + 1U); | ||
| 1019 | + EXPECT_EQ(mc2_ops_hccl::g_stubHcommCcuKernelLaunchArgs.back()[0], ctx.xnAddr); | ||
| 1020 | + EXPECT_EQ(Mc2CcKernelLaunch(stream_, opResCtx, sizeof(OpResCtx)), HCCL_SUCCESS); | ||
| 1021 | + } | ||
| 982 | } | 1022 | } |
| 983 | 1023 | ||
| 984 | TEST_F(CcuMc2TestSuite, HcclAllocComResourceByTiling_NullComm) | 1024 | TEST_F(CcuMc2TestSuite, HcclAllocComResourceByTiling_NullComm) |
| @@ -1071,8 +1111,14 @@ TEST_F(CcuMc2TestSuite, GetCcuOpParamResCtx_AllGatherMesh1D_KfcServerArgs) | |||
| 1071 | ASSERT_FALSE(skipGetRes); | 1111 | ASSERT_FALSE(skipGetRes); |
| 1072 | 1112 | ||
| 1073 | // 3. 调用GetCcuOpParamResCtx | 1113 | // 3. 调用GetCcuOpParamResCtx |
| 1114 | + auto executor = CollAlgExecRegistryV2::Instance().GetAlgExec(opParam.opType, algName); | ||
| 1115 | + ASSERT_NE(executor, nullptr); | ||
| 1116 | + AlgHierarchyInfoForAllLevel hierarchy; | ||
| 1117 | + AlgResourceRequest request; | ||
| 1118 | + ASSERT_EQ(CalcAlgResourceRequest(comm_, opParam, executor, topoInfo.get(), hierarchy, request), HCCL_SUCCESS); | ||
| 1074 | void* resCtxOut = nullptr; | 1119 | void* resCtxOut = nullptr; |
| 1075 | - EXPECT_EQ(GetCcuOpParamResCtx(comm_, algName, opParam, topoInfo.get(), opResCtx, &resCtxOut), HCCL_SUCCESS); | 1120 | + EXPECT_EQ( |
| 1121 | + GetCcuOpParamResCtx(comm_, algName, opParam, topoInfo.get(), opResCtx, &resCtxOut, &request), HCCL_SUCCESS); | ||
| 1076 | EXPECT_NE(resCtxOut, nullptr); | 1122 | EXPECT_NE(resCtxOut, nullptr); |
| 1077 | EXPECT_EQ(opParam.resCtx, resCtxOut); | 1123 | EXPECT_EQ(opParam.resCtx, resCtxOut); |
| 1078 | 1124 | ||
| @@ -1146,7 +1192,13 @@ TEST_F(CcuMc2TestSuite, GetCcuOpParamResCtx_TokenUpdateOnReuse) | |||
| 1146 | ASSERT_FALSE(skipGetRes); | 1192 | ASSERT_FALSE(skipGetRes); |
| 1147 | 1193 | ||
| 1148 | void* resCtxOut1 = nullptr; | 1194 | void* resCtxOut1 = nullptr; |
| 1149 | - EXPECT_EQ(GetCcuOpParamResCtx(comm_, algName, opParam1, topoInfo.get(), opResCtx1, &resCtxOut1), HCCL_SUCCESS); | 1195 | + auto executor1 = CollAlgExecRegistryV2::Instance().GetAlgExec(opParam1.opType, algName); |
| 1196 | + ASSERT_NE(executor1, nullptr); | ||
| 1197 | + AlgHierarchyInfoForAllLevel hierarchy1; | ||
| 1198 | + AlgResourceRequest request1; | ||
| 1199 | + ASSERT_EQ(CalcAlgResourceRequest(comm_, opParam1, executor1, topoInfo.get(), hierarchy1, request1), HCCL_SUCCESS); | ||
| 1200 | + EXPECT_EQ( | ||
| 1201 | + GetCcuOpParamResCtx(comm_, algName, opParam1, topoInfo.get(), opResCtx1, &resCtxOut1, &request1), HCCL_SUCCESS); | ||
| 1150 | EXPECT_NE(resCtxOut1, nullptr); | 1202 | EXPECT_NE(resCtxOut1, nullptr); |
| 1151 | 1203 | ||
| 1152 | // 验证第一次的token | 1204 | // 验证第一次的token |
| @@ -1173,7 +1225,13 @@ TEST_F(CcuMc2TestSuite, GetCcuOpParamResCtx_TokenUpdateOnReuse) | |||
| 1173 | ASSERT_FALSE(skipGetRes); | 1225 | ASSERT_FALSE(skipGetRes); |
| 1174 | 1226 | ||
| 1175 | void* resCtxOut2 = nullptr; | 1227 | void* resCtxOut2 = nullptr; |
| 1176 | - EXPECT_EQ(GetCcuOpParamResCtx(comm_, algName, opParam2, topoInfo.get(), opResCtx2, &resCtxOut2), HCCL_SUCCESS); | 1228 | + auto executor2 = CollAlgExecRegistryV2::Instance().GetAlgExec(opParam2.opType, algName); |
| 1229 | + ASSERT_NE(executor2, nullptr); | ||
| 1230 | + AlgHierarchyInfoForAllLevel hierarchy2; | ||
| 1231 | + AlgResourceRequest request2; | ||
| 1232 | + ASSERT_EQ(CalcAlgResourceRequest(comm_, opParam2, executor2, topoInfo.get(), hierarchy2, request2), HCCL_SUCCESS); | ||
| 1233 | + EXPECT_EQ( | ||
| 1234 | + GetCcuOpParamResCtx(comm_, algName, opParam2, topoInfo.get(), opResCtx2, &resCtxOut2, &request2), HCCL_SUCCESS); | ||
| 1177 | EXPECT_NE(resCtxOut2, nullptr); | 1235 | EXPECT_NE(resCtxOut2, nullptr); |
| 1178 | 1236 | ||
| 1179 | // 验证资源复用(相同的ctx地址) | 1237 | // 验证资源复用(相同的ctx地址) |
| @@ -1301,13 +1359,15 @@ TEST_F(CcuMc2TestSuite, CheckOpResSufficient_AlgNotRegistered) | |||
| 1301 | EXPECT_EQ(ret, HCCL_E_ALG_NOT_SUPPORTED); | 1359 | EXPECT_EQ(ret, HCCL_E_ALG_NOT_SUPPORTED); |
| 1302 | } | 1360 | } |
| 1303 | 1361 | ||
| 1304 | -TEST_F(CcuMc2TestSuite, CheckOpResSufficient_MixedOpsRejected) | 1362 | +TEST_F(CcuMc2TestSuite, CheckOpResSufficient_MixedOps) |
| 1305 | { | 1363 | { |
| 1306 | uint32_t opTypes[] = { | 1364 | uint32_t opTypes[] = { |
| 1307 | static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLGATHER), static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLREDUCE)}; | 1365 | static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLGATHER), static_cast<uint32_t>(HcclCMDType::HCCL_CMD_ALLREDUCE)}; |
| 1308 | Mc2TilingTestData tiling = BuildMc2Tiling(2, static_cast<uint8_t>(OpExecuteConfig::CCU_SCHED), opTypes, nullptr); | 1366 | Mc2TilingTestData tiling = BuildMc2Tiling(2, static_cast<uint8_t>(OpExecuteConfig::CCU_SCHED), opTypes, nullptr); |
| 1309 | 1367 | ||
| 1310 | - // 多算子场景先被CheckCcuAlgorithmsRegistered拒绝(tilingNum>1),不进入逐算子校验 | 1368 | + for (auto& cc : tiling.ccTiling) { |
| 1369 | + strcpy(cc.algConfig, "sole[mesh]"); | ||
| 1370 | + } | ||
| 1311 | EXPECT_EQ(CheckOpResSufficient(comm_, stream_, &tiling), HCCL_E_ALG_NOT_SUPPORTED); | 1371 | EXPECT_EQ(CheckOpResSufficient(comm_, stream_, &tiling), HCCL_E_ALG_NOT_SUPPORTED); |
| 1312 | } | 1372 | } |
| 1313 | 1373 | ||
| @@ -1774,7 +1834,7 @@ TEST_F(CcuMc2TestSuite, Mc2AcquireCcResCtx_PropagatesAlgorithmFailure) | |||
| 1774 | EXPECT_EQ( | 1834 | EXPECT_EQ( |
| 1775 | Mc2AcquireCcResCtx( | 1835 | Mc2AcquireCcResCtx( |
| 1776 | comm_, static_cast<uint8_t>(HcclCMDType::HCCL_CMD_ALLGATHER), ccArgs, &ccResCtx, &ccResCtxSize), | 1836 | comm_, static_cast<uint8_t>(HcclCMDType::HCCL_CMD_ALLGATHER), ccArgs, &ccResCtx, &ccResCtxSize), |
| 1777 | - HCCL_E_PARA); | 1837 | + HCCL_E_PTR); |
| 1778 | EXPECT_EQ(ccResCtx, nullptr); | 1838 | EXPECT_EQ(ccResCtx, nullptr); |
| 1779 | EXPECT_EQ(ccResCtxSize, 0U); | 1839 | EXPECT_EQ(ccResCtxSize, 0U); |
| 1780 | EXPECT_EQ(Mc2FreeCcArgs(ccArgs), HCCL_SUCCESS); | 1840 | EXPECT_EQ(Mc2FreeCcArgs(ccArgs), HCCL_SUCCESS); |
| @@ -10,9 +10,10 @@ | |||
| 10 | 10 | ||
| 11 | #include <cstddef> | 11 | #include <cstddef> |
| 12 | #include <gtest/gtest.h> | 12 | #include <gtest/gtest.h> |
| 13 | +#include <mockcpp/mockcpp.hpp> | ||
| 13 | #include <vector> | 14 | #include <vector> |
| 14 | #define private public | 15 | #define private public |
| 15 | -#include "kernel_operator.h" | 16 | +#include "include/adv_api/hccl/hccl.h" |
| 16 | #undef private | 17 | #undef private |
| 17 | 18 | ||
| 18 | using namespace AscendC; | 19 | using namespace AscendC; |
| @@ -203,4 +204,155 @@ TEST_F(CommonPrepareCheckTest, PrepareRejectsBatchWriteWithZeroSizedDtype) | |||
| 203 | EXPECT_EQ(impl.CommonPrepareImpl<false>(param), INVALID_HANDLE_ID); | 204 | EXPECT_EQ(impl.CommonPrepareImpl<false>(param), INVALID_HANDLE_ID); |
| 204 | EXPECT_EQ(impl.curHandleId_, 0); | 205 | EXPECT_EQ(impl.curHandleId_, 0); |
| 205 | } | 206 | } |
| 207 | +class CcuMultiTilingTest : public ::testing::Test { | ||
| 208 | +protected: | ||
| 209 | + using Impl = HcclImpl<HcclServerType::HCCL_SERVER_TYPE_CCU, DEFAULT_CFG>; | ||
| 210 | + struct TilingBlock { | ||
| 211 | + Mc2InitTilingInner init{}; | ||
| 212 | + Mc2CcTilingInner cc[2]{}; | ||
| 213 | + } block; | ||
| 214 | + Impl impl; | ||
| 215 | + HcclApi::OpResCtx context{}; | ||
| 216 | + CommonPrepareParamCcu handles[HCCL_MAX_HANDLE_ID]{}; | ||
| 217 | + std::vector<uint64_t> signals; | ||
| 218 | + std::vector<uint64_t> params; | ||
| 219 | + uint64_t finished = 0; | ||
| 220 | + | ||
| 221 | + static void StoreSignal(uint64_t* address, uint64_t value) { *address = value; } | ||
| 222 | + static uint8_t LoadSignal(uint8_t* address) { return *address; } | ||
| 223 | + | ||
| 224 | + void SetUp() override | ||
| 225 | + { | ||
| 226 | + MOCKER(AscendC::WriteGmBypassDCache<uint64_t>).stubs().will(invoke(StoreSignal)); | ||
| 227 | + MOCKER(AscendC::ReadGmBypassDCache<uint8_t>).stubs().will(invoke(LoadSignal)); | ||
| 228 | + signals.resize(HcclKfcProtocol::KFC_SIGNAL_REGION_NUM * CCU_MAX_MSG_NUM); | ||
| 229 | + params.resize(CCU_MSG_XN_NUM * CCU_MAX_MSG_NUM); | ||
| 230 | + context.ckeAddr = reinterpret_cast<uint64_t>(signals.data()); | ||
| 231 | + context.xnAddr = reinterpret_cast<uint64_t>(params.data()); | ||
| 232 | + context.rankSize = 2; | ||
| 233 | + context.res[1] = 1000; | ||
| 234 | + context.res[2] = 1; | ||
| 235 | + for (uint32_t i = 0; i < 2; ++i) { | ||
| 236 | + block.cc[i].opType = | ||
| 237 | + static_cast<uint32_t>(i == 0 ? HcclCMDType::HCCL_CMD_ALLREDUCE : HcclCMDType::HCCL_CMD_REDUCE_SCATTER); | ||
| 238 | + context.opType[i] = block.cc[i].opType; | ||
| 239 | + block.cc[i].srcDataType = HCCL_DATA_TYPE_FP16; | ||
| 240 | + block.cc[i].dstDataType = HCCL_DATA_TYPE_FP16; | ||
| 241 | + block.cc[i].reduceType = i == 0 ? HCCL_REDUCE_SUM : HCCL_REDUCE_MAX; | ||
| 242 | + context.algInfo[i].offset = offsetof(TilingBlock, cc) + i * sizeof(Mc2CcTilingInner); | ||
| 243 | + context.algorithmType[i] = i + 10; | ||
| 244 | + handles[i].commType.prepareType = static_cast<HcclCMDType>(block.cc[i].opType); | ||
| 245 | + handles[i].dataType = HCCL_DATA_TYPE_FP16; | ||
| 246 | + handles[i].dstDataType = HCCL_DATA_TYPE_FP16; | ||
| 247 | + handles[i].count = 32; | ||
| 248 | + impl.InitHandleInfo(i); | ||
| 249 | + impl.handleMissionNum_[i] = context.res[2]; | ||
| 250 | + impl.handleReqId_[i] = i; | ||
| 251 | + } | ||
| 252 | + for (auto& available : impl.msgQueueIsAvailable_) { | ||
| 253 | + available = true; | ||
| 254 | + } | ||
| 255 | + impl.newCcuFlag_ = true; | ||
| 256 | + impl.isInited_ = true; | ||
| 257 | + impl.workingFlag_ = true; | ||
| 258 | + impl.hcclNewContext_ = &context; | ||
| 259 | + impl.handleParamGM_ = handles; | ||
| 260 | + impl.finishCntGM_ = &finished; | ||
| 261 | + impl.curVersion_ = HcclTilingVersion::ONLINE_COMPILATION_TILING_VERSION; | ||
| 262 | + impl.tilingBaseAddr_ = reinterpret_cast<uint64_t>(&block); | ||
| 263 | + } | ||
| 264 | + void TearDown() override { GlobalMockObject::verify(); } | ||
| 265 | +}; | ||
| 266 | + | ||
| 267 | +TEST_F(CcuMultiTilingTest, SelectionAndHandleSnapshot) | ||
| 268 | +{ | ||
| 269 | + impl.curHandleId_ = 0; | ||
| 270 | + CommonPrepareParam param{}; | ||
| 271 | + param.commType.prepareType = HcclCMDType::HCCL_CMD_ALLREDUCE; | ||
| 272 | + param.dataType = HCCL_DATA_TYPE_FP16; | ||
| 273 | + param.dstDataType = HCCL_DATA_TYPE_FP16; | ||
| 274 | + param.count = 32; | ||
| 275 | + ASSERT_EQ(impl.SetCcTilingV2(context.algInfo[0].offset), HCCL_SUCCESS); | ||
| 276 | + ASSERT_EQ(impl.CommonPrepareImpl<false>(param), 0); | ||
| 277 | + ASSERT_EQ(impl.SetCcTilingV2(context.algInfo[1].offset), HCCL_SUCCESS); | ||
| 278 | + param.commType.prepareType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER; | ||
| 279 | + ASSERT_EQ(impl.CommonPrepareImpl<false>(param), 1); | ||
| 280 | + impl.CcuPrepareForOp(0); | ||
| 281 | + EXPECT_EQ(handles[0].op, HCCL_REDUCE_SUM); | ||
| 282 | + EXPECT_EQ(impl.GetAlgorithmType(0), 10U); | ||
| 283 | + EXPECT_EQ(impl.ccuParam_.dieSplitRatioPermille, 1000U); | ||
| 284 | + impl.CcuPrepareForOp(1); | ||
| 285 | + EXPECT_EQ(handles[1].op, HCCL_REDUCE_MAX); | ||
| 286 | + EXPECT_EQ(impl.GetAlgorithmType(1), 11U); | ||
| 287 | + EXPECT_EQ(impl.handleMissionNum_[0], 1U); | ||
| 288 | + EXPECT_EQ(impl.handleMissionNum_[1], 1U); | ||
| 289 | + EXPECT_EQ(impl.ccuParam_.dieSplitRatioPermille, 1000U); | ||
| 290 | + EXPECT_NE(GetOpId(&handles[0]), GetOpId(&handles[1])); | ||
| 291 | + impl.ccuUsedXnNum_ = 1; | ||
| 292 | + impl.xnData_[0] = GetOpId(&handles[0]); | ||
| 293 | + impl.CcuSendMsg(0, 0); | ||
| 294 | + impl.xnData_[0] = GetOpId(&handles[1]); | ||
| 295 | + impl.CcuSendMsg(1, 1); | ||
| 296 | + EXPECT_EQ(params[0], GetOpId(&handles[0])); | ||
| 297 | + EXPECT_EQ(params[CCU_MSG_XN_NUM], GetOpId(&handles[1])); | ||
| 298 | +} | ||
| 299 | + | ||
| 300 | +TEST_F(CcuMultiTilingTest, SequentialTilingsWrapTheSharedQueue) | ||
| 301 | +{ | ||
| 302 | + impl.workingFlag_ = false; | ||
| 303 | + impl.curHandleId_ = 0; | ||
| 304 | + CommonPrepareParam param{}; | ||
| 305 | + param.commType.prepareType = HcclCMDType::HCCL_CMD_ALLREDUCE; | ||
| 306 | + param.dataType = HCCL_DATA_TYPE_FP16; | ||
| 307 | + param.count = 32; | ||
| 308 | + param.repeat = 2; | ||
| 309 | + for (uint32_t turn = 0; turn < HCCL_MAX_HANDLE_ID; ++turn) { | ||
| 310 | + ASSERT_EQ(impl.SetCcTilingV2(context.algInfo[turn % 2U].offset), HCCL_SUCCESS); | ||
| 311 | + param.commType.prepareType = static_cast<HcclCMDType>(block.cc[turn % 2U].opType); | ||
| 312 | + const auto handle = impl.CommonPrepareImpl<true>(param); | ||
| 313 | + ASSERT_NE(handle, INVALID_HANDLE_ID); | ||
| 314 | + ASSERT_EQ(impl.Wait(handle), HCCL_SUCCESS); | ||
| 315 | + ASSERT_EQ(impl.Wait(handle), HCCL_SUCCESS); | ||
| 316 | + } | ||
| 317 | + EXPECT_EQ(impl.globalCurResId_, (2U * HCCL_MAX_HANDLE_ID) % CCU_MAX_MSG_NUM); | ||
| 318 | + EXPECT_EQ(impl.globalCurWaitId_, impl.globalCurResId_); | ||
| 319 | + for (auto available : impl.msgQueueIsAvailable_) { | ||
| 320 | + EXPECT_TRUE(available); | ||
| 321 | + } | ||
| 322 | +} | ||
| 323 | + | ||
| 324 | +TEST_F(CcuMultiTilingTest, RepeatRefillAndFinalizeUseTheSharedCursor) | ||
| 325 | +{ | ||
| 326 | + impl.workingFlag_ = false; | ||
| 327 | + impl.curHandleId_ = 1; | ||
| 328 | + impl.handleRepeatCnt_[0] = CCU_MAX_MSG_NUM + 1U; | ||
| 329 | + impl.CommitMsgInner(0); | ||
| 330 | + EXPECT_EQ(impl.handleCommitCnt_[0], CCU_MAX_MSG_NUM); | ||
| 331 | + for (uint32_t turn = 0; turn < CCU_MAX_MSG_NUM + 1U; ++turn) { | ||
| 332 | + ASSERT_EQ(impl.Wait(0), HCCL_SUCCESS); | ||
| 333 | + } | ||
| 334 | + EXPECT_EQ(impl.handleFinishCnt_[0], CCU_MAX_MSG_NUM + 1U); | ||
| 335 | + EXPECT_EQ(impl.globalCurResId_, 1U); | ||
| 336 | + impl.workingFlag_ = true; | ||
| 337 | + impl.Finalize(); | ||
| 338 | + EXPECT_EQ(params[CCU_MSG_XN_NUM], UINT64_MAX); | ||
| 339 | + EXPECT_EQ(*reinterpret_cast<uint64_t*>(impl.GetCommitCkeAddr(1, 0)), 1U); | ||
| 340 | + EXPECT_EQ(*reinterpret_cast<uint64_t*>(impl.GetCommitCkeAddr(1, 1)), 0U); | ||
| 341 | +} | ||
| 342 | + | ||
| 343 | +TEST_F(CcuMultiTilingTest, FinalizeAfterSerialWaitsWritesOneSentinel) | ||
| 344 | +{ | ||
| 345 | + impl.workingFlag_ = false; | ||
| 346 | + impl.curHandleId_ = 2; | ||
| 347 | + impl.Commit(0); | ||
| 348 | + ASSERT_EQ(impl.Wait(0), HCCL_SUCCESS); | ||
| 349 | + impl.Commit(1); | ||
| 350 | + ASSERT_EQ(impl.Wait(1), HCCL_SUCCESS); | ||
| 351 | + impl.workingFlag_ = true; | ||
| 352 | + impl.Finalize(); | ||
| 353 | + EXPECT_EQ(params[2U * CCU_MSG_XN_NUM], UINT64_MAX); | ||
| 354 | + EXPECT_EQ(params[0], 0U); | ||
| 355 | + EXPECT_EQ(params[CCU_MSG_XN_NUM], 0U); | ||
| 356 | +} | ||
| 357 | + | ||
| 206 | } // namespace | 358 | } // namespace |
不用opparamkey,optype来识别