LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/entrance/hcom - hcom_v2.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 87.0 % 793 690
Test Date: 2026-07-28 12:11:00 Functions: 81.8 % 66 54

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include <algorithm>
      12              : #include <list>
      13              : #include <vector>
      14              : #include <string>
      15              : #include <securec.h>
      16              : #include <hccl/hccl_types.h>
      17              : #include "hccl/base.h"
      18              : #include "orion_adapter_rts.h"
      19              : #include "hccl_communicator.h"
      20              : #include "comm_manager.h"
      21              : #include "hcom_v2.h"
      22              : #include "param_check_v2.h"
      23              : #include "hccl_common_v2.h"
      24              : #include "task_param.h"
      25              : #include "types.h"
      26              : #include "comm_topo_desc.h"
      27              : 
      28              : using namespace std;
      29              : using namespace Hccl;
      30              : 
      31          102 : static HcclResult GetHcclGroupParams(const std::string &strGroup, HcclGroupParamsV2& hcclGroupParamsV2)
      32              : {
      33          102 :     HcclCommInfoV2 &hcomCommInfoV2 = GetCommInfoV2();
      34          102 :     std::lock_guard<std::mutex> groupParaLock(hcomCommInfoV2.groupParamsLock);
      35          102 :     auto iter = hcomCommInfoV2.hcclGroupMap.find(strGroup);
      36          102 :     if (iter != hcomCommInfoV2.hcclGroupMap.end()) {
      37           99 :         hcclGroupParamsV2 = iter->second;
      38           99 :         return HCCL_SUCCESS;
      39              :     }
      40            9 :     HCCL_WARNING("comm group not in hcclGroupMap, please check groupName[%s].", strGroup.c_str());
      41            3 :     return HCCL_E_NOT_FOUND;
      42          102 : }
      43              : 
      44          102 : static HcclResult GetHcclCommV2(const char *group, std::shared_ptr<Hccl::HcclCommunicator> &hcclComm)
      45              : {
      46          102 :     std::string strGroup = (group == nullptr || strlen(group) == 0) ? HCCL_WORLD_GROUP : group;
      47          102 :     HcclGroupParamsV2 hcclGroupParamsV2;
      48          102 :     HcclResult ret = GetHcclGroupParams(strGroup, hcclGroupParamsV2);
      49          111 :     CHK_PRT_RET(ret == HCCL_E_NOT_FOUND,
      50              :                 HCCL_WARNING("[GetHcclCommV2]errNo[0x%016llx] group[%s] group is not exist",
      51              :                     HCOM_ERROR_CODE(HCCL_E_NOT_FOUND), strGroup.c_str()),
      52              :                 HCCL_E_NOT_FOUND);
      53           99 :     hcclComm = hcclGroupParamsV2.pComm;
      54           99 :     CHK_PTR_NULL(hcclComm);
      55          297 :     HCCL_INFO("[%s] success.", __func__);
      56           99 :     return HCCL_SUCCESS;
      57          102 : }
      58              : 
      59           79 : inline Hccl::CollOpParams GetHcclOpParams(void *inputPtr, void *outputPtr, u64 count, HcclDataType dataType, 
      60              :     Hccl::OpType opType, HcclReduceOp op = HCCL_REDUCE_RESERVED, bool isSuperKernel = false)
      61              : {
      62           79 :     Hccl::CollOpParams opParams;
      63           79 :     opParams.opType = opType;
      64           79 :     opParams.sendBuf = inputPtr;
      65           79 :     opParams.recvBuf = outputPtr;
      66           79 :     opParams.count = count;
      67           79 :     opParams.staticShape = true;
      68           79 :     if (dataType != HcclDataType::HCCL_DATA_TYPE_RESERVED) {
      69           77 :         opParams.dataType = HcclDataTypeToDataType(dataType);
      70              :     } else {
      71            2 :         opParams.dataType = Hccl::DataType::INVALID;
      72              :     }
      73           79 :     if (op == HCCL_REDUCE_SUM) {
      74           65 :         opParams.reduceOp = Hccl::ReduceOp::SUM;
      75           14 :     } else if (op == HCCL_REDUCE_PROD) {
      76            0 :         opParams.reduceOp = Hccl::ReduceOp::PROD;
      77           14 :     } else if (op == HCCL_REDUCE_MAX) {
      78            1 :         opParams.reduceOp = Hccl::ReduceOp::MAX;
      79           13 :     } else if (op == HCCL_REDUCE_MIN) {
      80            1 :         opParams.reduceOp = Hccl::ReduceOp::MIN;
      81              :     }
      82              : 
      83           79 :     if (opType == Hccl::OpType::ALLTOALL && isSuperKernel) {
      84            6 :         opParams.all2AllDataDes.sendCount = count;
      85            6 :         opParams.all2AllDataDes.recvCount = count;
      86            6 :         opParams.all2AllDataDes.sendType = HcclDataTypeToDataType(dataType);
      87            6 :         opParams.all2AllDataDes.recvType = HcclDataTypeToDataType(dataType);
      88              :     }
      89           79 :     return opParams;
      90            0 : }
      91              : 
      92            2 : HcclResult HcomAllGatherV2(const char *tag, void *inputPtr, void *outputPtr, u64 inputCount, HcclDataType dataType,
      93              :     const char *group, rtStream_t stream)
      94              : {
      95            6 :     HCCL_INFO("[%s] start.", __func__);
      96              : 
      97            2 :     HcclUs startut = TIME_NOW();
      98              :     
      99              :     /* 通信域 */
     100            2 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     101            2 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     102              :                 HCCL_ERROR("[AllGather] comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     103              :                 HCCL_E_NOT_FOUND);
     104            2 :     CHK_RET(HcomCheckOpParamV2(tag, inputCount, dataType, group, stream));
     105              : 
     106              :     /* 入参的正确性由HCCL确保 */
     107            2 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, outputPtr, inputCount, dataType, Hccl::OpType::ALLGATHER);
     108            2 :     std::string opTag = tag;
     109            2 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     110              : 
     111              :     /* 关键状态记录 */
     112            6 :     HCCL_RUN_INFO("hcom allgather success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
     113              :         "inputCount[%llu], data_type[%d]", DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr,
     114              :         inputCount, dataType);
     115              : 
     116            2 :     return HCCL_SUCCESS;
     117            2 : }
     118              : 
     119            9 : HcclResult HcomAllGatherVV2(const char *tag, void *sendBuf, u64 sendCount, void *recvBuf,
     120              :     void *recvCounts, void *rdispls, HcclDataType dataType, const char *group, rtStream_t stream)
     121              : {
     122           27 :     HCCL_INFO("[%s] start.", __func__);
     123            9 :     HcclUs startut = TIME_NOW();
     124              :     /* 获取通信域 */
     125            9 :     std::string opTag = tag;
     126            9 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     127            9 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     128              :                 HCCL_ERROR("[AllGatherV] comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     129              :                 HCCL_E_NOT_FOUND);
     130              :     /* 获取rank信息 */ 
     131              :     uint32_t rankId;
     132            9 :     CHK_RET(hcclComm->GetRankId(rankId));
     133              :     uint32_t rankSize;
     134            9 :     CHK_RET(hcclComm->GetRankSize(&rankSize));
     135              :     /* 参数合法性校验 */
     136            9 :     if (rankSize == 1) {
     137              :         /* rankSize为1时,退化为AllGather */
     138              :         // 检查异常回退AGV的情况
     139            3 :         if (sendCount == 0) {
     140            3 :             HCCL_WARNING("[AllGatherV] sendCount is 0 when single rank");
     141            1 :             return HCCL_SUCCESS;
     142              :         } else {
     143            5 :             CHK_PRT_RET(sendBuf == nullptr, HCCL_ERROR("[AllGatherV] sendBuf is null when single rank"), HCCL_E_PTR);
     144            1 :             CHK_PRT_RET(recvBuf == nullptr, HCCL_ERROR("[AllGatherV] recvBuf is null when single rank"), HCCL_E_PTR);
     145              :         }
     146            1 :         return HcomAllGatherV2(tag, sendBuf, recvBuf, sendCount, dataType, group, stream);
     147              :     }
     148           18 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParamV2(tag, sendCount, dataType, stream), tag);
     149           10 :     CHK_RET_AND_PRINT_IDE(HcomCheckVOpParamV2(rankId, rankSize, sendCount, recvCounts), tag);
     150            3 :     u64* counts = static_cast<u64 *>(recvCounts);
     151            3 :     u64 inputCount = 0;
     152            9 :     for(size_t index = 0; index < rankSize; index++){
     153            6 :         inputCount += counts[index];
     154              :     }
     155            3 :     if(inputCount == 0){
     156            3 :         HCCL_INFO("[%s] inputCount[%llu] is equal to zero", __func__, inputCount);
     157            1 :         return HCCL_SUCCESS;
     158              :     }
     159              :     /* opParams组装 */
     160            2 :     Hccl::CollOpParams opParams;
     161            2 :     opParams.opType = Hccl::OpType::ALLGATHERV;
     162            2 :     opParams.dataType = HcclDataTypeToDataType(dataType);
     163            2 :     opParams.dstRank = rankId;
     164            2 :     opParams.sendBuf = sendBuf;
     165            2 :     opParams.recvBuf = recvBuf;
     166            2 :     opParams.count = sendCount;
     167            2 :     opParams.vDataDes.counts = recvCounts;
     168            2 :     opParams.vDataDes.displs = rdispls;
     169            2 :     opParams.vDataDes.dataType = HcclDataTypeToDataType(dataType);
     170            2 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     171              :     /* 关键状态记录 */
     172            6 :     HCCL_RUN_INFO("hcom allgatherv success,take time [%lld]us, tag[%s], sendBuf[%p], sendCount[%llu], "\
     173              :         "recvBuf[%p], recvCounts[%p], sdispls[%p], data_type[%d]", DURATION_US(TIME_NOW() - startut), tag, sendBuf, sendCount,
     174              :         recvBuf, recvCounts, rdispls, dataType);
     175              : 
     176            2 :     return HCCL_SUCCESS;
     177            9 : }
     178              : 
     179            4 : HcclResult HcomAllReduceV2(const char *tag, void *inputPtr, void *outputPtr, u64 count, HcclDataType dataType,
     180              :     HcclReduceOp op, const char *group, rtStream_t stream)
     181              : {
     182           12 :     HCCL_INFO("[%s] start.", __func__);
     183              : 
     184            4 :     HcclUs startut = TIME_NOW();
     185              : 
     186              :     /* 通信域 */
     187            4 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     188            4 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     189              :                 HCCL_ERROR("[AllReduce] comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     190              :                 HCCL_E_NOT_FOUND);
     191              : 
     192              :     /* 入参校验 */
     193            7 :     CHK_RET(HcomCheckReductionOpV2(op));
     194            3 :     CHK_RET(HcomCheckReduceDataTypeV2(dataType, op));
     195            3 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, group, stream));
     196              : 
     197              :     /* 入参的正确性由HCCL确保 */
     198            3 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, outputPtr, count, dataType, Hccl::OpType::ALLREDUCE, op);
     199            3 :     std::string opTag = tag;
     200            3 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     201              : 
     202              :     /* 关键状态记录 */
     203            9 :     HCCL_RUN_INFO("hcom allreduce success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
     204              :                   "count[%llu], data_type[%d], op[%d]",
     205              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, count, dataType, op);
     206              : 
     207            3 :     return HCCL_SUCCESS;
     208            4 : }
     209              : 
     210            2 : HcclResult HcomReduceScatterV2(const char *tag, void *inputPtr, void *outputPtr, u64 count,
     211              :     HcclDataType dataType, HcclReduceOp op, const char *group, rtStream_t &stream)
     212              : {
     213            6 :     HCCL_INFO("[%s] start.", __func__);
     214              : 
     215            2 :     HcclUs startut = TIME_NOW();
     216              : 
     217              :     /* 通信域 */
     218            2 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     219            2 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     220              :                 HCCL_ERROR("[ReduceScatter] comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     221              :                 HCCL_E_NOT_FOUND);
     222              : 
     223              :     /* 入参校验 */
     224            2 :     CHK_RET(HcomCheckReductionOpV2(op));
     225            2 :     CHK_RET(HcomCheckReduceDataTypeV2(dataType, op));
     226            2 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, group, stream));
     227              : 
     228              :     /* 入参的正确性由HCCL确保 */
     229            2 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, outputPtr, count, dataType, Hccl::OpType::REDUCESCATTER, op);
     230            2 :     std::string opTag = tag;
     231            2 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     232              :     /* 关键状态记录 */
     233            6 :     HCCL_RUN_INFO("hcom reducescatter success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "\
     234              :         "inputCount[%llu], data_type[%d]", DURATION_US(TIME_NOW() - startut), tag, inputPtr,
     235              :         outputPtr, count, dataType);
     236              :  
     237            2 :     return HCCL_SUCCESS;
     238            2 : }
     239              : 
     240           10 : HcclResult HcomReduceScatterVV2(const char *tag, void *sendBuf, void *sendCounts, void *sdispls, void *recvBuf,
     241              :     u64 recvCount, HcclDataType dataType, HcclReduceOp op, const char *group, rtStream_t stream)
     242              : {
     243           30 :     HCCL_INFO("[%s] start.", __func__);
     244           10 :     HcclUs startut = TIME_NOW();
     245              :     /* 获取通信域 */
     246           10 :     std::string opTag = tag;
     247           10 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     248           10 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     249              :                 HCCL_ERROR("[ReduceScatterV] comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     250              :                 HCCL_E_NOT_FOUND);
     251              :     /* 获取rank信息 */
     252              :     uint32_t rankId;
     253           10 :     CHK_RET(hcclComm->GetRankId(rankId));
     254              :     uint32_t rankSize;
     255           10 :     CHK_RET(hcclComm->GetRankSize(&rankSize));
     256              :     /* 入参校验 */
     257           10 :     if (rankSize == 1) {
     258              :         /* rankSize为1时,退化为ReduceScatter */
     259              :         // 检查异常回退RSV的情况
     260            3 :         if (recvCount == 0) {
     261            3 :             HCCL_WARNING("[ReduceScatterV] recvCount is 0 when single rank");
     262            1 :             return HCCL_SUCCESS;
     263              :         } else {
     264            5 :             CHK_PRT_RET(sendBuf == nullptr, HCCL_ERROR("[ReduceScatterV] sendBuf is null when single rank"), HCCL_E_PTR);
     265            1 :             CHK_PRT_RET(recvBuf == nullptr, HCCL_ERROR("[ReduceScatterV] recvBuf is null when single rank"), HCCL_E_PTR);
     266              :         }
     267            1 :         return HcomReduceScatterV2(tag, sendBuf, recvBuf, recvCount, dataType, op, group, stream);
     268              :     }
     269           13 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParamV2(tag, recvCount, dataType, stream), tag);
     270            6 :     CHK_RET_AND_PRINT_IDE(HcomCheckReductionOpV2(op), opTag.c_str());
     271           12 :     CHK_RET_AND_PRINT_IDE(HcomCheckReduceDataTypeV2(dataType, op), opTag.c_str());
     272           17 :     CHK_RET_AND_PRINT_IDE(HcomCheckVOpParamV2(rankId, rankSize, recvCount, sendCounts), tag);
     273            3 :     u64* counts = static_cast<u64 *>(sendCounts);
     274            3 :     u64 inputCount = 0;
     275            9 :     for(size_t index = 0; index < rankSize; index++){
     276            6 :         inputCount += counts[index];
     277              :     }
     278            3 :     if(inputCount == 0){
     279            3 :         HCCL_INFO("[%s] inputCount[%llu] is equal to zero", __func__, inputCount);
     280            1 :         return HCCL_SUCCESS;
     281              :     }
     282              :     /* opParams组装 */ 
     283            2 :     Hccl::CollOpParams opParams;
     284            2 :     opParams.opType = Hccl::OpType::REDUCESCATTERV;
     285            2 :     opParams.dataType = HcclDataTypeToDataType(dataType);
     286            2 :     opParams.reduceOp = HcclReduceOpToReduceOp(op);
     287            2 :     opParams.dstRank = rankId;
     288            2 :     opParams.sendBuf = sendBuf;
     289            2 :     opParams.recvBuf = recvBuf;
     290            2 :     opParams.count = recvCount;
     291            2 :     opParams.vDataDes.counts = sendCounts;
     292            2 :     opParams.vDataDes.displs = sdispls;
     293            2 :     opParams.vDataDes.dataType = HcclDataTypeToDataType(dataType);
     294            2 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     295              :     /* 关键状态记录 */
     296            6 :     HCCL_RUN_INFO("hcom reducescatterv success,take time [%lld]us, tag[%s], sendBuf[%p], sendCounts[%p], "\
     297              :         "sdispls[%p], recvBuf[%p], recvCount[%llu], data_type[%d]", DURATION_US(TIME_NOW() - startut), tag, sendBuf, sendCounts, sdispls,
     298              :         recvBuf, recvCount, dataType);
     299              :  
     300            2 :     return HCCL_SUCCESS;
     301           10 : }
     302              : 
     303            1 : HcclResult HcomSendV2(const char *tag, void *inputPtr, u64 count, HcclDataType dataType, u32 destRank,
     304              :     u32 srTag, const char *group, rtStream_t &stream)
     305              : {
     306            3 :     HCCL_INFO("[%s] start.", __func__);
     307              : 
     308            1 :     HcclUs startut = TIME_NOW();
     309              :     
     310              :     /* 通信域 */
     311            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     312            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     313              :                 HCCL_ERROR("[SendV2] comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     314              :                 HCCL_E_NOT_FOUND);
     315            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, group, stream));
     316              :  
     317              :     /* 入参的正确性由HCCL确保 */
     318            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, nullptr, count, dataType, Hccl::OpType::SEND);
     319            1 :     opParams.dstRank = destRank;
     320            1 :     std::string opTag = tag;
     321            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     322              :     /* 关键状态记录 */
     323            3 :     HCCL_RUN_INFO("hcom send success,time[%lld]us,tag[%s],inputPtr[%p],count[%llu],dataType[%s],destRank[%u],"
     324              :         "srTag[%u]",
     325              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, count, GetDataTypeEnumStrV2(dataType).c_str(), destRank, srTag);
     326              :  
     327            1 :     return HCCL_SUCCESS;
     328            1 : }
     329              : 
     330            1 : HcclResult HcomReceiveV2(const char *tag, void *outputPtr, u64 count, HcclDataType dataType, u32 srcRank,
     331              :     u32 srTag, const char *group, rtStream_t &stream)
     332              : {
     333            3 :     HCCL_INFO("[%s] start.", __func__);
     334              : 
     335            1 :     HcclUs startut = TIME_NOW();
     336              : 
     337              :     /* 通信域 */
     338            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     339            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     340              :                 HCCL_ERROR("[Recv] comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     341              :                 HCCL_E_NOT_FOUND);
     342            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, group, stream));
     343              : 
     344              :     /* 入参的正确性由HCCL确保 */
     345            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(nullptr, outputPtr, count, dataType, Hccl::OpType::RECV);
     346            1 :     opParams.dstRank = srcRank;
     347            1 :     std::string opTag = tag;
     348            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     349              :     /* 关键状态记录 */
     350            3 :     HCCL_RUN_INFO("hcom receive success,time[%lld]us,tag[%s],outputPtr[%p],count[%llu],dataType[%s],srcRank[%u],"
     351              :         "srTag[%u]",
     352              :         DURATION_US(TIME_NOW() - startut), tag, outputPtr, count, GetDataTypeEnumStrV2(dataType).c_str(), srcRank, srTag); 
     353            1 :     return HCCL_SUCCESS;
     354            1 : }
     355              : 
     356            2 : HcclResult HcomGetRankIdV2(const char *group, u32 *rankId)
     357              : {
     358            6 :     HCCL_INFO("[%s] start.", __func__);
     359              : 
     360            2 :     HcclCommInfoV2 &hcomCommInfoV2 = GetCommInfoV2();
     361              : 
     362              :     // 校验通信域非空
     363            2 :     CHK_PRT_RET(hcomCommInfoV2.pComm == nullptr,
     364              :         HCCL_ERROR("[Get][RankId]hcomCommInfoV2.pComm is null, "
     365              :                    "please check if the initialize process is called."),
     366              :         HCCL_E_PTR);
     367              :     
     368              :     // 校验worldgroup
     369            2 :     std::string strGroup = (group == nullptr || strlen(group) == 0) ? HCCL_WORLD_GROUP : group;
     370            2 :     if (strGroup == HCCL_WORLD_GROUP) {
     371            2 :         *rankId = hcomCommInfoV2.commParams.myRank;
     372            6 :         HCCL_INFO("hcom get world rank id success, rankId[%u]", *rankId);
     373            2 :         return HCCL_SUCCESS;
     374              :     }
     375              : 
     376              :     // 获取group
     377            0 :     HcclGroupParamsV2 hcclGroupParamsV2;
     378            0 :     CHK_RET(GetHcclGroupParams(strGroup, hcclGroupParamsV2));
     379              : 
     380              :     // 获取rankId
     381            0 :     *rankId = hcclGroupParamsV2.groupRank;
     382              : 
     383            0 :     HCCL_INFO("hcom get rank id success, group[%s], rankId[%u]", strGroup.c_str(), *rankId);
     384            0 :     return HCCL_SUCCESS;
     385            2 : }
     386              : 
     387            3 : HcclResult HcomGetWorkspaceSubStreamNumV2(const char *group, u64 &streamNum, u64 dataSize, HcclDataType dataType, HcclCMDType optype)
     388              : {
     389            9 :     HCCL_INFO("[%s] start.", __func__);
     390              : 
     391            3 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     392            6 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     393              :                 HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     394              :                 HCCL_E_NOT_FOUND);
     395            2 :     HcclOpType hcclOpType = static_cast<HcclOpType::Value>(optype);
     396              :     
     397            2 :     if (OP_TYPE_MAP.find(optype) ==  OP_TYPE_MAP.end()) {
     398            3 :         HCCL_ERROR("[HcomGetWorkspaceSubStreamNumV2], does not support opType[%s].", hcclOpType.Describe().c_str());
     399            1 :         return HCCL_E_PARA;
     400              :     }
     401            1 :     Hccl::CollOffloadOpResReq resReq{};
     402            1 :     Hccl::OpType opType = OP_TYPE_MAP.at(optype);
     403            1 :     CHK_RET(hcclComm->CalcCollOffloadOpRes(opType, dataSize, dataType, resReq));
     404            1 :     streamNum = resReq.requiredSubQueNum;
     405            3 :     HCCL_INFO("[HcomGetWorkspaceSubStreamNumV2] GetWorkspaceSubStreamNum success, streamNum[%llu]", streamNum);
     406            1 :     return HCCL_SUCCESS;
     407            3 : }
     408              : 
     409            6 : HcclResult HcomGetWorkspaceMemSizeV2(
     410              :     const std::string &opType, u64 count, HcclDataType dataType, const char *group, u64 &memSize)
     411              : {
     412           18 :     HCCL_INFO("[%s] start.", __func__);
     413            6 :     if ((dataType < HCCL_DATA_TYPE_INT8) || (dataType > HCCL_DATA_TYPE_FP8E8M0)) {
     414            6 :         HCCL_ERROR("[%s] does not support data type[%s].", __func__, GetDataTypeEnumStrV2(dataType).c_str());
     415            2 :         return HCCL_E_PARA;
     416              :     }
     417              : 
     418            4 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     419            7 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     420              :                 HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     421              :                 HCCL_E_NOT_FOUND);
     422              :  
     423            3 :     if (OP_TYPE_STR.find(opType) ==  OP_TYPE_STR.end()) {
     424            6 :         HCCL_ERROR("[%s] does not support opType[%s].", __func__, opType.c_str());
     425            2 :         return HCCL_E_PARA;
     426              :     }
     427            1 :     Hccl::CollOffloadOpResReq resReq{};
     428            1 :     Hccl::OpType optype = OP_TYPE_STR.at(opType);
     429            1 :     u64 dataSize = SIZE_TABLE[dataType] * count;
     430            1 :     CHK_RET(hcclComm->CalcCollOffloadOpRes(optype, dataSize, dataType, resReq));
     431            1 :     memSize = resReq.requiredScratchMemSize;
     432            3 :     HCCL_INFO("[%s] GetWorkspaceMemSize success, memSize[%llu]", __func__, memSize);
     433            1 :     return HCCL_SUCCESS;
     434            4 : }
     435              : 
     436            3 : HcclResult HcomSetWorkspaceResourceV2(
     437              :     const std::string &tag, const char *group, std::vector<rtStream_t> stream, void *memPtr, u64 maxSize)
     438              : {
     439            9 :     HCCL_INFO("[%s] start.", __func__);
     440              : 
     441            3 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     442            6 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     443              :                 HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     444              :                 HCCL_E_NOT_FOUND);
     445              : 
     446              :     /* 设定 workspace 内存资源 */
     447            2 :     CHK_RET(hcclComm->SetCollOffloadSlaveStreams(tag, stream));
     448            2 :     CHK_RET(hcclComm->SetCollOffloadScratchBuf(tag, memPtr, maxSize));
     449              : 
     450            6 :     HCCL_INFO("[%s] success, maxSize[%llu]", __func__, maxSize);
     451            2 :     return HCCL_SUCCESS;
     452            3 : }
     453              : 
     454            1 : HcclResult HcomAlltoAllVV2(const void *sendBuf, const void *sendCounts, const void *sdispls, HcclDataType sendType,
     455              :                          const void *recvBuf, const void *recvCounts, const void *rdispls, HcclDataType recvType,
     456              :                          const char *group, rtStream_t stream, const char *tag)
     457              : {
     458            3 :     HCCL_INFO("[%s] start.", __func__);
     459              : 
     460            1 :     HcclUs startut = TIME_NOW();
     461              : 
     462              :     /* 通信域 */
     463            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     464            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     465              :                 HCCL_ERROR("[AlltoAllV]comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     466              :                 HCCL_E_NOT_FOUND);
     467            1 :     CHK_RET(HcomCheckOpParamV2(tag, 0, sendType, group, stream));
     468            1 :     CHK_RET(HcomCheckDataTypeV2(recvType));
     469              :  
     470              :     /* 根据ranksize校验相关入参 */
     471            1 :     u32 rankSize = 0;
     472            1 :     CHK_RET(hcclComm->GetRankSize(&rankSize));
     473            1 :     CHK_RET(HcomCheckAlltoAllVExternalMemV2(sendBuf, sendCounts, recvBuf, recvCounts, rankSize));
     474              :  
     475              :     /* 入参的正确性由HCCL确保 */
     476            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(const_cast<void*>(sendBuf), const_cast<void*>(recvBuf), 
     477            1 :                                                   0, HcclDataType::HCCL_DATA_TYPE_RESERVED, Hccl::OpType::ALLTOALLV);
     478            1 :     opParams.all2AllVDataDes.sendType = HcclDataTypeToDataType(sendType);
     479            1 :     opParams.all2AllVDataDes.recvType = HcclDataTypeToDataType(recvType);
     480            1 :     opParams.all2AllVDataDes.sendCounts = const_cast<void*>(sendCounts);
     481            1 :     opParams.all2AllVDataDes.recvCounts = const_cast<void*>(recvCounts);
     482            1 :     opParams.all2AllVDataDes.sdispls = const_cast<void*>(sdispls);
     483            1 :     opParams.all2AllVDataDes.rdispls = const_cast<void*>(rdispls);
     484            1 :     opParams.dataType = HcclDataTypeToDataType(sendType);
     485            1 :     std::string opTag = tag;
     486            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     487              :     
     488              :     /* 关键状态记录 */
     489            3 :     HCCL_RUN_INFO("HcomAlltoAllV success,take time [%lld]us, tag[%s], sendBuf[%p], recvBuf[%p], sendCounts[%p],"\
     490              :                "recvCounts[%p], sendType[%s], recvType[%s], group[%s].", DURATION_US(TIME_NOW() - startut),
     491              :                tag, sendBuf, recvBuf, sendCounts, recvCounts, GetDataTypeEnumStrV2(sendType).c_str(),
     492              :                GetDataTypeEnumStrV2(recvType).c_str(), group);
     493            1 :     return HCCL_SUCCESS;
     494            1 : }
     495              : 
     496            1 : HcclResult HcomAlltoAllVCV2(const void *sendBuf, const void *sendCountMatrix, HcclDataType sendType,
     497              :     const void *recvBuf, HcclDataType recvType, const char *group, rtStream_t stream, const char *tag)
     498              : {
     499            3 :     HCCL_INFO("[%s] start.", __func__);
     500              : 
     501            1 :     HcclUs startut = TIME_NOW();
     502              : 
     503              :     /* 获取通信域句柄并入参校验 */
     504            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     505            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     506              :                 HCCL_ERROR("[AlltoAllVC]comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     507              :                 HCCL_E_NOT_FOUND);
     508            1 :     CHK_RET(HcomCheckOpParamV2(tag, 0, sendType, group, stream));
     509            1 :     CHK_RET(HcomCheckDataTypeV2(recvType));
     510              : 
     511              :     /* 根据ranksize校验相关入参 */
     512            1 :     u32 rankSize = 0;
     513            1 :     CHK_RET(hcclComm->GetRankSize(&rankSize));
     514            1 :     u32 myRank = INVALID_VALUE_RANKID;
     515            1 :     CHK_RET(hcclComm->GetRankId(myRank));
     516            1 :     bool isEmpty = false;
     517            1 :     CHK_RET(HcomCheckAlltoAllVCEmptyV2(sendBuf, sendCountMatrix, recvBuf, rankSize, isEmpty));
     518            1 :     if(isEmpty) {
     519            3 :         HCCL_INFO("[HcclAlltoAllVCV2] sendCountMatrix is Empty");
     520            1 :         return HCCL_SUCCESS;
     521              :     }
     522            0 :     CHK_RET(HcomCheckAlltoAllVCExternalMemV2(sendBuf, sendCountMatrix, recvBuf, rankSize, myRank));
     523              : 
     524            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
     525            0 :     s32 streamId = HrtGetStreamId(stream);
     526            0 :     s32 deviceLogicId = HrtGetDevice();
     527              :     u64 sendCountMatrixHash;
     528            0 :     HcomGetHashFromSendCountMatrixV2(sendCountMatrixHash, sendCountMatrix, rankSize, tag);
     529              :     /* 接口交互信息日志 */
     530            0 :     HCCL_RUN_INFO("Entry-HcomAlltoAllVC:tag[%s], sendBuf[%p], sendCountMatrixHash[%llu], sendType[%s], "\
     531              :                "recvBuf[%p], recvType[%s], group[%s], streamId[%d], deviceLogicId[%d]",
     532              :                tag, sendBuf, sendCountMatrixHash, GetDataTypeEnumStrV2(sendType).c_str(),
     533              :                recvBuf, GetDataTypeEnumStrV2(recvType).c_str(), strGroup.c_str(), streamId, deviceLogicId);
     534              : 
     535              :     /* 入参的正确性由HCCL确保 */
     536            0 :     Hccl::CollOpParams opParams = GetHcclOpParams(const_cast<void*>(sendBuf), const_cast<void*>(recvBuf), 
     537            0 :                                                   0, HcclDataType::HCCL_DATA_TYPE_RESERVED, Hccl::OpType::ALLTOALLVC);
     538            0 :     opParams.all2AllVCDataDes.sendType = HcclDataTypeToDataType(sendType);
     539            0 :     opParams.all2AllVCDataDes.recvType = HcclDataTypeToDataType(recvType);
     540            0 :     opParams.all2AllVCDataDes.sendCountMatrix = const_cast<void*>(sendCountMatrix);
     541            0 :     opParams.dataType = HcclDataTypeToDataType(sendType);
     542            0 :     std::string opTag = tag;
     543            0 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     544              : 
     545              :     /* 关键状态记录 */
     546            0 :     HCCL_RUN_INFO("HcomAlltoAllVC success,take time [%lld]us, tag[%s], sendBuf[%p], recvBuf[%p], "\
     547              :                "sendType[%s], recvType[%s], group[%s].", DURATION_US(TIME_NOW() - startut),
     548              :                tag, sendBuf, recvBuf, GetDataTypeEnumStrV2(sendType).c_str(),
     549              :                GetDataTypeEnumStrV2(recvType).c_str(), group);
     550            0 :     return HCCL_SUCCESS;
     551            1 : }
     552              : 
     553            1 : HcclResult HcomAlltoAllV2(const void *sendBuf, u64 sendCount, HcclDataType sendType,
     554              :                         const void *recvBuf, u64 recvCount, HcclDataType recvType,
     555              :                         const char *group, rtStream_t stream, const char *tag)
     556              : {
     557            3 :     HCCL_INFO("[%s] start.", __func__);
     558              : 
     559            1 :     HcclUs startut = TIME_NOW();
     560              : 
     561              :     /* 通信域 */
     562            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     563            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     564              :                 HCCL_ERROR("[AlltoAll]comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     565              :                 HCCL_E_NOT_FOUND);
     566            1 :     CHK_RET(HcomCheckOpParamV2(tag, sendCount, sendType, stream));
     567            1 :     CHK_RET(HcomCheckOpParamV2(tag, recvCount, recvType, stream));
     568              :     
     569              :     /* 入参的正确性由HCCL确保 */
     570            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(const_cast<void*>(sendBuf), const_cast<void*>(recvBuf), 0, 
     571            1 :                                                   HcclDataType::HCCL_DATA_TYPE_RESERVED, Hccl::OpType::ALLTOALL);
     572            1 :     opParams.all2AllDataDes.recvCount = recvCount;
     573            1 :     opParams.all2AllDataDes.sendCount = sendCount;
     574            1 :     opParams.all2AllDataDes.sendType = HcclDataTypeToDataType(sendType);
     575            1 :     opParams.all2AllDataDes.recvType = HcclDataTypeToDataType(recvType);
     576            1 :     opParams.dataType = HcclDataTypeToDataType(sendType);
     577            1 :     std::string opTag = tag;
     578            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     579              : 
     580            3 :     HCCL_RUN_INFO("HcomAlltoAll success,take time [%lld]us, tag[%s], sendBuf[%p], recvBuf[%p], sendCount[%llu], "\
     581              :                "recvCounts[%llu], sendType[%s], recvType[%s], group[%s].", DURATION_US(TIME_NOW() - startut),
     582              :                tag, sendBuf, recvBuf, sendCount, recvCount, GetDataTypeEnumStrV2(sendType).c_str(),
     583              :                GetDataTypeEnumStrV2(recvType).c_str(), group);
     584              :  
     585            1 :     return HCCL_SUCCESS;
     586            1 : }
     587              : 
     588            1 : HcclResult HcomGetAlltoAllStagedWorkSpaceMemSizeV2(const char *group, u64 *sendCounts, u64 *sdispls,
     589              :     HcclDataType sendType, u64 *recvCounts, u64 *rdispls, HcclDataType recvType, u64 &memSize)
     590              : {
     591            3 :     HCCL_INFO("[%s] start.", __func__);
     592              : 
     593            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     594            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     595              :                 HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     596              :                 HCCL_E_NOT_FOUND);
     597            1 :     CHK_RET(HcomCheckDataTypeV2(sendType));
     598            1 :     CHK_RET(HcomCheckDataTypeV2(recvType));
     599              :  
     600            1 :     Hccl::CollOffloadOpResReq resReq{};
     601            1 :     Hccl::OpType optype = Hccl::OpType::ALLTOALL;
     602            1 :     u64 dataSize = 0; // ??
     603            1 :     CHK_RET(hcclComm->CalcCollOffloadOpRes(optype, dataSize, sendType, resReq));
     604            1 :     memSize = resReq.requiredScratchMemSize;
     605              : 
     606              :     // memSize = 200 * 1024 * 1024; //  需要200M
     607            3 :     HCCL_INFO("[%s] success, memSize[%llu]", __func__, memSize);
     608            1 :     return HCCL_SUCCESS;
     609            1 : }
     610              : 
     611            1 : HcclResult HcomGetAlltoAllvcStagedWorkSpaceMemSizeV2(const char *group, u64 &memSize)
     612              : {
     613            3 :     HCCL_INFO("[%s] start.", __func__);
     614              : 
     615            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     616            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     617              :                 HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     618              :                 HCCL_E_NOT_FOUND);
     619              : 
     620            1 :     Hccl::CollOffloadOpResReq resReq;
     621            1 :     Hccl::OpType optype = Hccl::OpType::ALLTOALLVC;
     622              :     
     623            1 :     u64 dataSize = 0; //不涉及ScratchMenSize
     624              :     // 为保证流程执行填写默认dataType
     625            1 :     CHK_RET(hcclComm->CalcCollOffloadOpRes(optype, dataSize, HCCL_DATA_TYPE_INT8, resReq));
     626            1 :     memSize = resReq.requiredScratchMemSize;
     627              : 
     628              :     // memSize = 200 * 1024 * 1024; //  需要200M
     629            3 :     HCCL_INFO("[%s] success, memSize[%llu]", __func__, memSize);
     630            1 :     return HCCL_SUCCESS;
     631            1 : }
     632              : 
     633            1 : HcclResult HcomBroadcastV2(const char *tag, void *ptr, u64 count, HcclDataType dataType,
     634              :     u32 root, const char *group, rtStream_t stream)
     635              : {
     636            3 :     HCCL_INFO("[%s] start.", __func__);
     637              : 
     638            1 :     HcclUs startut = TIME_NOW();
     639              : 
     640              :     /* 通信域 */
     641            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     642            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     643              :                 HCCL_ERROR("[Broadcast] comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     644              :                 HCCL_E_NOT_FOUND);
     645            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, group, stream));
     646              : 
     647              :     /* 入参的正确性由HCCL确保 */
     648            1 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
     649            1 :     CHK_RET(hcclComm->GetRankSize(&rankSize));
     650            1 :     CHK_RET(HcomCheckUserRankV2(rankSize, root));
     651            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(ptr, ptr, count, dataType, Hccl::OpType::BROADCAST);
     652            1 :     opParams.root = root;
     653            1 :     std::string opTag = tag;
     654            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     655              : 
     656              :     /* 关键状态记录 */
     657            3 :     HCCL_RUN_INFO("hcom broadcast success,take time [%lld]us,tag[%s], input_ptr[%p], count[%llu], data_type[%s], "\
     658              :         "root[%u]", DURATION_US(TIME_NOW() - startut), tag, ptr, count, GetDataTypeEnumStrV2(dataType).c_str(), root);
     659            1 :     return HCCL_SUCCESS;
     660            1 : }
     661              : 
     662            1 : HcclResult HcomReduceV2(const char *tag, void *inputPtr, void *outputPtr, u64 count, HcclDataType dataType,
     663              :     HcclReduceOp op, u32 root, const char *group, rtStream_t stream)
     664              : {
     665            3 :     HCCL_INFO("[%s] start.", __func__);
     666              : 
     667            1 :     HcclUs startut = TIME_NOW();
     668              : 
     669              :     /* 通信域 */
     670            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     671            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     672              :                 HCCL_ERROR("[Reduce] comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     673              :                 HCCL_E_NOT_FOUND);
     674              : 
     675              :     /* 入参校验 */
     676            1 :     CHK_RET(HcomCheckReductionOpV2(op));
     677            1 :     CHK_RET(HcomCheckReduceDataTypeV2(dataType, op));
     678            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, group, stream));
     679              : 
     680              :     /* 入参的正确性由HCCL确保 */
     681            1 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
     682            1 :     CHK_RET(hcclComm->GetRankSize(&rankSize));
     683            1 :     CHK_RET(HcomCheckUserRankV2(rankSize, root));
     684            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, outputPtr, count, dataType, Hccl::OpType::REDUCE, op);
     685            1 :     opParams.root = root;
     686            1 :     std::string opTag = tag;
     687            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     688              : 
     689              :     /* 关键状态记录 */
     690            3 :     HCCL_RUN_INFO("hcom reduce success, take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], "\
     691              :         "data_type[%s], op[%s], root[%u]", DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, count,
     692              :         GetDataTypeEnumStrV2(dataType).c_str(), GetReduceOpEnumStrV2(op).c_str(), root);
     693              :  
     694            1 :     return HCCL_SUCCESS;
     695            1 : }
     696              : 
     697            2 : HcclResult HcomGetLocalRankSizeV2(const char *group, u32 *localRankSize)
     698              : {
     699            2 :     CHK_RET(HcomCheckGroupNameV2(group));
     700            2 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     701            2 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     702              :                 HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     703              :                 HCCL_E_NOT_FOUND);
     704            2 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
     705            2 :     CHK_RET(hcclComm->GetRankSize(&rankSize));
     706            2 :     u32 layer0NetInstanceNum = 0;
     707            2 :     u32 *instSizeList = nullptr;
     708            8 :     CHK_RET(hcclComm->GetInstSizeListByNetLayer(0, &instSizeList, &layer0NetInstanceNum));
     709            0 :     if (layer0NetInstanceNum == 0) {
     710            0 :         HCCL_ERROR("[HcomGetLocalRankSizeV2] The layer0NetInstanceNum is zero, commId[%s]", hcclComm->GetId().c_str());
     711            0 :         return HCCL_E_INTERNAL;
     712              :     }
     713            0 :     *localRankSize = rankSize / layer0NetInstanceNum;
     714            0 :     HCCL_INFO("[HcomGetLocalRankSizeV2] end, layer0NetInstanceNum[%u], localRankSize[%u], rankSize[%u], commId[%s]",
     715              :         layer0NetInstanceNum, *localRankSize, rankSize, hcclComm->GetId().c_str());
     716            0 :     return HCCL_SUCCESS;
     717            2 : }
     718              : 
     719            1 : HcclResult HcomGetLocalRankIdV2(const char *group, u32 *localRankId)
     720              : {
     721            1 :     CHK_RET(HcomCheckGroupNameV2(group));
     722            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     723            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     724              :                 HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     725              :                 HCCL_E_NOT_FOUND);
     726            1 :     u32 rankId = INVALID_VALUE_RANKID;
     727            1 :     CHK_RET(hcclComm->GetRankId(rankId));
     728            1 :     u32 localRankSize = INVALID_VALUE_RANKSIZE;
     729            4 :     CHK_RET(HcomGetLocalRankSizeV2(group, &localRankSize));
     730            0 :     if (localRankSize == 0) {
     731            0 :         HCCL_ERROR("[HcomGetLocalRankIdV2] The localRankSize is zero, commId[%s]", hcclComm->GetId().c_str());
     732            0 :         return HCCL_E_INTERNAL;
     733              :     }
     734            0 :     *localRankId = rankId % localRankSize;
     735            0 :     HCCL_INFO("[HcomGetLocalRankIdV2] end, rankId[%u], localRankSize[%u], localRankId[%u], commId[%s]",
     736              :         rankId, localRankSize, *localRankId, hcclComm->GetId().c_str());
     737            0 :     return HCCL_SUCCESS;
     738            1 : }
     739              : 
     740            1 : HcclResult HcomGetCommHandleByGroupV2(const char *group, HcclComm *commHandle)
     741              : {
     742            3 :     HCCL_INFO("[%s] start.", __func__);
     743            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     744            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     745              :                 HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     746              :                 HCCL_E_NOT_FOUND);
     747            1 :     *commHandle = static_cast<HcclComm>(hcclComm.get());
     748            1 :     return HCCL_SUCCESS;
     749            1 : }
     750              : 
     751            2 : HcclResult HcomCalcTaskNumV2(HcomOpParam *hcomOpParam, u32 &taskNum)
     752              : {
     753              :     /* 通信域 */
     754            6 :     HCCL_INFO("HcomCalcTaskNumV2 start.");
     755            2 :         std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     756            2 :     CHK_PRT_RET(GetHcclCommV2(hcomOpParam->group, hcclComm) == HCCL_E_NOT_FOUND, 
     757              :             HCCL_ERROR("comm with group name [%s] is not found", 
     758              :                         hcomOpParam->group == nullptr ? HCCL_WORLD_GROUP : hcomOpParam->group),
     759              :             HCCL_E_NOT_FOUND);
     760              :             
     761            2 :         Hccl::DataType hcclDataType = Hccl::DataType::INVALID;
     762            2 :     if (hcomOpParam->dataType != HcclDataType::HCCL_DATA_TYPE_RESERVED) {
     763            2 :         hcclDataType = HcclDataTypeToDataType(hcomOpParam->dataType);
     764              :     }
     765              : 
     766            6 :         if (OP_TYPE_STR.find(hcomOpParam->opType) ==  OP_TYPE_STR.end()) {
     767            3 :         HCCL_ERROR("[HcomCalcTaskNumV2], does not support opType[%s].", hcomOpParam->opType);
     768            1 :         return HCCL_E_PARA;
     769              :     }
     770            1 :     Hccl::OpType hcclOpType = OP_TYPE_STR.at(hcomOpParam->opType);
     771            4 :         CHK_RET(hcclComm->CalcTaskNum(hcclOpType, hcclDataType, hcomOpParam->count, taskNum));
     772            0 :     return HCCL_SUCCESS;
     773            2 : }
     774              : 
     775            2 : HcclResult HcomGetTopoDescV2(const char *group, HcclTopoDescs *topoDescs, uint32_t topoSize)
     776              : {
     777              :     /* 通信域 */
     778            6 :     HCCL_INFO("[%s] start.", __func__);
     779            2 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     780            2 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     781              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     782              :             HCCL_E_NOT_FOUND);
     783              :     
     784            5 :     CHK_RET(hcclComm->GetTopoDesc(topoDescs, topoSize));
     785              :  
     786            1 :     return HCCL_SUCCESS;
     787            2 : }
     788              : 
     789            1 : HcclResult HcomCreateCommCclBufV2(const char *group)
     790              : {
     791              :     /* 通信域 */
     792            3 :     HCCL_INFO("[%s] start.", __func__);
     793            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     794            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     795              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     796              :             HCCL_E_NOT_FOUND);
     797            1 :     CHK_RET(hcclComm->CreateCommCclBuf());
     798            1 :     return HCCL_SUCCESS;
     799            1 : }
     800              :  
     801            1 : HcclResult HcomGetInCclBufV2(const char *group, void *&commInputPtr, u64 &commInputSize)
     802              : {
     803              :     /* 通信域 */
     804            3 :     HCCL_INFO("[%s] start.", __func__);
     805            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     806            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     807              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     808              :             HCCL_E_NOT_FOUND);
     809            1 :     CHK_RET(hcclComm->CreateCommCclBuf());
     810            1 :     CHK_RET(hcclComm->GetInCclBuf(commInputPtr, commInputSize));
     811            1 :     return HCCL_SUCCESS;
     812            1 : }
     813              :  
     814            1 : HcclResult HcomGetOutCclBufV2(const char *group, void *&commOutputPtr, u64 &commOutputSize)
     815              : {
     816              :     /* 通信域 */
     817            3 :     HCCL_INFO("[%s] start.", __func__);
     818            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     819            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     820              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     821              :             HCCL_E_NOT_FOUND);
     822            1 :     CHK_RET(hcclComm->CreateCommCclBuf());
     823            1 :     CHK_RET(hcclComm->GetOutCclBuf(commOutputPtr, commOutputSize));
     824            1 :     return HCCL_SUCCESS;
     825            1 : }
     826              : 
     827            1 : HcclResult HcomGetIndirectInCclBufV2(const char *group, void *&commInputPtr, u64 &commInputSize)
     828              : {
     829              :     /* 通信域 */
     830            3 :     HCCL_INFO("[%s] start.", __func__);
     831            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     832            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     833              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     834              :             HCCL_E_NOT_FOUND);
     835            1 :     CHK_RET(hcclComm->CreateCommCclBuf());
     836            1 :     CHK_RET(hcclComm->GetIndirectInputCclBuf(commInputPtr, commInputSize));
     837            1 :     return HCCL_SUCCESS;
     838            1 : }
     839              :  
     840            1 : HcclResult HcomGetIndirectOutCclBufV2(const char *group, void *&commOutputPtr, u64 &commOutputSize)
     841              : {
     842              :     /* 通信域 */
     843            3 :     HCCL_INFO("[%s] start.", __func__);
     844            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
     845            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
     846              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
     847              :             HCCL_E_NOT_FOUND);
     848            1 :     CHK_RET(hcclComm->CreateCommCclBuf());
     849            1 :     CHK_RET(hcclComm->GetIndirectOutputCclBuf(commOutputPtr, commOutputSize));
     850            1 :     return HCCL_SUCCESS;
     851            1 : }
     852              : 
     853              :  
     854            0 : HcclResult HcomGraphCreateCommCclBufV2(const int64_t &hcomComm)
     855              : {
     856              :     /* 通信域 */
     857            0 :     HCCL_INFO("[%s] start.", __func__);
     858            0 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator *>(hcomComm);
     859            0 :     CHK_RET(hcclComm->CreateCommCclBuf());
     860            0 :     return HCCL_SUCCESS;
     861              : }
     862              :  
     863            0 : HcclResult HcomGraphGetInCclBufV2(const int64_t &hcomComm, void *&commInputPtr, u64 &commInputSize)
     864              : {
     865            0 :     HCCL_INFO("[%s] start.", __func__);
     866            0 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator *>(hcomComm);
     867            0 :     CHK_RET(hcclComm->CreateCommCclBuf());
     868            0 :     CHK_RET(hcclComm->GetInCclBuf(commInputPtr, commInputSize));
     869            0 :     return HCCL_SUCCESS;
     870              : }
     871              :  
     872            0 : HcclResult HcomGraphGetOutCclBufV2(const int64_t &hcomComm, void *&commOutputPtr, u64 &commOutputSize)
     873              : {
     874            0 :     HCCL_INFO("[%s] start.", __func__);
     875            0 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator *>(hcomComm);
     876            0 :     CHK_RET(hcclComm->CreateCommCclBuf());
     877            0 :     CHK_RET(hcclComm->GetOutCclBuf(commOutputPtr, commOutputSize));
     878            0 :     return HCCL_SUCCESS;
     879              : }
     880              :  
     881            1 : HcclResult HcclCommGraphGetRankIdV2(s64 opBaseHcom, u32 *rankId)
     882              : {
     883            3 :     HCCL_INFO("[%s] start.", __func__);
     884            1 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator *>(opBaseHcom);
     885            1 :     CHK_RET(hcclComm->GetRankId(*rankId));
     886            1 :     return HCCL_SUCCESS;
     887              : }
     888              :  
     889            1 : HcclResult HcclCommGraphGetRankSizeV2(s64 opBaseHcom, u32 *rankSize)
     890              : {
     891            3 :     HCCL_INFO("[%s] start.", __func__);
     892            1 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator *>(opBaseHcom);
     893            1 :     CHK_RET(hcclComm->GetRankSize(rankSize));
     894            1 :     return HCCL_SUCCESS;
     895              : }
     896              :  
     897            1 : HcclResult HcclCommGraphAllGatherV2(const char *tag, void *inputPtr, void *outputPtr, u64 inputCount,
     898              :                                     HcclDataType dataType, s64 opBaseHcom, rtStream_t stream)
     899              : {
     900            3 :     HCCL_INFO("[%s] start.", __func__);
     901              :  
     902            1 :     HcclUs startut = TIME_NOW();
     903              :     
     904              :     /* 通信域 */  
     905            1 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator*>(opBaseHcom);
     906            1 :     CHK_PTR_NULL(hcclComm);
     907              : 
     908              :     /* 入参校验 */
     909            1 :     CHK_RET(HcomCheckOpParamV2(tag, inputCount, dataType, stream));
     910              : 
     911              :     /* 入参的正确性由HCCL确保 */
     912            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, outputPtr, inputCount, dataType, Hccl::OpType::ALLGATHER);
     913            1 :     std::string opTag = tag;
     914            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     915              :  
     916              :     /* 关键状态记录 */
     917            3 :     HCCL_RUN_INFO("hcom graph allgather success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
     918              :         "inputCount[%llu], data_type[%d]", DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr,
     919              :         inputCount, dataType);
     920              :  
     921            1 :     return HCCL_SUCCESS;
     922            1 : }
     923              :  
     924            1 : HcclResult HcomGraphAllReduceV2(const char *tag, void *inputPtr, void *outputPtr, u64 count, HcclDataType dataType,
     925              :                                 HcclReduceOp op, s64 opBaseHcom, rtStream_t stream)
     926              : {
     927            3 :     HCCL_INFO("[%s] start.", __func__);
     928              :  
     929            1 :     HcclUs startut = TIME_NOW();
     930              :     
     931              :     /* 通信域 */  
     932            1 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator*>(opBaseHcom);
     933            1 :     CHK_PTR_NULL(hcclComm);
     934              : 
     935              :     /* 入参校验 */
     936            1 :     CHK_RET(HcomCheckReductionOpV2(op));
     937            1 :     CHK_RET(HcomCheckReduceDataTypeV2(dataType, op));
     938            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, stream));
     939              : 
     940              :     /* 入参的正确性由HCCL确保 */
     941            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, outputPtr, count, dataType, Hccl::OpType::ALLREDUCE, op);
     942            1 :     std::string opTag = tag;
     943            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     944              :  
     945              :     /* 关键状态记录 */
     946            3 :     HCCL_RUN_INFO("hcom allreduce success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
     947              :                   "count[%llu], data_type[%d], op[%d]",
     948              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, count, dataType, op);
     949              :  
     950            1 :     return HCCL_SUCCESS;
     951            1 : }
     952              :  
     953            1 : HcclResult HcomGraphReduceScatterV2(const char *tag, void *inputPtr, void *outputPtr, u64 count, HcclDataType dataType,
     954              :                                     HcclReduceOp op, s64 opBaseHcom, rtStream_t &stream)
     955              : {
     956            3 :     HCCL_INFO("[%s] start.", __func__);
     957              :  
     958            1 :     HcclUs startut = TIME_NOW();
     959              :  
     960              :     /* 入参校验 */
     961            1 :     CHK_RET(HcomCheckReductionOpV2(op));
     962            1 :     CHK_RET(HcomCheckReduceDataTypeV2(dataType, op));
     963            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, stream));
     964              : 
     965              :     /* 通信域 */  
     966            1 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator*>(opBaseHcom);
     967            1 :     CHK_PTR_NULL(hcclComm);
     968              :  
     969              :     /* 入参的正确性由HCCL确保 */
     970            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, outputPtr, count, dataType, Hccl::OpType::REDUCESCATTER, op);
     971            1 :     std::string opTag = tag;
     972            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
     973              :     /* 关键状态记录 */
     974            3 :     HCCL_RUN_INFO("hcom reducescatter success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "\
     975              :         "inputCount[%llu], data_type[%d]", DURATION_US(TIME_NOW() - startut), tag, inputPtr,
     976              :         outputPtr, count, dataType);
     977              :  
     978            1 :     return HCCL_SUCCESS;
     979            1 : }
     980              :  
     981            1 : HcclResult HcomGraphReduceV2(const char *tag, void *inputPtr, void *outputPtr, u64 count, HcclDataType dataType,
     982              :                              HcclReduceOp op, u32 root, s64 opBaseHcom, rtStream_t stream)
     983              : {
     984            3 :     HCCL_INFO("[%s] start.", __func__);
     985              :  
     986            1 :     HcclUs startut = TIME_NOW();
     987              :  
     988              :     /* 入参校验 */
     989            1 :     CHK_RET(HcomCheckReductionOpV2(op));
     990            1 :     CHK_RET(HcomCheckReduceDataTypeV2(dataType, op));
     991            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, stream));
     992              : 
     993              :     /* 通信域 */
     994            1 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator*>(opBaseHcom);
     995            1 :     CHK_PTR_NULL(hcclComm);
     996              :  
     997              :     /* 入参的正确性由HCCL确保 */
     998            1 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
     999            1 :     CHK_RET(hcclComm->GetRankSize(&rankSize));
    1000            1 :     CHK_RET(HcomCheckUserRankV2(rankSize, root));
    1001            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, outputPtr, count, dataType, Hccl::OpType::REDUCE, op);
    1002            1 :     opParams.root = root;
    1003            1 :     std::string opTag = tag;
    1004            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
    1005              :  
    1006              :     /* 关键状态记录 */
    1007            3 :     HCCL_RUN_INFO("hcom reduce success, take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], "\
    1008              :         "data_type[%s], op[%s], root[%u]", DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, count,
    1009              :         GetDataTypeEnumStrV2(dataType).c_str(), GetReduceOpEnumStrV2(op).c_str(), root);
    1010              :  
    1011            1 :     return HCCL_SUCCESS;
    1012            1 : }
    1013              :  
    1014            1 : HcclResult HcomGraphSendV2(const char *tag, void *inputPtr, u64 count, HcclDataType dataType, u32 destRank, u32 srTag,
    1015              :                            s64 opBaseHcom, rtStream_t &stream)
    1016              : {
    1017            3 :     HCCL_INFO("[%s] start.", __func__);
    1018              :  
    1019            1 :     HcclUs startut = TIME_NOW();
    1020              :     
    1021              :     /* 通信域 */
    1022            1 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator*>(opBaseHcom);
    1023            1 :     CHK_PTR_NULL(hcclComm);
    1024              : 
    1025              :     /* 入参校验 */
    1026            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, stream));
    1027              : 
    1028              :     /* 入参的正确性由HCCL确保 */
    1029            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, nullptr, count, dataType, Hccl::OpType::SEND);
    1030            1 :     opParams.dstRank = destRank;
    1031            1 :     std::string opTag = tag;
    1032            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
    1033              :     /* 关键状态记录 */
    1034            3 :     HCCL_RUN_INFO("hcom send success,time[%lld]us,tag[%s],inputPtr[%p],count[%llu],dataType[%s],destRank[%u],"
    1035              :         "srTag[%u]",
    1036              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, count, GetDataTypeEnumStrV2(dataType).c_str(), destRank, srTag);
    1037              :  
    1038            1 :     return HCCL_SUCCESS;
    1039            1 : }
    1040              :  
    1041            1 : HcclResult HcomGraphReceiveV2(const char *tag, void *outputPtr, u64 count, HcclDataType dataType, u32 srcRank,
    1042              :                               u32 srTag, s64 opBaseHcom, rtStream_t &stream)
    1043              : {
    1044            3 :     HCCL_INFO("[%s] start.", __func__);
    1045              :  
    1046            1 :     HcclUs startut = TIME_NOW();
    1047              :  
    1048              :     /* 通信域 */
    1049            1 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator*>(opBaseHcom);
    1050            1 :     CHK_PTR_NULL(hcclComm);
    1051              : 
    1052              :     /* 入参校验 */
    1053            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, stream));
    1054              : 
    1055              :     /* 入参的正确性由HCCL确保 */
    1056            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(nullptr, outputPtr, count, dataType, Hccl::OpType::RECV);
    1057            1 :     opParams.dstRank = srcRank;
    1058            1 :     std::string opTag = tag;
    1059            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
    1060              :     /* 关键状态记录 */
    1061            3 :     HCCL_RUN_INFO("hcom receive success,time[%lld]us,tag[%s],outputPtr[%p],count[%llu],dataType[%s],srcRank[%u],"
    1062              :         "srTag[%u]",
    1063              :         DURATION_US(TIME_NOW() - startut), tag, outputPtr, count, GetDataTypeEnumStrV2(dataType).c_str(), srcRank, srTag); 
    1064            1 :     return HCCL_SUCCESS;
    1065            1 : }
    1066              :  
    1067            1 : HcclResult HcomGraphBroadcastV2(const char *tag, void *ptr, u64 count, HcclDataType dataType, u32 root,
    1068              :                                 s64 opBaseHcom, rtStream_t stream)
    1069              : {
    1070            3 :     HCCL_INFO("[%s] start.", __func__);
    1071              :  
    1072            1 :     HcclUs startut = TIME_NOW();
    1073              :  
    1074              :     /* 通信域 */
    1075            1 :     Hccl::HcclCommunicator* hcclComm = reinterpret_cast<Hccl::HcclCommunicator*>(opBaseHcom);
    1076            1 :     CHK_PTR_NULL(hcclComm);
    1077              : 
    1078              :     /* 入参校验 */
    1079            1 :     CHK_RET(HcomCheckOpParamV2(tag, count, dataType, stream));
    1080              : 
    1081              :     /* 入参的正确性由HCCL确保 */
    1082            1 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    1083            1 :     CHK_RET(hcclComm->GetRankSize(&rankSize));
    1084            1 :     CHK_RET(HcomCheckUserRankV2(rankSize, root));
    1085            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(ptr, ptr, count, dataType, Hccl::OpType::BROADCAST);
    1086            1 :     opParams.root = root;
    1087            1 :     std::string opTag = tag;
    1088            1 :     CHK_RET(hcclComm->LoadOffloadCollOp(opTag, opParams, stream));
    1089              :  
    1090              :     /* 关键状态记录 */
    1091            3 :     HCCL_RUN_INFO("hcom broadcast success,take time [%lld]us,tag[%s], input_ptr[%p], count[%llu], data_type[%s], "\
    1092              :         "root[%u]", DURATION_US(TIME_NOW() - startut), tag, ptr, count, GetDataTypeEnumStrV2(dataType).c_str(), root);
    1093            1 :     return HCCL_SUCCESS;
    1094            1 : }
    1095              : 
    1096            1 : HcclResult HcomGetDevTypeV2(Hccl::DevType &devType)
    1097              : {
    1098            3 :     HCCL_INFO("[%s] start.", __func__);
    1099            1 :     HcclCommInfoV2 &hcomCommInfoV2 = GetCommInfoV2();
    1100            1 :     devType = hcomCommInfoV2.commParams.devType;
    1101            3 :     HCCL_INFO("HcomGetDevTypeV2, devType[%s]", devType.Describe().c_str());
    1102            1 :     return HCCL_SUCCESS;
    1103              : }
    1104              : 
    1105            1 : HcclResult HcomGetDevIdV2(const char *group, s32 *devId)
    1106              : {
    1107            3 :     HCCL_INFO("[%s] start.", __func__);
    1108            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1109            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1110              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1111              :             HCCL_E_NOT_FOUND);
    1112            1 :     auto retDevId = static_cast<s32>(hcclComm->GetDeviceLogicId());
    1113            1 :     *devId = retDevId;
    1114            3 :     HCCL_INFO("HcomGetDeviceIdV2, devId[%d]", *devId);
    1115            1 :     return HCCL_SUCCESS;
    1116            1 : }
    1117              : 
    1118            1 : HcclResult HcomSetGlobalWorkSpaceV2(const char *group, const std::vector<void *> &globalWorkSpaceAddr)
    1119              : {   
    1120            3 :     HCCL_INFO("[%s] start.", __func__);
    1121              :     (void)globalWorkSpaceAddr;
    1122            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1123            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1124              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1125              :             HCCL_E_NOT_FOUND);
    1126            1 :     CHK_RET(hcclComm->SetGlobalWorkSpace());
    1127            1 :     return HCCL_SUCCESS;
    1128            1 : }
    1129              : 
    1130            0 : HcclResult HcomGetInitStatusV2(bool &initiated)
    1131              : {
    1132            0 :     HCCL_INFO("[%s] start.", __func__);
    1133            0 :     HcclCommInfoV2 &hcomCommInfoV2 = GetCommInfoV2();
    1134            0 :     initiated                      = !(hcomCommInfoV2.pComm == nullptr);
    1135            0 :     HCCL_INFO("[%s] initiated[%d].", __func__, initiated);
    1136            0 :     return HCCL_SUCCESS;
    1137              : }
    1138              : 
    1139              : /* 实现和1.0一致,获取到通信域指针后就返回成功 */
    1140            1 : HcclResult HcomCheckCommValidityV2(const char *group)
    1141              : {
    1142            3 :     HCCL_INFO("[%s] start.", __func__);
    1143            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1144            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1145              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1146              :             HCCL_E_NOT_FOUND);
    1147            1 :     return HCCL_SUCCESS;
    1148            1 : }
    1149              : 
    1150            1 : HcclResult HcomSupportDeterministicOptimV2(const char *group, bool &isDeterministicOptim)
    1151              : {
    1152            3 :     HCCL_INFO("[%s] start.", __func__);
    1153            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1154            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1155              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1156              :             HCCL_E_NOT_FOUND);
    1157            1 :     isDeterministicOptim = true;
    1158            3 :     HCCL_WARNING("HcomSupportDeterministicOptimV2 does not support at A5! set isDeterministicOptim to true.");
    1159            1 :     return HCCL_SUCCESS;
    1160            1 : }
    1161              : 
    1162            1 : HcclResult HcomSetAivCoreLimitV2(const char *group, u32 aivCoreLimit)
    1163              : {
    1164            3 :     HCCL_INFO("[%s] start.", __func__);
    1165            1 :     CHK_PRT_RET(aivCoreLimit == 0,
    1166              :         HCCL_ERROR("[HcomSetAivCoreLimitV2] aivCoreLimit[%u] invalid", aivCoreLimit), HCCL_E_PARA);
    1167            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1168            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1169              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1170              :             HCCL_E_NOT_FOUND);
    1171            1 :     CHK_RET(hcclComm->SetAivCoreLimit(aivCoreLimit));
    1172            3 :     HCCL_RUN_INFO("HcomSetAivCoreLimitV2 group[%s] aivCoreLimit[%u]", group ? group : HCCL_WORLD_GROUP, aivCoreLimit);
    1173            1 :     return HCCL_SUCCESS;
    1174            1 : }
    1175              : 
    1176            1 : HcclResult HcomSetQosCfgV2(const char *group, const u32 qosCfg)
    1177              : {
    1178            3 :     HCCL_INFO("[%s] start.", __func__);
    1179            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1180            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1181              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1182              :             HCCL_E_NOT_FOUND);
    1183              :     (void)qosCfg;
    1184            3 :     HCCL_WARNING("HcomSetQosCfgV2 does not support at A5!");
    1185            1 :     return HCCL_SUCCESS;
    1186            1 : }
    1187              : 
    1188           31 : HcclResult HcomGraphSelectAlgV2(s64 comm, const char *group, HcclCMDType opType, u64 count, HcclDataType dataType, HcclReduceOp op,
    1189              :                            int32_t aivCoreLimit, bool &ifAiv, std::string &algName)
    1190              : {
    1191           93 :     HCCL_INFO("[%s] start.", __func__);
    1192              :     (void)comm;
    1193           31 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1194           31 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1195              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1196              :             HCCL_E_NOT_FOUND);
    1197              : 
    1198           31 :     CHK_RET(HcomCheckOpParamV2(count, dataType, group));
    1199              : 
    1200           31 :     HcclOpType hcclOpType = static_cast<HcclOpType::Value>(opType);
    1201           31 :     if (OP_TYPE_MAP.find(opType) == OP_TYPE_MAP.end()) {
    1202            3 :         HCCL_ERROR("[HcomGraphSelectAlgV2], does not support opType[%s].", hcclOpType.Describe().c_str());
    1203            1 :         return HCCL_E_NOT_SUPPORT;
    1204              :     }
    1205           30 :     Hccl::OpType optype = OP_TYPE_MAP.at(opType);
    1206           30 :     Hccl::CollOpParams opParams = GetHcclOpParams(nullptr, nullptr, count, dataType, optype, op, true);
    1207           36 :     CHK_RET(hcclComm->ExecAlgSelect(opParams, aivCoreLimit, ifAiv, algName));
    1208           28 :     return HCCL_SUCCESS;
    1209           31 : }
    1210              : 
    1211           28 : HcclResult HcomSelectAlgV2(s64 comm, const char *group, HcclCMDType opType, u64 count, HcclDataType dataType, HcclReduceOp op,
    1212              :                                 int32_t aivCoreLimit, bool &ifAiv, std::string &algName)
    1213              : {
    1214              :     /* 通信域 */
    1215           84 :     HCCL_INFO("[%s] start.", __func__);
    1216              :     (void)group;
    1217           28 :     Hccl::HcclCommunicator *hcclComm = reinterpret_cast<Hccl::HcclCommunicator *>(comm);
    1218              : 
    1219           28 :     CHK_RET(HcomCheckOpParamV2(count, dataType));
    1220              : 
    1221           28 :     HcclOpType hcclOpType = static_cast<HcclOpType::Value>(opType);
    1222           28 :     if (OP_TYPE_MAP.find(opType) == OP_TYPE_MAP.end()) {
    1223            3 :         HCCL_ERROR("[HcomSelectAlgV2], does not support opType[%s].", hcclOpType.Describe().c_str());
    1224            1 :         return HCCL_E_NOT_SUPPORT;
    1225              :     }
    1226           27 :     Hccl::OpType optype = OP_TYPE_MAP.at(opType);
    1227           27 :     Hccl::CollOpParams opParams = GetHcclOpParams(nullptr, nullptr, count, dataType, optype, op, true);
    1228           27 :     CHK_RET(hcclComm->ExecAlgSelect(opParams, aivCoreLimit, ifAiv, algName));
    1229           27 :     return HCCL_SUCCESS;
    1230           27 : }
    1231              : 
    1232            1 : HcclResult HcomUnloadTaskV2(const std::string group, const char *tag)
    1233              : {
    1234            3 :     HCCL_INFO("[%s] start.", __func__);
    1235            1 :     HcclUs startut = TIME_NOW();
    1236            1 :     CHK_RET(HcomCheckGroupNameV2(group.c_str()));
    1237            1 :     CHK_RET(HcomCheckTagV2(tag));
    1238            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1239            1 :     HcclResult ret = GetHcclCommV2(group.c_str(), hcclComm);
    1240            1 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1241              :                 HCCL_WARNING("[HcomUnloadTaskV2]errNo[0x%016llx] group[%s] group is not exist",
    1242              :                     HCOM_ERROR_CODE(HCCL_E_NOT_FOUND), group.c_str()),
    1243              :                 HCCL_SUCCESS);
    1244            1 :     std::string opTag = tag;
    1245            1 :     CHK_RET(hcclComm->ClearOpResource(opTag));
    1246            3 :     HCCL_RUN_INFO("hcom unload task success,take time [%lld]us,tag[%s]", DURATION_US(TIME_NOW() - startut), tag);
    1247            1 :     return HCCL_SUCCESS;
    1248            1 : }
    1249              : 
    1250            0 : HcclResult HcclCommResetQosCfgV2()
    1251              : {
    1252            0 :     HCCL_WARNING("HcclCommResetQosCfgV2 does not support!");
    1253            0 :     return HCCL_SUCCESS;
    1254              : }
    1255              : 
    1256            0 : HcclResult HcomResetQosCfgV2()
    1257              : {
    1258            0 :     HCCL_WARNING("HcomGetCommCCLBufferSizeV2 does not support!");
    1259            0 :     return HCCL_SUCCESS;
    1260              : }
    1261              : 
    1262            0 : HcclResult HcclCommSetQosCfgV2()
    1263              : {
    1264            0 :     HCCL_WARNING("HcclCommSetQosCfgV2 does not support!");
    1265            0 :     return HCCL_SUCCESS;
    1266              : }
    1267              : 
    1268            1 : HcclResult HcomGetCommCCLBufferSizeV2()
    1269              : {
    1270            3 :     HCCL_WARNING("HcomGetCommCCLBufferSizeV2 does not support!");
    1271            1 :     return HCCL_SUCCESS;
    1272              : }
    1273              : 
    1274            1 : HcclResult HcomSetAivClearEnableV2(const char *group, bool aivClearEnable)
    1275              : {
    1276            3 :     HCCL_INFO("[%s] start.", __func__);
    1277            1 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1278            1 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1279              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1280              :             HCCL_E_NOT_FOUND);
    1281            1 :     CHK_RET(HcomCheckGroupNameV2(group));
    1282              :  
    1283            1 :     CHK_RET(hcclComm->SetAivClearEnable(aivClearEnable));
    1284            3 :     HCCL_INFO("[%s] end.", __func__);
    1285            1 :     return HCCL_SUCCESS;
    1286            1 : }
    1287              : 
    1288            2 : HcclResult HcomCalcNumBlocksV2(const char *group, HcclCMDType opType, u64 count, HcclDataType dataType, int32_t aivCoreLimit,
    1289              :         std::string &algName, u32 &numBlocks)
    1290              : {
    1291            6 :     HCCL_INFO("[%s] start.", __func__);
    1292            2 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1293            2 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1294              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1295              :             HCCL_E_NOT_FOUND);
    1296              : 
    1297            2 :     CHK_RET(HcomCheckOpParamV2(count, dataType, group));
    1298              : 
    1299            2 :     HcclOpType hcclOpType = static_cast<HcclOpType::Value>(opType);
    1300            2 :     if (OP_TYPE_MAP.find(opType) == OP_TYPE_MAP.end()) {
    1301            3 :         HCCL_ERROR("[HcomGraphSelectAlgV2], does not support opType[%s].", hcclOpType.Describe().c_str());
    1302            1 :         return HCCL_E_NOT_SUPPORT;
    1303              :     }
    1304            1 :     Hccl::OpType optype = OP_TYPE_MAP.at(opType);
    1305            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(nullptr, nullptr, count, dataType, optype, HCCL_REDUCE_RESERVED,true);
    1306            1 :     CHK_RET(hcclComm->CalcNumBlocks(opParams, aivCoreLimit, algName, numBlocks));
    1307            3 :     HCCL_INFO("[%s] end.", __func__);
    1308            1 :     return HCCL_SUCCESS;
    1309            2 : }
    1310              : 
    1311            2 : HcclResult HcclGetAlgExecParamV2(const std::string &tag, const char *group, u64 count, void *inputPtr, void *outputPtr,
    1312              :                                  HcclCMDType opType, bool clearEnable, HcclDataType dataType, HcclReduceOp op,
    1313              :                                  void *&commContext, u64 &len, u32 aivCoreLimit)
    1314              : {
    1315            6 :     HCCL_INFO("[%s] start.", __func__);
    1316            2 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1317            2 :     CHK_PRT_RET(GetHcclCommV2(group, hcclComm) == HCCL_E_NOT_FOUND, 
    1318              :             HCCL_ERROR("comm with group name [%s] is not found", group == nullptr ? HCCL_WORLD_GROUP : group),
    1319              :             HCCL_E_NOT_FOUND);
    1320              : 
    1321            2 :     CHK_RET(HcomCheckOpParamV2(count, dataType, group));
    1322              : 
    1323            2 :     HcclOpType hcclOpType = static_cast<HcclOpType::Value>(opType);
    1324            2 :     if (OP_TYPE_MAP.find(opType) == OP_TYPE_MAP.end()) {
    1325            3 :         HCCL_ERROR("[HcomGraphSelectAlgV2], does not support opType[%s].", hcclOpType.Describe().c_str());
    1326            1 :         return HCCL_E_NOT_SUPPORT;
    1327              :     }
    1328            1 :     Hccl::OpType optype = OP_TYPE_MAP.at(opType);
    1329            1 :     Hccl::CollOpParams opParams = GetHcclOpParams(inputPtr, outputPtr, count, dataType, optype, op, true);
    1330            1 :     opParams.opTag              = tag;
    1331            1 :     CHK_RET(hcclComm->GetAlgExecParam(opParams, clearEnable, commContext, len, aivCoreLimit));
    1332            3 :     HCCL_INFO("[%s] end.", __func__);
    1333            1 :     return HCCL_SUCCESS;
    1334            2 : }
    1335              : 
    1336              : #ifdef __cplusplus
    1337              : extern "C" {
    1338              : #endif // __cplusplus
    1339            0 : HcclResult HcomGetL0TopoTypeExV2(const char *group, CommTopo *topoType, uint32_t flag)
    1340              : {
    1341            0 :     CHK_PTR_NULL(topoType);
    1342            0 :     CHK_PTR_NULL(group);
    1343              : 
    1344            0 :     bool isSetDevice = static_cast<bool>(flag & (~(0xfffffffe)));
    1345            0 :     if (isSetDevice) {
    1346            0 :         HCCL_ERROR("current only support no setdevice, flag[%u]", flag);
    1347            0 :         return HCCL_E_PARA;
    1348              :     }
    1349              : 
    1350            0 :     std::string identifier(group);
    1351            0 :     return CommTopoDesc::GetInstance().GetL0TopoType(identifier, topoType);
    1352            0 : }
    1353              : 
    1354            0 : HcclResult HcomGetRankSizeExV2(const char *group, uint32_t *rankSize, uint32_t flag)
    1355              : {
    1356            0 :     CHK_PTR_NULL(rankSize);
    1357            0 :     CHK_PTR_NULL(group);
    1358              : 
    1359            0 :     bool isSetDevice = static_cast<bool>(flag & (~(0xfffffffe)));
    1360            0 :     if (isSetDevice) {
    1361            0 :         HCCL_ERROR("current only support no setdevice, flag[%u]", flag);
    1362            0 :         return HCCL_E_PARA;
    1363              :     }
    1364              : 
    1365            0 :     std::string identifier(group);
    1366            0 :     return CommTopoDesc::GetInstance().GetRankSize(identifier, rankSize);
    1367            0 : }
    1368              : 
    1369            0 : HcclResult HcomMc2AiCpuStreamAllocAndGetV2(const char *group, u32 streamMode, rtStream_t *aiCpuStream)
    1370              : {
    1371            0 :     CHK_PTR_NULL(group);
    1372            0 :     CHK_PTR_NULL(aiCpuStream);
    1373              :     (void)streamMode;
    1374              : 
    1375            0 :     std::shared_ptr<Hccl::HcclCommunicator> hcclComm;
    1376            0 :     CHK_RET(GetHcclCommV2(group, hcclComm));
    1377            0 :     CHK_RET(hcclComm->Mc2AiCpuStreamAllocAndGetV2(aiCpuStream));
    1378            0 :     CHK_PTR_NULL(*aiCpuStream);
    1379            0 :     return HCCL_SUCCESS;
    1380            0 : }
    1381              : 
    1382            0 : HcclResult HcomSetAttachedStreamV2()
    1383              : {
    1384            0 :     HCCL_WARNING("HcomSetAttachedStreamV2 does not support!");
    1385            0 :     return HCCL_SUCCESS;
    1386              : }
    1387              : 
    1388            0 : HcclResult HcomReleaseSubCommsV2()
    1389              : {
    1390            0 :     HCCL_WARNING("HcomReleaseSubCommsV2 does not support!");
    1391            0 :     return HCCL_SUCCESS;
    1392              : }
    1393              : 
    1394              : #ifdef __cplusplus
    1395              : }
    1396              : #endif // __cplusplus
        

Generated by: LCOV version 2.0-1