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

Generated by: LCOV version 2.0-1