LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/hcom - hcom.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 4.3 % 2444 105
Test Date: 2026-08-18 17:47:01 Functions: 3.9 % 154 6

            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 "hcom_private.h"
      18              : #include "config.h"
      19              : #include "externalinput_pub.h"
      20              : #include "workflow_pub.h"
      21              : #include "gradient_segment.h"
      22              : #include "hccl/base.h"
      23              : #include "rank_consistentcy_checker.h"
      24              : #include "param_check_pub.h"
      25              : #include "comm_configer.h"
      26              : 
      27              : #include "../common/src/topo/topoinfo_detect.h"
      28              : #include "profiling_manager.h"
      29              : #include "../op_base/src/op_base.h"
      30              : #include "adapter_rts_common.h"
      31              : #include "adapter_prof.h"
      32              : #include "topoinfo_ranktableParser_pub.h"
      33              : #include "hccl_communicator.h"
      34              : #include "hccl/hcom.h"
      35              : #include "topoinfo_ranktableOffline.h"
      36              : #include "mmpa_api.h"
      37              : #include "hccl_tbe_task.h"
      38              : #include "hcom_private_v2.h"
      39              : #include "comm_topo_desc.h"
      40              : #include "hcom_common.h"
      41              : #include "hcom_pub.h"
      42              : 
      43              : using namespace std;
      44              : using namespace hccl;
      45              : 
      46            0 : HcclResult CallMsprofReportHostApi(
      47              :     hccl::hcclComm* hcclComm, HcclCMDType cmdType, uint64_t beginTime, u64 count, HcclDataType dataType)
      48              : {
      49            0 :     auto& profilingManager = hccl::ProfilingManager::Instance();
      50            0 :     AlgType algType;
      51            0 :     if (cmdType == HcclCMDType::HCCL_CMD_RECEIVE || cmdType == HcclCMDType::HCCL_CMD_SEND) {
      52            0 :         algType.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_RESERVED;
      53            0 :         algType.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_RESERVED;
      54              :     } else {
      55            0 :         CHK_RET(hcclComm->GetAlgType(algType, cmdType));
      56              :     }
      57            0 :     uint64_t groupName = hrtMsprofGetHashId(hcclComm->GetIdentifier().c_str(), hcclComm->GetIdentifier().length());
      58            0 :     CHK_RET(profilingManager.CallMsprofReportHostApi(cmdType, beginTime, count, dataType, algType, groupName));
      59            0 :     hcclComm->SetAivCoreLimit(0);
      60            0 :     HCCL_DEBUG(
      61              :         "CallMsprofReportHostApi success, cmdType[%d], count[%llu], dataType[%d], algType[%d], groupName[%llu]",
      62              :         cmdType, count, dataType, algType.algoLevel0, groupName);
      63            0 :     return HCCL_SUCCESS;
      64              : }
      65              : 
      66              : HcclResult HcomCheckInitClusterInfo(const char* rankTableM, const char* identify);
      67              : HcclResult HcomFlushBackloggedGroups();
      68              : HcclResult HcomCollRemotePairedParaCheck(const HcomRemoteOperationParams& params);
      69              : 
      70            0 : HcclResult HcomInit(const char* rankTableM, const char* identify, WorkMode commWorkMode)
      71              : {
      72            0 :     HcclResult ret = HCCL_SUCCESS;
      73            0 :     bool& isAutoTuneModeOpen = HcomGetCtxAutoTuneMode();
      74            0 :     isAutoTuneModeOpen = false;
      75            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
      76              : 
      77              :     /*--------------入参合法性检测---------------------*/
      78            0 :     CHK_PTR_NULL(rankTableM);
      79            0 :     CHK_PTR_NULL(identify);
      80              : 
      81              :     /* 防止重复调用初始化 */
      82            0 :     CHK_PRT_RET(
      83              :         (hcomInfo.pComm != nullptr),
      84              :         HCCL_ERROR(
      85              :             "[Init][Result]errNo[0x%016llx] identify[%s], "
      86              :             "multiple initialization is not supported",
      87              :             HCOM_ERROR_CODE(HCCL_E_UNAVAIL), identify),
      88              :         HCCL_E_UNAVAIL);
      89              : 
      90              :     /* --------------初始化------------------------- */
      91            0 :     bool errorFlag = false;
      92            0 :     s32 logicDevId = 0;
      93            0 :     hcomInfo.params.commWorkMode = commWorkMode;
      94              :     do {
      95            0 :         ret = InitHcomMiscInfo(hcomInfo.params, rankTableM);
      96            0 :         CHK_PRT_BREAK(
      97              :             ret != HCCL_SUCCESS, HCCL_ERROR("[Init][Result]errNo[0x%016llx] init other Info.", HCOM_ERROR_CODE(ret)),
      98              :             errorFlag = true);
      99              : 
     100              :         DevType deviceType;
     101            0 :         if (commWorkMode != HCCL_MODE_SCHED_OS) {
     102            0 :             CHK_PRT_BREAK(hrtGetDevice(&logicDevId) != HCCL_SUCCESS, , errorFlag = true);
     103            0 :             CHK_RET(hrtGetDeviceType(deviceType));
     104              :             // 为适配12包,做此修改
     105            0 :             (void)HcomCheckrtMemcpyAddrAsync(identify);
     106              :         } else {
     107            0 :             deviceType = DevType::DEV_TYPE_NOSOC;
     108              :         }
     109            0 :         ret = CfgGetClusterInfo(
     110            0 :             rankTableM, identify, hcomInfo.params, hcomInfo.rankTable, GetExternalInputInterSuperPodRetryEnable(),
     111              :             deviceType);
     112            0 :         CHK_PRT_BREAK(
     113              :             ret != HCCL_SUCCESS,
     114              :             HCCL_ERROR(
     115              :                 "[Init][Result]errNo[0x%016llx] cfg get ranktable[%p] info "
     116              :                 "error: identify[%s]",
     117              :                 HCOM_ERROR_CODE(ret), rankTableM, identify),
     118              :             errorFlag = true);
     119              : 
     120              :         // HCCL_MODE_SCHED_OS仅在910A等同构集合通信场景才存在,此处仅希望异构资源池化场景进入
     121            0 :         if (commWorkMode != HCCL_MODE_SCHED_OS) {
     122              :             /*
     123              :             此case仅希望310 soc形态才能进入(此时有reacource.json来配置通信协议)
     124              :             但是310有板卡形态有可能进入(无reacource.json),因此设定serverNum!=1的条件
     125              :             因为310板卡形态跑大模型切分(AllReduce)当前都是单机(serverNum=1),因此无需通信协议解析
     126              :             */
     127            0 :             if (hcomInfo.rankTable.serverNum != SINGLE_SERVER_NUM
     128            0 :                 && (deviceType == DevType::DEV_TYPE_310P3 || deviceType == DevType::DEV_TYPE_310P1)) {
     129            0 :                 CHK_RET(InitExternalInputHeterog());
     130              :             }
     131              :         }
     132              : 
     133              :         const char* group;
     134              : 
     135            0 :         hcomInfo.pComm.reset(new (std::nothrow) hccl::hcclComm(0, 0, HCCL_WORLD_GROUP));
     136              : 
     137            0 :         CHK_PRT_RET(
     138              :             hcomInfo.pComm == nullptr,
     139              :             HCCL_ERROR("[Init][Result]hcomInfo.pComm is null, "
     140              :                        "create failed"),
     141              :             HCCL_E_PTR);
     142            0 :         CommConfig commConfig(HCCL_WORLD_GROUP);
     143            0 :         ret = hcomInfo.pComm->init(hcomInfo.params, commConfig, hcomInfo.rankTable);
     144            0 :         CHK_PRT_BREAK(
     145              :             ret != HCCL_SUCCESS, HCCL_ERROR("[Init][Result]errNo[0x%016llx] hcclComm init error", HCOM_ERROR_CODE(ret)),
     146              :             errorFlag = true);
     147              : 
     148            0 :         group = hcomInfo.pComm->GetIdentifier().c_str();
     149              : 
     150            0 :         ret = ShowRanktableConfigInfo(hcomInfo.cloudFlag, hcomInfo.params, hcomInfo.rankTable);
     151            0 :         CHK_PRT_BREAK(
     152              :             ret != HCCL_SUCCESS,
     153              :             HCCL_ERROR("[Init][Result]errNo[0x%016llx] put ranktable info error", HCOM_ERROR_CODE(ret)),
     154              :             errorFlag = true);
     155            0 :         if (commWorkMode != HCCL_MODE_SCHED_OS) {
     156            0 :             ret = InitWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB);
     157            0 :             CHK_PRT_BREAK(
     158              :                 ret != HCCL_SUCCESS,
     159              :                 HCCL_ERROR("[Init][Result]errNo[0x%016llx] init work flow mode error", HCCL_ERROR_CODE(ret)),
     160              :                 errorFlag = true);
     161              :         }
     162              : 
     163            0 :         ret = HcomFlushBackloggedGroups();
     164            0 :         CHK_PRT_BREAK(
     165              :             ret != HCCL_SUCCESS,
     166              :             HCCL_ERROR("[Init][Result]errNo[0x%016llx] create backlogged group failed", HCOM_ERROR_CODE(ret)),
     167              :             errorFlag = true);
     168              : 
     169            0 :         ret = HcomSetGroupTopoInfo(hcomInfo.pComm->GetIdentifier().c_str(), hcomInfo.rankTable.rankNum);
     170              : 
     171            0 :         CHK_PRT_BREAK(
     172              :             ret != HCCL_SUCCESS,
     173              :             HCCL_ERROR(
     174              :                 "[Init][Result]errNo[0x%016llx] SetGroupTopoInfo error, "
     175              :                 "group[%s]",
     176              :                 HCOM_ERROR_CODE(ret), group),
     177              :             errorFlag = true);
     178            0 :     } while (0);
     179              : 
     180            0 :     if (errorFlag) {
     181            0 :         HCCL_ERROR(
     182              :             "[Init][Result]hcom init failed, rankNum[%u], rank[%u], server[%s], device[%d], return[0x%016llx]",
     183              :             hcomInfo.rankTable.rankNum, hcomInfo.params.rank, hcomInfo.params.serverId.c_str(), logicDevId,
     184              :             HCOM_ERROR_CODE(ret));
     185            0 :         (void)HcomDestroy();
     186            0 :         return ret;
     187              :     }
     188            0 :     return HCCL_SUCCESS;
     189              : }
     190              : 
     191              : HcclResult
     192            0 : HcomInitByString(const char* rankTableM, const char* identify, WorkMode commWorkMode, HcomInitConfig* initConfig)
     193              : {
     194            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
     195            0 :     CHK_PTR_NULL(rankTableM);
     196            0 :     CHK_PTR_NULL(identify);
     197              : 
     198            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
     199              :         CHK_RET(HcomInitByStringV2(rankTableM, identify));
     200              :         s32 myRank = std::atoi(identify);
     201              :         Hccl::RankId rank = static_cast<Hccl::RankId>(myRank);
     202              :         void* commV2 = nullptr;
     203              :         CHK_RET(HcomGetCommV2(&commV2));
     204              :         CHK_RET(HcomInitCollComm(rank, &commV2, hcomInfo.pComm));
     205              :         u32 rankNum = 0;
     206              :         CHK_RET(HcomGetRankSize(HCCL_WORLD_GROUP, &rankNum));
     207              :         CHK_RET(HcomSetGroupTopoInfo(HCCL_WORLD_GROUP, rankNum));
     208              :         return HCCL_SUCCESS;
     209              :     }());
     210              : 
     211            0 :     if (initConfig != nullptr) {
     212              :         DevType devType;
     213            0 :         CHK_RET(hrtGetDeviceType(devType));
     214              : 
     215            0 :         CHK_RET(HcomSetAlgorithm(initConfig->algo));
     216            0 :         CHK_RET(HcomSetExecTimeOut(initConfig->execTimeOut));
     217            0 :         if (devType != DevType::DEV_TYPE_910_93) {
     218            0 :             CHK_RET(HcomSetDeterministic(initConfig->deterministic));
     219              :         } else {
     220            0 :             HCCL_WARNING("ParserHcclDeterministic: device type is 910_93, use default setting");
     221              :         }
     222              :     }
     223              : 
     224            0 :     HcclUs startut = TIME_NOW();
     225            0 :     HcclResult ret = HCCL_SUCCESS;
     226            0 :     CHK_RET(InitExternalInput());
     227            0 :     CHK_RET(InitEnvConfig());
     228            0 :     CHK_RET(HcomCheckInitClusterInfo(rankTableM, identify));
     229            0 :     HCCL_RUN_INFO(
     230              :         "Entry-HcomInitByString, rankTableM[%s], identify[%s], commWorkMode[%d]", rankTableM, identify, commWorkMode);
     231              : 
     232            0 :     ret = HcomInit(rankTableM, identify, commWorkMode);
     233              : 
     234            0 :     CHK_PRT_RET(
     235              :         ret != HCCL_SUCCESS,
     236              :         HCCL_ERROR(
     237              :             "[HcomInitByString]errNo[0x%016llx] rankTable[%p] identify[%s] "
     238              :             "hcom init failed.",
     239              :             HCCL_ERROR_CODE(ret), rankTableM, identify),
     240              :         ret);
     241            0 :     hcomInfo.isHcomInit = true;
     242              : 
     243              :     /* 关键状态记录 */
     244            0 :     HCCL_RUN_INFO(
     245              :         "[HCCL_TRACE]hcom init by string success,take time [%lld]us, rankTableAddr[%p], rankNum[%u], "
     246              :         "rank[%u]",
     247              :         DURATION_US(TIME_NOW() - startut), rankTableM, hcomInfo.rankTable.rankNum, hcomInfo.params.rank);
     248            0 :     return HCCL_SUCCESS;
     249              : }
     250              : 
     251            0 : HcclResult GenerateRootInfo(HcclRootHandle& rootInfo)
     252              : {
     253            0 :     std::string identifier = "hccl_world_group";
     254            0 :     CHK_PRT_RET(
     255              :         (identifier.length() >= ROOTINFO_INDENTIFIER_MAX_LENGTH),
     256              :         HCCL_ERROR("[Setup][Server]rootinfo identifier len[%zu] is invalid.", identifier.length()), HCCL_E_INTERNAL);
     257              :     s32 sret
     258            0 :         = memcpy_s(&rootInfo.identifier[0], sizeof(rootInfo.identifier), identifier.c_str(), (identifier.length() + 1));
     259            0 :     CHK_PRT_RET(
     260              :         sret != EOK,
     261              :         HCCL_ERROR(
     262              :             "[Setup][Server]errNo[0x%016llx] memcpy failed. ret[%d], params:"
     263              :             "destMaxSize[%zu],count[%zu]",
     264              :             HCOM_ERROR_CODE(HCCL_E_MEMORY), sret, sizeof(rootInfo.identifier), (identifier.length() + 1)),
     265              :         HCCL_E_MEMORY);
     266              : 
     267            0 :     s32 sRet = strncpy_s(
     268            0 :         rootInfo.ip, sizeof(rootInfo.ip), GetExternalInputMasterInfo().serverIp.GetReadableIP(),
     269            0 :         strlen(GetExternalInputMasterInfo().serverIp.GetReadableIP()));
     270            0 :     CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[Setup][Server]str copy fail. return[%d]", sRet), HCCL_E_INTERNAL);
     271              : 
     272            0 :     rootInfo.port = GetExternalInputMasterInfo().port;
     273            0 :     rootInfo.nicDeploy = NICDeployment::NIC_DEPLOYMENT_DEVICE;
     274            0 :     return HCCL_SUCCESS;
     275            0 : }
     276              : 
     277            0 : HcclResult HcomGenerteRanktable(std::string& rankTableM, std::string& rankId)
     278              : {
     279            0 :     s32 logicDevId = 0;
     280            0 :     u32 devPhyId = 0;
     281            0 :     CHK_RET(hrtGetDevice(&logicDevId));
     282            0 :     CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<u32>(logicDevId), devPhyId));
     283              : 
     284              :     // true代表感知白名单disable配置
     285            0 :     CHK_RET(HcclNetInit(NICDeployment::NIC_DEPLOYMENT_HOST, devPhyId, logicDevId, true));
     286              : 
     287            0 :     HcclIpAddress localHostIp;
     288            0 :     CHK_RET(GetLocalHostIP(localHostIp, devPhyId));
     289              :     HcclRootHandle rootHandle;
     290            0 :     CHK_RET(GenerateRootInfo(rootHandle));
     291              : 
     292            0 :     std::shared_ptr<TopoInfoDetect> topoDetectAgent;
     293            0 :     EXCEPTION_CATCH(topoDetectAgent = std::make_shared<TopoInfoDetect>(), return HCCL_E_PTR);
     294            0 :     std::shared_ptr<TopoInfoDetect> topoDetectServer;
     295            0 :     EXCEPTION_CATCH(topoDetectServer = std::make_shared<TopoInfoDetect>(), return HCCL_E_PTR);
     296              : 
     297              :     DevType devType;
     298            0 :     CHK_RET(hrtGetDeviceType(devType));
     299            0 :     bool retryEnable = devType == DevType::DEV_TYPE_910_93
     300            0 :                        && (GetExternalInputInterServerRetryEnable() || GetExternalInputInterSuperPodRetryEnable());
     301            0 :     HCCL_INFO("[HcomGenerteRanktable] retryEnable is [%d]", retryEnable);
     302            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
     303              : 
     304              :     bool isRoot
     305            0 :         = (localHostIp == GetExternalInputMasterInfo().serverIp
     306            0 :            && logicDevId == static_cast<s32>(GetExternalInputMasterInfo().serverDeviceId));
     307            0 :     if (isRoot) {
     308              :         HcclResult ret
     309            0 :             = topoDetectServer->SetupServerByMasterInfo(localHostIp, GetExternalInputMasterInfo().port, rootHandle);
     310            0 :         CHK_PRT_RET(
     311              :             ret != HCCL_SUCCESS,
     312              :             HCCL_ERROR(
     313              :                 "[%s][%s]%s failed, localHostIp[%s] and localhostPort[%u] ret[%u]", LOG_KEYWORDS_INIT_GROUP.c_str(),
     314              :                 LOG_KEYWORDS_RANKTABLE_DETECT.c_str(), __func__, localHostIp.GetReadableAddress(),
     315              :                 GetExternalInputMasterInfo().port, ret),
     316              :             ret);
     317              :     }
     318              : 
     319            0 :     CHK_PRT_RET(
     320              :         topoDetectAgent->SetupAgentByMasterInfo(localHostIp, rootHandle) != HCCL_SUCCESS,
     321              :         HCCL_ERROR("[Init][CommMasterInfo]setup topo detect error"), HCCL_E_INTERNAL);
     322            0 :     RankTable_t rankTable;
     323            0 :     CHK_PRT_RET(
     324              :         topoDetectAgent->GetCluterInfo(rankTable) != HCCL_SUCCESS,
     325              :         HCCL_ERROR("[Init][CommMasterInfo]GetCluterInfo error"), HCCL_E_INTERNAL);
     326            0 :     u32 rankIdNum = 0;
     327            0 :     CHK_PRT_RET(
     328              :         topoDetectAgent->GetRankId(rankIdNum) != HCCL_SUCCESS,
     329              :         HCCL_ERROR("[Init][CommMasterInfo]topoDetectAgent error"), HCCL_E_INTERNAL);
     330              : 
     331            0 :     CHK_RET(topoDetectAgent->TransformRankTableStr(rankTable, rankTableM));
     332            0 :     rankId = to_string(rankIdNum);
     333            0 :     CHK_PRT_RET(
     334              :         topoDetectAgent->WaitComplete(rootHandle) != HCCL_SUCCESS,
     335              :         HCCL_ERROR("[Init][CommMasterInfo]topoDetectAgent teardown fail"), HCCL_E_INTERNAL);
     336              : 
     337            0 :     CHK_PRT_RET(
     338              :         topoDetectAgent->GetAgentListenSocket(hcomInfo.params.commPortConfig) != HCCL_SUCCESS,
     339              :         HCCL_ERROR("[Init][CommMasterInfo]HcclGetCommListenSockets failed."), HCCL_E_INTERNAL);
     340              : 
     341            0 :     if (retryEnable) {
     342            0 :         hcomInfo.params.commConnections.isRoot = isRoot;
     343            0 :         if (isRoot) {
     344            0 :             hcomInfo.hcclCommTopoInfoDetectServer.insert({rootHandle.identifier, topoDetectServer});
     345            0 :             topoDetectServer->GetServerConnections(hcomInfo.params.commConnections.serverConnections);
     346              :         }
     347            0 :         hcomInfo.hcclCommTopoInfoDetectAgent.insert({rootHandle.identifier, topoDetectAgent});
     348            0 :         topoDetectAgent->GetAgentConnection(hcomInfo.params.commConnections.agentConnection);
     349              :     }
     350              : 
     351            0 :     return HCCL_SUCCESS;
     352            0 : }
     353              : 
     354            0 : HcclResult HcomInitByMasterInfo(
     355              :     const char* masterIp, const char* masterPort, const char* masterDeviceId, const char* rankSize, const char* rankIp,
     356              :     HcomInitConfig* initConfig)
     357              : {
     358            0 :     CHK_RET(SetMasterInfo(masterIp, masterPort, masterDeviceId, rankSize, rankIp));
     359            0 :     HcclUs startut = TIME_NOW();
     360            0 :     HcclResult ret = HCCL_SUCCESS;
     361              : 
     362            0 :     if (initConfig != nullptr) {
     363              :         DevType devType;
     364            0 :         CHK_RET(hrtGetDeviceType(devType));
     365              : 
     366            0 :         CHK_RET(HcomSetAlgorithm(initConfig->algo));
     367            0 :         CHK_RET(HcomSetExecTimeOut(initConfig->execTimeOut));
     368            0 :         if (devType != DevType::DEV_TYPE_910_93) {
     369            0 :             CHK_RET(HcomSetDeterministic(initConfig->deterministic));
     370              :         } else {
     371            0 :             HCCL_WARNING("ParserHcclDeterministic: device type is 910_93, use default setting");
     372              :         }
     373              :     }
     374              : 
     375            0 :     s32 logicDevId = 0;
     376            0 :     CHK_RET(hrtGetDevice(&logicDevId));
     377              :     // 读取rankTable文件到内存
     378            0 :     std::string rankTableM;
     379            0 :     std::string identify;
     380            0 :     HCCL_RUN_INFO(
     381              :         "Entry-HcomInitByMasterInfo:masterIp[%s], masterPort[%s], master device id[%s], rankSize[%s], rankIp[%s], "
     382              :         "deviceId[%d]",
     383              :         masterIp, masterPort, masterDeviceId, rankSize, rankIp, logicDevId);
     384              : 
     385            0 :     CHK_RET(InitExternalInput()); // 生成ranktable前需要提前感知部分配置
     386            0 :     CHK_RET(InitEnvConfig());
     387            0 :     ret = HcomGenerteRanktable(rankTableM, identify);
     388            0 :     CHK_PRT_RET(
     389              :         ret != HCCL_SUCCESS,
     390              :         HCCL_ERROR(
     391              :             "[HcomInitByMasterInfo]errNo[0x%016llx] masterIp[%s], masterPort[%s], "
     392              :             "masterDeviceId[%s] rankSize[%s] deviceId[%d] load rankTable error.",
     393              :             HCCL_ERROR_CODE(HCCL_E_INTERNAL), masterIp, masterPort, masterDeviceId, rankSize, logicDevId),
     394              :         HCCL_E_INTERNAL);
     395            0 :     CHK_RET(HcomCheckInitClusterInfo(rankTableM.c_str(), identify.c_str()));
     396              : 
     397              :     // 调用初始化接口
     398            0 :     ret = HcomInit(rankTableM.c_str(), identify.c_str());
     399            0 :     CHK_PRT_RET(
     400              :         ret != HCCL_SUCCESS,
     401              :         HCCL_ERROR(
     402              :             "[HcomInitByMasterInfo]errNo[0x%016llx] identify[%s] "
     403              :             "hcom init failed.",
     404              :             HCCL_ERROR_CODE(ret), identify.c_str()),
     405              :         ret);
     406            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
     407            0 :     hcomInfo.isHcomInit = true;
     408              :     /* 关键状态记录 */
     409            0 :     HCCL_RUN_INFO(
     410              :         "[HCCL_TRACE]hcom init by masterinfo success,take time [%lld]us, rankNum[%u], rank[%u], "
     411              :         "server[%s], device[%d]",
     412              :         DURATION_US(TIME_NOW() - startut), hcomInfo.rankTable.rankNum, hcomInfo.params.rank,
     413              :         hcomInfo.params.serverId.c_str(), hcomInfo.params.logicDevId);
     414            0 :     return HCCL_SUCCESS;
     415            0 : }
     416              : 
     417            0 : HcclResult HcomSetProfilingMode(HcomProfilingMode profilingMode, const char* profilingOption)
     418              : {
     419            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
     420            0 :     HCCL_INFO("Set profiling option[%s].", profilingOption);
     421            0 :     hcomInfo.params.profilingMode = profilingMode;
     422            0 :     hcomInfo.params.profilingOption = profilingOption;
     423            0 :     return HCCL_SUCCESS;
     424              : }
     425              : 
     426            0 : HcclResult HcomDestroyOneDeviceHeterog([[maybe_unused]] HcomInfo& hcomInfo) { return HCCL_SUCCESS; }
     427              : 
     428            0 : HcclResult HcomAllGather(
     429              :     const char* tag, void* inputPtr, void* outputPtr, u64 inputCount, HcclDataType dataType, const char* group,
     430              :     rtStream_t stream)
     431              : {
     432              :     HcclResult ret;
     433            0 :     HcclUs startut = TIME_NOW();
     434            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
     435              : 
     436            0 :     s32 deviceLogicId = 0;
     437            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
     438              : 
     439            0 :     CHK_PRT_RET(inputCount == 0, HCCL_WARNING("input count is 0, return AllGather success"), HCCL_SUCCESS);
     440              :     // 参数合法性校验
     441              : 
     442            0 :     RPT_INPUT_ERR(
     443              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     444              :         std::vector<std::string>({"HcomAllGather", "nullptr", "inputPtr", "non-null pointer"}));
     445            0 :     CHK_PTR_NULL(inputPtr);
     446            0 :     RPT_INPUT_ERR(
     447              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     448              :         std::vector<std::string>({"HcomAllGather", "nullptr", "outputPtr", "non-null pointer"}));
     449            0 :     CHK_PTR_NULL(outputPtr);
     450            0 :     RPT_INPUT_ERR(
     451              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     452              :         std::vector<std::string>({"HcomAllGather", "nullptr", "stream", "non-null pointer"}));
     453            0 :     CHK_PTR_NULL(stream);
     454              : 
     455            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
     456            0 :     s32 streamId = 0;
     457            0 :     ret = hrtGetStreamId(stream, streamId);
     458            0 :     CHK_PRT_RET(
     459              :         ret != HCCL_SUCCESS, HCCL_ERROR("[AllGather][Result]Call hrtGetStreamId error[%d].", ret), HCCL_E_RUNTIME);
     460              :     /* 接口交互信息日志 */
     461            0 :     HCCL_USER_CRITICAL_LOG(
     462              :         "Entry-HcomAllGather:tag[%s], inputPtr[%p], outputPtr[%p], inputCount[%llu], dataType[%s], "
     463              :         "group[%s], streamId[%d], deviceLogicId[%d]",
     464              :         tag, inputPtr, outputPtr, inputCount, GetDataTypeEnumStr(dataType).c_str(), strGroup.c_str(), streamId,
     465              :         deviceLogicId);
     466            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
     467            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
     468              : 
     469              :     // HcomAllGatherV2
     470            0 :     HCCLV2_FUNC_RUN(HcomAllGatherV2(tag, inputPtr, outputPtr, inputCount, dataType, group, stream));
     471              : 
     472            0 :     CHK_RET(HcomCheckOpParam(tag, inputCount, dataType, group, stream));
     473            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
     474            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
     475            0 :     ret = hcclComm->AllGather(tag, inputPtr, outputPtr, inputCount, dataType, stream);
     476            0 :     CHK_PRT_RET(
     477              :         ret != HCCL_SUCCESS,
     478              :         HCCL_ERROR(
     479              :             "[AllGather][Result]errNo[0x%016llx] hcclComm AllGather error, "
     480              :             "tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s]",
     481              :             HCOM_ERROR_CODE(ret), tag, inputPtr, outputPtr, inputCount, GetDataTypeEnumStr(dataType).c_str()),
     482              :         ret);
     483            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_ALLGATHER, beginTime, inputCount, dataType));
     484              :     /* 关键状态记录 */
     485            0 :     HCCL_RUN_INFO(
     486              :         "hcom AllGather success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
     487              :         "count[%llu], data_type[%s]",
     488              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, inputCount, GetDataTypeEnumStr(dataType).c_str());
     489              : 
     490            0 :     return HCCL_SUCCESS;
     491            0 : }
     492              : 
     493            0 : HcclResult HcomAllGatherV(
     494              :     const char* tag, const void* sendBuf, u64 sendCount, const void* recvBuf, const void* recvCounts,
     495              :     const void* rdispls, HcclDataType dataType, const char* group, rtStream_t stream)
     496              : {
     497              :     HcclResult ret;
     498            0 :     HcclUs startut = TIME_NOW();
     499            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
     500              : 
     501            0 :     s32 deviceLogicId = 0;
     502            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
     503              : 
     504              :     // 参数合法性校验
     505            0 :     RPT_INPUT_ERR(
     506              :         recvCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),
     507              :         std::vector<std::string>({"HcomAllGatherV", "nullptr", "recvCounts", "non-null pointer"}));
     508            0 :     CHK_PTR_NULL(recvCounts);
     509            0 :     RPT_INPUT_ERR(
     510              :         rdispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),
     511              :         std::vector<std::string>({"HcomAllGatherV", "nullptr", "rdispls", "non-null pointer"}));
     512            0 :     CHK_PTR_NULL(rdispls);
     513            0 :     RPT_INPUT_ERR(
     514              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),
     515              :         std::vector<std::string>({"HcomAllGatherV", "nullptr", "stream", "non-null pointer"}));
     516            0 :     CHK_PTR_NULL(stream);
     517            0 :     if (UNLIKELY(sendCount > 0 && sendBuf == nullptr)) {
     518            0 :         RPT_INPUT_ERR(
     519              :             true, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),
     520              :             std::vector<std::string>({"HcomAllGatherV", "nullptr", "sendBuf", "non-null pointer"}));
     521            0 :         CHK_PTR_NULL(sendBuf);
     522              :     }
     523              : 
     524            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
     525            0 :     s32 streamId = 0;
     526            0 :     ret = hrtGetStreamId(stream, streamId);
     527            0 :     CHK_PRT_RET(
     528              :         ret != HCCL_SUCCESS, HCCL_ERROR("[AllGatherV][Result]Call hrtGetStreamId error[%d].", ret), HCCL_E_RUNTIME);
     529              :     /* 接口交互信息日志 */
     530            0 :     HCCL_USER_CRITICAL_LOG(
     531              :         "Entry-HcomAllGatherV:tag[%s], inputPtr[%p], outputPtr[%p], sendCount[%llu], dataType[%s], "
     532              :         "recvCounts[%p], rdispls[%p], group[%s], streamId[%d], deviceLogicId[%d]",
     533              :         tag, sendBuf, recvBuf, sendCount, GetDataTypeEnumStr(dataType).c_str(), recvCounts, rdispls, strGroup.c_str(),
     534              :         streamId, deviceLogicId);
     535            0 :     if (sendBuf != nullptr) {
     536            0 :         CHK_RET(PrintMemoryAttr(sendBuf));
     537              :     }
     538            0 :     if (recvBuf != nullptr) {
     539            0 :         CHK_RET(PrintMemoryAttr(recvBuf));
     540              :     }
     541            0 :     HCCLV2_FUNC_RUN(HcomAllGatherVV2(
     542              :         tag, const_cast<void*>(sendBuf), sendCount, const_cast<void*>(recvBuf), const_cast<void*>(recvCounts),
     543              :         const_cast<void*>(rdispls), dataType, group, stream));
     544            0 :     CHK_RET(HcomCheckOpParam(tag, 0, dataType, group, stream));
     545            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
     546            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
     547            0 :     ret = hcclComm->AllGatherV(tag, sendBuf, sendCount, recvBuf, recvCounts, rdispls, dataType, stream);
     548            0 :     CHK_PRT_RET(
     549              :         ret != HCCL_SUCCESS,
     550              :         HCCL_ERROR(
     551              :             "[AllGatherV][Result]errNo[0x%016llx] hcclComm AllGatherV error, "
     552              :             "tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s]",
     553              :             HCOM_ERROR_CODE(ret), tag, sendBuf, recvBuf, sendCount, GetDataTypeEnumStr(dataType).c_str()),
     554              :         ret);
     555            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_ALLGATHER_V, beginTime, sendCount, dataType));
     556              :     /* 关键状态记录 */
     557            0 :     HCCL_RUN_INFO(
     558              :         "hcom AllGatherv success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
     559              :         "count[%llu], data_type[%s]",
     560              :         DURATION_US(TIME_NOW() - startut), tag, sendBuf, recvBuf, sendCount, GetDataTypeEnumStr(dataType).c_str());
     561              : 
     562            0 :     return HCCL_SUCCESS;
     563            0 : }
     564              : 
     565            0 : HcclResult HcomGetInitStatus(bool* initiated)
     566              : {
     567            0 :     CHK_PTR_NULL(initiated);
     568            0 :     HCCLV2_FUNC_RUN(HcomGetInitStatusV2(*initiated));
     569            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
     570            0 :     *initiated = !(hcomInfo.pComm == nullptr);
     571              : 
     572            0 :     HCCL_INFO("Get Hcom Init Status: [%d]", *initiated);
     573            0 :     return HCCL_SUCCESS;
     574              : }
     575              : 
     576            0 : HcclResult HcomAllReduce(
     577              :     const char* tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op,
     578              :     const char* group, rtStream_t stream)
     579              : {
     580            0 :     HcclUs startut = TIME_NOW();
     581            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
     582              : 
     583            0 :     s32 deviceLogicId = 0;
     584            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
     585              : 
     586            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return AllReduce success"), HCCL_SUCCESS);
     587              :     // 入参合法性校验
     588              : 
     589            0 :     RPT_INPUT_ERR(
     590              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     591              :         std::vector<std::string>({"HcomAllReduce", "nullptr", "inputPtr", "non-null pointer"}));
     592            0 :     CHK_PTR_NULL(inputPtr);
     593            0 :     RPT_INPUT_ERR(
     594              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     595              :         std::vector<std::string>({"HcomAllReduce", "nullptr", "outputPtr", "non-null pointer"}));
     596            0 :     CHK_PTR_NULL(outputPtr);
     597            0 :     RPT_INPUT_ERR(
     598              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     599              :         std::vector<std::string>({"HcomAllReduce", "nullptr", "stream", "non-null pointer"}));
     600            0 :     CHK_PTR_NULL(stream);
     601              : 
     602            0 :     s32 streamId = 0;
     603            0 :     CHK_RET(HcomCheckReductionOp("HcomAllReduce", op));
     604            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
     605              : 
     606            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
     607              :     /* 接口交互信息日志 */
     608            0 :     HCCL_USER_CRITICAL_LOG(
     609              :         "Entry-HcomAllReduce:tag[%s], inputPtr[%p], outputPtr[%p], count[%llu], dataType[%s], op[%s], "
     610              :         "group[%s], streamId[%d], deviceLogicId[%d]",
     611              :         tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
     612              :         strGroup.c_str(), streamId, deviceLogicId);
     613            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
     614            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
     615              : 
     616              :     // HcomAllReduceV2
     617            0 :     HCCLV2_FUNC_RUN(HcomAllReduceV2(tag, inputPtr, outputPtr, count, dataType, op, group, stream));
     618            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType, group, stream));
     619            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
     620            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
     621              :     /* 入参的正确性由HCCL确保 */
     622            0 :     HcclResult ret = hcclComm->AllReduce(tag, inputPtr, outputPtr, count, dataType, op, stream);
     623            0 :     CHK_PRT_RET(
     624              :         ret != HCCL_SUCCESS,
     625              :         HCCL_ERROR(
     626              :             "[AllReduce][Result]errNo[0x%016llx] hcclComm AllReduce error, "
     627              :             "tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s]",
     628              :             HCOM_ERROR_CODE(ret), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
     629              :             GetReduceOpEnumStr(op).c_str()),
     630              :         ret);
     631            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_ALLREDUCE, beginTime, count, dataType));
     632              :     /* 关键状态记录 */
     633            0 :     HCCL_RUN_INFO(
     634              :         "hcom AllReduce success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
     635              :         "count[%llu], data_type[%s], op[%s]",
     636              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
     637              :         GetReduceOpEnumStr(op).c_str());
     638              : 
     639            0 :     return HCCL_SUCCESS;
     640            0 : }
     641              : 
     642            0 : HcclResult HcomBroadcast(
     643              :     const char* tag, void* ptr, u64 count, HcclDataType dataType, u32 root, const char* group, rtStream_t stream)
     644              : {
     645            0 :     HcclUs startut = TIME_NOW();
     646            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
     647              : 
     648            0 :     s32 deviceLogicId = 0;
     649            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
     650              : 
     651            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return BroadCast success"), HCCL_SUCCESS);
     652              :     // 入参合法性校验
     653            0 :     RPT_INPUT_ERR(
     654              :         ptr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     655              :         std::vector<std::string>({"HcomBroadcast", "nullptr", "ptr", "non-null pointer"}));
     656            0 :     CHK_PTR_NULL(ptr);
     657            0 :     RPT_INPUT_ERR(
     658              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     659              :         std::vector<std::string>({"HcomBroadcast", "nullptr", "stream", "non-null pointer"}));
     660            0 :     CHK_PTR_NULL(stream);
     661              : 
     662            0 :     s32 streamId = 0;
     663            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
     664            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
     665              :     /* 接口交互信息日志 */
     666            0 :     HCCL_USER_CRITICAL_LOG(
     667              :         "Entry-HcomBroadcast:tag[%s], ptr[%p], count[%llu], dataType[%s], root[%u], "
     668              :         "group[%s], streamId[%d], deviceLogicId[%d]",
     669              :         tag, ptr, count, GetDataTypeEnumStr(dataType).c_str(), root, strGroup.c_str(), streamId, deviceLogicId);
     670            0 :     CHK_RET(PrintMemoryAttr(ptr));
     671              : 
     672              :     // HcomBroadcastV2
     673            0 :     HCCLV2_FUNC_RUN(HcomBroadcastV2(tag, ptr, count, dataType, root, group, stream));
     674            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType, group, stream));
     675            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
     676            0 :     CHK_RET(HcomCheckUserRank(hcomInfo.params.totalRanks, root));
     677            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
     678            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
     679            0 :     u32 aivCoreLimit = 0;
     680            0 :     CHK_RET(hcclComm->GetNumBlocks(aivCoreLimit));
     681              :     /* 入参的正确性由HCCL确保 */
     682            0 :     HcclResult ret = hcclComm->Broadcast(tag, ptr, count, dataType, root, stream);
     683            0 :     CHK_PRT_RET(
     684              :         ret != HCCL_SUCCESS,
     685              :         HCCL_ERROR(
     686              :             "[Broadcast][Result]errNo[0x%016llx] hcclComm BroadCast error,tag[%s], input_ptr[%p],"
     687              :             "count[%llu], data_type[%s], root[%u]",
     688              :             HCOM_ERROR_CODE(ret), tag, ptr, count, GetDataTypeEnumStr(dataType).c_str(), root),
     689              :         ret);
     690            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_BROADCAST, beginTime, count, dataType));
     691              :     /* 关键状态记录 */
     692            0 :     HCCL_RUN_INFO(
     693              :         "hcom BroadCast success,take time [%lld]us,tag[%s], input_ptr[%p], count[%llu], data_type[%s], "
     694              :         "root[%u]",
     695              :         DURATION_US(TIME_NOW() - startut), tag, ptr, count, GetDataTypeEnumStr(dataType).c_str(), root);
     696              : 
     697            0 :     return HCCL_SUCCESS;
     698            0 : }
     699              : 
     700            0 : HcclResult HcomReduce(
     701              :     const char* tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op, u32 root,
     702              :     const char* group, rtStream_t stream)
     703              : {
     704            0 :     HcclUs startut = TIME_NOW();
     705            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
     706              : 
     707            0 :     s32 deviceLogicId = 0;
     708            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
     709              : 
     710            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return Reduce success"), HCCL_SUCCESS);
     711              : 
     712              :     // 入参合法性校验
     713            0 :     RPT_INPUT_ERR(
     714              :         tag == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     715              :         std::vector<std::string>({"HcomReduce", "nullptr", "tag", "non-null pointer"}));
     716            0 :     CHK_PTR_NULL(tag);
     717            0 :     RPT_INPUT_ERR(
     718              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     719              :         std::vector<std::string>({"HcomReduce", "nullptr", "inputPtr", "non-null pointer"}));
     720            0 :     CHK_PTR_NULL(inputPtr);
     721            0 :     RPT_INPUT_ERR(
     722              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     723              :         std::vector<std::string>({"HcomReduce", "nullptr", "outputPtr", "non-null pointer"}));
     724            0 :     CHK_PTR_NULL(outputPtr);
     725            0 :     RPT_INPUT_ERR(
     726              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     727              :         std::vector<std::string>({"HcomReduce", "nullptr", "stream", "non-null pointer"}));
     728            0 :     CHK_PTR_NULL(stream);
     729            0 :     CHK_RET(HcomCheckReductionOp("HcomReduce", op));
     730              : 
     731            0 :     s32 streamId = 0;
     732            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
     733            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
     734              :     /* 接口交互信息日志 */
     735            0 :     HCCL_USER_CRITICAL_LOG(
     736              :         "Entry-HcomReduce:tag[%s], inputPtr[%p], outputPtr[%p], count[%llu], dataType[%s], op[%s], "
     737              :         "root[%u], group[%s], streamId[%d], deviceLogicId[%d]",
     738              :         tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(), root,
     739              :         strGroup.c_str(), streamId, deviceLogicId);
     740            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
     741            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
     742              : 
     743              :     // HcomReduceV2
     744            0 :     HCCLV2_FUNC_RUN(HcomReduceV2(tag, inputPtr, outputPtr, count, dataType, op, root, group, stream));
     745            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType, group, stream));
     746            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
     747            0 :     CHK_PRT_RET(
     748              :         hcomInfo.pComm == nullptr,
     749              :         HCCL_ERROR("[Reduce][Result]hcomInfo.pComm is null, "
     750              :                    "please check if the initialize process is called."),
     751              :         HCCL_E_PTR);
     752            0 :     CHK_RET(HcomCheckUserRank(hcomInfo.params.totalRanks, root));
     753              : 
     754            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
     755            0 :     CHK_RET(HcomGetCommByGroup(group, hcclComm));
     756              :     /* 入参的正确性由HCCL确保 */
     757            0 :     HcclResult ret = hcclComm->Reduce(tag, inputPtr, outputPtr, count, dataType, op, root, stream);
     758            0 :     CHK_PRT_RET(
     759              :         ret != HCCL_SUCCESS,
     760              :         HCCL_ERROR(
     761              :             "[Reduce][Result]errNo[0x%016llx] hcclComm Reduce error, tag[%s], "
     762              :             "input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s], root[%u]",
     763              :             HCOM_ERROR_CODE(ret), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
     764              :             GetReduceOpEnumStr(op).c_str(), root),
     765              :         ret);
     766            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_REDUCE, beginTime, count, dataType));
     767            0 :     HcclUs endut = TIME_NOW();
     768              :     /* 关键状态记录 */
     769            0 :     HCCL_RUN_INFO(
     770              :         "hcom Reduce success, take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], "
     771              :         "data_type[%s], op[%s], root[%u]",
     772              :         DURATION_US(endut - startut), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
     773              :         GetReduceOpEnumStr(op).c_str(), root);
     774              : 
     775            0 :     return HCCL_SUCCESS;
     776            0 : }
     777              : 
     778            0 : HcclResult HcomReduceScatter(
     779              :     const char* tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op,
     780              :     const char* group, rtStream_t stream)
     781              : {
     782            0 :     HcclUs startut = TIME_NOW();
     783            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
     784              : 
     785            0 :     s32 deviceLogicId = 0;
     786            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
     787              : 
     788            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return ReduceScatter success"), HCCL_SUCCESS);
     789              :     // 入参合法性校验
     790              : 
     791            0 :     RPT_INPUT_ERR(
     792              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     793              :         std::vector<std::string>({"HcomReduceScatter", "nullptr", "inputPtr", "non-null pointer"}));
     794            0 :     CHK_PTR_NULL(inputPtr);
     795            0 :     RPT_INPUT_ERR(
     796              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     797              :         std::vector<std::string>({"HcomReduceScatter", "nullptr", "outputPtr", "non-null pointer"}));
     798            0 :     CHK_PTR_NULL(outputPtr);
     799            0 :     RPT_INPUT_ERR(
     800              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     801              :         std::vector<std::string>({"HcomReduceScatter", "nullptr", "stream", "non-null pointer"}));
     802            0 :     CHK_PTR_NULL(stream);
     803            0 :     CHK_RET(HcomCheckReductionOp("HcomReduceScatter", op));
     804              : 
     805            0 :     s32 streamId = 0;
     806            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
     807            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
     808              :     /* 接口交互信息日志 */
     809            0 :     HCCL_USER_CRITICAL_LOG(
     810              :         "Entry-HcomReduceScatter:tag[%s], inputPtr[%p], outputPtr[%p], count[%llu], dataType[%s], op[%s], "
     811              :         "group[%s], streamId[%d], deviceLogicId[%d]",
     812              :         tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
     813              :         strGroup.c_str(), streamId, deviceLogicId);
     814            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
     815            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
     816              : 
     817            0 :     HCCLV2_FUNC_RUN(HcomReduceScatterV2(tag, inputPtr, outputPtr, count, dataType, op, group, stream));
     818            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType, group, stream));
     819            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
     820            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
     821              :     /* 入参的正确性由HCCL确保 */
     822            0 :     HcclResult ret = hcclComm->ReduceScatter(tag, inputPtr, outputPtr, count, dataType, op, stream);
     823            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     824              :                 HCCL_ERROR(
     825              :                     "[ReduceScatter][Result]errNo[0x%016llx] hcclComm ReduceScatter "
     826              :                     "error, tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s]",
     827              :                     HCOM_ERROR_CODE(ret), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
     828              :                     GetReduceOpEnumStr(op).c_str());
     829              :                 , ret);
     830            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_REDUCE_SCATTER, beginTime, count, dataType));
     831              :     /* 关键状态记录 */
     832            0 :     HCCL_RUN_INFO(
     833              :         "hcom reduceScatter success, take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], "
     834              :         "data_type[%s], op[%s]",
     835              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
     836              :         GetReduceOpEnumStr(op).c_str());
     837              : 
     838            0 :     return HCCL_SUCCESS;
     839            0 : }
     840              : 
     841            0 : HcclResult HcomReduceScatterV(
     842              :     const char* tag, void* sendBuf, const void* sendCounts, const void* sdispls, void* recvBuf, u64 recvCount,
     843              :     HcclDataType dataType, HcclReduceOp op, const char* group, rtStream_t stream)
     844              : {
     845            0 :     HcclUs startut = TIME_NOW();
     846            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
     847              : 
     848              :     // 入参合法性校验
     849            0 :     RPT_INPUT_ERR(
     850              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),
     851              :         std::vector<std::string>({"HcomReduceScatterV", "nullptr", "stream", "non-null pointer"}));
     852            0 :     CHK_PTR_NULL(stream);
     853            0 :     RPT_INPUT_ERR(
     854              :         sendCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),
     855              :         std::vector<std::string>({"HcomReduceScatterV", "nullptr", "sendCounts", "non-null pointer"}));
     856            0 :     CHK_PTR_NULL(sendCounts);
     857            0 :     RPT_INPUT_ERR(
     858              :         sdispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),
     859              :         std::vector<std::string>({"HcomReduceScatterV", "nullptr", "sdispls", "non-null pointer"}));
     860            0 :     CHK_PTR_NULL(sdispls);
     861            0 :     if (UNLIKELY(recvCount > 0 && recvBuf == nullptr)) {
     862            0 :         RPT_INPUT_ERR(
     863              :             true, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),
     864              :             std::vector<std::string>({"HcomReduceScatterV", "nullptr", "recvBuf", "non-null pointer"}));
     865            0 :         CHK_PTR_NULL(recvBuf);
     866              :     }
     867              : 
     868            0 :     s32 streamId = 0;
     869            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
     870            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
     871              :     /* 接口交互信息日志 */
     872            0 :     HCCL_RUN_INFO(
     873              :         "Entry-HcomReduceScatterV:tag[%s], inputPtr[%p], outputPtr[%p], count[%llu], dataType[%s], op[%s], "
     874              :         "group[%s], streamId[%d]",
     875              :         tag, sendBuf, recvBuf, recvCount, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
     876              :         strGroup.c_str(), streamId);
     877            0 :     if (sendBuf != nullptr) {
     878            0 :         CHK_RET(PrintMemoryAttr(sendBuf));
     879              :     }
     880            0 :     if (recvBuf != nullptr) {
     881            0 :         CHK_RET(PrintMemoryAttr(recvBuf));
     882              :     }
     883              : 
     884            0 :     HCCLV2_FUNC_RUN(HcomReduceScatterVV2(
     885              :         tag, sendBuf, const_cast<void*>(sendCounts), const_cast<void*>(sdispls), recvBuf, recvCount, dataType, op,
     886              :         group, stream));
     887            0 :     CHK_RET(HcomCheckOpParam(tag, 0, dataType, group, stream));
     888            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
     889            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
     890              :     /* 入参的正确性由HCCL确保 */
     891              :     HcclResult ret
     892            0 :         = hcclComm->ReduceScatterV(tag, sendBuf, sendCounts, sdispls, recvBuf, recvCount, dataType, op, stream);
     893            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     894              :                 HCCL_ERROR(
     895              :                     "[ReduceScatterV][Result]errNo[0x%016llx] hcclComm ReduceScatter "
     896              :                     "error, tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s]",
     897              :                     HCOM_ERROR_CODE(ret), tag, sendBuf, recvBuf, recvCount, GetDataTypeEnumStr(dataType).c_str(),
     898              :                     GetReduceOpEnumStr(op).c_str());
     899              :                 , ret);
     900            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_REDUCE_SCATTER, beginTime, 0, dataType));
     901              :     /* 关键状态记录 */
     902            0 :     HCCL_RUN_INFO(
     903              :         "hcom ReduceScatterv success, take time [%lld]us, tag[%s], sendBuf[%p], recvBuf[%p], count[%llu], "
     904              :         "data_type[%s], op[%s]",
     905              :         DURATION_US(TIME_NOW() - startut), tag, sendBuf, recvBuf, recvCount, GetDataTypeEnumStr(dataType).c_str(),
     906              :         GetReduceOpEnumStr(op).c_str());
     907              : 
     908            0 :     return HCCL_SUCCESS;
     909            0 : }
     910              : 
     911              : /*
     912              :  * 点对点发送接口: 需要对应的hcom_receive执行才会实际发送。先分片,条件满足之后改为不分片
     913              :  * 发送端需要接收端准备好才会发送
     914              :  */
     915            0 : HcclResult HcomSend(
     916              :     const char* tag, void* inputPtr, u64 count, HcclDataType dataType, u32 destRank, u32 srTag, const char* group,
     917              :     rtStream_t stream)
     918              : {
     919            0 :     HcclUs startut = TIME_NOW();
     920            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
     921              : 
     922            0 :     s32 deviceLogicId = 0;
     923            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
     924              : 
     925            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return send success"), HCCL_SUCCESS);
     926              : 
     927              :     // 入参合法性校验
     928            0 :     RPT_INPUT_ERR(
     929              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     930              :         std::vector<std::string>({"HcomSend", "nullptr", "inputPtr", "non-null pointer"}));
     931            0 :     CHK_PTR_NULL(inputPtr);
     932            0 :     RPT_INPUT_ERR(
     933              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     934              :         std::vector<std::string>({"HcomSend", "nullptr", "stream", "non-null pointer"}));
     935            0 :     CHK_PTR_NULL(stream);
     936              : 
     937            0 :     s32 streamId = 0;
     938            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
     939            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
     940              :     /* 接口交互信息日志 */
     941            0 :     HCCL_USER_CRITICAL_LOG(
     942              :         "Entry-HcomSend:tag[%s], inputPtr[%p], count[%llu], dataType[%s], destRank[%u], srTag[%u], "
     943              :         "group[%s], streamId[%d], deviceLogicId[%d]",
     944              :         tag, inputPtr, count, GetDataTypeEnumStr(dataType).c_str(), destRank, srTag, strGroup.c_str(), streamId,
     945              :         deviceLogicId);
     946            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
     947              : 
     948              :     // HcomSendV2
     949            0 :     HCCLV2_FUNC_RUN(HcomSendV2(tag, inputPtr, count, dataType, destRank, srTag, group, stream));
     950            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType, group, stream));
     951            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
     952            0 :     CHK_RET(HcomCheckUserRank(hcomInfo.params.totalRanks, destRank));
     953              : 
     954            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
     955            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
     956              : 
     957            0 :     u32 localGroupRank = INVALID_VALUE_RANKID;
     958            0 :     CHK_RET(hcclComm->GetGroupRank(localGroupRank));
     959              :     /* 调用HCCL的send, 入参的正确性由HCCL确保 */
     960            0 :     HcclResult ret = hcclComm->send(tag, inputPtr, count, dataType, destRank, stream, srTag, localGroupRank);
     961            0 :     CHK_PRT_RET(
     962              :         ret != HCCL_SUCCESS,
     963              :         HCCL_ERROR(
     964              :             "[Send][Result]errNo[0x%016llx] hcclComm send error, tag[%s], "
     965              :             "inputPtr[%p], count[%llu], dataType[%s], destRank[%u], group[%s]",
     966              :             HCOM_ERROR_CODE(ret), tag, inputPtr, count, GetDataTypeEnumStr(dataType).c_str(), destRank,
     967              :             strGroup.c_str()),
     968              :         ret);
     969            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_SEND, beginTime, count, dataType));
     970              :     /* 关键状态记录 */
     971            0 :     HCCL_RUN_INFO(
     972              :         "hcom send success,time[%lld]us,tag[%s],inputPtr[%p],count[%llu],dataType[%s],destRank[%u],"
     973              :         "srTag[%u],localGroupRank[%u]",
     974              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, count, GetDataTypeEnumStr(dataType).c_str(), destRank, srTag,
     975              :         localGroupRank);
     976              : 
     977            0 :     return HCCL_SUCCESS;
     978            0 : }
     979              : 
     980              : /*
     981              :  * 点对点接收接口: 需要对应的hcom_receive执行才会实际发送。先分片,条件满足之后改为不分片
     982              :  * 发送端需要接收端准备好才会发送
     983              :  */
     984            0 : HcclResult HcomReceive(
     985              :     const char* tag, void* outputPtr, u64 count, HcclDataType dataType, u32 srcRank, u32 srTag, const char* group,
     986              :     rtStream_t stream)
     987              : {
     988            0 :     HcclUs startut = TIME_NOW();
     989            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
     990              : 
     991            0 :     s32 deviceLogicId = 0;
     992            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
     993            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return receive success"), HCCL_SUCCESS);
     994              : 
     995              :     // 入参合法性校验
     996            0 :     RPT_INPUT_ERR(
     997              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     998              :         std::vector<std::string>({"HcomReceive", "nullptr", "outputPtr", "non-null pointer"}));
     999            0 :     CHK_PTR_NULL(outputPtr);
    1000            0 :     RPT_INPUT_ERR(
    1001              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1002              :         std::vector<std::string>({"HcomReceive", "nullptr", "stream", "non-null pointer"}));
    1003            0 :     CHK_PTR_NULL(stream);
    1004              : 
    1005            0 :     s32 streamId = 0;
    1006            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    1007            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    1008              :     /* 接口交互信息日志 */
    1009            0 :     HCCL_USER_CRITICAL_LOG(
    1010              :         "Entry-HcomReceive:tag[%s], outputPtr[%p], count[%llu], dataType[%s], srcRank[%u], srTag[%u],"
    1011              :         "group[%s], streamId[%d], deviceLogicId[%d]",
    1012              :         tag, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), srcRank, srTag, strGroup.c_str(), streamId,
    1013              :         deviceLogicId);
    1014            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
    1015              : 
    1016              :     // HcomReceiveV2
    1017            0 :     HCCLV2_FUNC_RUN(HcomReceiveV2(tag, outputPtr, count, dataType, srcRank, srTag, group, stream));
    1018            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType, group, stream));
    1019            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    1020            0 :     CHK_RET(HcomCheckUserRank(hcomInfo.params.totalRanks, srcRank));
    1021              : 
    1022            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    1023            0 :     HcclResult ret = HcomGetCommByGroup(strGroup.c_str(), hcclComm);
    1024            0 :     CHK_PRT_RET(
    1025              :         ret != HCCL_SUCCESS,
    1026              :         HCCL_ERROR(
    1027              :             "[Receive][Result]errNo[0x%016llx] get comm by group[%s] error", HCOM_ERROR_CODE(ret), strGroup.c_str()),
    1028              :         ret);
    1029              : 
    1030            0 :     u32 localGroupRank = INVALID_VALUE_RANKID;
    1031            0 :     CHK_RET(hcclComm->GetGroupRank(localGroupRank));
    1032            0 :     ret = hcclComm->receive(tag, outputPtr, count, dataType, srcRank, stream, srTag, localGroupRank);
    1033            0 :     CHK_PRT_RET(
    1034              :         ret != HCCL_SUCCESS,
    1035              :         HCCL_ERROR(
    1036              :             "[Receive][Result]errNo[0x%016llx] hcclComm receive error,tag[%s], "
    1037              :             "outputPtr[%p], count[%llu], dataType[%s], srcRank[%u], group[%s]",
    1038              :             HCOM_ERROR_CODE(ret), tag, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), srcRank,
    1039              :             strGroup.c_str()),
    1040              :         ret);
    1041              : 
    1042            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_RECEIVE, beginTime, count, dataType));
    1043              :     /* 关键状态记录 */
    1044            0 :     HCCL_RUN_INFO(
    1045              :         "hcom receive success,time[%lld]us,tag[%s],outputPtr[%p],count[%llu],dataType[%s],srcRank[%u],"
    1046              :         "srTag[%u], localGroupRank[%u]",
    1047              :         DURATION_US(TIME_NOW() - startut), tag, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), srcRank, srTag,
    1048              :         localGroupRank);
    1049              : 
    1050            0 :     return HCCL_SUCCESS;
    1051            0 : }
    1052              : 
    1053            0 : HcclResult HcclCommGraphAllGather(
    1054              :     const char* tag, void* inputPtr, void* outputPtr, u64 inputCount, HcclDataType dataType, s64 opBaseHcom,
    1055              :     rtStream_t stream)
    1056              : {
    1057              :     HcclResult ret;
    1058            0 :     HcclUs startut = TIME_NOW();
    1059            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    1060            0 :     CHK_PRT_RET(inputCount == 0, HCCL_WARNING("input count is 0, return AllGather success"), HCCL_SUCCESS);
    1061              :     // 参数合法性校验
    1062            0 :     RPT_INPUT_ERR(
    1063              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1064              :         std::vector<std::string>({"HcclCommGraphAllGather", "nullptr", "inputPtr", "non-null pointer"}));
    1065            0 :     CHK_PTR_NULL(inputPtr);
    1066            0 :     RPT_INPUT_ERR(
    1067              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1068              :         std::vector<std::string>({"HcclCommGraphAllGather", "nullptr", "outputPtr", "non-null pointer"}));
    1069            0 :     CHK_PTR_NULL(outputPtr);
    1070            0 :     RPT_INPUT_ERR(
    1071              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1072              :         std::vector<std::string>({"HcclCommGraphAllGather", "nullptr", "stream", "non-null pointer"}));
    1073            0 :     CHK_PTR_NULL(stream);
    1074              : 
    1075            0 :     s32 streamId = 0;
    1076            0 :     ret = hrtGetStreamId(stream, streamId);
    1077            0 :     CHK_PRT_RET(
    1078              :         ret != HCCL_SUCCESS, HCCL_ERROR("[AllGather][Result]Call hrtGetStreamId error[%d].", ret), HCCL_E_RUNTIME);
    1079              :     /* 接口交互信息日志 */
    1080            0 :     HCCL_RUN_INFO(
    1081              :         "Entry-HcclCommGraphAllGather:tag[%s], inputPtr[%p], outputPtr[%p], inputCount[%llu], dataType[%s], "
    1082              :         "opBaseHcom[%lld] streamId[%d]",
    1083              :         tag, inputPtr, outputPtr, inputCount, GetDataTypeEnumStr(dataType).c_str(), opBaseHcom, streamId);
    1084            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
    1085            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
    1086              : 
    1087              :     // HcclCommGraphAllGatherV2
    1088            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    1089              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1090              :         CHK_PTR_NULL(hcclComm);
    1091              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1092              :         CHK_PTR_NULL(commV2);
    1093              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    1094              :         CHK_RET(HcclCommGraphAllGatherV2(tag, inputPtr, outputPtr, inputCount, dataType, opBaseHcom, stream));
    1095              :         return HCCL_SUCCESS;
    1096              :     }());
    1097            0 :     CHK_RET(HcomCheckOpParam(tag, inputCount, dataType, stream));
    1098            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1099            0 :     CHK_PTR_NULL(hcclComm);
    1100            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1101            0 :     ret = hcclComm->AllGather(tag, inputPtr, outputPtr, inputCount, dataType, stream);
    1102            0 :     CHK_PRT_RET(
    1103              :         ret != HCCL_SUCCESS,
    1104              :         HCCL_ERROR(
    1105              :             "[AllGather][Result]errNo[0x%016llx] hcclComm AllGather error, "
    1106              :             "tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s]",
    1107              :             HCOM_ERROR_CODE(ret), tag, inputPtr, outputPtr, inputCount, GetDataTypeEnumStr(dataType).c_str()),
    1108              :         ret);
    1109            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLGATHER, beginTime, inputCount, dataType));
    1110              :     /* 关键状态记录 */
    1111            0 :     HCCL_RUN_INFO(
    1112              :         "HcclCommGraphAllGather success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
    1113              :         "count[%llu], data_type[%s], opBaseHcom[%lld]",
    1114              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, inputCount, GetDataTypeEnumStr(dataType).c_str(),
    1115              :         opBaseHcom);
    1116              : 
    1117            0 :     return HCCL_SUCCESS;
    1118              : }
    1119              : 
    1120            0 : HcclResult HcclCommGraphAllReduce(
    1121              :     const char* tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op, s64 opBaseHcom,
    1122              :     rtStream_t stream)
    1123              : {
    1124            0 :     HcclUs startut = TIME_NOW();
    1125            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    1126            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return AllReduce success"), HCCL_SUCCESS);
    1127              :     // 入参合法性校验
    1128            0 :     RPT_INPUT_ERR(
    1129              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1130              :         std::vector<std::string>({"HcclCommGraphAllReduce", "nullptr", "inputPtr", "non-null pointer"}));
    1131            0 :     CHK_PTR_NULL(inputPtr);
    1132            0 :     RPT_INPUT_ERR(
    1133              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1134              :         std::vector<std::string>({"HcclCommGraphAllReduce", "nullptr", "outputPtr", "non-null pointer"}));
    1135            0 :     CHK_PTR_NULL(outputPtr);
    1136            0 :     RPT_INPUT_ERR(
    1137              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1138              :         std::vector<std::string>({"HcclCommGraphAllReduce", "nullptr", "stream", "non-null pointer"}));
    1139            0 :     CHK_PTR_NULL(stream);
    1140            0 :     CHK_RET(HcomCheckReductionOp("HcclCommGraphAllReduce", op));
    1141            0 :     s32 streamId = 0;
    1142            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    1143              : 
    1144              :     /* 接口交互信息日志 */
    1145            0 :     HCCL_RUN_INFO(
    1146              :         "Entry-HcclCommGraphAllReduce:tag[%s], inputPtr[%p], outputPtr[%p], count[%llu], dataType[%s], "
    1147              :         "op[%s], opBaseHcom[%lld], streamId[%d]",
    1148              :         tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
    1149              :         opBaseHcom, streamId);
    1150            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
    1151            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
    1152              : 
    1153              :     // HcomGraphAllReduceV2
    1154            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    1155              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1156              :         CHK_PTR_NULL(hcclComm);
    1157              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1158              :         CHK_PTR_NULL(commV2);
    1159              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    1160              :         CHK_RET(HcomGraphAllReduceV2(tag, inputPtr, outputPtr, count, dataType, op, opBaseHcom, stream));
    1161              :         return HCCL_SUCCESS;
    1162              :     }());
    1163            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType, stream));
    1164            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1165            0 :     CHK_PTR_NULL(hcclComm);
    1166            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1167              :     /* 入参的正确性由HCCL确保 */
    1168            0 :     HcclResult ret = hcclComm->AllReduce(tag, inputPtr, outputPtr, count, dataType, op, stream);
    1169            0 :     CHK_PRT_RET(
    1170              :         ret != HCCL_SUCCESS,
    1171              :         HCCL_ERROR(
    1172              :             "[AllReduce][Result]errNo[0x%016llx] hcclComm AllReduce error, "
    1173              :             "tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s]",
    1174              :             HCOM_ERROR_CODE(ret), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
    1175              :             GetReduceOpEnumStr(op).c_str()),
    1176              :         ret);
    1177            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLREDUCE, beginTime, count, dataType));
    1178              :     /* 关键状态记录 */
    1179            0 :     HCCL_RUN_INFO(
    1180              :         "HcclCommGraphAllReduce success,take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
    1181              :         "count[%llu], data_type[%s], op[%s], opBaseHcom[%lld]",
    1182              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
    1183              :         GetReduceOpEnumStr(op).c_str(), opBaseHcom);
    1184              : 
    1185            0 :     return HCCL_SUCCESS;
    1186              : }
    1187              : 
    1188            0 : HcclResult HcclCommGraphReduce(
    1189              :     const char* tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op, u32 root,
    1190              :     s64 opBaseHcom, rtStream_t stream)
    1191              : {
    1192            0 :     HcclUs startut = TIME_NOW();
    1193            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    1194            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return Reduce success"), HCCL_SUCCESS);
    1195              : 
    1196              :     // 入参合法性校验
    1197            0 :     RPT_INPUT_ERR(
    1198              :         tag == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1199              :         std::vector<std::string>({"HcclCommGraphReduce", "nullptr", "tag", "non-null pointer"}));
    1200            0 :     CHK_PTR_NULL(tag);
    1201            0 :     RPT_INPUT_ERR(
    1202              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1203              :         std::vector<std::string>({"HcclCommGraphReduce", "nullptr", "inputPtr", "non-null pointer"}));
    1204            0 :     CHK_PTR_NULL(inputPtr);
    1205            0 :     RPT_INPUT_ERR(
    1206              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1207              :         std::vector<std::string>({"HcclCommGraphReduce", "nullptr", "outputPtr", "non-null pointer"}));
    1208            0 :     CHK_PTR_NULL(outputPtr);
    1209            0 :     RPT_INPUT_ERR(
    1210              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1211              :         std::vector<std::string>({"HcclCommGraphReduce", "nullptr", "stream", "non-null pointer"}));
    1212            0 :     CHK_PTR_NULL(stream);
    1213            0 :     CHK_RET(HcomCheckReductionOp("HcclCommGraphReduce", op));
    1214            0 :     u32 totalRanks = 0;
    1215            0 :     CHK_RET(HcclCommGraphGetRankSize(opBaseHcom, &totalRanks));
    1216            0 :     CHK_RET(HcomCheckUserRank(totalRanks, root));
    1217            0 :     s32 streamId = 0;
    1218            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    1219              :     /* 接口交互信息日志 */
    1220            0 :     HCCL_RUN_INFO(
    1221              :         "Entry-HcclCommGraphReduce:tag[%s], inputPtr[%p], outputPtr[%p], count[%llu], dataType[%s], op[%s], "
    1222              :         "root[%u], opBaseHcom[%lld], streamId[%d]",
    1223              :         tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(), root,
    1224              :         opBaseHcom, streamId);
    1225            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
    1226            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
    1227              : 
    1228              :     // HcomGraphReduceV2
    1229            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    1230              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1231              :         CHK_PTR_NULL(hcclComm);
    1232              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1233              :         CHK_PTR_NULL(commV2);
    1234              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    1235              :         CHK_RET(HcomGraphReduceV2(tag, inputPtr, outputPtr, count, dataType, op, root, opBaseHcom, stream));
    1236              :         return HCCL_SUCCESS;
    1237              :     }());
    1238            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType));
    1239            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1240            0 :     CHK_PTR_NULL(hcclComm);
    1241            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1242              :     /* 入参的正确性由HCCL确保 */
    1243            0 :     HcclResult ret = hcclComm->Reduce(tag, inputPtr, outputPtr, count, dataType, op, root, stream);
    1244            0 :     CHK_PRT_RET(
    1245              :         ret != HCCL_SUCCESS,
    1246              :         HCCL_ERROR(
    1247              :             "[Reduce][Result]errNo[0x%016llx] hcclComm Reduce error, tag[%s], "
    1248              :             "input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s], root[%u]",
    1249              :             HCOM_ERROR_CODE(ret), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
    1250              :             GetReduceOpEnumStr(op).c_str(), root),
    1251              :         ret);
    1252            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_REDUCE, beginTime, count, dataType));
    1253            0 :     HcclUs endut = TIME_NOW();
    1254              :     /* 关键状态记录 */
    1255            0 :     HCCL_RUN_INFO(
    1256              :         "HcclCommGraphReduce success, take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
    1257              :         "count[%llu], data_type[%s], op[%s], root[%u], opBaseHcom[%lld]",
    1258              :         DURATION_US(endut - startut), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
    1259              :         GetReduceOpEnumStr(op).c_str(), root, opBaseHcom);
    1260              : 
    1261            0 :     return HCCL_SUCCESS;
    1262              : }
    1263              : 
    1264            0 : HcclResult HcclCommGraphBroadcast(
    1265              :     const char* tag, void* ptr, u64 count, HcclDataType dataType, u32 root, s64 opBaseHcom, rtStream_t stream)
    1266              : {
    1267            0 :     HcclUs startut = TIME_NOW();
    1268            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    1269            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return BroadCast success"), HCCL_SUCCESS);
    1270              : 
    1271              :     // 入参合法性校验
    1272            0 :     RPT_INPUT_ERR(
    1273              :         ptr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1274              :         std::vector<std::string>({"HcclCommGraphBroadcast", "nullptr", "ptr", "non-null pointer"}));
    1275            0 :     CHK_PTR_NULL(ptr);
    1276            0 :     RPT_INPUT_ERR(
    1277              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1278              :         std::vector<std::string>({"HcclCommGraphBroadcast", "nullptr", "stream", "non-null pointer"}));
    1279            0 :     CHK_PTR_NULL(stream);
    1280            0 :     u32 totalRanks = 0;
    1281            0 :     CHK_RET(HcclCommGraphGetRankSize(opBaseHcom, &totalRanks));
    1282            0 :     CHK_RET(HcomCheckUserRank(totalRanks, root));
    1283              : 
    1284            0 :     s32 streamId = 0;
    1285            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    1286              :     /* 接口交互信息日志 */
    1287            0 :     HCCL_RUN_INFO(
    1288              :         "Entry-HcclCommGraphBroadcast:tag[%s], ptr[%p], count[%llu], dataType[%s], root[%u], "
    1289              :         "opBaseHcom[%lld], streamId[%d]",
    1290              :         tag, ptr, count, GetDataTypeEnumStr(dataType).c_str(), root, opBaseHcom, streamId);
    1291              : 
    1292            0 :     CHK_RET(PrintMemoryAttr(ptr));
    1293            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    1294              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1295              :         CHK_PTR_NULL(hcclComm);
    1296              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1297              :         CHK_PTR_NULL(commV2);
    1298              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    1299              :         CHK_RET(HcomGraphBroadcastV2(tag, ptr, count, dataType, root, opBaseHcom, stream));
    1300              :         return HCCL_SUCCESS;
    1301              :     }());
    1302            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType));
    1303            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1304            0 :     CHK_PTR_NULL(hcclComm);
    1305            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1306            0 :     u32 aivCoreLimit = 0;
    1307            0 :     CHK_RET(hcclComm->GetNumBlocks(aivCoreLimit));
    1308              :     /* 入参的正确性由HCCL确保 */
    1309            0 :     HcclResult ret = hcclComm->Broadcast(tag, ptr, count, dataType, root, stream);
    1310            0 :     CHK_PRT_RET(
    1311              :         ret != HCCL_SUCCESS,
    1312              :         HCCL_ERROR(
    1313              :             "[Broadcast][Result]errNo[0x%016llx] hcclComm BroadCast error,tag[%s], input_ptr[%p],"
    1314              :             "count[%llu], data_type[%s], root[%u]",
    1315              :             HCOM_ERROR_CODE(ret), tag, ptr, count, GetDataTypeEnumStr(dataType).c_str(), root),
    1316              :         ret);
    1317            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_BROADCAST, beginTime, count, dataType));
    1318              :     /* 关键状态记录 */
    1319            0 :     HCCL_RUN_INFO(
    1320              :         "HcclCommGraphBroadcast success,take time [%lld]us,tag[%s], input_ptr[%p], count[%llu], "
    1321              :         "data_type[%s], root[%u], opBaseHcom[%lld]",
    1322              :         DURATION_US(TIME_NOW() - startut), tag, ptr, count, GetDataTypeEnumStr(dataType).c_str(), root, opBaseHcom);
    1323              : 
    1324            0 :     return HCCL_SUCCESS;
    1325              : }
    1326            0 : HcclResult HcclCommGraphReduceScatter(
    1327              :     const char* tag, void* inputPtr, void* outputPtr, u64 count, HcclDataType dataType, HcclReduceOp op, s64 opBaseHcom,
    1328              :     rtStream_t stream)
    1329              : {
    1330            0 :     HcclUs startut = TIME_NOW();
    1331            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    1332            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return ReduceScatter success"), HCCL_SUCCESS);
    1333              :     // 入参合法性校验
    1334            0 :     RPT_INPUT_ERR(
    1335              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1336              :         std::vector<std::string>({"HcclCommGraphReduceScatter", "nullptr", "inputPtr", "non-null pointer"}));
    1337            0 :     CHK_PTR_NULL(inputPtr);
    1338            0 :     RPT_INPUT_ERR(
    1339              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1340              :         std::vector<std::string>({"HcclCommGraphReduceScatter", "nullptr", "outputPtr", "non-null pointer"}));
    1341            0 :     CHK_PTR_NULL(outputPtr);
    1342            0 :     RPT_INPUT_ERR(
    1343              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1344              :         std::vector<std::string>({"HcclCommGraphReduceScatter", "nullptr", "stream", "non-null pointer"}));
    1345            0 :     CHK_PTR_NULL(stream);
    1346            0 :     CHK_RET(HcomCheckReductionOp("HcclCommGraphReduceScatter", op));
    1347              : 
    1348            0 :     s32 streamId = 0;
    1349            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    1350              :     /* 接口交互信息日志 */
    1351            0 :     HCCL_RUN_INFO(
    1352              :         "Entry-HcclCommGraphReduceScatter:tag[%s], inputPtr[%p], outputPtr[%p], count[%llu], dataType[%s], "
    1353              :         "op[%s], opBaseHcom[%lld], streamId[%d]",
    1354              :         tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
    1355              :         opBaseHcom, streamId);
    1356            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
    1357            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
    1358              : 
    1359            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    1360              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1361              :         CHK_PTR_NULL(hcclComm);
    1362              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1363              :         CHK_PTR_NULL(commV2);
    1364              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    1365              :         CHK_RET(HcomGraphReduceScatterV2(tag, inputPtr, outputPtr, count, dataType, op, opBaseHcom, stream));
    1366              :         return HCCL_SUCCESS;
    1367              :     }());
    1368            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType));
    1369            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1370            0 :     CHK_PTR_NULL(hcclComm);
    1371            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1372              :     /* 入参的正确性由HCCL确保 */
    1373            0 :     HcclResult ret = hcclComm->ReduceScatter(tag, inputPtr, outputPtr, count, dataType, op, stream);
    1374            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1375              :                 HCCL_ERROR(
    1376              :                     "[ReduceScatter][Result]errNo[0x%016llx] hcclComm ReduceScatter error, tag[%s],"
    1377              :                     "input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s]",
    1378              :                     HCOM_ERROR_CODE(ret), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
    1379              :                     GetReduceOpEnumStr(op).c_str());
    1380              :                 , ret);
    1381            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_REDUCE_SCATTER, beginTime, count, dataType));
    1382              :     /* 关键状态记录 */
    1383            0 :     HCCL_RUN_INFO(
    1384              :         "HcclCommGraphReduceScatter success, take time [%lld]us, tag[%s], input_ptr[%p], output_ptr[%p], "
    1385              :         "count[%llu], data_type[%s], op[%s], opBaseHcom[%lld]",
    1386              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(),
    1387              :         GetReduceOpEnumStr(op).c_str(), opBaseHcom);
    1388              : 
    1389            0 :     return HCCL_SUCCESS;
    1390              : }
    1391            0 : HcclResult HcclCommGraphSend(
    1392              :     const char* tag, void* inputPtr, u64 count, HcclDataType dataType, u32 destRank, u32 srTag, s64 opBaseHcom,
    1393              :     rtStream_t stream)
    1394              : {
    1395            0 :     HcclUs startut = TIME_NOW();
    1396            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    1397            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return send success"), HCCL_SUCCESS);
    1398              : 
    1399              :     // 入参合法性校验
    1400            0 :     RPT_INPUT_ERR(
    1401              :         inputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1402              :         std::vector<std::string>({"HcclCommGraphSend", "nullptr", "inputPtr", "non-null pointer"}));
    1403            0 :     CHK_PTR_NULL(inputPtr);
    1404            0 :     RPT_INPUT_ERR(
    1405              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1406              :         std::vector<std::string>({"HcclCommGraphSend", "nullptr", "stream", "non-null pointer"}));
    1407            0 :     CHK_PTR_NULL(stream);
    1408            0 :     u32 totalRanks = 0;
    1409            0 :     CHK_RET(HcclCommGraphGetRankSize(opBaseHcom, &totalRanks));
    1410            0 :     CHK_RET(HcomCheckUserRank(totalRanks, destRank));
    1411              : 
    1412            0 :     s32 streamId = 0;
    1413            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    1414              :     /* 接口交互信息日志 */
    1415            0 :     HCCL_RUN_INFO(
    1416              :         "Entry-HcclCommGraphSend:tag[%s], inputPtr[%p], count[%llu], dataType[%s], destRank[%u], srTag[%u], "
    1417              :         "opBaseHcom[%lld], streamId[%d]",
    1418              :         tag, inputPtr, count, GetDataTypeEnumStr(dataType).c_str(), destRank, srTag, opBaseHcom, streamId);
    1419              : 
    1420            0 :     CHK_RET(PrintMemoryAttr(inputPtr));
    1421            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    1422              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1423              :         CHK_PTR_NULL(hcclComm);
    1424              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1425              :         CHK_PTR_NULL(commV2);
    1426              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    1427              :         CHK_RET(HcomGraphSendV2(tag, inputPtr, count, dataType, destRank, srTag, opBaseHcom, stream));
    1428              :         return HCCL_SUCCESS;
    1429              :     }());
    1430            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType));
    1431            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1432            0 :     CHK_PTR_NULL(hcclComm);
    1433            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1434              : 
    1435            0 :     u32 rankID = 0;
    1436            0 :     CHK_RET(HcclCommGraphGetRankId(opBaseHcom, &rankID));
    1437              :     /* 调用HCCL的send, 入参的正确性由HCCL确保 */
    1438            0 :     HcclResult ret = hcclComm->send(tag, inputPtr, count, dataType, destRank, stream, srTag, rankID);
    1439            0 :     CHK_PRT_RET(
    1440              :         ret != HCCL_SUCCESS,
    1441              :         HCCL_ERROR(
    1442              :             "[Send][Result]errNo[0x%016llx] hcclComm send error, tag[%s], "
    1443              :             "inputPtr[%p], count[%llu], dataType[%s], destRank[%u]",
    1444              :             HCOM_ERROR_CODE(ret), tag, inputPtr, count, GetDataTypeEnumStr(dataType).c_str(), destRank),
    1445              :         ret);
    1446            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_SEND, beginTime, count, dataType));
    1447              :     /* 关键状态记录 */
    1448            0 :     HCCL_RUN_INFO(
    1449              :         "HcclCommGraphSend success,time[%lld]us,tag[%s],inputPtr[%p],count[%llu],dataType[%s],destRank[%u],"
    1450              :         "srTag[%u], opBaseHcom[%lld]",
    1451              :         DURATION_US(TIME_NOW() - startut), tag, inputPtr, count, GetDataTypeEnumStr(dataType).c_str(), destRank, srTag,
    1452              :         opBaseHcom);
    1453              : 
    1454            0 :     return HCCL_SUCCESS;
    1455              : }
    1456            0 : HcclResult HcclCommGraphReceive(
    1457              :     const char* tag, void* outputPtr, u64 count, HcclDataType dataType, u32 srcRank, u32 srTag, s64 opBaseHcom,
    1458              :     rtStream_t stream)
    1459              : {
    1460            0 :     HcclUs startut = TIME_NOW();
    1461            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    1462            0 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return receive success"), HCCL_SUCCESS);
    1463              :     // 入参合法性校验
    1464            0 :     RPT_INPUT_ERR(
    1465              :         outputPtr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1466              :         std::vector<std::string>({"HcclCommGraphReceive", "nullptr", "outputPtr", "non-null pointer"}));
    1467            0 :     CHK_PTR_NULL(outputPtr);
    1468            0 :     RPT_INPUT_ERR(
    1469              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1470              :         std::vector<std::string>({"HcclCommGraphReceive", "nullptr", "stream", "non-null pointer"}));
    1471            0 :     CHK_PTR_NULL(stream);
    1472            0 :     u32 totalRanks = 0;
    1473            0 :     CHK_RET(HcclCommGraphGetRankSize(opBaseHcom, &totalRanks));
    1474            0 :     CHK_RET(HcomCheckUserRank(totalRanks, srcRank));
    1475              : 
    1476            0 :     s32 streamId = 0;
    1477            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    1478              :     /* 接口交互信息日志 */
    1479            0 :     HCCL_RUN_INFO(
    1480              :         "Entry-HcclCommGraphReceive:tag[%s], outputPtr[%p], count[%llu], dataType[%s], srcRank[%u], "
    1481              :         "srTag[%u], opBaseHcom[%lld], streamId[%d]",
    1482              :         tag, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), srcRank, srTag, opBaseHcom, streamId);
    1483            0 :     CHK_RET(PrintMemoryAttr(outputPtr));
    1484            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    1485              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1486              :         CHK_PTR_NULL(hcclComm);
    1487              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1488              :         CHK_PTR_NULL(commV2);
    1489              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    1490              :         CHK_RET(HcomGraphReceiveV2(tag, outputPtr, count, dataType, srcRank, srTag, opBaseHcom, stream));
    1491              :         return HCCL_SUCCESS;
    1492              :     }());
    1493            0 :     CHK_RET(HcomCheckOpParam(tag, count, dataType));
    1494              : 
    1495            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1496            0 :     CHK_PTR_NULL(hcclComm);
    1497            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1498              : 
    1499              :     /* 记录指令信息用于一致性校验 */
    1500            0 :     u32 rankID = 0;
    1501            0 :     CHK_RET(HcclCommGraphGetRankId(opBaseHcom, &rankID));
    1502            0 :     HcclResult ret = hcclComm->receive(tag, outputPtr, count, dataType, srcRank, stream, srTag, rankID);
    1503            0 :     CHK_PRT_RET(
    1504              :         ret != HCCL_SUCCESS,
    1505              :         HCCL_ERROR(
    1506              :             "[Receive][Result]errNo[0x%016llx] hcclComm receive error,tag[%s], "
    1507              :             "outputPtr[%p], count[%llu], dataType[%s], srcRank[%u],",
    1508              :             HCOM_ERROR_CODE(ret), tag, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), srcRank),
    1509              :         ret);
    1510            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_RECEIVE, beginTime, count, dataType));
    1511              :     /* 关键状态记录 */
    1512            0 :     HCCL_RUN_INFO(
    1513              :         "HcclCommGraphReceive success,time[%lld]us, tag[%s], outputPtr[%p], count[%llu], dataType[%s], "
    1514              :         "srcRank[%u], srTag[%u], opBaseHcom[%lld],",
    1515              :         DURATION_US(TIME_NOW() - startut), tag, outputPtr, count, GetDataTypeEnumStr(dataType).c_str(), srcRank, srTag,
    1516              :         opBaseHcom);
    1517              : 
    1518            0 :     return HCCL_SUCCESS;
    1519              : }
    1520            0 : HcclResult HcclCommGraphGetAlltoAllStagedWorkSpaceMemSize(
    1521              :     s64 opBaseHcom, u64* sendCounts, u64* sdispls, HcclDataType sendType, u64* recvCounts, u64* rdispls,
    1522              :     HcclDataType recvType, u64& memSize)
    1523              : {
    1524            0 :     CHK_PTR_NULL(sendCounts);
    1525            0 :     CHK_PTR_NULL(sdispls);
    1526            0 :     CHK_PTR_NULL(recvCounts);
    1527            0 :     CHK_PTR_NULL(rdispls);
    1528            0 :     CHK_RET(HcomCheckDataType(sendType));
    1529            0 :     CHK_RET(HcomCheckDataType(recvType));
    1530              : 
    1531            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1532            0 :     CHK_PTR_NULL(hcclComm);
    1533            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1534            0 :     CHK_RET(hcclComm->GetAlltoAllStagedWorkSpaceMemSize(
    1535              :         sendCounts, sdispls, sendType, recvCounts, rdispls, recvType, memSize));
    1536            0 :     return HCCL_SUCCESS;
    1537              : }
    1538            0 : HcclResult HcclCommGraphSetWorkspaceResource(
    1539              :     const std::string& tag, s64 opBaseHcom, std::vector<rtStream_t> stream, void* memPtr, u64 maxSize)
    1540              : {
    1541            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1542            0 :     CHK_PTR_NULL(hcclComm);
    1543            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1544              : 
    1545            0 :     CHK_RET(hcclComm->SetWorkspaceResource(tag, memPtr, maxSize, stream));
    1546            0 :     return HCCL_SUCCESS;
    1547              : }
    1548              : 
    1549            0 : HcclResult HcclCommGraphGetRankSize(s64 opBaseHcom, u32* rankSize)
    1550              : {
    1551            0 :     RPT_INPUT_ERR(
    1552              :         rankSize == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1553              :         std::vector<std::string>({"HcclCommGraphGetRankSize", "nullptr", "rankSize", "non-null pointer"}));
    1554            0 :     CHK_PTR_NULL(rankSize);
    1555            0 :     bool& isAutoTuneModeOpen = HcomGetCtxAutoTuneMode();
    1556            0 :     if (isAutoTuneModeOpen) {
    1557            0 :         *rankSize = 1;
    1558            0 :         return HCCL_SUCCESS;
    1559              :     }
    1560            0 :     HCCL_INFO("HcclCommGraphGetRankSize:opBaseHcom[%lld]", opBaseHcom);
    1561            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    1562              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1563              :         CHK_PTR_NULL(hcclComm);
    1564              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1565              :         CHK_PTR_NULL(commV2);
    1566              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    1567              :         CHK_RET(HcclCommGraphGetRankSizeV2(opBaseHcom, rankSize));
    1568              :         return HCCL_SUCCESS;
    1569              :     }());
    1570              : 
    1571            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1572            0 :     CHK_PTR_NULL(hcclComm);
    1573            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1574            0 :     CHK_RET(hcclComm->GetRankSize(*rankSize));
    1575              : 
    1576            0 :     return HCCL_SUCCESS;
    1577              : }
    1578              : 
    1579            0 : HcclResult HcclCommGraphGetRankId(s64 opBaseHcom, u32* rankId)
    1580              : {
    1581            0 :     RPT_INPUT_ERR(
    1582              :         rankId == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1583              :         std::vector<std::string>({"HcclCommGraphGetRankId", "nullptr", "rankId", "non-null pointer"}));
    1584            0 :     CHK_PTR_NULL(rankId);
    1585            0 :     bool& isAutoTuneModeOpen = HcomGetCtxAutoTuneMode();
    1586            0 :     if (isAutoTuneModeOpen) {
    1587            0 :         *rankId = 0;
    1588            0 :         return HCCL_SUCCESS;
    1589              :     }
    1590            0 :     HCCL_INFO("HcclCommGraphGetRankId:opBaseHcom[%lld]", opBaseHcom);
    1591            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    1592              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1593              :         CHK_PTR_NULL(hcclComm);
    1594              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1595              :         CHK_PTR_NULL(commV2);
    1596              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    1597              :         CHK_RET(HcclCommGraphGetRankIdV2(opBaseHcom, rankId));
    1598              :         return HCCL_SUCCESS;
    1599              :     }());
    1600              : 
    1601            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1602            0 :     CHK_PTR_NULL(hcclComm);
    1603            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    1604            0 :     CHK_RET(hcclComm->GetUserRank(*rankId));
    1605              : 
    1606            0 :     return HCCL_SUCCESS;
    1607              : }
    1608              : 
    1609            0 : HcclResult HcclCommGraphGetWorkspaceSubStreamNum(
    1610              :     u64 count, HcclDataType dataType, HcclReduceOp op, const std::string& algName, s64 opBaseHcom, u64& streamNum,
    1611              :     u64 dataSize, bool ifAiv, HcclCMDType opType)
    1612              : {
    1613            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1614            0 :     return hcclComm->GetWorkspaceSubStreamNum(count, dataType, op, algName, streamNum, dataSize, ifAiv, opType);
    1615              : }
    1616              : 
    1617              : HcclResult
    1618            0 : HcclCommGraphGetAllReduceScratchSize(s64 opBaseHcom, const u64 count, const HcclDataType dataType, u64& outScratchSize)
    1619              : {
    1620            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1621            0 :     CHK_PTR_NULL(hcclComm);
    1622            0 :     return hcclComm->GetAllReduceScratchSize(count, dataType, outScratchSize);
    1623              : }
    1624              : 
    1625            0 : HcclResult HcclCommGraphGetIdentifier(s64 opBaseHcom, std::string& identifier)
    1626              : {
    1627            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1628            0 :     CHK_PTR_NULL(hcclComm);
    1629            0 :     identifier = hcclComm->GetIdentifier();
    1630            0 :     return HCCL_SUCCESS;
    1631              : }
    1632              : 
    1633            0 : HcclResult GenerateGroupHash(std::string& group, std::string& groupHash)
    1634              : {
    1635              :     std::hash<std::string> hashString;
    1636            0 :     size_t nameHash = hashString(group);
    1637            0 :     groupHash = std::to_string(nameHash);
    1638            0 :     return HCCL_SUCCESS;
    1639              : }
    1640              : 
    1641            0 : HcclResult GenerateCclOpTag(const std::string& opType, const int64_t& hcomComm, std::string& group, std::string& sTag)
    1642              : {
    1643            0 :     HcomOpTagInfo& opTagInfo = HcomGetCtxOpTagInfo();
    1644              : 
    1645              :     // middle 在获取到hcomComm时,等于identifier;在获取到group时,等于group
    1646            0 :     std::string middle;
    1647            0 :     if (hcomComm == static_cast<int64_t>(CommNumHcom::COMM_VALUE_DEFAULT)) {
    1648            0 :         middle = group;
    1649              :     } else {
    1650            0 :         CHK_RET(HcclCommGraphGetIdentifier(hcomComm, middle));
    1651              :     }
    1652              :     std::hash<std::string> hashString;
    1653            0 :     size_t nameHash = hashString(middle);
    1654            0 :     sTag = opType + "_" + std::to_string(nameHash);
    1655              :     // 多张图node name重复导致tag相同,因此对tag添加索引 tag = op type + node name + identifier name + index
    1656              : 
    1657            0 :     auto iter = opTagInfo.opIndex.find(middle);
    1658            0 :     if (iter == opTagInfo.opIndex.end()) {
    1659            0 :         opTagInfo.opIndex.insert({middle, 0});
    1660            0 :         iter = opTagInfo.opIndex.find(middle);
    1661            0 :         CHK_PRT_RET(
    1662              :             (iter == opTagInfo.opIndex.end()),
    1663              :             HCCL_ERROR("[Generate][OpTag]generate tag fail. get the op index failed. ret[%d]", HCCL_E_INTERNAL),
    1664              :             HCCL_E_INTERNAL);
    1665              :     }
    1666              : 
    1667            0 :     sTag = sTag + "_" + std::to_string(iter->second++);
    1668              : 
    1669            0 :     HCCL_INFO("generate ccl op tag success, tag[%s]", sTag.c_str());
    1670            0 :     return HCCL_SUCCESS;
    1671            0 : }
    1672              : 
    1673            0 : HcclResult HcomGetDevId(const char* group, s32* devId)
    1674              : {
    1675            0 :     HCCLV2_FUNC_RUN(HcomGetDevIdV2(group, devId));
    1676              :     /* 获取rankId */
    1677            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    1678            0 :     if (group != nullptr && HcclGetCommHandle(group, hcclComm) == HCCL_SUCCESS) {
    1679            0 :         CHK_RET(hcclComm->GetDeviceId(*devId));
    1680              :     } else {
    1681            0 :         if (group == nullptr) {
    1682            0 :             group = HCCL_WORLD_GROUP;
    1683              :         }
    1684            0 :         u32 rankId = 0;
    1685            0 :         CHK_RET(HcomGetRankId(group, &rankId));
    1686            0 :         u32 worldRankId = 0;
    1687            0 :         CHK_RET(HcomGetWorldRankFromGroupRank(group, rankId, &worldRankId));
    1688            0 :         HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    1689              : 
    1690            0 :         for (auto it : hcomInfo.rankTable.rankList) {
    1691            0 :             if (worldRankId == it.rankId) {
    1692            0 :                 u32 deviceLogicId = 0;
    1693            0 :                 CHK_RET(hrtGetDeviceIndexByPhyId(static_cast<u32>(it.deviceInfo.devicePhyId), deviceLogicId));
    1694            0 :                 *devId = static_cast<s32>(deviceLogicId);
    1695            0 :                 return HCCL_SUCCESS;
    1696              :             }
    1697            0 :         }
    1698            0 :         HCCL_WARNING("[Get][DevId]rankList has no item with rankId[%u]", worldRankId);
    1699              :     }
    1700              : 
    1701            0 :     return HCCL_SUCCESS;
    1702            0 : }
    1703              : 
    1704            0 : HcclResult HcclCommGraphGetDevId(s64 opBaseHcom, s32* devId)
    1705              : {
    1706            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    1707            0 :     CHK_PTR_NULL(hcclComm);
    1708            0 :     CHK_PTR_NULL(devId);
    1709            0 :     CHK_RET(hcclComm->GetDeviceId(*devId));
    1710            0 :     HCCL_INFO("HcclCommGraphGetDevId devID[%d]", *devId);
    1711            0 :     return HCCL_SUCCESS;
    1712              : }
    1713              : 
    1714            0 : HcclResult HcomGetLocalRankSize(const char* group, u32* localRankSize)
    1715              : {
    1716            0 :     RPT_INPUT_ERR(
    1717              :         localRankSize == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1718              :         std::vector<std::string>({"HcomGetLocalRankSize", "nullptr", "localRankSize", "non-null pointer"}));
    1719            0 :     CHK_PTR_NULL(localRankSize);
    1720              : 
    1721            0 :     HCCLV2_FUNC_RUN(HcomGetLocalRankSizeV2(group, localRankSize));
    1722            0 :     bool& isAutoTuneModeOpen = HcomGetCtxAutoTuneMode();
    1723            0 :     if (isAutoTuneModeOpen) {
    1724            0 :         *localRankSize = 1;
    1725            0 :         return HCCL_SUCCESS;
    1726              :     }
    1727            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    1728            0 :     CHK_PRT_RET(
    1729              :         hcomInfo.pComm == nullptr,
    1730              :         HCCL_ERROR("[Get][LocalRankSize]hcomInfo.pComm is null, "
    1731              :                    "please check if the initialize process is called."),
    1732              :         HCCL_E_PTR);
    1733            0 :     HcclResult ret = HcomCheckGroupName(group);
    1734            0 :     RPT_INPUT_ERR(
    1735              :         ret != HCCL_SUCCESS, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1736              :         std::vector<std::string>(
    1737              :             {"HcomGetLocalRankSize",
    1738              :              {group, strnlen(group, GROUP_NAME_MAX_LEN + 1)},
    1739              :              "group",
    1740              :              "a non-empty string of length 1 to " + std::to_string(GROUP_NAME_MAX_LEN)
    1741              :                  + ", containing only alphanumeric characters and underscores"}));
    1742            0 :     CHK_PRT_RET(
    1743              :         ret != HCCL_SUCCESS,
    1744              :         HCCL_ERROR(
    1745              :             "[%s][%s]errNo[0x%016llx] get local ranksize "
    1746              :             "group name is invalid",
    1747              :             LOG_KEYWORDS_TASK_EXEC.c_str(), LOG_KEYWORDS_INVALID_ARGUMENT.c_str(), HCOM_ERROR_CODE(ret)),
    1748              :         ret);
    1749              : 
    1750            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    1751              : 
    1752            0 :     u32 rankSize = 0;
    1753            0 :     u32 serverNum = 0;
    1754            0 :     CHK_RET(GetGroupRankInfo(strGroup.c_str(), RankInfoType::RANK_SIZE_IN_GROUP, 0, &rankSize));
    1755            0 :     CHK_RET(GetGroupRankInfo(strGroup.c_str(), RankInfoType::SERVER_NUM_IN_GROUP, 0, &serverNum));
    1756              : 
    1757            0 :     CHK_PRT_RET(
    1758              :         serverNum == 0,
    1759              :         HCCL_ERROR("[Get][LocalRankSize]errNo[0x%016llx] server num is zero", HCOM_ERROR_CODE(HCCL_E_PARA)),
    1760              :         HCCL_E_PARA);
    1761              : 
    1762            0 :     *localRankSize = rankSize / serverNum;
    1763            0 :     HCCL_INFO("hcom get local rank size success, group[%s]", strGroup.c_str());
    1764              : 
    1765            0 :     return HCCL_SUCCESS;
    1766            0 : }
    1767              : 
    1768            0 : HcclResult HcomGetRankId(const char* group, u32* rankId)
    1769              : {
    1770            0 :     RPT_INPUT_ERR(
    1771              :         rankId == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1772              :         std::vector<std::string>({"HcomGetRankId", "nullptr", "rankId", "non-null pointer"}));
    1773            0 :     CHK_PTR_NULL(rankId);
    1774            0 :     bool& isAutoTuneModeOpen = HcomGetCtxAutoTuneMode();
    1775            0 :     if (isAutoTuneModeOpen) {
    1776            0 :         *rankId = 0;
    1777            0 :         return HCCL_SUCCESS;
    1778              :     }
    1779              : 
    1780            0 :     HcclResult ret = HcomCheckGroupName(group);
    1781            0 :     RPT_INPUT_ERR(
    1782              :         ret != HCCL_SUCCESS, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1783              :         std::vector<std::string>(
    1784              :             {"HcomGetRankId",
    1785              :              {group, strnlen(group, GROUP_NAME_MAX_LEN + 1)},
    1786              :              "group",
    1787              :              "a non-empty string of length 1 to " + std::to_string(GROUP_NAME_MAX_LEN)
    1788              :                  + ", containing only alphanumeric characters and underscores"}));
    1789            0 :     CHK_PRT_RET(
    1790              :         ret != HCCL_SUCCESS,
    1791              :         HCCL_ERROR(
    1792              :             "[%s][%s]errNo[0x%016llx] get_rank_id group name is invalid", LOG_KEYWORDS_TASK_EXEC.c_str(),
    1793              :             LOG_KEYWORDS_INVALID_ARGUMENT.c_str(), HCOM_ERROR_CODE(ret)),
    1794              :         ret);
    1795              : 
    1796              :     // HcomGetRankIdV2
    1797            0 :     HCCLV2_FUNC_RUN(HcomGetRankIdV2(group, rankId));
    1798            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    1799            0 :     CHK_RET(HcomGetCommByGroup(group, hcclComm));
    1800            0 :     CHK_RET(hcclComm->GetGroupRank(*rankId));
    1801            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    1802            0 :     HCCL_INFO("hcom get rank id success, group[%s], rankId[%u]", strGroup.c_str(), *rankId);
    1803              : 
    1804            0 :     return HCCL_SUCCESS;
    1805            0 : }
    1806              : 
    1807            0 : HcclResult HcomGetLocalRankId(const char* group, u32* localRankId)
    1808              : {
    1809            0 :     CHK_PTR_NULL(localRankId);
    1810            0 :     bool& isAutoTuneModeOpen = HcomGetCtxAutoTuneMode();
    1811            0 :     if (isAutoTuneModeOpen) {
    1812            0 :         *localRankId = 0;
    1813            0 :         return HCCL_SUCCESS;
    1814              :     }
    1815              : 
    1816            0 :     HCCLV2_FUNC_RUN(HcomGetLocalRankIdV2(group, localRankId));
    1817            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    1818            0 :     CHK_PRT_RET(
    1819              :         hcomInfo.pComm == nullptr,
    1820              :         HCCL_ERROR("[Get][LocalRankId]hcomInfo.pComm is null, "
    1821              :                    "please check if the initialize process is called."),
    1822              :         HCCL_E_PTR);
    1823            0 :     CHK_RET(HcomCheckGroupName(group));
    1824              : 
    1825            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    1826              : 
    1827            0 :     u32 rankId = 0;
    1828            0 :     u32 localRankSize = 0;
    1829            0 :     CHK_RET(GetGroupRankInfo(strGroup.c_str(), RankInfoType::RANK_ID_IN_GROUP, 0, &rankId));
    1830            0 :     CHK_RET(HcomGetLocalRankSize(strGroup.c_str(), &localRankSize));
    1831              : 
    1832            0 :     CHK_PRT_RET(
    1833              :         localRankSize == 0,
    1834              :         HCCL_ERROR("[Get][LocalRankId]errNo[0x%016llx] local rank size is zero", HCOM_ERROR_CODE(HCCL_E_PARA)),
    1835              :         HCCL_E_PARA);
    1836              : 
    1837            0 :     *localRankId = rankId % localRankSize;
    1838            0 :     HCCL_INFO("hcom get local rank id success, group[%s]", strGroup.c_str());
    1839              : 
    1840            0 :     return HCCL_SUCCESS;
    1841            0 : }
    1842              : 
    1843              : HcclResult GetRankListHeterog(u32 rankNum, const u32* rankIds, HcclGroupParams& params);
    1844            0 : HcclResult HcomCreateGroupImplHeterog(const std::string& group, const std::vector<u32>& rankIds)
    1845              : {
    1846            0 :     HcclUs startut = TIME_NOW();
    1847            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    1848            0 :     std::string rankId;
    1849            0 :     for (u32 i = 0; i < rankIds.size(); i++) {
    1850            0 :         if (i < rankIds.size() - 1) {
    1851            0 :             rankId += to_string(rankIds[i]) + ',';
    1852            0 :         } else if (i == rankIds.size() - 1) {
    1853            0 :             rankId += to_string(rankIds[i]);
    1854              :         }
    1855              :     }
    1856              :     /* 接口交互信息日志 */
    1857            0 :     HCCL_RUN_INFO(
    1858              :         "Entry-HcomCreateGroup:group[%s], rankNum[%zu], rankIds[%s]", group.c_str(), rankIds.size(), rankId.c_str());
    1859              : 
    1860            0 :     CHK_PRT_RET(
    1861              :         hcomInfo.pComm == nullptr,
    1862              :         HCCL_ERROR("[Create][Group]hcomInfo.pComm is null, please check if the initialize process is called."),
    1863              :         HCCL_E_PTR);
    1864              : 
    1865            0 :     CHK_PRT_RET(
    1866              :         hcomInfo.rankTable.rankList.empty(), HCCL_ERROR("[Create][Group]group[%s] rankList is empty", group.c_str()),
    1867              :         HCCL_E_INTERNAL);
    1868              : 
    1869              :     /* 已经存在的group不允许再次创建 */
    1870            0 :     std::unique_lock<std::mutex> groupParaLock(hcomInfo.groupParamsLock);
    1871            0 :     if (hcomInfo.hcomGroupMap.find(group) != hcomInfo.hcomGroupMap.end()) {
    1872            0 :         HCCL_ERROR(
    1873              :             "[Create][Group]errNo[0x%016llx] group[%s] is already exist", HCOM_ERROR_CODE(HCCL_E_PARA), group.c_str());
    1874            0 :         return HCCL_E_PARA;
    1875              :     }
    1876            0 :     groupParaLock.unlock();
    1877              : 
    1878            0 :     HcclGroupParams groupParamsTem;
    1879            0 :     CHK_RET(GetRankListHeterog(rankIds.size(), rankIds.data(), groupParamsTem));
    1880              : 
    1881              :     // 如果是groupRank = INVALID_VALUE_RANKID,即本rank不参与create group
    1882            0 :     if (groupParamsTem.groupRank == INVALID_VALUE_RANKID) {
    1883            0 :         HCCL_ERROR(
    1884              :             "[Create][Group]errNo[0x%016llx] confirm groupRank from worldRank[%u] error",
    1885              :             HCOM_ERROR_CODE(HCCL_E_NOT_FOUND), hcomInfo.params.rank);
    1886            0 :         return HCCL_E_NOT_FOUND;
    1887              :     }
    1888              : 
    1889              :     /* 入参的正确性由HCCL确保 */
    1890              : 
    1891            0 :     CHK_RET(hcomInfo.pComm->CreateGroup(
    1892              :         group, groupParamsTem.groupRank, hcomInfo.params.rank, groupParamsTem.groupRanks, groupParamsTem.pSubComm));
    1893            0 :     CHK_SMART_PTR_NULL(groupParamsTem.pSubComm);
    1894              : 
    1895            0 :     groupParaLock.lock();
    1896            0 :     hcomInfo.hcomGroupMap.insert(std::make_pair(group, groupParamsTem));
    1897            0 :     groupParaLock.unlock();
    1898              : 
    1899            0 :     HCCL_RUN_INFO(
    1900              :         "hcom create group[%s] success, take time [%lld]us", group.c_str(), DURATION_US(TIME_NOW() - startut));
    1901            0 :     return HCCL_SUCCESS;
    1902            0 : }
    1903              : 
    1904            0 : HcclResult HcomAbortGroup(const char* group)
    1905              : {
    1906              :     /* 调优模式直接返回success */
    1907            0 :     bool& isAutoTuneModeOpen = HcomGetCtxAutoTuneMode();
    1908            0 :     if (isAutoTuneModeOpen) {
    1909            0 :         return HCCL_SUCCESS;
    1910              :     }
    1911            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    1912            0 :     CHK_PRT_RET(
    1913              :         hcomInfo.pComm == nullptr,
    1914              :         HCCL_ERROR("[Destroy][Group]hcomInfo.pComm is null, "
    1915              :                    "please check if the initialize process is called."),
    1916              :         HCCL_E_PTR);
    1917              : 
    1918            0 :     HCCL_RUN_INFO("Entry-HcomAbortGroup : group[%s]", group);
    1919            0 :     CHK_RET(DestroyFlag(group, true));
    1920            0 :     u32 ref = 0;
    1921            0 :     CHK_RET(HcomQueryGroupRef(group, ref));
    1922            0 :     while (ref != 0) {
    1923            0 :         std::shared_ptr<hccl::hcclComm> hcclComm = nullptr;
    1924            0 :         CHK_RET(HcomGetCommByGroup(group, hcclComm));
    1925            0 :         SaluSleep(ONE_HUNDRED_MICROSECOND_OF_USLEEP);
    1926            0 :         CHK_RET(HcomQueryGroupRef(group, ref));
    1927            0 :     }
    1928              : 
    1929            0 :     HCCL_RUN_INFO("hcom abort group[%s] success.", group);
    1930            0 :     return HCCL_SUCCESS;
    1931              : }
    1932              : 
    1933            0 : HcclResult HcomDestroyGroupImplHeterog(const std::string& group)
    1934              : {
    1935              :     /* 接口交互信息日志 */
    1936            0 :     HCCL_RUN_INFO("Entry-HcomDestroyGroup:group[%s]", group.c_str());
    1937            0 :     CHK_RET(HcomAbortGroup(group.c_str()));
    1938              : 
    1939            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    1940            0 :     std::unique_lock<std::mutex> groupParaLock(hcomInfo.groupParamsLock);
    1941            0 :     auto iter = hcomInfo.hcomGroupMap.find(group);
    1942            0 :     if (iter == hcomInfo.hcomGroupMap.end()) {
    1943            0 :         HCCL_ERROR(
    1944              :             "[Destroy][Group]errNo[0x%016llx] group[%s] is not exist", HCOM_ERROR_CODE(HCCL_E_PARA), group.c_str());
    1945            0 :         return HCCL_E_PARA;
    1946              :     }
    1947              : 
    1948            0 :     CHK_RET(hcomInfo.pComm->DestroyGroup(group));
    1949              : 
    1950            0 :     (iter->second).groupRanks.clear(); // 清除该服务器内相关group的对应信息
    1951              : 
    1952            0 :     hcomInfo.hcomGroupMap.erase(group);
    1953            0 :     groupParaLock.unlock();
    1954              : 
    1955            0 :     HCCL_RUN_INFO("hcom destroy group[%s] success.", group.c_str());
    1956            0 :     return HCCL_SUCCESS;
    1957            0 : }
    1958              : 
    1959            0 : bool HcomCallBackGroupIsInitHeterog([[maybe_unused]] HcomInfo& hcomInfo) { return false; }
    1960              : 
    1961            0 : HcclResult GetRankListHeterog(u32 rankNum, const u32* rankIds, HcclGroupParams& params)
    1962              : {
    1963            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    1964            0 :     std::vector<RankInfo_t> rankList;
    1965            0 :     params.totalRanks = rankNum;
    1966            0 :     params.worldRank = hcomInfo.params.rank;
    1967            0 :     params.groupRank = INVALID_VALUE_RANKID;
    1968            0 :     for (u32 i = 0; i < rankNum; i++) {
    1969            0 :         params.groupRanks.push_back(rankIds[i]);
    1970              :     }
    1971              : 
    1972            0 :     std::sort(params.groupRanks.begin(), params.groupRanks.end());
    1973            0 :     if (params.groupRanks[rankNum - 1] >= hcomInfo.rankTable.rankNum) {
    1974            0 :         HCCL_ERROR(
    1975              :             "[get][RankList]errNo[0x%016llx] groupRanks[%u]:%u is invalid", HCOM_ERROR_CODE(HCCL_E_PARA), rankNum - 1,
    1976              :             params.groupRanks[rankNum - 1]);
    1977            0 :         return HCCL_E_PARA;
    1978              :     }
    1979            0 :     if (hcomInfo.rankTable.rankList.size() <= params.groupRanks[0]) {
    1980            0 :         HCCL_ERROR(
    1981              :             "[get][RankList]errNo[0x%016llx] groupRanks[0] is invalid:[%u]", HCOM_ERROR_CODE(HCCL_E_PARA),
    1982              :             params.groupRanks[0]);
    1983            0 :         return HCCL_E_PARA;
    1984              :     }
    1985              :     // groupRanks 个数已经校验非0
    1986            0 :     std::string serverId = hcomInfo.rankTable.rankList[params.groupRanks[0]].serverId;
    1987            0 :     u32 serverNum = 1; // severNum初始值应为1,代表groupId为0的serverId;
    1988            0 :     RankInfo_t rankInfo;
    1989            0 :     for (u32 i = 0; i < rankNum; i++) {
    1990            0 :         rankInfo = hcomInfo.rankTable.rankList[params.groupRanks[i]];
    1991              :         // 校验worldRankID
    1992            0 :         if (rankInfo.rankId != params.groupRanks[i]) {
    1993            0 :             HCCL_ERROR(
    1994              :                 "[get][RankList]errNo[0x%016llx] in rankList, worldRanks[%u] is invalid", HCOM_ERROR_CODE(HCCL_E_PARA),
    1995              :                 rankInfo.rankId);
    1996            0 :             return HCCL_E_PARA;
    1997              :         }
    1998            0 :         if (params.groupRanks[i] == params.worldRank) {
    1999            0 :             params.groupRank = i;
    2000              :         }
    2001            0 :         if (rankInfo.serverId != serverId) {
    2002            0 :             serverNum++;
    2003            0 :             serverId = rankInfo.serverId;
    2004              :         }
    2005            0 :         rankInfo.rankId = i;          // 放入groupRankid
    2006            0 :         rankList.push_back(rankInfo); // ranktable中的ranklist是以rankid的顺序排列的
    2007            0 :         rankInfo.serverId = "";       // 释放前先指空字符串
    2008              :     }
    2009            0 :     params.serverNum = serverNum;
    2010            0 :     bool isStandardCard = false;
    2011            0 :     CHK_RET(hcomInfo.pComm->IsStandardCard(isStandardCard));
    2012            0 :     if (!isStandardCard && hcomInfo.params.deviceType != DevType::DEV_TYPE_910B
    2013            0 :         && hcomInfo.params.deviceType != DevType::DEV_TYPE_910_93) {
    2014            0 :         CHK_RET(CheckRankTableConfigInfo(rankList, rankNum, serverNum));
    2015              :     }
    2016            0 :     return HCCL_SUCCESS;
    2017            0 : }
    2018              : 
    2019            0 : HcclResult HcomGetSplitStrategy(
    2020              :     const char* group, const struct model_feature* feature, u32** segmentIdxPtr, u32* len, bool* configured,
    2021              :     GradSplitForceMode force, OriginalGraphShapeType shapeType)
    2022              : {
    2023            0 :     CHK_PTR_NULL(feature);
    2024            0 :     CHK_PTR_NULL(feature->model_name);
    2025            0 :     CHK_PTR_NULL(feature->gradient_size);
    2026            0 :     CHK_PTR_NULL(feature->gradient_time);
    2027            0 :     CHK_PTR_NULL(segmentIdxPtr);
    2028            0 :     CHK_PTR_NULL(len);
    2029            0 :     CHK_PTR_NULL(configured);
    2030              : 
    2031            0 :     bool bRet = feature->gradient_num == 0;
    2032            0 :     CHK_PRT_RET(
    2033              :         bRet, HCCL_ERROR("[Get][SplitStrategy]errNo[0x%016llx] gradient num is zero", HCOM_ERROR_CODE(HCCL_E_PARA)),
    2034              :         HCCL_E_PARA);
    2035            0 :     CHK_RET(HcomCheckGroupName(group));
    2036              : 
    2037            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2038              :     /* 接口交互信息日志 */
    2039            0 :     HCCL_RUN_INFO("Entry-HcomGetSplitStrategy:group[%s], feature[%p]", strGroup.c_str(), feature);
    2040              : 
    2041              :     /* 获取梯度切分策略 */
    2042            0 :     std::vector<u32> segmentIdx;
    2043            0 :     CHK_RET(GetGradientSegment(strGroup, feature, segmentIdx, *configured, force, shapeType));
    2044            0 :     *len = static_cast<u32>(segmentIdx.size());
    2045            0 :     *segmentIdxPtr = new u32[*len];
    2046            0 :     std::copy(segmentIdx.begin(), segmentIdx.end(), *segmentIdxPtr);
    2047              : 
    2048            0 :     return HCCL_SUCCESS;
    2049            0 : }
    2050              : 
    2051            1 : HcclResult GetGradientSegment(
    2052              :     const std::string& group, const struct model_feature* feature, std::vector<u32>& segmentList, bool& configured,
    2053              :     GradSplitForceMode force, OriginalGraphShapeType shapeType)
    2054              : {
    2055              :     HcclResult ret;
    2056            1 :     HCCL_INFO(
    2057              :         "<gradient_segment group %s, model gradient num %u, model name %s>", group.c_str(), feature->gradient_num,
    2058              :         feature->model_name);
    2059              :     /* 分段算法实现 */
    2060            1 :     std::unique_ptr<hccl::GradientSegment> segmentImpl;
    2061            1 :     segmentImpl.reset(new (std::nothrow) GradientSegment());
    2062            1 :     CHK_SMART_PTR_NULL(segmentImpl);
    2063              : 
    2064              :     /* 校验基于总层数索引是否正确 */
    2065            1 :     std::unique_lock<std::mutex> segmentIdxMapLock(g_segmentIdxMapLock);
    2066            1 :     auto gIdxSearch = g_segmentIdxMap.find(group);
    2067            1 :     if (gIdxSearch != g_segmentIdxMap.end()) {
    2068            0 :         bool bRet = (gIdxSearch->second.size() != 0) && (gIdxSearch->second.back() != (feature->gradient_num - 1));
    2069            0 :         CHK_PRT_RET(
    2070              :             bRet,
    2071              :             HCCL_ERROR(
    2072              :                 "[Get][GradientSegment]illegal segmentIndex maxVal=%u should be equal %u", gIdxSearch->second.back(),
    2073              :                 feature->gradient_num - 1),
    2074              :             HCCL_E_PARA);
    2075              :     }
    2076            1 :     segmentIdxMapLock.unlock();
    2077            1 :     ret = segmentImpl->GetGradientSegmentExecutor(group, feature, segmentList, configured, force, shapeType);
    2078            1 :     if (ret == HCCL_SUCCESS) {
    2079            1 :         std::string printStr;
    2080            1 :         u32 baseIndex = 0;
    2081            2 :         for (u32 i = 0; i < segmentList.size(); i++) {
    2082            1 :             printStr.append("[");
    2083            1 :             printStr.append(std::to_string(baseIndex));
    2084            1 :             printStr.append(",");
    2085            1 :             printStr.append(std::to_string(segmentList[i]));
    2086            1 :             printStr.append("] ");
    2087            1 :             baseIndex = segmentList[i] + 1;
    2088              :         }
    2089            1 :         HCCL_RUN_INFO(
    2090              :             "gradient segment result: segment num: %zu, segment index list: %s ", segmentList.size(), printStr.c_str());
    2091            1 :     }
    2092            1 :     return ret;
    2093            1 : }
    2094              : 
    2095            0 : HcclResult HcomExecSelectAlg(
    2096              :     s64 comm, const char* group, HcclCMDType opType, u64 count, HcclDataType dataType, HcclReduceOp op,
    2097              :     int32_t aivCoreLimit, bool& ifAiv, char* algName)
    2098              : {
    2099            0 :     std::string tempAlgName;
    2100            0 :     if (comm != static_cast<int64_t>(CommNumHcom::COMM_VALUE_DEFAULT)) {
    2101            0 :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(comm);
    2102            0 :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    2103            0 :         CHK_PTR_NULL(commV2);
    2104            0 :         comm = reinterpret_cast<s64>(commV2);
    2105            0 :         CHK_RET(HcomSelectAlgV2(comm, group, opType, count, dataType, op, aivCoreLimit, ifAiv, tempAlgName));
    2106              :     } else {
    2107            0 :         std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2108            0 :         CHK_RET(HcomGraphSelectAlgV2(comm, group, opType, count, dataType, op, aivCoreLimit, ifAiv, tempAlgName));
    2109            0 :     }
    2110            0 :     int32_t sret = memcpy_s(algName, ALG_NAME_MAX_LEN, tempAlgName.c_str(), (tempAlgName.length() + 1));
    2111            0 :     CHK_PRT_RET(
    2112              :         sret != EOK,
    2113              :         HCCL_ERROR(
    2114              :             "[HcomExecSelectAlg][algName]memcpy failed. ret[%d],"
    2115              :             "params:destMaxSize[%zu],count[%zu]",
    2116              :             sret, ALG_NAME_MAX_LEN, (tempAlgName.length() + 1)),
    2117              :         HCCL_E_PARA);
    2118            0 :     return HCCL_SUCCESS;
    2119            0 : }
    2120              : 
    2121           14 : HcclResult HcomSelectAlg(
    2122              :     s64 comm, const char* group, u64 count, void* counts, HcclDataType dataType, HcclReduceOp op, HcclCMDType opType,
    2123              :     int32_t aivCoreLimit, bool* ifAiv, char* algName)
    2124              : {
    2125           14 :     CHK_PTR_NULL(ifAiv);
    2126           13 :     HCCLV2_FUNC_RUN(HcomExecSelectAlg(comm, group, opType, count, dataType, op, aivCoreLimit, *ifAiv, algName));
    2127           13 :     HcclWorkflowMode lastWorkflowMode = GetWorkflowMode();
    2128           13 :     SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB);
    2129           13 :     std::string tempAlgName;
    2130           13 :     if (comm != static_cast<int64_t>(CommNumHcom::COMM_VALUE_DEFAULT)) {
    2131            9 :         hccl::hcclComm* hcclHcomComm = reinterpret_cast<hccl::hcclComm*>(comm);
    2132            9 :         CHK_RET(hcclHcomComm->HcclSelectAlg(opType, count, counts, dataType, op, aivCoreLimit, *ifAiv, tempAlgName));
    2133              :     } else {
    2134            4 :         std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2135            4 :         std::shared_ptr<hccl::hcclComm> hcclComm;
    2136            4 :         CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
    2137            3 :         CHK_RET(hcclComm->HcclSelectAlg(opType, count, counts, dataType, op, aivCoreLimit, *ifAiv, tempAlgName));
    2138            6 :     }
    2139           10 :     int32_t sret = memcpy_s(algName, ALG_NAME_MAX_LEN, tempAlgName.c_str(), (tempAlgName.length() + 1));
    2140           10 :     CHK_PRT_RET(
    2141              :         sret != EOK,
    2142              :         HCCL_ERROR(
    2143              :             "[HcomSelectAlg][algName]memcpy failed. ret[%d],"
    2144              :             "params:destMaxSize[%zu],count[%zu]",
    2145              :             sret, ALG_NAME_MAX_LEN, (tempAlgName.length() + 1)),
    2146              :         HCCL_E_PARA);
    2147              : 
    2148           10 :     SetWorkflowMode(lastWorkflowMode);
    2149           10 :     return HCCL_SUCCESS;
    2150           13 : }
    2151              : 
    2152            0 : HcclResult HcomCalcAivCoreNum(
    2153              :     const char* group, HcclCMDType opType, u64 count, void* counts, HcclDataType dataType, int32_t aivCoreLimit,
    2154              :     char* algName, u32* numBlocks)
    2155              : {
    2156            0 :     CHK_PTR_NULL(numBlocks);
    2157            0 :     std::string algNamV2(algName);
    2158            0 :     HCCLV2_FUNC_RUN(HcomCalcNumBlocksV2(group, opType, count, dataType, aivCoreLimit, algNamV2, *numBlocks));
    2159            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2160            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2161            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
    2162            0 :     std::string algNam(algName);
    2163            0 :     CHK_RET(hcclComm->HcclCalcNumBlocks(opType, count, counts, dataType, aivCoreLimit, algNam, *numBlocks));
    2164              : 
    2165            0 :     return HCCL_SUCCESS;
    2166            0 : }
    2167              : 
    2168            0 : HcclResult HcomGetAlgExecParam(
    2169              :     const char* tag, const char* group, u64 count, void* inputPtr, void* outputPtr, HcclCMDType opType,
    2170              :     bool clearEnable, HcclDataType dataType, HcclReduceOp op, void** commContext, u64* len, u32 aivCoreLimit)
    2171              : {
    2172            0 :     CHK_PTR_NULL(commContext);
    2173            0 :     CHK_PTR_NULL(len);
    2174            0 :     HCCLV2_FUNC_RUN(HcclGetAlgExecParamV2(
    2175              :         tag, group, count, inputPtr, outputPtr, opType, clearEnable, dataType, op, *commContext, *len, aivCoreLimit));
    2176              : 
    2177            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2178            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2179            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
    2180              : 
    2181            0 :     CHK_RET(hcclComm->HcclGetAlgExecParam(
    2182              :         tag, count, inputPtr, outputPtr, opType, clearEnable, dataType, op, *commContext, *len, aivCoreLimit));
    2183            0 :     return HCCL_SUCCESS;
    2184            0 : }
    2185              : // 取得所需的从stream数目
    2186            6 : HcclResult HcomGetWorkspaceSubStreamNum(
    2187              :     const char* group, u64& streamNum, u64 dataSize, HcclDataType dataType, u32 aivCoreLimit, HcclReduceOp reduceOp,
    2188              :     u64 count, HcclCMDType optype)
    2189              : {
    2190            6 :     HCCLV2_FUNC_RUN(HcomGetWorkspaceSubStreamNumV2(group, streamNum, dataSize, dataType, optype));
    2191            6 :     std::shared_ptr<hccl::hcclComm> hcclComm{};
    2192            6 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    2193            6 :     hcclComm = hcomInfo.pComm;
    2194            6 :     CHK_RET(HcomCheckGroupName(group));
    2195            6 :     HcclResult ret = HCCL_SUCCESS;
    2196            6 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2197            6 :     if (strGroup != HCCL_WORLD_GROUP && hcomInfo.pComm != nullptr) {
    2198            0 :         std::unique_lock<std::mutex> groupParaLock(hcomInfo.groupParamsLock);
    2199            0 :         auto iter = hcomInfo.hcomGroupMap.find(strGroup);
    2200            0 :         if (iter != hcomInfo.hcomGroupMap.end()) {
    2201            0 :             hcclComm = (iter->second).pSubComm;
    2202              :         } else {
    2203            0 :             HCCL_WARNING("[HcomGetWorkspaceSubStreamNum], please check if the initialize process is called.");
    2204            0 :             streamNum = 0;
    2205              :         }
    2206            6 :     } else if (hcomInfo.pComm == nullptr) {
    2207            6 :         ret = HcclGetCommHandle(group, hcclComm);
    2208            6 :         CHK_PRT_RET(
    2209              :             ret != HCCL_SUCCESS,
    2210              :             HCCL_WARNING("[HcomGetWorkspaceSubStreamNum], please check if the initialize process is called."),
    2211              :             HCCL_SUCCESS);
    2212              :     }
    2213            2 :     CHK_PRT_RET(hcclComm == nullptr, HCCL_ERROR("[HcomGetWorkspaceSubStreamNum] Get Comm is null"), HCCL_E_PTR);
    2214              : 
    2215            2 :     string algName;
    2216            2 :     bool ifAiv = false;
    2217            2 :     void* counts = nullptr;
    2218            2 :     ret = hcclComm->HcclSelectAlg(optype, count, counts, dataType, reduceOp, aivCoreLimit, ifAiv, algName);
    2219            2 :     CHK_PRT_RET(
    2220              :         ret != HCCL_SUCCESS,
    2221              :         HCCL_ERROR(
    2222              :             "[HcomGetWorkspaceSubStreamNum] HcclSelectAlg failed, ret[%d], optype[%d], count[%llu],"
    2223              :             "dataType[%d], reduceOp[%d]",
    2224              :             ret, optype, count, dataType, reduceOp),
    2225              :         ret);
    2226            2 :     CHK_RET(hcclComm->GetWorkspaceSubStreamNum(count, dataType, reduceOp, algName, streamNum, dataSize, ifAiv, optype));
    2227            2 :     HCCL_INFO(
    2228              :         "[%s] get streamNum[%llu] for optype[%d], algName[%s], count[%llu], dataType[%d], reduceOp[%d], ifAiv[%d]",
    2229              :         __func__, streamNum, optype, algName.c_str(), count, dataType, reduceOp, ifAiv);
    2230            2 :     return HCCL_SUCCESS;
    2231            6 : }
    2232              : 
    2233              : HcclResult
    2234            0 : HcomGetWorkspaceMemSize(const std::string& opType, u64 count, HcclDataType dataType, const char* group, u64& memSize)
    2235              : {
    2236            0 :     HCCLV2_FUNC_RUN(HcomGetWorkspaceMemSizeV2(opType, count, dataType, group, memSize));
    2237            0 :     u32 rankSize = 0;
    2238            0 :     std::shared_ptr<hccl::hcclComm> hcclComm{};
    2239            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    2240            0 :     if (hcomInfo.pComm != nullptr) {
    2241            0 :         hcclComm = hcomInfo.pComm;
    2242            0 :         if (group == nullptr) {
    2243            0 :             group = HCCL_WORLD_GROUP;
    2244              :         }
    2245            0 :         CHK_RET(HcomGetRankSize(group, &rankSize));
    2246            0 :         CHK_RET(hcclComm->GetWorkspaceMemSize(opType, count, dataType, rankSize, memSize));
    2247            0 :     } else if (group != nullptr && HcclGetCommHandle(group, hcclComm) == HCCL_SUCCESS) {
    2248            0 :         CHK_RET(hcclComm->GetRankSize(rankSize));
    2249            0 :         CHK_RET(hcclComm->GetWorkspaceMemSize(opType, count, dataType, rankSize, memSize));
    2250              :     } else {
    2251            0 :         HCCL_WARNING("[GetWorkspaceMemSize] please check if the initialize process is called.");
    2252            0 :         memSize = 0;
    2253            0 :         return HCCL_SUCCESS;
    2254              :     }
    2255              :     /* 用户申请内存,获取memSize大小 */
    2256              : 
    2257            0 :     CHK_PRT_RET(
    2258              :         memSize > DEVICE_MEMORY_MAX_ALLOC_SIZE,
    2259              :         HCCL_ERROR("[GetWorkspaceMemSize]workspace memory size is over than %llu bytes.", DEVICE_MEMORY_MAX_ALLOC_SIZE),
    2260              :         HCCL_E_PARA);
    2261            0 :     return HCCL_SUCCESS;
    2262            0 : }
    2263              : 
    2264            0 : HcclResult HcomGetAlltoAllStagedWorkSpaceMemSize(
    2265              :     const char* group, u64* sendCounts, u64* sdispls, HcclDataType sendType, u64* recvCounts, u64* rdispls,
    2266              :     HcclDataType recvType, u64& memSize)
    2267              : {
    2268            0 :     CHK_PTR_NULL(sendCounts);
    2269            0 :     CHK_PTR_NULL(sdispls);
    2270            0 :     CHK_PTR_NULL(recvCounts);
    2271            0 :     CHK_PTR_NULL(rdispls);
    2272              : 
    2273            0 :     HCCLV2_FUNC_RUN(HcomGetAlltoAllStagedWorkSpaceMemSizeV2(
    2274              :         group, sendCounts, sdispls, sendType, recvCounts, rdispls, recvType, memSize));
    2275            0 :     CHK_RET(HcomCheckDataType(sendType));
    2276            0 :     CHK_RET(HcomCheckDataType(recvType));
    2277            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2278              : 
    2279            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2280            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
    2281            0 :     CHK_RET(hcclComm->GetAlltoAllStagedWorkSpaceMemSize(
    2282              :         sendCounts, sdispls, sendType, recvCounts, rdispls, recvType, memSize));
    2283            0 :     return HCCL_SUCCESS;
    2284            0 : }
    2285              : 
    2286            0 : HcclResult HcomGetAlltoAllvcStagedWorkSpaceMemSize(
    2287              :     const char* group, std::vector<SendRecvInfo>& allMeshAggregationSendRecvInfo, u64& memSize)
    2288              : {
    2289            0 :     HCCLV2_FUNC_RUN(HcomGetAlltoAllvcStagedWorkSpaceMemSizeV2(group, memSize));
    2290            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2291            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2292            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
    2293            0 :     CHK_RET(hcclComm->GetAlltoAllStagedWorkSpaceMemSize(allMeshAggregationSendRecvInfo, memSize));
    2294            0 :     return HCCL_SUCCESS;
    2295            0 : }
    2296              : 
    2297              : HcclResult
    2298            0 : HcomGetAllReduceScratchSize(const char* group, const u64 count, const HcclDataType dataType, u64& outScratchSize)
    2299              : {
    2300            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2301            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    2302            0 :     if (hcomInfo.pComm != nullptr) {
    2303            0 :         hcclComm = hcomInfo.pComm;
    2304            0 :         CHK_RET(HcomCheckGroupName(group));
    2305            0 :         std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2306            0 :         if (strGroup == HCCL_WORLD_GROUP) {
    2307            0 :             hcclComm = hcomInfo.pComm;
    2308              :         } else {
    2309            0 :             std::unique_lock<std::mutex> groupParaLock(hcomInfo.groupParamsLock);
    2310            0 :             auto iter = hcomInfo.hcomGroupMap.find(strGroup);
    2311            0 :             if (iter != hcomInfo.hcomGroupMap.end()) {
    2312            0 :                 hcclComm = (iter->second).pSubComm;
    2313            0 :                 CHK_PRT_RET(hcclComm == nullptr, HCCL_ERROR("[Get][CommByGroup] Get Comm is null"), HCCL_E_PTR);
    2314              :             } else {
    2315            0 :                 u64 memSize = SIZE_TABLE[dataType] * count;
    2316            0 :                 const u32 DEVICE_EIGHT = 8;
    2317            0 :                 if (memSize <= HCCL_SMALL_COUNT_GRAPH_64_KB) {
    2318              :                     // 小数据
    2319            0 :                     outScratchSize = memSize * (DEVICE_EIGHT - 1);
    2320              :                 }
    2321            0 :                 HCCL_DEBUG("[HcomGetAllReduceScratchSize] outScratchSize %llu", outScratchSize);
    2322            0 :                 groupParaLock.unlock();
    2323            0 :                 return HCCL_SUCCESS;
    2324              :             }
    2325            0 :             groupParaLock.unlock();
    2326            0 :         }
    2327            0 :     } else if (group == nullptr || HcclGetCommHandle(group, hcclComm) != HCCL_SUCCESS) {
    2328            0 :         HCCL_WARNING("[GetAllReduceScratchSize], please check if the initialize process is called.");
    2329            0 :         outScratchSize = 0;
    2330            0 :         return HCCL_SUCCESS;
    2331              :     }
    2332            0 :     return hcclComm->GetAllReduceScratchSize(count, dataType, outScratchSize);
    2333            0 : }
    2334              : 
    2335            0 : HcclResult HcomGetCCLBufferAvailableSize(u64& size)
    2336              : {
    2337            0 :     size = GetExternalInputCCLBuffSize() - CCL_COMM_INBUFFER_UNALIGNED_RESERVE_SIZE;
    2338            0 :     return HCCL_SUCCESS;
    2339              : }
    2340              : 
    2341            0 : HcclResult HcomCheckCommValidity(const char* group)
    2342              : {
    2343            0 :     HCCLV2_FUNC_RUN(HcomCheckCommValidityV2(group));
    2344            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2345            0 :     if (HcomGetCommByGroup(group, hcclComm) != HCCL_SUCCESS) {
    2346            0 :         return HCCL_E_PTR;
    2347              :     }
    2348              : 
    2349            0 :     return HCCL_SUCCESS;
    2350            0 : }
    2351              : 
    2352              : HcclResult
    2353            0 : HcomSetWorkspaceResource(const char* tag, const char* group, rtStream_t* stream, s32 len, void* memPtr, u64 maxSize)
    2354              : {
    2355            0 :     if (len < 0) {
    2356            0 :         HCCL_ERROR("[HcomSetWorkspaceResource] len is %d", len);
    2357            0 :         return HCCL_E_PARA;
    2358              :     }
    2359            0 :     std::vector<rtStream_t> rtStream(stream, stream + len);
    2360              : 
    2361            0 :     HCCLV2_FUNC_RUN(HcomSetWorkspaceResourceV2(tag, group, rtStream, memPtr, maxSize));
    2362            0 :     if (group == nullptr) {
    2363            0 :         group = HCCL_WORLD_GROUP;
    2364              :     }
    2365              : 
    2366            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2367            0 :     if (HcomGetCommByGroup(group, hcclComm) == HCCL_SUCCESS) {
    2368              :         /* 设定 workspace 内存资源 */
    2369            0 :         CHK_RET(hcclComm->SetWorkspaceResource(tag, memPtr, maxSize, rtStream));
    2370              :     }
    2371              : 
    2372            0 :     return HCCL_SUCCESS;
    2373            0 : }
    2374              : 
    2375            0 : HcclResult HcclCommSetAttachedStream(s64 opBaseHcom, u32 graphId, const std::vector<rtStream_t>& stream)
    2376              : {
    2377            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    2378            0 :     CHK_PTR_NULL(hcclComm);
    2379            0 :     CHK_RET(hcclComm->SetAttachedStream(graphId, stream));
    2380              : 
    2381            0 :     return HCCL_SUCCESS;
    2382              : }
    2383              : 
    2384            0 : void HcomSetAutoTuneMode(bool autoTuneMode)
    2385              : {
    2386            0 :     bool& isAutoTuneModeOpen = HcomGetCtxAutoTuneMode();
    2387            0 :     isAutoTuneModeOpen = autoTuneMode;
    2388            0 : }
    2389              : 
    2390            0 : HcclResult HcomSetExecTimeOut(const char* execTimeOut)
    2391              : {
    2392            0 :     HCCL_RUN_INFO("HcomSetExecTimeOut:execTimeOut[%s]s", execTimeOut);
    2393            0 :     if (execTimeOut == nullptr) {
    2394            0 :         return HCCL_SUCCESS;
    2395              :     }
    2396            0 :     CHK_RET(SetHccLExecTimeOut(execTimeOut, HcclExecTimeoutSet::HCCL_EXEC_TIMEOUT_SET_BY_OPTIONS));
    2397            0 :     return HCCL_SUCCESS;
    2398              : }
    2399              : 
    2400            0 : HcclResult HcomSetAlgorithm(const char* algo)
    2401              : {
    2402            0 :     HCCL_RUN_INFO("HcomSetAlgorithm:algo[%s]", algo);
    2403            0 :     if (algo == nullptr) {
    2404            0 :         return HCCL_SUCCESS;
    2405              :     }
    2406            0 :     CHK_RET(SetHcclAlgoConfig(algo));
    2407            0 :     return HCCL_SUCCESS;
    2408              : }
    2409              : 
    2410            0 : HcclResult HcomSetDeterministic(u8 deterministic)
    2411              : {
    2412            0 :     HCCL_RUN_INFO("HcomSetDeterministic:deterministic[%u]", deterministic);
    2413            0 :     CHK_RET(SetDeterministic(deterministic));
    2414            0 :     return HCCL_SUCCESS;
    2415              : }
    2416              : 
    2417            0 : HcclResult HcomGetAlgorithm(u32 level, char** algo)
    2418              : {
    2419            0 :     CHK_PTR_NULL(algo);
    2420            0 :     std::string str = "none";
    2421            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    2422            0 :     CHK_PRT_RET(
    2423              :         hcomInfo.pComm == nullptr,
    2424              :         HCCL_ERROR("[Get][Algorithm]hcomInfo.pComm is null, "
    2425              :                    "please check if the initialize process is called."),
    2426              :         HCCL_E_PTR);
    2427            0 :     AlgType algType;
    2428            0 :     CHK_RET(hcomInfo.pComm->GetAlgType(algType, HcclCMDType::HCCL_CMD_ALL));
    2429            0 :     if (level == 0) {
    2430            0 :         if (algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_WHOLE_RING
    2431            0 :             || algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_8P_RING
    2432            0 :             || algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_4P_RING
    2433            0 :             || algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_NP_SINGLE_RING
    2434            0 :             || algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_NP_DOUBLE_RING) {
    2435            0 :             str = "ring";
    2436            0 :         } else if (
    2437            0 :             algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_NP_MESH
    2438            0 :             || algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_4P_MESH
    2439            0 :             || algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_2P_MESH
    2440            0 :             || algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_1P_MESH) {
    2441            0 :             str = "mesh";
    2442            0 :         } else if (
    2443            0 :             algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_RESERVED
    2444            0 :             && algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR) {
    2445            0 :             str = "NHR";
    2446            0 :         } else if (
    2447            0 :             algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_RESERVED
    2448            0 :             && algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR_V1) {
    2449            0 :             str = "NHR_V1";
    2450            0 :         } else if (
    2451            0 :             algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_RESERVED
    2452            0 :             && algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_AHC) {
    2453            0 :             str = "AHC";
    2454            0 :         } else if (
    2455            0 :             algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_RESERVED
    2456            0 :             && algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_AHC_BROKE) {
    2457            0 :             str = "AHC_BROKE";
    2458            0 :         } else if (
    2459            0 :             algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_RESERVED
    2460            0 :             && algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB) {
    2461            0 :             str = "NB";
    2462              :         } else {
    2463            0 :             HCCL_WARNING(
    2464              :                 "[Get][Algorithm] No valid Level 0 AlgType, which is [%d]", static_cast<s32>(algType.algoLevel0));
    2465            0 :             return HCCL_E_NOT_FOUND;
    2466              :         }
    2467            0 :     } else if (level == 1) {
    2468            0 :         if (algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_WHOLE_RING
    2469            0 :             || (algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_RESERVED
    2470            0 :                 && algType.algoLevel1 != AlgTypeLevel1::ALG_LEVEL1_RESERVED)) {
    2471            0 :             str = "none";
    2472            0 :         } else if (algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_HD) {
    2473            0 :             str = "H-D";
    2474            0 :         } else if (
    2475            0 :             algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_PIPELINE
    2476            0 :             || algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_RING) {
    2477            0 :             str = "ring";
    2478            0 :         } else if (algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR) {
    2479            0 :             str = "NHR";
    2480            0 :         } else if (algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR_V1) {
    2481            0 :             str = "NHR_V1";
    2482            0 :         } else if (algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_AHC) {
    2483            0 :             str = "AHC";
    2484            0 :         } else if (algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_AHC_BROKE) {
    2485            0 :             str = "AHC_BROKE";
    2486            0 :         } else if (algType.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB) {
    2487            0 :             str = "NB";
    2488              :         } else {
    2489            0 :             HCCL_WARNING(
    2490              :                 "[Get][Algorithm] No valid Level 1 AlgType, which is [%d]", static_cast<s32>(algType.algoLevel1));
    2491            0 :             return HCCL_E_NOT_FOUND;
    2492              :         }
    2493              :     }
    2494            0 :     *algo = const_cast<char*>(str.c_str());
    2495            0 :     return HCCL_SUCCESS;
    2496            0 : }
    2497              : 
    2498            0 : HcclResult HcomGetBandWidthPerNPU(u32 level, float* bandWidth)
    2499              : {
    2500            0 :     CHK_PTR_NULL(bandWidth);
    2501            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    2502            0 :     CHK_PRT_RET(
    2503              :         hcomInfo.pComm == nullptr,
    2504              :         HCCL_ERROR("[Get][BandWidth]hcomInfo.pComm is null, "
    2505              :                    "please check if the initialize process is called."),
    2506              :         HCCL_E_PTR);
    2507            0 :     CHK_RET(hcomInfo.pComm->GetBandWidthPerNPU(level, *bandWidth));
    2508            0 :     return HCCL_SUCCESS;
    2509              : }
    2510              : 
    2511            0 : HcclResult HcomReleaseSubComms()
    2512              : {
    2513            0 :     HCCLV2_FUNC_RUN(HcomReleaseSubCommsV2());
    2514            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    2515            0 :     if (hcomInfo.pComm) {
    2516            0 :         CHK_RET(hcomInfo.pComm->ReleaseSubComms());
    2517              :     }
    2518              : 
    2519            0 :     auto iter = hcomInfo.hcomGroupMap.begin();
    2520            0 :     while (iter != hcomInfo.hcomGroupMap.end()) {
    2521            0 :         if (iter->second.pSubComm) {
    2522            0 :             CHK_RET(iter->second.pSubComm->ReleaseSubComms());
    2523              :         }
    2524            0 :         iter++;
    2525              :     }
    2526            0 :     return HCCL_SUCCESS;
    2527              : }
    2528              : 
    2529            0 : HcclResult HcomAlltoAllV(
    2530              :     const void* sendBuf, const void* sendCounts, const void* sdispls, HcclDataType sendType, const void* recvBuf,
    2531              :     const void* recvCounts, const void* rdispls, HcclDataType recvType, const char* group, rtStream_t stream,
    2532              :     const char* tag)
    2533              : {
    2534            0 :     HcclUs startut = TIME_NOW();
    2535            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2536              :     // 入参合法性校验
    2537            0 :     CHK_PTR_NULL(sendCounts);
    2538            0 :     CHK_PTR_NULL(sdispls);
    2539            0 :     CHK_PTR_NULL(recvCounts);
    2540            0 :     CHK_PTR_NULL(rdispls);
    2541            0 :     RPT_INPUT_ERR(
    2542              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    2543              :         std::vector<std::string>({"HcomAlltoAllV", "nullptr", "stream", "non-null pointer"}));
    2544            0 :     CHK_PTR_NULL(stream);
    2545            0 :     s32 streamId = 0;
    2546            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    2547            0 :     s32 deviceLogicId = 0;
    2548            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
    2549              : 
    2550            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2551            0 :     if (sendBuf != nullptr) {
    2552            0 :         CHK_RET(PrintMemoryAttr(sendBuf));
    2553              :     }
    2554            0 :     if (recvBuf != nullptr) {
    2555            0 :         CHK_RET(PrintMemoryAttr(recvBuf));
    2556              :     }
    2557              : 
    2558              :     /* 接口交互信息日志 */
    2559            0 :     HCCL_USER_CRITICAL_LOG(
    2560              :         "Entry-HcomAlltoAllV:tag[%s], sendBuf[%p], recvBuf[%p], sendCounts[%p], recvCounts[%p],"
    2561              :         "sendType[%s], recvType[%s], group[%s], streamId[%d], deviceLogicId[%d]",
    2562              :         tag, sendBuf, recvBuf, sendCounts, recvCounts, GetDataTypeEnumStr(sendType).c_str(),
    2563              :         GetDataTypeEnumStr(recvType).c_str(), strGroup.c_str(), streamId, deviceLogicId);
    2564              : 
    2565              :     // HcomAlltoAllV2
    2566            0 :     HCCLV2_FUNC_RUN(HcomAlltoAllVV2(
    2567              :         sendBuf, sendCounts, sdispls, sendType, recvBuf, recvCounts, rdispls, recvType, group, stream, tag));
    2568            0 :     CHK_RET(HcomCheckOpParam(tag, 0, sendType, group, stream));
    2569            0 :     CHK_RET(HcomCheckDataType(recvType));
    2570            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2571            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
    2572              : 
    2573              :     // 根据ranksize校验相关入参
    2574            0 :     u32 rankSize = 0;
    2575            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    2576            0 :     CHK_RET(HcomCheckAlltoAllVExternalMem(sendBuf, sendCounts, recvBuf, recvCounts, rankSize));
    2577            0 :     u32 rankId = 0;
    2578            0 :     CHK_RET(hcclComm->GetUserRank(rankId));
    2579            0 :     u32 aivCoreLimit = 0;
    2580            0 :     CHK_RET(hcclComm->GetNumBlocks(aivCoreLimit));
    2581            0 :     HcclWorkflowMode mode = GetWorkflowMode();
    2582            0 :     CHK_PRT_RET(
    2583              :         mode == HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED, HCCL_ERROR("Invalid Workflow Mode[%d]", mode),
    2584              :         HCCL_E_INTERNAL);
    2585            0 :     CHK_RET(hcclComm->AlltoAllV(
    2586              :         sendBuf, sendCounts, sdispls, sendType, recvBuf, recvCounts, rdispls, recvType, stream, tag));
    2587              : 
    2588            0 :     u64 sendCount = 0;
    2589            0 :     for (u32 i = 0; i < rankSize; i++) {
    2590            0 :         sendCount += *(static_cast<const u64*>(sendCounts) + i);
    2591              :     }
    2592            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_ALLTOALLV, beginTime, sendCount, sendType));
    2593              :     /* 关键状态记录 */
    2594            0 :     HcclUs endut = TIME_NOW();
    2595            0 :     HCCL_RUN_INFO(
    2596              :         "HcomAlltoAllV success,take time [%lld]us, tag[%s], sendBuf[%p], recvBuf[%p], sendCounts[%p], "
    2597              :         "recvCounts[%p], sendType[%s], recvType[%s], group[%s], streamId[%d]",
    2598              :         DURATION_US(endut - startut), tag, sendBuf, recvBuf, sendCounts, recvCounts,
    2599              :         GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str(), strGroup.c_str(), streamId);
    2600            0 :     return HCCL_SUCCESS;
    2601            0 : }
    2602              : 
    2603            0 : HcclResult HcomAlltoAllVC(
    2604              :     const void* sendBuf, const void* sendCountMatrix, HcclDataType sendType, const void* recvBuf, HcclDataType recvType,
    2605              :     const char* group, rtStream_t stream, const char* tag)
    2606              : {
    2607            0 :     HcclUs startut = TIME_NOW();
    2608            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2609              :     // 入参合法性校验
    2610            0 :     CHK_PTR_NULL(sendCountMatrix);
    2611            0 :     RPT_INPUT_ERR(
    2612              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    2613              :         std::vector<std::string>({"HcomAlltoAllVC", "nullptr", "stream", "non-null pointer"}));
    2614            0 :     CHK_PTR_NULL(stream);
    2615            0 :     s32 streamId = 0;
    2616            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    2617            0 :     s32 deviceLogicId = 0;
    2618            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
    2619              : 
    2620            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    2621            0 :     if (sendBuf != nullptr) {
    2622            0 :         CHK_RET(PrintMemoryAttr(sendBuf));
    2623              :     }
    2624            0 :     if (recvBuf != nullptr) {
    2625            0 :         CHK_RET(PrintMemoryAttr(recvBuf));
    2626              :     }
    2627              :     // HcomAlltoAllVCV2
    2628            0 :     HCCLV2_FUNC_RUN(HcomAlltoAllVCV2(sendBuf, sendCountMatrix, sendType, recvBuf, recvType, group, stream, tag));
    2629            0 :     CHK_RET(HcomCheckOpParam(tag, 0, sendType, group, stream));
    2630            0 :     CHK_RET(HcomCheckDataType(recvType));
    2631              : 
    2632              :     // 根据ranksize校验相关入参
    2633            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2634            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
    2635            0 :     u32 rankSize = 0;
    2636            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    2637            0 :     u32 userRank = 0;
    2638            0 :     hcclComm->GetGroupRank(userRank);
    2639            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    2640            0 :     u32 rank = hcomInfo.params.userRank;
    2641            0 :     CHK_RET(HcomCheckAlltoAllVCExternalMem(sendBuf, sendCountMatrix, recvBuf, rankSize, rank));
    2642              : 
    2643              :     u64 sendCountMatrixHash;
    2644            0 :     HcomGetHashFromSendCountMatrix(sendCountMatrixHash, sendCountMatrix, rankSize, tag);
    2645              : 
    2646              :     /* 接口交互信息日志 */
    2647            0 :     HCCL_USER_CRITICAL_LOG(
    2648              :         "Entry-HcomAlltoAllVC:tag[%s], sendBuf[%p], sendCountMatrixHash[%llu], sendType[%s], "
    2649              :         "recvBuf[%p], recvType[%s], group[%s], streamId[%d], deviceLogicId[%d]",
    2650              :         tag, sendBuf, sendCountMatrixHash, GetDataTypeEnumStr(sendType).c_str(), recvBuf,
    2651              :         GetDataTypeEnumStr(recvType).c_str(), strGroup.c_str(), streamId, deviceLogicId);
    2652              : 
    2653            0 :     u32 aivCoreLimit = 0;
    2654            0 :     CHK_RET(hcclComm->GetNumBlocks(aivCoreLimit));
    2655            0 :     HcclWorkflowMode mode = GetWorkflowMode();
    2656            0 :     CHK_PRT_RET(
    2657              :         mode == HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED, HCCL_ERROR("Invalid Workflow Mode[%d]", mode),
    2658              :         HCCL_E_INTERNAL);
    2659              :     /* 入参的正确性由HCCL确保 */
    2660            0 :     CHK_RET(hcclComm->AlltoAllVC(sendBuf, sendCountMatrix, sendType, recvBuf, recvType, stream, tag));
    2661              : 
    2662            0 :     u64 sendCount = 0;
    2663            0 :     for (u32 i = 0; i < rankSize; i++) {
    2664            0 :         sendCount += *(static_cast<const u64*>(sendCountMatrix) + userRank * rankSize + i);
    2665              :     }
    2666            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_ALLTOALLVC, beginTime, sendCount, sendType));
    2667              :     /* 关键状态记录 */
    2668            0 :     HcclUs endut = TIME_NOW();
    2669            0 :     HCCL_RUN_INFO(
    2670              :         "HcomAlltoAllVC success,take time [%lld]us, tag[%s], sendBuf[%p], sendCountMatrix[%p], "
    2671              :         "sendType[%s], recvBuf[%p], recvType[%s], group[%s], streamId[%d]",
    2672              :         DURATION_US(endut - startut), tag, sendBuf, sendCountMatrix, GetDataTypeEnumStr(sendType).c_str(), recvBuf,
    2673              :         GetDataTypeEnumStr(recvType).c_str(), strGroup.c_str(), streamId);
    2674            0 :     return HCCL_SUCCESS;
    2675            0 : }
    2676              : 
    2677            0 : HcclResult HcclCommGraphAlltoAllV(
    2678              :     const void* sendBuf, const void* sendCounts, const void* sdispls, HcclDataType sendType, const void* recvBuf,
    2679              :     const void* recvCounts, const void* rdispls, HcclDataType recvType, s64 opBaseHcom, rtStream_t stream,
    2680              :     const char* tag)
    2681              : {
    2682            0 :     HcclUs startut = TIME_NOW();
    2683            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2684              :     // 入参合法性校验
    2685            0 :     CHK_PTR_NULL(sendCounts);
    2686            0 :     CHK_PTR_NULL(sdispls);
    2687            0 :     CHK_PTR_NULL(recvCounts);
    2688            0 :     CHK_PTR_NULL(rdispls);
    2689              : 
    2690            0 :     CHK_RET(HcomCheckOpParam(tag, 0, sendType, stream));
    2691            0 :     CHK_RET(HcomCheckDataType(recvType));
    2692            0 :     s32 streamId = 0;
    2693            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    2694            0 :     s32 deviceLogicId = 0;
    2695            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
    2696              : 
    2697              :     // 根据ranksize校验相关入参
    2698            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    2699            0 :     CHK_PTR_NULL(hcclComm);
    2700            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    2701            0 :     u32 rankSize = 0;
    2702            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    2703            0 :     u32 rankId = 0;
    2704            0 :     CHK_RET(hcclComm->GetUserRank(rankId));
    2705            0 :     CHK_RET(HcomCheckAlltoAllVExternalMem(sendBuf, sendCounts, recvBuf, recvCounts, rankSize));
    2706            0 :     if (sendBuf != nullptr) {
    2707            0 :         CHK_RET(PrintMemoryAttr(sendBuf));
    2708              :     }
    2709            0 :     if (recvBuf != nullptr) {
    2710            0 :         CHK_RET(PrintMemoryAttr(recvBuf));
    2711              :     }
    2712              : 
    2713              :     /* 接口交互信息日志 */
    2714            0 :     HCCL_USER_CRITICAL_LOG(
    2715              :         "Entry-HcomAlltoAllV:tag[%s], sendBuf[%p], recvBuf[%p], sendCounts[%p], recvCounts[%p],"
    2716              :         "sendType[%s], recvType[%s], streamId[%d], deviceLogicId[%d]",
    2717              :         tag, sendBuf, recvBuf, sendCounts, recvCounts, GetDataTypeEnumStr(sendType).c_str(),
    2718              :         GetDataTypeEnumStr(recvType).c_str(), streamId, deviceLogicId);
    2719              : 
    2720            0 :     u32 aivCoreLimit = 0;
    2721            0 :     CHK_RET(hcclComm->GetNumBlocks(aivCoreLimit));
    2722            0 :     HcclWorkflowMode mode = GetWorkflowMode();
    2723            0 :     CHK_PRT_RET(
    2724              :         mode == HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED, HCCL_ERROR("Invalid Workflow Mode[%d]", mode),
    2725              :         HCCL_E_INTERNAL);
    2726              :     /* 入参的正确性由HCCL确保 */
    2727            0 :     CHK_RET(hcclComm->AlltoAllV(
    2728              :         sendBuf, sendCounts, sdispls, sendType, recvBuf, recvCounts, rdispls, recvType, stream, tag));
    2729            0 :     u64 sendCount = 0;
    2730            0 :     for (u32 i = 0; i < rankSize; i++) {
    2731            0 :         sendCount += *(static_cast<const u64*>(sendCounts) + i);
    2732              :     }
    2733            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLTOALLV, beginTime, sendCount, sendType));
    2734              :     /* 关键状态记录 */
    2735            0 :     HcclUs endut = TIME_NOW();
    2736            0 :     HCCL_RUN_INFO(
    2737              :         "HcomAlltoAllV success,take time [%lld]us, tag[%s], sendBuf[%p], recvBuf[%p], sendCounts[%p], "
    2738              :         "recvCounts[%p], sendType[%s], recvType[%s], streamId[%d]",
    2739              :         DURATION_US(endut - startut), tag, sendBuf, recvBuf, sendCounts, recvCounts,
    2740              :         GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str(), streamId);
    2741            0 :     return HCCL_SUCCESS;
    2742              : }
    2743              : 
    2744            0 : HcclResult HcclCommGraphAlltoAllVC(
    2745              :     const void* sendBuf, const void* sendCountMatrix, HcclDataType sendType, const void* recvBuf, HcclDataType recvType,
    2746              :     s64 opBaseHcom, rtStream_t stream, const char* tag)
    2747              : {
    2748            0 :     HcclUs startut = TIME_NOW();
    2749            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2750              :     // 入参合法性校验
    2751            0 :     CHK_PTR_NULL(sendCountMatrix);
    2752              : 
    2753            0 :     CHK_RET(HcomCheckOpParam(tag, 0, sendType, stream));
    2754            0 :     CHK_RET(HcomCheckDataType(recvType));
    2755            0 :     s32 streamId = 0;
    2756            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    2757            0 :     s32 deviceLogicId = 0;
    2758            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
    2759              : 
    2760              :     // 根据ranksize校验相关入参
    2761            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    2762            0 :     CHK_PTR_NULL(hcclComm);
    2763            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    2764            0 :     u32 rankSize = 0;
    2765            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    2766            0 :     u32 userRank = 0;
    2767            0 :     hcclComm->GetGroupRank(userRank);
    2768            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    2769            0 :     u32 rank = hcomInfo.params.userRank;
    2770            0 :     CHK_RET(HcomCheckAlltoAllVCExternalMem(sendBuf, sendCountMatrix, recvBuf, rankSize, rank));
    2771            0 :     if (sendBuf != nullptr) {
    2772            0 :         CHK_RET(PrintMemoryAttr(sendBuf));
    2773              :     }
    2774            0 :     if (recvBuf != nullptr) {
    2775            0 :         CHK_RET(PrintMemoryAttr(recvBuf));
    2776              :     }
    2777              : 
    2778              :     u64 sendCountMatrixHash;
    2779            0 :     HcomGetHashFromSendCountMatrix(sendCountMatrixHash, sendCountMatrix, rankSize, tag);
    2780              : 
    2781              :     /* 接口交互信息日志 */
    2782            0 :     HCCL_USER_CRITICAL_LOG(
    2783              :         "Entry-HcomAlltoAllVC:tag[%s], sendBuf[%p], sendCountMatrixHash[%llu], sendType[%s], "
    2784              :         "recvBuf[%p], recvType[%s], streamId[%d], deviceLogicId[%d]",
    2785              :         tag, sendBuf, sendCountMatrixHash, GetDataTypeEnumStr(sendType).c_str(), recvBuf,
    2786              :         GetDataTypeEnumStr(recvType).c_str(), streamId, deviceLogicId);
    2787              : 
    2788            0 :     u32 aivCoreLimit = 0;
    2789            0 :     CHK_RET(hcclComm->GetNumBlocks(aivCoreLimit));
    2790            0 :     HcclWorkflowMode mode = GetWorkflowMode();
    2791            0 :     CHK_PRT_RET(
    2792              :         mode == HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED, HCCL_ERROR("Invalid Workflow Mode[%d]", mode),
    2793              :         HCCL_E_INTERNAL);
    2794              :     /* 入参的正确性由HCCL确保 */
    2795            0 :     CHK_RET(hcclComm->AlltoAllVC(sendBuf, sendCountMatrix, sendType, recvBuf, recvType, stream, tag));
    2796              : 
    2797            0 :     u64 sendCount = 0;
    2798            0 :     for (u32 i = 0; i < rankSize; i++) {
    2799            0 :         sendCount += *(static_cast<const u64*>(sendCountMatrix) + userRank * rankSize + i);
    2800              :     }
    2801            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLTOALLVC, beginTime, sendCount, sendType));
    2802              :     /* 关键状态记录 */
    2803            0 :     HcclUs endut = TIME_NOW();
    2804            0 :     HCCL_RUN_INFO(
    2805              :         "HcomAlltoAllVC success, take time [%lld]us, tag[%s], sendBuf[%p], recvBuf[%p], sendCountMatrix[%p], "
    2806              :         "sendType[%s], recvType[%s], streamId[%d]",
    2807              :         DURATION_US(endut - startut), tag, sendBuf, recvBuf, sendCountMatrix, GetDataTypeEnumStr(sendType).c_str(),
    2808              :         GetDataTypeEnumStr(recvType).c_str(), streamId);
    2809            0 :     return HCCL_SUCCESS;
    2810              : }
    2811              : 
    2812            0 : HcclResult HcomUnloadTask(const char* group, const char* tag)
    2813              : {
    2814            0 :     CHK_PTR_NULL(tag);
    2815            0 :     HCCLV2_FUNC_RUN(HcomUnloadTaskV2(group, tag));
    2816            0 :     std::shared_ptr<hcclComm> hcclComm;
    2817            0 :     if (HcomGetCommByGroup(group, hcclComm) == HCCL_SUCCESS) {
    2818            0 :         CHK_PRT_RET(
    2819              :             hcclComm == nullptr,
    2820              :             HCCL_WARNING("[UnloadAllTask]hcclComm is null, "
    2821              :                          "please check if the initialize process is called."),
    2822              :             HCCL_SUCCESS);
    2823            0 :         HCCL_INFO("[UnloadTask]HcomUnloadTask: tag[%s]", tag);
    2824            0 :         CHK_RET(hcclComm->ClearOpResource(tag));
    2825              :     }
    2826              : 
    2827            0 :     return HCCL_SUCCESS;
    2828            0 : }
    2829              : 
    2830            0 : HcclResult HcomGetServerNumAndDeviceNumPerServer(u32* serverNum, u32* deviceNumPerServer, u32* deviceNumPerAggregation)
    2831              : {
    2832            0 :     CHK_PTR_NULL(serverNum);
    2833            0 :     CHK_PTR_NULL(deviceNumPerServer);
    2834            0 :     CHK_PTR_NULL(deviceNumPerAggregation);
    2835            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    2836            0 :     CHK_PRT_RET(
    2837              :         hcomInfo.pComm == nullptr,
    2838              :         HCCL_ERROR("[GetServerNumAndDeviceNumPerServer]hcomInfo.pComm is null, "
    2839              :                    "please check if the initialize process is called."),
    2840              :         HCCL_E_INTERNAL);
    2841              :     u32 totalDevNum;
    2842            0 :     *serverNum = hcomInfo.rankTable.serverNum;
    2843            0 :     totalDevNum = hcomInfo.rankTable.deviceNum;
    2844            0 :     if ((totalDevNum % *serverNum) != 0) {
    2845            0 :         HCCL_ERROR("devicenum is not Integer.");
    2846              :     }
    2847            0 :     *deviceNumPerServer = totalDevNum / *serverNum;
    2848              : 
    2849            0 :     CHK_RET(hcomInfo.pComm->GetDeviceNumPerAggregation(*deviceNumPerAggregation));
    2850              : 
    2851            0 :     return HCCL_SUCCESS;
    2852              : }
    2853              : 
    2854              : static RankTable_t g_rankTableSetInfo;
    2855            0 : HcclResult HcomSetRankTableImpl(const char* rankTableStr)
    2856              : {
    2857            0 :     HCCL_RUN_INFO("Entry-HcomSetRankTable: rankTable \"%s\"", rankTableStr);
    2858            0 :     u32 rankTableSize = 0;
    2859            0 :     HcclResult ret = HcomCheckRankTable(rankTableStr, rankTableSize);
    2860            0 :     CHK_PRT_RET(
    2861              :         ret != HCCL_SUCCESS, HCCL_ERROR("[Init][Result]errNo[0x%016llx] input rankTable error", HCOM_ERROR_CODE(ret)),
    2862              :         ret);
    2863              : 
    2864            0 :     std::string identify = "0";
    2865            0 :     HcomInfo hcomInfo;
    2866            0 :     ret = CfgGetClusterInfoWithoutDev(rankTableStr, identify, hcomInfo.params, hcomInfo.rankTable);
    2867            0 :     CHK_PRT_RET(
    2868              :         ret != HCCL_SUCCESS,
    2869              :         HCCL_ERROR(
    2870              :             "[Init][Result]errNo[0x%016llx] cfg get ranktable[%p] info error: "
    2871              :             "identify[%s]",
    2872              :             HCOM_ERROR_CODE(ret), rankTableStr, identify.c_str()),
    2873              :         ret);
    2874              : 
    2875            0 :     g_rankTableSetInfo = hcomInfo.rankTable;
    2876            0 :     return HCCL_SUCCESS;
    2877            0 : }
    2878              : 
    2879            0 : HcclResult HcomGetActualRankSizeImpl(const char* group, u32* rankSize)
    2880              : {
    2881              :     (void)group;
    2882            0 :     *rankSize = g_rankTableSetInfo.rankNum;
    2883            0 :     return HCCL_SUCCESS;
    2884              : }
    2885              : 
    2886            0 : HcclResult HcclCommGraphUnloadTask(s64 opBaseHcom, const char* tag)
    2887              : {
    2888              : #if (!defined(HCCD)) && (!defined(CCL_KERNEL_AICPU))
    2889            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    2890            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    2891              :         hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    2892              :         CHK_PTR_NULL(hcclComm);
    2893              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    2894              :         CHK_PTR_NULL(commV2);
    2895              :         opBaseHcom = reinterpret_cast<s64>(commV2);
    2896              :         CHK_RET(HcclCommGraphUnloadTaskV2(opBaseHcom, tag));
    2897              :         return HCCL_SUCCESS;
    2898              :     }());
    2899              : #endif
    2900            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    2901            0 :     CHK_PRT_RET(
    2902              :         hcclComm == nullptr,
    2903              :         HCCL_WARNING("[HcclCommGraphUnloadTask]hcclComm is null, "
    2904              :                      "please check if the initialize process is called."),
    2905              :         HCCL_SUCCESS);
    2906            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB));
    2907            0 :     HCCL_INFO("[UnloadTask]HcclCommGraphUnloadTask: tag[%s]", tag);
    2908            0 :     CHK_RET(hcclComm->ClearOpResource(tag));
    2909            0 :     return HCCL_SUCCESS;
    2910              : }
    2911              : 
    2912            0 : HcclResult HcomSetGlobalWorkSpace(const char* group, void** globalWorkSpaceAddr, u32 len)
    2913              : {
    2914            0 :     std::vector<void*> workspaceAddrVec(globalWorkSpaceAddr, globalWorkSpaceAddr + len);
    2915            0 :     HCCLV2_FUNC_RUN(HcomSetGlobalWorkSpaceV2(group, workspaceAddrVec));
    2916            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2917            0 :     std::vector<void*> globalWorkSpaceAdd(globalWorkSpaceAddr, globalWorkSpaceAddr + len);
    2918            0 :     CHK_RET(HcomGetCommByGroup(group, hcclComm));
    2919            0 :     CHK_RET(hcclComm->SetGlobalWorkSpace(globalWorkSpaceAdd));
    2920            0 :     return HCCL_SUCCESS;
    2921            0 : }
    2922              : 
    2923            0 : HcclResult HcclCommSetGlobalWorkSpace(s64 opBaseHcom, std::vector<void*>& globalWorkSpaceAddr)
    2924              : {
    2925              :     DevType devType;
    2926            0 :     CHK_RET(hrtGetDeviceType(devType));
    2927            0 :     if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
    2928            0 :         HCCL_WARNING(" A5/A6 does not support this interface");
    2929            0 :         return HCCL_SUCCESS;
    2930              :     }
    2931              : 
    2932            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    2933            0 :     CHK_PTR_NULL(hcclComm);
    2934            0 :     CHK_RET(hcclComm->SetGlobalWorkSpace(globalWorkSpaceAddr));
    2935            0 :     return HCCL_SUCCESS;
    2936              : }
    2937              : 
    2938            0 : HcclResult HcomGetandClearOverFlowTasks(const char* group, hccl::HcclDumpInfo** hcclDumpInfoPtr, s32* len)
    2939              : {
    2940              :     DevType devType;
    2941            0 :     CHK_RET(hrtGetDeviceType(devType));
    2942            0 :     if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
    2943            0 :         HCCL_WARNING("A5 does not support get and clear hcom over flow tasks.");
    2944            0 :         return HCCL_SUCCESS;
    2945              :     }
    2946              : 
    2947            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2948            0 :     CHK_RET(HcomGetCommByGroup(group, hcclComm));
    2949            0 :     std::vector<hccl::HcclDumpInfo> hcclDumpInfo;
    2950            0 :     CHK_RET(hcclComm->GetandClearOverFlowTasks(hcclDumpInfo));
    2951            0 :     if (hcclDumpInfo.size() > 0) {
    2952            0 :         *hcclDumpInfoPtr = static_cast<hccl::HcclDumpInfo*>(malloc(hcclDumpInfo.size() * sizeof(hccl::HcclDumpInfo)));
    2953            0 :         if (*hcclDumpInfoPtr == nullptr) {
    2954            0 :             HCCL_ERROR(
    2955              :                 "[HcomGetandClearOverFlowTasks][HcclDumpInfo]mem malloc size[%zu] failed.",
    2956              :                 hcclDumpInfo.size() * sizeof(hccl::HcclDumpInfo));
    2957            0 :             return HCCL_E_MEMORY;
    2958              :         }
    2959            0 :         int32_t sret = memcpy_s(
    2960            0 :             *hcclDumpInfoPtr, hcclDumpInfo.size() * sizeof(hccl::HcclDumpInfo), hcclDumpInfo.data(),
    2961            0 :             hcclDumpInfo.size() * sizeof(hccl::HcclDumpInfo));
    2962            0 :         CHK_PRT_RET(
    2963              :             sret != EOK,
    2964              :             HCCL_ERROR(
    2965              :                 "[HcomGetandClearOverFlowTasks][HcclDumpInfo]memcpy failed. ret[%d], "
    2966              :                 "hcclDumpInfo:size[%zu]",
    2967              :                 sret, hcclDumpInfo.size()),
    2968              :             HCCL_E_MEMORY);
    2969              :     }
    2970            0 :     *len = hcclDumpInfo.size();
    2971            0 :     return HCCL_SUCCESS;
    2972            0 : }
    2973              : 
    2974            0 : HcclResult HcclCommGetandClearOverFlowTasks(s64 opBaseHcom, std::vector<hccl::HcclDumpInfo>& hcclDumpInfo)
    2975              : {
    2976              :     DevType devType;
    2977            0 :     CHK_RET(hrtGetDeviceType(devType));
    2978            0 :     if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
    2979            0 :         HCCL_WARNING("A5 does not support get and clear hcclcom over flow tasks.");
    2980            0 :         return HCCL_SUCCESS;
    2981              :     }
    2982              : 
    2983            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    2984            0 :     CHK_PTR_NULL(hcclComm);
    2985            0 :     CHK_RET(hcclComm->GetandClearOverFlowTasks(hcclDumpInfo));
    2986            0 :     return HCCL_SUCCESS;
    2987              : }
    2988              : 
    2989            0 : HcclResult HcomSupportDeterministicOptim(const char* group, bool* isDeterministicOptim)
    2990              : {
    2991            0 :     CHK_PTR_NULL(isDeterministicOptim);
    2992            0 :     HCCLV2_FUNC_RUN(HcomSupportDeterministicOptimV2(group, *isDeterministicOptim));
    2993            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    2994            0 :     CHK_RET(HcomGetCommByGroup(group, hcclComm));
    2995            0 :     CHK_RET(hcclComm->SupportDeterministicOptim(*isDeterministicOptim));
    2996            0 :     return HCCL_SUCCESS;
    2997            0 : }
    2998              : 
    2999            0 : HcclResult HcomGetHccsLinkNum(const char* group, u32* numHccsLink)
    3000              : {
    3001            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    3002            0 :     CHK_RET(HcomGetCommByGroup(group, hcclComm));
    3003            0 :     CHK_RET(hcclComm->GetHccsLinkNum(*numHccsLink));
    3004            0 :     return HCCL_SUCCESS;
    3005            0 : }
    3006              : 
    3007            0 : HcclResult HcclCommSupportDeterministicOptim(s64 opBaseHcom, bool& isDeterministicOptim)
    3008              : {
    3009            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    3010            0 :     CHK_PTR_NULL(hcclComm);
    3011            0 :     CHK_RET(hcclComm->SupportDeterministicOptim(isDeterministicOptim));
    3012            0 :     return HCCL_SUCCESS;
    3013              : }
    3014              : 
    3015            0 : std::vector<u64> GenerateSendCountMatrix(u64 count, u32 rankSize)
    3016              : {
    3017            0 :     std::vector<u64> sendCountMatrix(rankSize * rankSize, count);
    3018            0 :     return sendCountMatrix;
    3019              : }
    3020              : 
    3021            0 : HcclResult HcomAllToAll(
    3022              :     const void* sendBuf, u64 sendCount, HcclDataType sendType, const void* recvBuf, u64 recvCount,
    3023              :     HcclDataType recvType, const char* group, rtStream_t stream, const char* tag)
    3024              : {
    3025            0 :     HcclUs startut = TIME_NOW();
    3026            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    3027              :     // 入参合法性校验
    3028            0 :     CHK_PTR_NULL(sendBuf);
    3029            0 :     CHK_PTR_NULL(recvBuf);
    3030            0 :     RPT_INPUT_ERR(
    3031              :         stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    3032              :         std::vector<std::string>({"HcomAllToAll", "nullptr", "stream", "non-null pointer"}));
    3033            0 :     CHK_PTR_NULL(stream);
    3034              : 
    3035            0 :     s32 streamId = 0;
    3036            0 :     CHK_RET(hrtGetStreamId(stream, streamId));
    3037            0 :     s32 deviceLogicId = 0;
    3038            0 :     CHK_RET(hrtGetDevice(&deviceLogicId));
    3039              : 
    3040            0 :     if (sendBuf != nullptr) {
    3041            0 :         CHK_RET(PrintMemoryAttr(sendBuf));
    3042              :     }
    3043            0 :     if (recvBuf != nullptr) {
    3044            0 :         CHK_RET(PrintMemoryAttr(recvBuf));
    3045              :     }
    3046              : 
    3047            0 :     CHK_PRT_RET(sendCount == 0, HCCL_WARNING("send count is 0, return AllToAll success"), HCCL_SUCCESS);
    3048            0 :     CHK_PRT_RET(recvCount == 0, HCCL_WARNING("recv count is 0, return AllToAll success"), HCCL_SUCCESS);
    3049              : 
    3050            0 :     std::string strGroup = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    3051              :     /* 接口交互信息日志 */
    3052            0 :     HCCL_USER_CRITICAL_LOG(
    3053              :         "Entry-HcomAllToAll:tag[%s], sendBuf[%p], recvBuf[%p], sendCount[%llu], recvCount[%llu],"
    3054              :         "sendType[%s], recvType[%s], group[%s], streamId[%d], deviceLogicId[%d]",
    3055              :         tag, sendBuf, recvBuf, sendCount, recvCount, GetDataTypeEnumStr(sendType).c_str(),
    3056              :         GetDataTypeEnumStr(recvType).c_str(), strGroup.c_str(), streamId, deviceLogicId);
    3057              : 
    3058              :     // HcomAlltoAllV2
    3059            0 :     HCCLV2_FUNC_RUN(HcomAlltoAllV2(sendBuf, sendCount, sendType, recvBuf, recvCount, recvType, group, stream, tag));
    3060            0 :     CHK_RET(HcomCheckOpParam(tag, sendCount, sendType, stream));
    3061            0 :     CHK_RET(HcomCheckOpParam(tag, recvCount, recvType, stream));
    3062            0 :     CHK_RET(HcomCheckDataType(sendType));
    3063            0 :     CHK_RET(HcomCheckDataType(recvType));
    3064              :     // 根据ranksize校验相关入参
    3065            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    3066            0 :     CHK_RET(HcomGetCommByGroup(strGroup.c_str(), hcclComm));
    3067            0 :     u32 rankSize = 0, rankId = 0;
    3068            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    3069            0 :     CHK_RET(hcclComm->GetUserRank(rankId));
    3070            0 :     u32 aivCoreLimit = 0;
    3071            0 :     CHK_RET(hcclComm->GetNumBlocks(aivCoreLimit));
    3072              : 
    3073            0 :     HcclWorkflowMode mode = GetWorkflowMode();
    3074            0 :     CHK_PRT_RET(
    3075              :         mode == HcclWorkflowMode::HCCL_WORKFLOW_MODE_RESERVED, HCCL_ERROR("Invalid Workflow Mode[%d]", mode),
    3076              :         HCCL_E_INTERNAL);
    3077              :     /* 入参的正确性由HCCL确保 */
    3078            0 :     CHK_RET(hcclComm->AlltoAll(sendBuf, sendCount, sendType, recvBuf, recvCount, recvType, stream, tag));
    3079            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm.get(), HcclCMDType::HCCL_CMD_ALLTOALLV, beginTime, sendCount, sendType));
    3080              :     /* 关键状态记录 */
    3081            0 :     HcclUs endut = TIME_NOW();
    3082            0 :     HCCL_RUN_INFO(
    3083              :         "HcomAllToAll success,take time [%lld]us, tag[%s], sendBuf[%p], recvBuf[%p], sendCount[%llu], "
    3084              :         "recvCounts[%llu], sendType[%s], recvType[%s], group[%s], streamId[%d]",
    3085              :         DURATION_US(endut - startut), tag, sendBuf, recvBuf, sendCount, recvCount, GetDataTypeEnumStr(sendType).c_str(),
    3086              :         GetDataTypeEnumStr(recvType).c_str(), strGroup.c_str(), streamId);
    3087            0 :     return HCCL_SUCCESS;
    3088            0 : }
    3089              : 
    3090            0 : HcclResult HcclIgetLookupRequest(
    3091              :     [[maybe_unused]] HcclComm comm, [[maybe_unused]] s32* tag, [[maybe_unused]] ServiceHandle* handle,
    3092              :     [[maybe_unused]] uint64_t* keys, [[maybe_unused]] uint64_t keyMaxNum, [[maybe_unused]] HcclRequest* request)
    3093              : {
    3094            0 :     HCCL_ERROR("[Iget][LookupRequest] is not support HcclIgetLookupRequest interface");
    3095            0 :     return HCCL_E_PARA;
    3096              : }
    3097              : 
    3098            0 : HcclResult HcomCollRemotePairedParaCheck(const HcomRemoteOperationParams& params)
    3099              : {
    3100            0 :     CHK_PTR_NULL(params.keyAddr);
    3101            0 :     CHK_PTR_NULL(params.value);
    3102            0 :     CHK_PTR_NULL(params.tableId);
    3103            0 :     CHK_PTR_NULL(params.indices);
    3104            0 :     CHK_PTR_NULL(params.numUniqued);
    3105            0 :     CHK_PTR_NULL(params.psSeg);
    3106            0 :     CHK_PTR_NULL(params.psSegNum);
    3107              : 
    3108            0 :     return HCCL_SUCCESS;
    3109              : }
    3110              : 
    3111            0 : HcclResult HcomInitByRankTable(const char* rankTable, uint32_t rankId)
    3112              : {
    3113            0 :     return HcomInitByString(rankTable, std::to_string(rankId).c_str(), HCCL_MODE_SCHED_OS);
    3114              : }
    3115              : 
    3116              : inline void GenerateHcomSendRecvOpTag(
    3117              :     HcomOperationType opType, const char* group, u32 tag, u32 selfRank, u32 peerRank, std::string& opTag)
    3118              : {
    3119              :     std::string groupStr = (group == nullptr) ? HCCL_WORLD_GROUP : group;
    3120              :     if (opType == HCOM_OP_TYPE_SEND) {
    3121              :         opTag = groupStr + "_" + std::to_string(tag) + "_" + std::to_string(selfRank) + "_" + std::to_string(peerRank);
    3122              :     } else if (opType == HCOM_OP_TYPE_RECV) {
    3123              :         opTag = groupStr + "_" + std::to_string(tag) + "_" + std::to_string(peerRank) + "_" + std::to_string(selfRank);
    3124              :     }
    3125              :     return;
    3126              : }
    3127              : 
    3128            0 : HcclResult HcomGetTopoDesc(const char* group, HcclTopoDescs* topoDescs, uint32_t topoSize)
    3129              : {
    3130            0 :     CHK_PTR_NULL(topoDescs);
    3131            0 :     CHK_PTR_NULL(group);
    3132            0 :     HCCLV2_FUNC_RUN(HcomGetTopoDescV2(group, topoDescs, topoSize));
    3133              : 
    3134            0 :     std::shared_ptr<hcclComm> hcclComm;
    3135            0 :     s32 deviceLogicId = 0;
    3136            0 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    3137            0 :     if (HcomGetCommByGroup(group, hcclComm) == HCCL_SUCCESS) {
    3138            0 :         CHK_RET(hcclComm->GetTopoDesc(topoDescs, topoSize));
    3139              :     } else {
    3140            0 :         return HCCL_E_PTR;
    3141              :     }
    3142              : 
    3143            0 :     return HCCL_SUCCESS;
    3144            0 : }
    3145              : 
    3146              : #ifdef __cplusplus
    3147              : extern "C" {
    3148              : #endif // __cplusplus
    3149            0 : HcclResult HcomGetL0TopoTypeEx(const char* group, CommTopo* topoType, uint32_t flag)
    3150              : {
    3151            0 :     HCCLV2_FUNC_RUN(HcomGetL0TopoTypeExV2(group, topoType, flag));
    3152              : #define IS_SET_DEVICE_MASK 0xfffffffe
    3153            0 :     CHK_PTR_NULL(topoType);
    3154            0 :     CHK_PTR_NULL(group);
    3155              : 
    3156            0 :     bool isSetDevice = static_cast<bool>(flag & (~(0xfffffffe)));
    3157            0 :     if (isSetDevice) {
    3158            0 :         HCCL_ERROR("current only support no setdevice, flag[%u]", flag);
    3159            0 :         return HCCL_E_PARA;
    3160              :     }
    3161              : 
    3162            0 :     std::string identifier(group);
    3163            0 :     return CommTopoDesc::GetInstance().GetL0TopoType(identifier, topoType);
    3164            0 : }
    3165              : 
    3166            0 : HcclResult HcomGetRankSizeEx(const char* group, uint32_t* rankSize, uint32_t flag)
    3167              : {
    3168            0 :     HCCLV2_FUNC_RUN(HcomGetRankSizeExV2(group, rankSize, flag));
    3169              : #define IS_SET_DEVICE_MASK 0xfffffffe
    3170            0 :     CHK_PTR_NULL(rankSize);
    3171            0 :     CHK_PTR_NULL(group);
    3172              : 
    3173            0 :     bool isSetDevice = static_cast<bool>(flag & (~(0xfffffffe)));
    3174            0 :     if (isSetDevice) {
    3175            0 :         HCCL_ERROR("current only support no setdevice, flag[%u]", flag);
    3176            0 :         return HCCL_E_PARA;
    3177              :     }
    3178              : 
    3179            0 :     std::string identifier(group);
    3180            0 :     return CommTopoDesc::GetInstance().GetRankSize(identifier, rankSize);
    3181            0 : }
    3182              : #ifdef __cplusplus
    3183              : }
    3184              : #endif // __cplusplus
    3185              : 
    3186            0 : HcclResult HcomGetCommCCLBufferSize(const char* group, uint64_t& size)
    3187              : {
    3188            0 :     HCCLV2_FUNC_RUN(HcomGetCommCCLBufferSizeV2());
    3189            0 :     CHK_PTR_NULL(group);
    3190            0 :     std::shared_ptr<hcclComm> hcclComm;
    3191            0 :     CHK_RET(HcomGetCommByGroup(group, hcclComm));
    3192            0 :     HcclResult ret = hcclComm->GetCommUserMemSize(size);
    3193            0 :     CHK_PRT_RET(ret == HCCL_SUCCESS, HCCL_INFO("[%s]get comm ccl buffer size from user mem size", __func__), ret);
    3194            0 :     if (0 == hcclComm->GetConfigInCCLbufferSize()) {
    3195            0 :         size = GetExternalInputCCLBuffSize();
    3196            0 :         HCCL_INFO("[%s]get comm ccl buffer size from external input", __func__);
    3197              :     } else {
    3198            0 :         size = hcclComm->GetConfigInCCLbufferSize();
    3199            0 :         HCCL_INFO("[%s]get comm ccl buffer size from comm config", __func__);
    3200              :     }
    3201            0 :     return HCCL_SUCCESS;
    3202            0 : }
    3203              : 
    3204            0 : bool HcomIsNormalComm([[maybe_unused]] const char* group)
    3205              : {
    3206            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    3207            0 :     return (hcomInfo.pComm != nullptr);
    3208              : }
    3209              : 
    3210            0 : HcclResult HcomClearAivSyncBuf(const char* group, bool aivClearEnable)
    3211              : {
    3212            0 :     HCCLV2_FUNC_RUN(HcomSetAivClearEnableV2(group, aivClearEnable));
    3213            0 :     CHK_PTR_NULL(group);
    3214            0 :     std::shared_ptr<hcclComm> hcclComm;
    3215            0 :     if (HcomGetCommByGroup(group, hcclComm) == HCCL_SUCCESS) {
    3216            0 :         CHK_RET(hcclComm->SetClearAivSyncBuf(aivClearEnable));
    3217              :     }
    3218              : 
    3219            0 :     return HCCL_SUCCESS;
    3220            0 : }
    3221              : 
    3222            0 : HcclResult HcclCommGraphClearAivSyncBuf(s64 comm, bool aivClearEnable)
    3223              : {
    3224            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(comm);
    3225            0 :     if (hcclComm != nullptr) {
    3226            0 :         CHK_RET(hcclComm->SetClearAivSyncBuf(aivClearEnable));
    3227              :     }
    3228            0 :     return HCCL_SUCCESS;
    3229              : }
    3230              : 
    3231            0 : HcclResult HcomSetAivCoreLimit(const char* group, u32 aivCoreLimit)
    3232              : {
    3233            0 :     CHK_PRT_RET(
    3234              :         aivCoreLimit == 0, HCCL_ERROR("[HcomSetAivCoreLimit] aivCoreLimit[%u] invalid", aivCoreLimit), HCCL_E_PARA);
    3235            0 :     HCCLV2_FUNC_RUN(HcomSetAivCoreLimitV2(group, aivCoreLimit));
    3236              : 
    3237            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    3238            0 :     CHK_RET(HcomGetCommByGroup(group, hcclComm));
    3239            0 :     CHK_RET(hcclComm->SetAivCoreLimit(aivCoreLimit));
    3240              : 
    3241            0 :     HCCL_RUN_INFO("HcomSetAivCoreLimit group[%s] aivCoreLimit[%u]", group ? group : HCCL_WORLD_GROUP, aivCoreLimit);
    3242            0 :     return HCCL_SUCCESS;
    3243            0 : }
    3244              : 
    3245            0 : HcclResult HcclCommGraphSetAivCoreLimit(s64 comm, u32 aivCoreLimit)
    3246              : {
    3247            0 :     CHK_PRT_RET(
    3248              :         (comm == 0 || aivCoreLimit == 0),
    3249              :         HCCL_ERROR("[HcclCommGraphSetAivCoreLimit] comm[%lld] or aivCoreLimit[%u] invalid", comm, aivCoreLimit),
    3250              :         HCCL_E_PARA);
    3251              : 
    3252              :     DevType devType;
    3253            0 :     CHK_RET(hrtGetDeviceType(devType));
    3254            0 :     if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
    3255            0 :         HCCL_WARNING("A5 does not support get and clear hcclcom set aiv core limit.");
    3256            0 :         return HCCL_SUCCESS;
    3257              :     }
    3258              : 
    3259            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(comm);
    3260            0 :     CHK_RET(hcclComm->SetAivCoreLimit(aivCoreLimit));
    3261              : 
    3262            0 :     HCCL_RUN_INFO("HcclCommGraphSetAivCoreLimit hcclComm[%p] aivCoreLimit[%u]", hcclComm, aivCoreLimit);
    3263            0 :     return HCCL_SUCCESS;
    3264              : }
    3265              : 
    3266            0 : HcclResult HcomCalcTaskNum(HcomOpParam* hcomOpParam, u32& taskNum)
    3267              : {
    3268            0 :     CHK_PTR_NULL(hcomOpParam);
    3269            0 :     HCCLV2_FUNC_RUN(HcomCalcTaskNumV2(hcomOpParam, taskNum));
    3270            0 :     return HCCL_SUCCESS;
    3271              : }
    3272              : 
    3273           47 : __attribute__((constructor)) void CallBackInit()
    3274              : {
    3275           47 :     HcomGroupCallbackFuncInstall(
    3276              :         HcomCreateGroupImplHeterog, HcomCallBackGroupIsInitHeterog, HcomDestroyGroupImplHeterog,
    3277              :         HcomDestroyOneDeviceHeterog);
    3278           47 : }
    3279              : 
    3280            1 : HcclResult HcomGetGroupNameByOpBase(s64 opBaseHcom, char** groupname)
    3281              : {
    3282            1 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    3283            1 :     CHK_PTR_NULL(hcclComm);
    3284            1 :     *groupname = const_cast<char*>(hcclComm->GetIdentifier().c_str());
    3285            1 :     return HCCL_SUCCESS;
    3286              : }
    3287              : 
    3288            0 : HcclResult GetGroupNameByOpBaseHcom(s64 opBaseHcom, char** groupname)
    3289              : {
    3290            0 :     hccl::hcclComm* hcclComm = reinterpret_cast<hccl::hcclComm*>(opBaseHcom);
    3291            0 :     CHK_PTR_NULL(hcclComm);
    3292            0 :     *groupname = const_cast<char*>(hcclComm->GetIdentifier().c_str());
    3293            0 :     return HCCL_SUCCESS;
    3294              : }
    3295              : 
    3296            0 : HcclResult HcomCreateComResourceByComm(HcclComm comm, u32 streamMode, bool isOpbaseMode, void** commContext, bool isMC2)
    3297              : {
    3298            0 :     CHK_RET(HcclCreateComResourceByComm(comm, streamMode, isOpbaseMode, commContext, isMC2));
    3299            0 :     return HCCL_SUCCESS;
    3300              : }
    3301              : 
    3302            0 : HcclWorkflowMode HcomGetWorkflowMode() { return GetWorkflowMode(); }
    3303              : 
    3304            0 : HcclResult HcomSetWorkflowMode(HcclWorkflowMode mode)
    3305              : {
    3306            0 :     SetWorkflowMode(mode);
    3307            0 :     return HCCL_SUCCESS;
    3308              : }
    3309              : 
    3310            0 : HcclResult GetModuleInfo(DevType devType, const std::vector<RankInfo_t>& rankList, bool& multiModuleDiffDeviceNumMode)
    3311              : {
    3312            0 :     multiModuleDiffDeviceNumMode = false;
    3313              : 
    3314            0 :     if (devType != DevType::DEV_TYPE_910B || rankList.size() == 0) {
    3315            0 :         return HCCL_SUCCESS;
    3316              :     }
    3317              : 
    3318            0 :     std::map<u32, std::vector<RankInfo_t>> moduleMap;
    3319            0 :     for (RankInfo_t rankInfo : rankList) {
    3320            0 :         if (static_cast<s32>(rankInfo.deviceInfo.devicePhyId) == HOST_DEVICE_ID) {
    3321            0 :             continue;
    3322              :         }
    3323            0 :         u32 moduleIdx = rankInfo.serverIdx * FACTOR_NUM_TWO + rankInfo.deviceInfo.devicePhyId / DEVICE_PER_MODULE;
    3324            0 :         auto iter = moduleMap.find(moduleIdx);
    3325            0 :         if (iter == moduleMap.end()) {
    3326            0 :             std::vector<RankInfo_t> rankInfoList;
    3327            0 :             rankInfoList.push_back(rankInfo);
    3328            0 :             moduleMap.insert(std::make_pair(moduleIdx, rankInfoList));
    3329            0 :         } else {
    3330            0 :             iter->second.push_back(rankInfo);
    3331              :         }
    3332            0 :     }
    3333              : 
    3334              :     // 无NPU参与通信
    3335            0 :     if (moduleMap.size() == 0) {
    3336            0 :         return HCCL_SUCCESS;
    3337              :     }
    3338            0 :     u32 preDeviceNum = moduleMap.begin()->second.size();
    3339            0 :     u32 curDeviceNum = preDeviceNum;
    3340            0 :     for (auto moduleInfo : moduleMap) {
    3341            0 :         curDeviceNum = moduleInfo.second.size();
    3342            0 :         HCCL_DEBUG("[HcomOpUtils][GetModuleInfo] module[%d] contains [%d]devices", moduleInfo.first, curDeviceNum);
    3343            0 :         for (auto rankInfo : moduleInfo.second) {
    3344            0 :             HCCL_DEBUG(
    3345              :                 "[HcomOpUtils][GetModuleInfo] moduleIdx[%d] Info: rankId[%d], serverId[%s], serverIdx[%d], "
    3346              :                 "devicePhyId[%d]",
    3347              :                 moduleInfo.first, rankInfo.rankId, rankInfo.serverId.c_str(), rankInfo.serverIdx,
    3348              :                 rankInfo.deviceInfo.devicePhyId);
    3349            0 :         }
    3350            0 :         if (curDeviceNum != preDeviceNum) {
    3351            0 :             multiModuleDiffDeviceNumMode = true;
    3352            0 :             HCCL_INFO(
    3353              :                 "[HcomOpUtils][GetModuleInfo] different module contains different numbers of cards:[%d]",
    3354              :                 multiModuleDiffDeviceNumMode);
    3355            0 :             return HCCL_SUCCESS;
    3356              :         }
    3357            0 :     }
    3358            0 :     return HCCL_SUCCESS;
    3359            0 : }
    3360              : 
    3361            0 : HcclResult HcomCalcOpOnline(HcomOpParam* hcomOpParam, HcomResResponse* hcomResResponse)
    3362              : {
    3363            0 :     HCCL_INFO("[HcomCalcOpOnline] calc online resource start...");
    3364            0 :     u64 streamNum = 0;
    3365            0 :     u64 opMemSize = 0;
    3366            0 :     u32 taskNum = 0;
    3367              :     HcclResult ret;
    3368            0 :     std::string sCollectiveType(hcomOpParam->opType);
    3369              : 
    3370            0 :     CHK_PTR_NULL(hcomOpParam->socVersion);
    3371            0 :     std::string socVersionStr(hcomOpParam->socVersion);
    3372              :     DevType devType;
    3373            0 :     CHK_RET(GetOffDeviceTypeWithoutDev(socVersionStr, devType));
    3374              : 
    3375            0 :     auto iter = HCCL_OPTYPE_NAME_MAP.find(hcomOpParam->opType);
    3376            0 :     HcclCMDType hcclOpType = (iter != HCCL_OPTYPE_NAME_MAP.end()) ? iter->second : HcclCMDType::HCCL_CMD_INVALID;
    3377              : 
    3378            0 :     u32 dataTypeSize = 0;
    3379            0 :     ret = SalGetDataTypeSize(hcomOpParam->dataType, dataTypeSize);
    3380            0 :     CHK_PRT_RET(
    3381              :         ret != HCCL_SUCCESS,
    3382              :         HCCL_ERROR("[GetOp][WorkspaceMemSize]op[%s]: get data size failed. ret[%d]", sCollectiveType.c_str(), ret),
    3383              :         ret);
    3384              : 
    3385            0 :     CHK_RET(HcomCheckCount(hcomOpParam->count));
    3386              : 
    3387            0 :     u64 opDataSize = dataTypeSize * hcomOpParam->count;
    3388              : 
    3389            0 :     CHK_RET(HcomGetWorkspaceSubStreamNum(
    3390              :         hcomOpParam->group, streamNum, opDataSize, hcomOpParam->dataType, hcomOpParam->aivCoreLimit,
    3391              :         hcomOpParam->reduceOp, hcomOpParam->count, hcclOpType));
    3392            0 :     if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
    3393            0 :         CHK_RET(HcomGetWorkspaceMemSize(
    3394              :             hcomOpParam->opType, hcomOpParam->count, hcomOpParam->dataType, hcomOpParam->group, opMemSize));
    3395            0 :     } else {
    3396            0 :         CHK_RET(GetOpWorkspaceMemSize(false, hcclOpType, hcomOpParam, 0, opMemSize));
    3397              :     }
    3398              : 
    3399            0 :     HcomInfo& hcomInfo = HcomGetCtxHomInfo();
    3400            0 :     u32 serverNum = hcomInfo.rankTable.serverNum;
    3401            0 :     u32 deviceNumPerServer = (serverNum == 0) ? 0 : (hcomInfo.rankTable.deviceNum + serverNum - 1) / serverNum;
    3402            0 :     HCCL_INFO("get HcomInfo from Context");
    3403              : 
    3404              :     // 获取multiModuleDiffDeviceNumMode信息
    3405            0 :     bool multiModuleDiffDeviceNumMode = false;
    3406            0 :     ret = GetModuleInfo(devType, hcomInfo.rankTable.rankList, multiModuleDiffDeviceNumMode);
    3407            0 :     if (ret != HCCL_SUCCESS) {
    3408            0 :         HCCL_WARNING("call GetModuleInfo error, failed to get multiModuleDiffDeviceNumMode.");
    3409              :     }
    3410              : 
    3411            0 :     if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
    3412            0 :         CHK_RET(CalcTaskNumV2(hcomOpParam, taskNum));
    3413            0 :     } else {
    3414            0 :         CHK_RET(CalcTaskNum(
    3415              :             hcomOpParam, streamNum, deviceNumPerServer, serverNum, multiModuleDiffDeviceNumMode, taskNum, devType));
    3416              :     }
    3417              : 
    3418            0 :     hcomResResponse->streamNum = streamNum;
    3419            0 :     hcomResResponse->opMemSize = opMemSize;
    3420            0 :     hcomResResponse->taskNum = taskNum;
    3421              : 
    3422            0 :     return HCCL_SUCCESS;
    3423            0 : }
    3424              : 
    3425            0 : HcclResult HcomCalcOpResOffline(HcomOpParam* hcomOpParam, HcomResResponse* hcomResResponse)
    3426              : {
    3427            0 :     HCCL_INFO("[HcomCalcOpResOffline] calc offline resource start...");
    3428              :     // 获取需回传的信息
    3429            0 :     u64 streamNum = 0;
    3430            0 :     u64 opMemSize = 0;
    3431            0 :     u32 taskNum = 0;
    3432              : 
    3433            0 :     CHK_PTR_NULL(hcomOpParam->rankTable);
    3434            0 :     std::string rankTableString(hcomOpParam->rankTable);
    3435              : 
    3436            0 :     auto iter = HCCL_OPTYPE_NAME_MAP.find(hcomOpParam->opType);
    3437            0 :     HcclCMDType hcclOpType = (iter != HCCL_OPTYPE_NAME_MAP.end()) ? iter->second : HcclCMDType::HCCL_CMD_INVALID;
    3438              : 
    3439            0 :     CHK_PTR_NULL(hcomOpParam->socVersion);
    3440            0 :     std::string socVersionStr(hcomOpParam->socVersion);
    3441              :     DevType devType;
    3442            0 :     CHK_RET(GetOffDeviceTypeWithoutDev(socVersionStr, devType));
    3443              : 
    3444              :     // 先根据逻辑ranktable获取device数量
    3445            0 :     s32 deviceNumPerServer = 0;
    3446            0 :     s32 serverNum = 0;
    3447            0 :     bool multiModuleDiffDeviceNumMode = false;
    3448            0 :     RankTable_t clusterInfo;
    3449              :     // world group 从逻辑ranktable里获取device数量
    3450            0 :     if (hcomOpParam->groupListSize == 0) {
    3451            0 :         CHK_RET(GetClusterInfoAndDeviceNum(rankTableString, clusterInfo, deviceNumPerServer));
    3452            0 :         serverNum = clusterInfo.serverNum;
    3453              :     } else {
    3454            0 :         CHK_RET(GetServerAndDevNumFromGroupList(
    3455              :             hcomOpParam->groupList, hcomOpParam->groupListSize, rankTableString, devType, serverNum, deviceNumPerServer,
    3456              :             multiModuleDiffDeviceNumMode));
    3457              :     }
    3458              : 
    3459            0 :     if (hcomOpParam->rankSize == 0) {
    3460            0 :         hcomOpParam->rankSize = deviceNumPerServer;
    3461              :     }
    3462              : 
    3463            0 :     string algName;
    3464            0 :     bool ifAiv = false;
    3465            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    3466            0 :     std::string group = hcomOpParam->group == nullptr ? HCCL_WORLD_GROUP : hcomOpParam->group;
    3467            0 :     CHK_RET(HcomGetCommByGroup(group.c_str(), hcclComm));
    3468            0 :     void* counts = nullptr;
    3469            0 :     HcclResult ret = hcclComm->HcclSelectAlg(
    3470            0 :         hcclOpType, hcomOpParam->count, counts, hcomOpParam->dataType, hcomOpParam->reduceOp, hcomOpParam->aivCoreLimit,
    3471              :         ifAiv, algName);
    3472            0 :     CHK_PRT_RET(
    3473              :         ret != HCCL_SUCCESS,
    3474              :         HCCL_ERROR(
    3475              :             "[HcomGetWorkspaceSubStreamNum] HcclSelectAlg failed, ret[%d], optype[%d], count[%llu],"
    3476              :             "dataType[%d], reduceOp[%d]",
    3477              :             ret, hcclOpType, hcomOpParam->count, hcomOpParam->dataType, hcomOpParam->reduceOp),
    3478              :         ret);
    3479            0 :     CHK_RET(GetStreamNumOfflineComp(hcclOpType, serverNum, deviceNumPerServer, ifAiv, devType, streamNum, group));
    3480            0 :     CHK_RET(GetOpWorkspaceMemSize(true, hcclOpType, hcomOpParam, serverNum, opMemSize));
    3481              : 
    3482            0 :     if (devType == DevType::DEV_TYPE_950 || devType == DevType::DEV_TYPE_960) {
    3483              :         // host展开已日落, Task任务数按照当前需求最多的CCU加速模式[AIV, AICPU使用较少]预估
    3484            0 :         taskNum = ESTIMATE_CCU_TASK_PER_STREAM;
    3485              :     }
    3486              : 
    3487            0 :     hcomResResponse->streamNum = streamNum;
    3488            0 :     hcomResResponse->opMemSize = opMemSize;
    3489            0 :     hcomResResponse->taskNum = taskNum;
    3490              : 
    3491            0 :     return HCCL_SUCCESS;
    3492            0 : }
    3493              : 
    3494            0 : HcclResult GetOffDeviceTypeWithoutDev(std::string socVersionStr, DevType& devType)
    3495              : {
    3496              :     // 离线编译第一阶段获取devType从SOC_VERSION里获取
    3497            0 :     DevType tempDevType = DevType::DEV_TYPE_COUNT;
    3498            0 :     CHK_RET(hrtGetDeviceTypeBySocVersion(socVersionStr, tempDevType));
    3499              : 
    3500            0 :     if (tempDevType != DevType::DEV_TYPE_910 && tempDevType != DevType::DEV_TYPE_910B
    3501            0 :         && tempDevType != DevType::DEV_TYPE_310P1 && tempDevType != DevType::DEV_TYPE_310P3
    3502            0 :         && tempDevType != DevType::DEV_TYPE_910_93 && tempDevType != DevType::DEV_TYPE_950
    3503            0 :         && tempDevType != DevType::DEV_TYPE_960) {
    3504            0 :         HCCL_ERROR("[offline][compilation] cur dev type[%u] is not support.", tempDevType);
    3505            0 :         return HCCL_E_RUNTIME;
    3506              :     }
    3507            0 :     devType = tempDevType;
    3508            0 :     HCCL_DEBUG("[offline] Get devtype[%u]....", devType);
    3509            0 :     return HCCL_SUCCESS;
    3510              : }
    3511              : 
    3512            0 : HcclResult GetStreamNumOfflineComp(
    3513              :     HcclCMDType hcclOpType, s32 serverNum, s32 deviceNumPerServer, bool ifAiv, DevType devType, u64& streamNum,
    3514              :     const std::string& group)
    3515              : {
    3516            0 :     switch (devType) {
    3517            0 :         case DevType::DEV_TYPE_310P1:
    3518              :         case DevType::DEV_TYPE_310P3: {
    3519            0 :             streamNum = 0;
    3520            0 :             break;
    3521              :         }
    3522              : 
    3523            0 :         case DevType::DEV_TYPE_910B:
    3524              :         case DevType::DEV_TYPE_910:
    3525              :         case DevType::DEV_TYPE_950:
    3526              :         case DevType::DEV_TYPE_960:
    3527              :         case DevType::DEV_TYPE_910_93: {
    3528            0 :             CHK_RET(
    3529              :                 GetStremNumOfflineByDev(devType, hcclOpType, serverNum, deviceNumPerServer, ifAiv, streamNum, group));
    3530            0 :             break;
    3531              :         }
    3532              : 
    3533            0 :         default: {
    3534            0 :             HCCL_ERROR(
    3535              :                 "[Get][OfflineCompStreamNum] The current device type does not support offline compilation, "
    3536              :                 "The value of device type is [%u]",
    3537              :                 devType);
    3538            0 :             return HCCL_E_NOT_SUPPORT;
    3539              :         }
    3540              :     }
    3541            0 :     HCCL_INFO("[GetStreamNumOfflineComp]stream num is [%llu]", streamNum);
    3542            0 :     return HCCL_SUCCESS;
    3543              : }
    3544              : 
    3545            0 : HcclResult GetStremNumOfflineByDev(
    3546              :     const DevType& devType, HcclCMDType hcclOpType, s32 serverNum, s32 deviceNumPerServer, bool ifAiv, u64& streamNum,
    3547              :     const std::string& group)
    3548              : {
    3549            0 :     if (ifAiv) {
    3550            0 :         streamNum = 0; // 离线编译下,从流数量设置为0
    3551            0 :         HCCL_INFO("[GetStremNumOfflineByDev] set AIV stream num is 0 When in Aiv mode");
    3552            0 :         return HCCL_SUCCESS;
    3553              :     }
    3554              : 
    3555            0 :     if (hcclOpType == HcclCMDType::HCCL_CMD_SEND || hcclOpType == HcclCMDType::HCCL_CMD_RECEIVE) {
    3556            0 :         streamNum = 0;
    3557            0 :         return HCCL_SUCCESS;
    3558              :     }
    3559              : 
    3560            0 :     if (devType == DevType::DEV_TYPE_910 && deviceNumPerServer == HCCL_DEVICE_NUM_EIGHT) {
    3561            0 :         CHK_RET(GetSubStreamNum(devType, deviceNumPerServer, streamNum, serverNum, group));
    3562            0 :     } else if (devType == DevType::DEV_TYPE_910_93) {
    3563            0 :         CHK_RET(GetSubStreamNum(devType, deviceNumPerServer, streamNum, serverNum, group));
    3564              :     } else {
    3565            0 :         streamNum = deviceNumPerServer > HCCL_DEVICE_NUM_ONE ? deviceNumPerServer - MINUS_MESH_STREAM_NUM : 0;
    3566              :     }
    3567            0 :     HCCL_INFO(
    3568              :         "[GetStremNumOfflineByDev] get device num per server is [%u] streamNum [%u]", deviceNumPerServer, streamNum);
    3569            0 :     return HCCL_SUCCESS;
    3570              : }
    3571              : 
    3572              : HcclResult
    3573            0 : GetSubStreamNum(const DevType& devType, s32 deviceNum, u64& streamNum, s32& serverNum, const std::string& group)
    3574              : {
    3575            0 :     if (devType == DevType::DEV_TYPE_910B) {
    3576            0 :         constexpr u64 maxStream = 6;
    3577            0 :         streamNum = std::min(maxStream, static_cast<u64>(deviceNum) - MINUS_MESH_STREAM_NUM);
    3578            0 :         if (CommConfiger::GetInstance().GetCommConfigAlgoConfig(group)[HCCL_ALGO_LEVEL_1]
    3579            0 :             == HcclAlgoType::HCCL_ALGO_TYPE_PIPELINE) {
    3580            0 :             streamNum = static_cast<u64>(deviceNum);
    3581              :         }
    3582            0 :     } else if (devType == DevType::DEV_TYPE_910_93) {
    3583            0 :         if (serverNum == 1) {
    3584            0 :             streamNum = static_cast<u64>(deviceNum) - MINUS_MESH_STREAM_NUM;
    3585              :         } else {
    3586            0 :             constexpr u64 streamNumFor91093 = 3;
    3587            0 :             streamNum = streamNumFor91093;
    3588              :         }
    3589              :     } else {
    3590            0 :         if (deviceNum > HCCL_DEVICE_NUM_EIGHT) {
    3591            0 :             streamNum = OFFLINE_BUILD_SUB_STEAM_NUM[HCCL_DEVICE_NUM_EIGHT];
    3592            0 :         } else if (OFFLINE_BUILD_SUB_STEAM_NUM.count(deviceNum) != 0) {
    3593            0 :             streamNum = OFFLINE_BUILD_SUB_STEAM_NUM[deviceNum];
    3594              :         } else {
    3595            0 :             streamNum = 0;
    3596              :         }
    3597              :     }
    3598              : 
    3599            0 :     if (SatisfyIntraSuperPod(devType, deviceNum, true)) {
    3600            0 :         streamNum = std::max(static_cast<u64>(deviceNum - 1u), streamNum);
    3601            0 :     } else if (FullmeshPairwiseSatisfyHighPerfAlltoallMeshCondition(
    3602            0 :                    devType, deviceNum * serverNum, true,
    3603            0 :                    CommConfiger::GetInstance().GetCommConfigAlgoConfig(group, HcclCMDType::HCCL_CMD_ALLTOALL))) {
    3604            0 :         streamNum = std::max(static_cast<u64>(deviceNum * serverNum - 1u), streamNum);
    3605              :     }
    3606              : 
    3607            0 :     HCCL_DEBUG("[GetSubStreamNum]deviceNum[%d], streamNum[%llu]", deviceNum, streamNum);
    3608            0 :     return HCCL_SUCCESS;
    3609              : }
    3610              : 
    3611            0 : HcclResult GetClusterInfoAndDeviceNum(const std::string rankTableString, RankTable_t& clusterInfo, s32& deviceNum)
    3612              : {
    3613            0 :     HCCL_DEBUG("[get][offlineStreamNum]rankTableString[%s]", rankTableString.c_str());
    3614            0 :     TopoinfoRanktableOffline myTopoRanktable(rankTableString);
    3615            0 :     CHK_RET(myTopoRanktable.Init());
    3616            0 :     CHK_RET(myTopoRanktable.GetClusterInfo(clusterInfo));
    3617            0 :     CHK_RET(myTopoRanktable.GetDeviceNumPerServer(deviceNum));
    3618            0 :     CHK_PRT_RET(
    3619              :         deviceNum == 0,
    3620              :         HCCL_ERROR("[GetStremNumOfflineByDev]cur device num per server is 0, "
    3621              :                    "maybe ranktable is incomplete"),
    3622              :         HCCL_E_PARA);
    3623            0 :     return HCCL_SUCCESS;
    3624            0 : }
    3625              : 
    3626            0 : HcclResult GetServerAndDevNumFromGroupList(
    3627              :     const u32* groupList, u32 groupListSize, const std::string rankTableString, DevType devType, s32& serverNum,
    3628              :     s32& deviceNumPerServer, bool& multiModuleDiffDeviceNumMode)
    3629              : {
    3630            0 :     deviceNumPerServer = 0;
    3631            0 :     serverNum = 0;
    3632              : 
    3633            0 :     if (groupListSize == 0) {
    3634            0 :         return HCCL_SUCCESS;
    3635              :     }
    3636            0 :     CHK_PTR_NULL(groupList);
    3637              : 
    3638              :     try {
    3639              :         // 获取并设定stream 数量
    3640              :         // 能获取到group list时进入离线编译的流程去获取从流个数
    3641            0 :         CHK_RET(GetServerAndDevNumFromLogRanktable(
    3642              :             rankTableString, groupList, groupListSize, devType, serverNum, deviceNumPerServer,
    3643              :             multiModuleDiffDeviceNumMode));
    3644              : 
    3645            0 :         HCCL_INFO("deviceNumPerServer:[%d] serverNum:[%d]", deviceNumPerServer, serverNum);
    3646            0 :     } catch (const std::exception& e) {
    3647            0 :         HCCL_ERROR("[HcomCalcOpRunningParam] exception caught. err[%s]", e.what());
    3648            0 :         return HCCL_E_INTERNAL;
    3649            0 :     }
    3650            0 :     return HCCL_SUCCESS;
    3651              : }
    3652              : 
    3653            0 : HcclResult GetServerAndDevNumFromLogRanktable(
    3654              :     const std::string rankTableString, const u32* groupList, u32 groupListSize, DevType devType, s32& serverNum,
    3655              :     s32& deviceNum, bool& multiModuleDiffDeviceNumMode)
    3656              : {
    3657            0 :     HCCL_INFO("Entry GetServerAndDevNumFromLogRanktable");
    3658            0 :     RankTable_t clusterInfo;
    3659            0 :     TopoinfoRanktableOffline myTopoRanktable(rankTableString);
    3660            0 :     CHK_RET(myTopoRanktable.Init());
    3661            0 :     CHK_RET(myTopoRanktable.GetClusterInfo(clusterInfo));
    3662              : 
    3663            0 :     CHK_RET(GetServerAndDevNumFromRanklist(
    3664              :         groupList, groupListSize, clusterInfo.rankList, devType, serverNum, deviceNum, multiModuleDiffDeviceNumMode));
    3665            0 :     return HCCL_SUCCESS;
    3666            0 : }
    3667              : 
    3668            0 : HcclResult GetServerAndDevNumFromRanklist(
    3669              :     const u32* groupList, u32 groupListSize, const std::vector<RankInfo_t>& rankList, DevType devType, s32& serverNum,
    3670              :     s32& deviceNum, bool& multiModuleDiffDeviceNumMode)
    3671              : {
    3672            0 :     u32 serverId = 0;
    3673            0 :     std::map<u32, s32> serverAndDevNum;
    3674            0 :     deviceNum = 0;
    3675            0 :     for (u32 i = 0; i < groupListSize; i++) {
    3676            0 :         u32 rankId = groupList[i];
    3677            0 :         CHK_RET(GetServerIdByRankId(rankList, rankId, serverId));
    3678            0 :         if (serverAndDevNum.find(serverId) == serverAndDevNum.end()) {
    3679            0 :             serverAndDevNum[serverId] = 1;
    3680              :         } else {
    3681            0 :             serverAndDevNum[serverId]++;
    3682              :         }
    3683              :         // 可能存在不同server内device数量不一致的情况,因此求最大值
    3684            0 :         if (serverAndDevNum[serverId] > deviceNum) {
    3685            0 :             deviceNum = serverAndDevNum[serverId];
    3686              :         }
    3687              :     }
    3688            0 :     serverNum = serverAndDevNum.size();
    3689              : 
    3690              :     // 获取multiModuleDiffDeviceNumMode信息
    3691            0 :     HcclResult ret = GetModuleInfo(devType, rankList, multiModuleDiffDeviceNumMode);
    3692            0 :     if (ret != HCCL_SUCCESS) {
    3693            0 :         HCCL_WARNING("call GetModuleInfo error, failed to get multiModuleDiffDeviceNumMode.");
    3694              :     }
    3695            0 :     return HCCL_SUCCESS;
    3696            0 : }
    3697              : 
    3698            0 : HcclResult GetServerIdByRankId(const std::vector<RankInfo_t>& rankList, const u32& rankId, u32& serverId)
    3699              : {
    3700            0 :     for (auto& iter : rankList) {
    3701            0 :         if (iter.rankId == rankId) {
    3702            0 :             serverId = iter.serverIdx;
    3703            0 :             return HCCL_SUCCESS;
    3704              :         }
    3705              :     }
    3706            0 :     return HCCL_E_NOT_FOUND;
    3707              : }
    3708              : 
    3709            0 : HcclResult GetOpWorkspaceMemSize(
    3710              :     bool isOfflineCompilation, HcclCMDType hcclOpType, HcomOpParam* hcomOpParam, s32 serverNum, u64& opMemSize)
    3711              : {
    3712              :     HcclResult ret;
    3713            0 :     const u32 alignSize = HCCL_ALIGN_SIZE;
    3714            0 :     u32 dataTypeSize = 0;
    3715            0 :     std::string sCollectiveType(hcomOpParam->opType);
    3716              : 
    3717            0 :     ret = SalGetDataTypeSize(hcomOpParam->dataType, dataTypeSize);
    3718            0 :     CHK_PRT_RET(
    3719              :         ret != HCCL_SUCCESS,
    3720              :         HCCL_ERROR("[GetOp][WorkspaceMemSize]op[%s]: get data size failed. ret[%d]", sCollectiveType.c_str(), ret),
    3721              :         ret);
    3722              : 
    3723            0 :     u64 getMemSize = 0;
    3724            0 :     u32 rankSize = hcomOpParam->rankSize;
    3725            0 :     CHK_RET(GetOpScratchMemSize(
    3726              :         isOfflineCompilation, hcclOpType, hcomOpParam, getMemSize, dataTypeSize, rankSize, serverNum));
    3727              : 
    3728              :     // 算子所需的内存大小,加上固定32kb长度,并按对齐后回传
    3729            0 :     opMemSize = HCCL_WORKSPACE_MEM_32_KB;
    3730            0 :     opMemSize += getMemSize;
    3731            0 :     opMemSize = (opMemSize + alignSize - 1) / alignSize * alignSize;
    3732              : 
    3733            0 :     HCCL_INFO(
    3734              :         "workspace memory size: op[%s], data type[%s], count[%llu], "
    3735              :         "group[%s], rank size[%u], size[%llu], mem size[%llu].",
    3736              :         sCollectiveType.c_str(), GetDataTypeEnumStr(hcomOpParam->dataType).c_str(), hcomOpParam->count,
    3737              :         hcomOpParam->group, rankSize, getMemSize, opMemSize);
    3738              : 
    3739            0 :     return HCCL_SUCCESS;
    3740            0 : }
    3741              : 
    3742            7 : HcclResult GetOpScratchMemSize(
    3743              :     bool isOfflineCompilation, HcclCMDType hcclOpType, HcomOpParam* hcomOpParam, u64& opMemSize, u32 dataTypeSize,
    3744              :     s32 rankSize, s32 serverNum)
    3745              : {
    3746            7 :     CHK_PTR_NULL(hcomOpParam);
    3747            7 :     constexpr u8 devType_950 = 6; // 950枚举值为6,需要统一整改
    3748            7 :     constexpr u8 devType_960 = 8; // 960枚举值为8
    3749            7 :     u64 count = hcomOpParam->count;
    3750           14 :     std::string sCollectiveType(hcomOpParam->opType);
    3751              : 
    3752            7 :     std::string socVersionStr(hcomOpParam->socVersion);
    3753            7 :     DevType devType = DevType::DEV_TYPE_COUNT;
    3754            7 :     CHK_RET(hrtGetDeviceTypeBySocVersion(socVersionStr, devType));
    3755              : 
    3756            6 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    3757            6 :     std::string group = hcomOpParam->group == nullptr ? HCCL_WORLD_GROUP : hcomOpParam->group;
    3758              :     // 获取通信域句柄,因为91095不需要获取通信域句柄以感知aivonly,暂时规避
    3759            6 :     if (static_cast<u8>(devType) != devType_950 && static_cast<u8>(devType) != devType_960) {
    3760            6 :         CHK_RET(HcomGetCommByGroup(group.c_str(), hcclComm));
    3761              :     }
    3762              : 
    3763              :     std::vector<HcclAlgoType> algoTypeArr
    3764            5 :         = CommConfiger::GetInstance().GetCommConfigAlgoConfig(group, HcclCMDType::HCCL_CMD_ALLTOALLV);
    3765              :     bool UseOneLayerAlltoAllv
    3766            5 :         = (algoTypeArr[0] == HcclAlgoType::HCCL_ALGO_TYPE_NA
    3767            5 :            && algoTypeArr[1] == HcclAlgoType::HCCL_ALGO_TYPE_PAIRWISE);
    3768              : 
    3769              :     // 是否需要额外申请scratch mem
    3770            5 :     if (hcclOpType == HCCL_CMD_REDUCE_SCATTER_V) {
    3771            0 :         CHK_RET(GetRedcueScatterVScratchMemSize(hcomOpParam, opMemSize));
    3772            5 :     } else if (hcclOpType == HCCL_CMD_REDUCE_SCATTER) {
    3773              :         // ReduceScatter 所需workspace memory: count * 单个数据的size * rank_size
    3774            2 :         opMemSize = count * dataTypeSize * rankSize;
    3775              : 
    3776              :         u8 deterministic;
    3777            2 :         std::string socVersionStr(hcomOpParam->socVersion);
    3778            2 :         DevType devType = DevType::DEV_TYPE_COUNT;
    3779            2 :         CHK_RET(hrtGetDeviceTypeBySocVersion(socVersionStr, devType));
    3780            2 :         CHK_RET(GetDeterministic(devType, hcomOpParam->geDeterministic, deterministic));
    3781            2 :         if (deterministic == DETERMINISTIC_ENABLE || deterministic == DETERMINISTIC_STRICT) {
    3782            0 :             const u32 NUM_SIZE_TWO = 2;
    3783            0 :             opMemSize *= NUM_SIZE_TWO;
    3784              :         }
    3785            5 :     } else if (hcclOpType == HCCL_CMD_ALLTOALL) {
    3786              :         // AlltoAll 所需workspace memory :input mem size
    3787            1 :         opMemSize += (count * dataTypeSize * rankSize);
    3788            2 :     } else if (hcclOpType == HCCL_CMD_BROADCAST) {
    3789            2 :         if (count * dataTypeSize <= HCCL_MID_COUNT_32_MB) {
    3790            1 :             opMemSize += count * dataTypeSize * HCCL_MEMSIZE_HD_FACTOR;
    3791              :         }
    3792            0 :     } else if (
    3793            0 :         (hcclOpType == HCCL_CMD_ALLTOALLV || hcclOpType == HCCL_CMD_ALLTOALLVC) && !UseOneLayerAlltoAllv
    3794            0 :         && static_cast<u32>(rankSize) > HCCL_ALLTOALLV_P2P_SIZE) {
    3795              :         // 离线编译场景需要重新计算
    3796            0 :         if (isOfflineCompilation) {
    3797            0 :             if (hcclOpType == HCCL_CMD_ALLTOALLV) {
    3798            0 :                 HCCL_ERROR("[GetOpScratchMemSize] offline compilation is not support HcomAllToAllV");
    3799            0 :                 return HCCL_E_PARA;
    3800              :             }
    3801              :         }
    3802            0 :         s32 deviceLogicId = 0;
    3803            0 :         if (!isOfflineCompilation) {
    3804              :             // 获取deviceLogicID
    3805            0 :             CHK_RET(HcomGetDevId(hcomOpParam->group, &deviceLogicId));
    3806            0 :             CHK_RET(hrtSetDevice(deviceLogicId));
    3807              :         }
    3808            0 :         if (hcclOpType == HCCL_CMD_ALLTOALLV) {
    3809            0 :             CHK_RET(GetAlltoAllvStagedScratchMemSize(hcomOpParam, rankSize, opMemSize));
    3810              :         } else {
    3811            0 :             CHK_RET(GetAlltoAllvcStagedScratchMemSize(hcomOpParam, rankSize, opMemSize));
    3812              :         }
    3813            0 :         if (!isOfflineCompilation) {
    3814            0 :             CHK_RET(hrtResetDevice(deviceLogicId));
    3815              :         }
    3816            0 :     } else if (hcclOpType == HCCL_CMD_ALLREDUCE) {
    3817              :         // 判断 aiv_only
    3818            0 :         bool isAivOnlyMode = false;
    3819              :         u8 deterministic;
    3820              : 
    3821              :         // 91095环境下,暂时不需要感知是否为aivonly模式
    3822            0 :         if (static_cast<u8>(devType) != devType_950 && static_cast<u8>(devType) != devType_960) {
    3823            0 :             CHK_RET(hcclComm->GetOnlyAivModeConfig(isAivOnlyMode));
    3824              :         }
    3825            0 :         CHK_RET(GetDeterministic(devType, hcomOpParam->geDeterministic, deterministic));
    3826              : 
    3827            0 :         if (deterministic != DETERMINISTIC_DISABLE) {
    3828            0 :             CHK_RET(GetAllReduceScratchMemSize(isOfflineCompilation, hcomOpParam, serverNum, rankSize, opMemSize));
    3829              :         } else {
    3830              :             // 数据量大以及aivOnly的情况下需要申请scratch mem
    3831            0 :             if (count * dataTypeSize <= HCCL_MID_COUNT_16_MB || isAivOnlyMode) {
    3832            0 :                 opMemSize += count * dataTypeSize * HCCL_MEMSIZE_HD_FACTOR;
    3833              :             }
    3834              :         }
    3835              :     }
    3836              : 
    3837            5 :     HCCL_INFO("workspace memory size: op[%s], scratch mem size[%llu]", sCollectiveType.c_str(), opMemSize);
    3838            5 :     return HCCL_SUCCESS;
    3839            7 : }
    3840              : 
    3841            0 : HcclResult GetAlltoAllvStagedScratchMemSize(HcomOpParam* hcomOpParam, u32 rankSize, u64& getMemSize)
    3842              : {
    3843            0 :     if (rankSize > ALLTOALLV_RANK_MAX_NUM) {
    3844            0 :         HCCL_ERROR("[GetAlltoAllvStagedScratchMemSize] Invalid rankSize[%u]", rankSize);
    3845            0 :         return HCCL_E_PARA;
    3846              :     }
    3847            0 :     u64 memSize = 0;
    3848              : 
    3849            0 :     std::vector<u64> sendCountsUnsigned(rankSize, 0);
    3850            0 :     std::vector<u64> sendDisplsUnsigned(rankSize, 0);
    3851            0 :     std::vector<u64> recvCountsUnsigned(rankSize, 0);
    3852            0 :     std::vector<u64> recvDisplsUnsigned(rankSize, 0);
    3853              : 
    3854            0 :     for (u32 i = 0; i < rankSize; i++) {
    3855            0 :         sendCountsUnsigned[i] = static_cast<u64*>(hcomOpParam->All2AllDataDes.sendCounts)[i];
    3856            0 :         sendDisplsUnsigned[i] = static_cast<u64*>(hcomOpParam->All2AllDataDes.sendDispls)[i];
    3857            0 :         recvCountsUnsigned[i] = static_cast<u64*>(hcomOpParam->All2AllDataDes.recvCounts)[i];
    3858            0 :         recvDisplsUnsigned[i] = static_cast<u64*>(hcomOpParam->All2AllDataDes.recvDispls)[i];
    3859              :     }
    3860              : 
    3861            0 :     CHK_RET(HcomGetAlltoAllStagedWorkSpaceMemSize(
    3862              :         hcomOpParam->group, sendCountsUnsigned.data(), sendDisplsUnsigned.data(), hcomOpParam->All2AllDataDes.sendType,
    3863              :         recvCountsUnsigned.data(), recvDisplsUnsigned.data(), hcomOpParam->All2AllDataDes.recvType, memSize));
    3864              : 
    3865            0 :     getMemSize += memSize;
    3866              : 
    3867            0 :     return HCCL_SUCCESS;
    3868            0 : }
    3869              : 
    3870            0 : HcclResult GetAlltoAllvcStagedScratchMemSize(HcomOpParam* hcomOpParam, u32 rankSize, u64& getMemSize)
    3871              : {
    3872            0 :     if (rankSize > ALLTOALLVC_RANK_MAX_NUM) {
    3873            0 :         HCCL_ERROR("[GetAlltoAllvcStagedScratchMemSize] Invalid rankSize[%u]", rankSize);
    3874            0 :         return HCCL_E_PARA;
    3875              :     }
    3876            0 :     u64 memSize = 0;
    3877            0 :     HcclDataType sendType = hcomOpParam->All2AllDataDes.sendType;
    3878            0 :     HcclDataType recvType = hcomOpParam->All2AllDataDes.recvType;
    3879              : 
    3880            0 :     int64_t* sendCountMatrix = static_cast<int64_t*>(hcomOpParam->All2AllDataDes.sendCountMatrix);
    3881              : 
    3882            0 :     u32 sendTypeSize = 0, recvTypeSize = 0;
    3883            0 :     CHK_RET(SalGetDataTypeSize(sendType, sendTypeSize));
    3884            0 :     CHK_RET(SalGetDataTypeSize(recvType, recvTypeSize));
    3885            0 :     std::vector<SendRecvInfo> allMeshAggregationSendRecvInfo;
    3886            0 :     for (u32 i = 0; i < rankSize; i++) {
    3887            0 :         SendRecvInfo sendRecvInfo;
    3888            0 :         u64 curSendDispls = 0;
    3889            0 :         u64 curRecvDispls = 0;
    3890            0 :         for (u32 j = 0; j < rankSize; j++) {
    3891            0 :             u64 curSendCounts = sendCountMatrix[i * rankSize + j];
    3892            0 :             sendRecvInfo.sendCounts.push_back(curSendCounts);
    3893            0 :             sendRecvInfo.sendDispls.push_back(curSendDispls);
    3894            0 :             sendRecvInfo.sendLength.push_back(curSendCounts * sendTypeSize);
    3895            0 :             sendRecvInfo.sendOffset.push_back(curSendDispls * sendTypeSize);
    3896            0 :             HCCL_DEBUG(
    3897              :                 "GetAlltoAllvcStagedScratchMemSize rankID[%u], curSendCounts[%llu], curSendDispls[%llu]", i,
    3898              :                 curSendCounts, curSendDispls);
    3899            0 :             curSendDispls += curSendCounts;
    3900              : 
    3901            0 :             u64 curRecvCounts = sendCountMatrix[i + rankSize * j];
    3902            0 :             sendRecvInfo.recvCounts.push_back(curRecvCounts);
    3903            0 :             sendRecvInfo.recvDispls.push_back(curRecvDispls);
    3904            0 :             sendRecvInfo.recvLength.push_back(curRecvCounts * recvTypeSize);
    3905            0 :             sendRecvInfo.recvOffset.push_back(curRecvDispls * recvTypeSize);
    3906            0 :             HCCL_DEBUG(
    3907              :                 "GetAlltoAllvcStagedScratchMemSize rankID[%u], curRecvCounts[%llu], curRecvDispls[%llu]", i,
    3908              :                 curRecvCounts, curRecvDispls);
    3909            0 :             curRecvDispls += curRecvCounts;
    3910              :         }
    3911            0 :         allMeshAggregationSendRecvInfo.push_back(std::move(sendRecvInfo));
    3912            0 :     }
    3913              : 
    3914            0 :     CHK_RET(HcomGetAlltoAllvcStagedWorkSpaceMemSize(hcomOpParam->group, allMeshAggregationSendRecvInfo, memSize));
    3915            0 :     getMemSize += memSize;
    3916              : 
    3917            0 :     return HCCL_SUCCESS;
    3918            0 : }
    3919              : 
    3920            0 : HcclResult GetRedcueScatterVScratchMemSize(HcomOpParam* hcomOpParam, u64& getMemSize)
    3921              : {
    3922              :     DevType devType;
    3923            0 :     std::string socVerStr(hcomOpParam->socVersion);
    3924            0 :     CHK_RET(GetOffDeviceTypeWithoutDev(socVerStr, devType));
    3925              :     u8 deterministic;
    3926            0 :     CHK_RET(GetDeterministic(devType, hcomOpParam->geDeterministic, deterministic));
    3927              : 
    3928            0 :     const u32 deviceEight = 8;
    3929            0 :     const u32 paddingLen = 1024;
    3930            0 :     u64 dataTypeSize = SIZE_TABLE[hcomOpParam->dataType];
    3931            0 :     u64 ranksize = hcomOpParam->rankSize;
    3932              :     // 910B 确定性 || 910B 多module
    3933            0 :     if (devType == DevType::DEV_TYPE_910B && (deterministic != DETERMINISTIC_DISABLE || ranksize > deviceEight)) {
    3934            0 :         u64 maxCount = 0;
    3935            0 :         for (u32 i = 0; i < ranksize; i++) {
    3936              :             // reducescatterv复用HcomOpParam的All2AllDataDes字段
    3937            0 :             maxCount = std::max(maxCount, static_cast<u64*>(hcomOpParam->All2AllDataDes.sendCounts)[i]);
    3938              :         }
    3939            0 :         getMemSize = (maxCount * dataTypeSize + paddingLen) * ranksize;
    3940            0 :         HCCL_INFO("[GetRedcueScatterVScratchMemSize] maxCount[%llu], getMemSize[%llu]", maxCount, getMemSize);
    3941            0 :     } else if (devType == DevType::DEV_TYPE_910B && ranksize <= deviceEight) {
    3942            0 :         getMemSize = hcomOpParam->count * dataTypeSize * ranksize;
    3943            0 :         HCCL_INFO("[GetRedcueScatterVScratchMemSize] getMemSize[%llu]", getMemSize);
    3944              :     } else {
    3945            0 :         getMemSize = hcomOpParam->count * dataTypeSize;
    3946              :     }
    3947            0 :     HCCL_DEBUG("[GetRedcueScatterVScratchMemSize] rankSize[%llu] getMemSize[%llu]", ranksize, getMemSize);
    3948            0 :     return HCCL_SUCCESS;
    3949            0 : }
    3950              : 
    3951            0 : HcclResult GetAllReduceScratchMemSize(
    3952              :     bool isOfflineCompilation, HcomOpParam* hcomOpParam, s32 serverNum, s32 rankSize, u64& getMemSize)
    3953              : {
    3954            0 :     u64 scratchSize = 0;
    3955              : 
    3956            0 :     bool no_impl_compile = isOfflineCompilation || hcomOpParam->groupListSize > 0;
    3957            0 :     if (no_impl_compile) {
    3958            0 :         HcclResult ret = GetAllReduceScratchSizeWithoutDev(hcomOpParam, serverNum, rankSize, scratchSize);
    3959            0 :         CHK_PRT_RET(
    3960              :             ret != HCCL_SUCCESS,
    3961              :             HCCL_ERROR("no_impl_compile [GetAllReduceScratchMemSize] fail ", HCOM_ERROR_CODE(HCCL_E_PARA)),
    3962              :             HCCL_E_PARA);
    3963              :     } else {
    3964            0 :         CHK_RET(
    3965              :             HcomGetAllReduceScratchSize(hcomOpParam->group, hcomOpParam->count, hcomOpParam->dataType, scratchSize));
    3966              :     }
    3967            0 :     u64 memSize = SIZE_TABLE[hcomOpParam->dataType] * hcomOpParam->count;
    3968              : 
    3969            0 :     HCCL_DEBUG(
    3970              :         "[GetAllReduceScratchMemSize] serverNum=%u, memSize=%llu, rankSize=%u, scratchSize=%llu", serverNum, memSize,
    3971              :         rankSize, scratchSize);
    3972            0 :     getMemSize += scratchSize;
    3973              : 
    3974            0 :     return HCCL_SUCCESS;
    3975              : }
    3976              : 
    3977            0 : HcclResult GetAllReduceScratchSizeWithoutDev(HcomOpParam* hcomOpParam, s32 serverNum, s32 rankSize, u64& scratchSize)
    3978              : {
    3979              :     // 检查是否使能确定性计算
    3980              : 
    3981            0 :     bool supportInlineReduce
    3982            0 :         = (hcomOpParam->reduceOp != HCCL_REDUCE_PROD) && (hcomOpParam->dataType != HcclDataType::HCCL_DATA_TYPE_INT64);
    3983              : 
    3984              :     DevType devType;
    3985            0 :     std::string socVerStr(hcomOpParam->socVersion);
    3986            0 :     CHK_RET(GetOffDeviceTypeWithoutDev(socVerStr, devType));
    3987            0 :     bool isAscend910B = (devType == DevType::DEV_TYPE_910B);
    3988            0 :     u64 memSize = SIZE_TABLE[hcomOpParam->dataType] * hcomOpParam->count;
    3989              :     u8 deterministic;
    3990            0 :     CHK_RET(GetDeterministic(devType, hcomOpParam->geDeterministic, deterministic));
    3991            0 :     if (deterministic != DETERMINISTIC_DISABLE && serverNum <= 1 && isAscend910B && supportInlineReduce) {
    3992            0 :         const u32 deviceEight = 8;
    3993            0 :         const s32 deviceTwo = 2;
    3994              : 
    3995            0 :         scratchSize = 0;
    3996            0 :         if (serverNum == 0) {
    3997              :             // 无效serverNum,按最大需求申请
    3998            0 :             if (memSize <= HCCL_SMALL_COUNT_GRAPH_64_KB) {
    3999              :                 // 小数据
    4000            0 :                 scratchSize = memSize * (deviceEight - 1);
    4001              :             }
    4002            0 :         } else if (serverNum == 1 && rankSize > deviceTwo) {
    4003              :             // 有效serverNum,按实际需求申请
    4004            0 :             if (memSize <= HCCL_SMALL_COUNT_GRAPH_64_KB) {
    4005              :                 // 小数据
    4006            0 :                 if (rankSize == deviceEight) {
    4007            0 :                     scratchSize = 0; // Small Count HD
    4008              :                 } else {
    4009            0 :                     scratchSize = memSize * (rankSize - 1); // Small Count Reduce+Bcast
    4010              :                 }
    4011              :             }
    4012              :         }
    4013              :     }
    4014            0 :     HCCL_DEBUG(
    4015              :         "[GetAllReduceScratchMemSizeWithoutDev] serverNum[%d], memSize[%llu], rankSize[%d], scratchSize[%llu]",
    4016              :         serverNum, memSize, rankSize, scratchSize);
    4017            0 :     return HCCL_SUCCESS;
    4018            0 : }
    4019              : 
    4020            0 : bool IsNeedCalTaskNum(HcclCMDType opType)
    4021              : {
    4022              :     const std::vector<HcclCMDType> hcomNeedCalTaskNumMap
    4023              :         = {HCCL_CMD_ALLREDUCE, HCCL_CMD_ALLGATHER, HCCL_CMD_REDUCE_SCATTER,
    4024            0 :            HCCL_CMD_ALLTOALL,  HCCL_CMD_ALLTOALLV, HCCL_CMD_ALLTOALLVC};
    4025            0 :     auto it = std::find(hcomNeedCalTaskNumMap.begin(), hcomNeedCalTaskNumMap.end(), opType);
    4026            0 :     return (it != hcomNeedCalTaskNumMap.end()) ? true : false;
    4027            0 : }
    4028              : 
    4029            0 : HcclResult GetDefaultAlgoLevel1(s32 serverNum, AlgTypeLevel1& algType)
    4030              : {
    4031            0 :     u32 num = serverNum;
    4032            0 :     if (num >= HCCL_INTER_SERVER_RING_ALGO_MAX_SUPPORT_SERVER_NUM) {
    4033              :         // server 数为 8 以上:使用 HD 算法
    4034            0 :         algType = AlgTypeLevel1::ALG_LEVEL1_HD;
    4035              :     } else {
    4036              :         // server 数为 2 的非整数次幂:使用 RING 算法
    4037              :         // server 数为 2 的整数次幂:使用 HD 算法
    4038              :         algType
    4039            0 :             = (((num & (num - 1)) != 0) || (num == 1)) ? AlgTypeLevel1::ALG_LEVEL1_RING : AlgTypeLevel1::ALG_LEVEL1_HD;
    4040              :     }
    4041              : 
    4042            0 :     return HCCL_SUCCESS;
    4043              : }
    4044              : 
    4045            0 : HcclResult GetAlgoLevel1(s32 serverNum, std::string& opType, AlgTypeLevel1& algType)
    4046              : {
    4047            0 :     char* mmSysGetEnvValue = nullptr;
    4048            0 :     MM_SYS_GET_ENV(MM_ENV_HCCL_ALGO, mmSysGetEnvValue);
    4049            0 :     std::string hcclAlgo = (mmSysGetEnvValue != nullptr) ? mmSysGetEnvValue : "EmptyString";
    4050            0 :     if (hcclAlgo != "EmptyString") {
    4051              :         // 删除空格
    4052            0 :         std::string rawAlgoConfig = hcclAlgo;
    4053            0 :         rawAlgoConfig.erase(std::remove(rawAlgoConfig.begin(), rawAlgoConfig.end(), ' '), rawAlgoConfig.end());
    4054              : 
    4055            0 :         std::string algoConfig;
    4056            0 :         CHK_RET(SplitHcclOpTypeConfig(rawAlgoConfig, opType, algoConfig));
    4057              : 
    4058              :         // 匹配字段"level1:"
    4059            0 :         std::string level1 = "level1:";
    4060            0 :         std::size_t found = algoConfig.find(level1);
    4061            0 :         if ((found == 0) || (found == (algoConfig.length() - level1.size())) || found == std::string::npos) {
    4062              :             // HCCL_ALGO中"level1:"配置有问题,走默认获取AlgoLevel1方式
    4063            0 :             HCCL_WARNING("Level 1 is not configured.");
    4064            0 :             CHK_RET(GetDefaultAlgoLevel1(serverNum, algType));
    4065              :         } else {
    4066              :             // 截取HCCL_ALGO中"level1:"之后的字段
    4067            0 :             std::string remainAlgoConfig = algoConfig.substr(found + level1.size());
    4068            0 :             std::string level1AlgoConfig = remainAlgoConfig.substr(0, remainAlgoConfig.find(";"));
    4069              : 
    4070              :             const std::map<std::string, AlgTypeLevel1> hcclAlgoLevel1Map = {
    4071            0 :                 {"null", AlgTypeLevel1::ALG_LEVEL1_RESERVED},
    4072            0 :                 {"ring", AlgTypeLevel1::ALG_LEVEL1_WHOLE_RING},
    4073            0 :                 {"pipeline", AlgTypeLevel1::ALG_LEVEL1_PIPELINE},
    4074            0 :                 {"fullmesh", AlgTypeLevel1::ALG_LEVEL1_RESERVED},
    4075            0 :                 {"H-D_R", AlgTypeLevel1::ALG_LEVEL1_HD},
    4076            0 :                 {"pairwise", AlgTypeLevel1::ALG_LEVEL1_RESERVED},
    4077            0 :                 {"NHR", AlgTypeLevel1::ALG_LEVEL1_NHR},
    4078            0 :                 {"NHR_V1", AlgTypeLevel1::ALG_LEVEL1_NHR_V1},
    4079            0 :                 {"AHC", AlgTypeLevel1::ALG_LEVEL1_AHC},
    4080            0 :                 {"AHC_BROKE", AlgTypeLevel1::ALG_LEVEL1_AHC_BROKE},
    4081            0 :                 {"NB", AlgTypeLevel1::ALG_LEVEL1_NB},
    4082            0 :                 {"NA", AlgTypeLevel1::ALG_LEVEL1_RESERVED},
    4083            0 :             };
    4084              : 
    4085            0 :             auto iterAlgoLevel1 = hcclAlgoLevel1Map.find(level1AlgoConfig);
    4086            0 :             if (iterAlgoLevel1 == hcclAlgoLevel1Map.end()) {
    4087            0 :                 HCCL_ERROR(
    4088              :                     "[GetAlgoLevel1] algo config is invalid, level %s is not supported.", level1AlgoConfig.c_str());
    4089            0 :                 return HCCL_E_PARA;
    4090              :             }
    4091              : 
    4092            0 :             algType = iterAlgoLevel1->second;
    4093            0 :             if (algType == AlgTypeLevel1::ALG_LEVEL1_RESERVED) {
    4094            0 :                 CHK_RET(GetDefaultAlgoLevel1(serverNum, algType));
    4095              :             }
    4096            0 :         }
    4097            0 :     } else {
    4098            0 :         CHK_RET(GetDefaultAlgoLevel1(serverNum, algType));
    4099              :     }
    4100              : 
    4101            0 :     HCCL_INFO("[GetAlgoLevel1] level1[%u].", algType);
    4102            0 :     auto iter = HCCL_ALGO_LEVEL1_NAME_MAP.find(algType);
    4103            0 :     CHK_PRT_RET(
    4104              :         iter == HCCL_ALGO_LEVEL1_NAME_MAP.end(), HCCL_ERROR("level1: algType[%u] is invalid.", algType),
    4105              :         HCCL_E_INTERNAL);
    4106            0 :     HCCL_DEBUG(
    4107              :         "hccl algorithm: there are %d server in level1,"
    4108              :         " the algorithm for setting environment variables is %s algo.",
    4109              :         serverNum, iter->second.c_str());
    4110            0 :     return HCCL_SUCCESS;
    4111            0 : }
    4112              : 
    4113              : HcclResult
    4114            0 : SplitHcclOpTypeConfig(const std::string& algoConfig, const std::string& opType, std::string& specificAlgoConfig)
    4115              : {
    4116              :     // 对algoConfig进行/切分
    4117            0 :     std::size_t foundSeparator = algoConfig.find("/");
    4118            0 :     if ((foundSeparator == algoConfig.length() - 1) || (foundSeparator == 0)) {
    4119            0 :         HCCL_ERROR("[HcomOpUtils][SplitHcclOpType]algo config is invalid at split sign.");
    4120            0 :         return HCCL_E_PARA;
    4121            0 :     } else if (foundSeparator == std::string::npos) {
    4122            0 :         specificAlgoConfig = algoConfig;
    4123            0 :         return HCCL_SUCCESS;
    4124              :     }
    4125              : 
    4126            0 :     std::string remainAlgoConfig = algoConfig.substr(foundSeparator + 1);
    4127            0 :     std::string currentConfig = algoConfig.substr(0, foundSeparator);
    4128            0 :     std::size_t foundEqual = currentConfig.find("=");
    4129            0 :     if ((foundEqual == algoConfig.length() - 1) || (foundEqual == 0) || (foundEqual == std::string::npos)) {
    4130            0 :         HCCL_ERROR("[HcomOpUtils][SplitHcclOpType]algo config is invalid at equal sign.");
    4131            0 :         return HCCL_E_PARA;
    4132              :     }
    4133              : 
    4134            0 :     std::string currentOpType = currentConfig.substr(0, foundEqual);
    4135            0 :     if (currentOpType == opType) {
    4136            0 :         specificAlgoConfig = currentConfig;
    4137            0 :         return HCCL_SUCCESS;
    4138              :     }
    4139              : 
    4140            0 :     if (!remainAlgoConfig.empty()) {
    4141            0 :         CHK_RET(SplitHcclOpTypeConfig(remainAlgoConfig, opType, specificAlgoConfig));
    4142              :     }
    4143            0 :     return HCCL_SUCCESS;
    4144            0 : }
    4145              : 
    4146            0 : HcclResult GetDefaultAlgoLevel0Module(s32 deviceNumPerServer, AlgTypeLevel0& algType, std::string soc_version)
    4147              : {
    4148            0 :     if (soc_version == "Ascend910B") {
    4149            0 :         algType = AlgTypeLevel0::ALG_LEVEL0_8P_RING;
    4150            0 :     } else if (deviceNumPerServer == TASK_NUM_DEVICE_FOUR) {
    4151            0 :         algType = AlgTypeLevel0::ALG_LEVEL0_4P_MESH;
    4152              :     } else {
    4153            0 :         algType = AlgTypeLevel0::ALG_LEVEL0_NP_SINGLE_RING;
    4154              :     }
    4155            0 :     auto iter = HCCL_ALGO_LEVEL0_NAME_MAP.find(algType);
    4156            0 :     CHK_PRT_RET(
    4157              :         iter == HCCL_ALGO_LEVEL0_NAME_MAP.end(), HCCL_ERROR("level0: algType[%u] is invalid.", algType),
    4158              :         HCCL_E_INTERNAL);
    4159            0 :     HCCL_DEBUG(
    4160              :         "hccl algorithm: [Module(aiserver)] there are %d device in level0, using %s algo.", deviceNumPerServer,
    4161              :         iter->second.c_str());
    4162            0 :     return HCCL_SUCCESS;
    4163              : }
    4164              : 
    4165              : HcclResult
    4166            0 : GetAlgType(s32 deviceNumPerServer, s32 serverNum, std::string opType, std::string socVersionStr, AlgType& algType)
    4167              : {
    4168              :     AlgTypeLevel0 algType0;
    4169              :     AlgTypeLevel1 algType1;
    4170              : 
    4171              :     // 因为非标卡计算出来的task num比标卡场景多,因此task num精确评估暂不区分标卡和非标卡
    4172            0 :     CHK_RET(GetDefaultAlgoLevel0Module(deviceNumPerServer, algType0, socVersionStr));
    4173            0 :     CHK_RET(GetAlgoLevel1(serverNum, opType, algType1));
    4174            0 :     algType.algoLevel0 = algType0;
    4175            0 :     algType.algoLevel1 = algType1;
    4176            0 :     HCCL_INFO("average device count [%d], algorithm type [%u] is selected.", deviceNumPerServer, algType.algoLevel0);
    4177            0 :     return HCCL_SUCCESS;
    4178              : }
    4179              : 
    4180            0 : HcclResult GetDfxTaskNum(const std::string& sCollectiveType, u32& taskNum)
    4181              : {
    4182            0 :     if (sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLREDUCE) {
    4183            0 :         taskNum += DFX_PADDING_TASK_NUM;
    4184              :     }
    4185            0 :     taskNum += DFX_DEFAULT_TASK_NUM;
    4186            0 :     HCCL_DEBUG("[GetDfxTaskNum] cur task num[%u].", taskNum);
    4187            0 :     return HCCL_SUCCESS;
    4188              : }
    4189              : 
    4190            0 : HcclResult GetToSlaveStreamTaskNum(const std::string& sCollectiveType, u64 streamNum, u64 piplineSliceNum, u32& taskNum)
    4191              : {
    4192            0 :     u32 taskNumTmp = 0;
    4193            0 :     if (sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLREDUCE) {
    4194            0 :         taskNumTmp = streamNum * MASTER_STREAM_EVENT_NUM * COM_STEP_NUM;
    4195              :     } else {
    4196            0 :         taskNumTmp = streamNum * MASTER_STREAM_EVENT_NUM;
    4197              :     }
    4198            0 :     if (piplineSliceNum >= MIN_PIPLINE_SLICE_NUM) {
    4199            0 :         taskNumTmp += piplineSliceNum * PIPLINE_STREAM_EVENT_NUM * COM_STEP_NUM;
    4200              :     }
    4201            0 :     taskNum += taskNumTmp;
    4202            0 :     HCCL_DEBUG("[GetToSlaveStreamTaskNum] cur task num[%u].", taskNum);
    4203            0 :     return HCCL_SUCCESS;
    4204              : }
    4205              : 
    4206            0 : HcclResult GetToMasterStreamTaskNum(const std::string& sCollectiveType, u32& taskNum)
    4207              : {
    4208            0 :     if (sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLREDUCE) {
    4209            0 :         taskNum += (SLAVE_STREAM_EVENT_NUM * COM_STEP_NUM);
    4210              :     } else {
    4211            0 :         taskNum += SLAVE_STREAM_EVENT_NUM;
    4212              :     }
    4213            0 :     HCCL_DEBUG("[GetToMasterStreamTaskNum] cur task num[%u].", taskNum);
    4214            0 :     return HCCL_SUCCESS;
    4215              : }
    4216              : 
    4217            0 : HcclResult GetCombineComTaskNum(
    4218              :     const std::string& sCollectiveType, s32 serverNum, s32 deviceNumPerServer, u32& intraTaskNum, u32& interTaskNum)
    4219              : {
    4220              :     // 打平拓扑server内通信task数量为0
    4221            0 :     intraTaskNum = 0;
    4222              : 
    4223            0 :     interTaskNum = 0;
    4224            0 :     u32 commStep = deviceNumPerServer * serverNum - 1; // 默认根据ring算法评估
    4225              : 
    4226              :     // 计算通信task的数量
    4227            0 :     if (sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLREDUCE) {
    4228            0 :         interTaskNum = ALLREDUCE_DEFAULT_COM_STEP * commStep;
    4229            0 :     } else if (sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLGATHER) {
    4230            0 :         interTaskNum = ALLGATHER_DEFAULT_COM_STEP * commStep;
    4231            0 :     } else if (sCollectiveType == HCCL_KERNEL_OP_TYPE_REDUCESCATTER) {
    4232            0 :         interTaskNum = REDUCESCATTER_DEFAULT_COM_STEP * commStep;
    4233            0 :     } else if (
    4234            0 :         sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLTOALL || sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLTOALLV
    4235            0 :         || sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLTOALLVC) {
    4236            0 :         interTaskNum = ALLTOALL_DEFAULT_COM_STEP * commStep;
    4237              :     } else {
    4238            0 :         HCCL_ERROR(
    4239              :             "[HcomOpUtils][GetCombineComTaskNum]The current operator [%s] do not support tasknum "
    4240              :             "accurate evaluation.",
    4241              :             sCollectiveType.c_str());
    4242            0 :         return HCCL_E_NOT_SUPPORT;
    4243              :     }
    4244              : 
    4245            0 :     HCCL_INFO(
    4246              :         "[HcomOpUtils][GetCombineComTaskNum]op[%s], cur intraTaskNum is[%u], interTaskNum is[%u], commStep[%u].",
    4247              :         sCollectiveType.c_str(), intraTaskNum, interTaskNum, commStep);
    4248            0 :     return HCCL_SUCCESS;
    4249              : }
    4250              : 
    4251            0 : HcclResult GetIntraComTaskNum(
    4252              :     const std::string& sCollectiveType, s32 deviceNumPerServer, [[maybe_unused]] u64 streamNum, const AlgType& algType,
    4253              :     u32& taskNum, u64 totalSize)
    4254              : {
    4255            0 :     taskNum = 0;
    4256            0 :     u32 commStep = 0;
    4257            0 :     u32 commStepDeter = 0;
    4258              : 
    4259              :     // 获取通信步骤
    4260            0 :     if (algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_8P_RING) {
    4261            0 :         commStep += ALG_8P_RING_COMM_STEP;
    4262            0 :         commStepDeter = commStep;
    4263            0 :     } else if (algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_NP_DOUBLE_RING) {
    4264            0 :         commStep += (deviceNumPerServer - 1);
    4265            0 :         commStepDeter = commStep;
    4266            0 :     } else if (algType.algoLevel0 == AlgTypeLevel0::ALG_LEVEL0_4P_MESH || deviceNumPerServer > TASK_NUM_DEVICE_ONE) {
    4267              :         // 涉及确定性计算的通信步骤单独计算
    4268            0 :         if (totalSize <= HCCL_SMALL_COUNT_GRAPH_64_KB) {
    4269            0 :             commStepDeter += (deviceNumPerServer - 1);
    4270              :         } else {
    4271              :             commStepDeter
    4272            0 :                 += (GetExternalInputHcclDeterministicV2() != DETERMINISTIC_DISABLE ?
    4273            0 :                         ((deviceNumPerServer - 1) * (deviceNumPerServer - 1)) :
    4274              :                         (deviceNumPerServer - 1));
    4275              :         }
    4276            0 :         commStep += (deviceNumPerServer - 1);
    4277              :     }
    4278              :     // 计算通信task的数量
    4279            0 :     if (sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLREDUCE) {
    4280            0 :         taskNum = REDUCESCATTER_DEFAULT_COM_STEP * commStepDeter + ALLGATHER_DEFAULT_COM_STEP * commStep;
    4281            0 :     } else if (sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLGATHER) {
    4282            0 :         taskNum = ALLGATHER_DEFAULT_COM_STEP * commStep;
    4283            0 :     } else if (sCollectiveType == HCCL_KERNEL_OP_TYPE_REDUCESCATTER) {
    4284            0 :         taskNum = REDUCESCATTER_DEFAULT_COM_STEP * commStepDeter;
    4285            0 :     } else if (
    4286            0 :         sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLTOALL || sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLTOALLV
    4287            0 :         || sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLTOALLVC) {
    4288            0 :         commStep = deviceNumPerServer - 1; // 按照pairwise计算server内通信步数
    4289            0 :         taskNum = ALLTOALL_DEFAULT_COM_STEP * commStep;
    4290              :     } else {
    4291            0 :         HCCL_ERROR("The current operator is not supported tasknum accurate evaluation.");
    4292            0 :         return HCCL_E_NOT_SUPPORT;
    4293              :     }
    4294            0 :     HCCL_INFO(
    4295              :         "[GetIntraComTaskNum] op[%s], cur tasknum is[%u], commStep[%u], totalSize[%llu]", sCollectiveType.c_str(),
    4296              :         taskNum, commStep, totalSize);
    4297            0 :     return HCCL_SUCCESS;
    4298              : }
    4299              : 
    4300            0 : HcclResult GetBetweenServersStep(s32 serverNum, u32& commStep)
    4301              : {
    4302            0 :     if ((serverNum & (serverNum - 1)) == 0) {
    4303              :         // 如果serverNum是2的整数次幂,使用HD算法评估CollectiveOp的taskNum
    4304            0 :         commStep += SalLog2(serverNum);
    4305            0 :     } else if (serverNum < SERVER_NUM_EIGHT) {
    4306              :         // 如果serverNum是2的非整数次幂并且小于8,使用ring算法评估CollectiveOp的taskNum
    4307            0 :         commStep += (serverNum - 1);
    4308              :     } else {
    4309              :         // 计算大于serverNum的最大2的整数次幂的值;以N为rankSize, 使用HD算法评估CollectiveOp的taskNum
    4310            0 :         s32 bit = 0;
    4311            0 :         while (serverNum > 0) {
    4312            0 :             serverNum >>= 1;
    4313            0 :             bit++;
    4314              :         }
    4315            0 :         commStep += bit;
    4316              :     }
    4317            0 :     HCCL_DEBUG("Get BetweenServers Step [%u]", commStep);
    4318            0 :     return HCCL_SUCCESS;
    4319              : }
    4320              : 
    4321            0 : HcclResult GetInterComTaskNum(
    4322              :     const std::string& sCollectiveType, s32 serverNum, s32 deviceNumPerServer, DevType devType, u32& taskNum,
    4323              :     const std::string& group)
    4324              : {
    4325            0 :     taskNum = 0;
    4326            0 :     u32 commStep = 0;
    4327              : 
    4328              :     // 获取server间通信步骤
    4329            0 :     if (serverNum > SERVER_NUM_ONE) {
    4330            0 :         CHK_RET(GetBetweenServersStep(serverNum, commStep)); // 默认情况下根据serverNum按ring或HD算法评估
    4331              :         // 计算通信task的数量
    4332            0 :         if (sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLREDUCE) {
    4333            0 :             taskNum = ALLREDUCE_DEFAULT_COM_STEP * commStep;
    4334            0 :         } else if (sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLGATHER) {
    4335            0 :             taskNum = ALLGATHER_DEFAULT_COM_STEP * commStep;
    4336            0 :         } else if (sCollectiveType == HCCL_KERNEL_OP_TYPE_REDUCESCATTER) {
    4337            0 :             taskNum = REDUCESCATTER_DEFAULT_COM_STEP * commStep;
    4338            0 :         } else if (
    4339            0 :             sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLTOALL || sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLTOALLV
    4340            0 :             || sCollectiveType == HCCL_KERNEL_OP_TYPE_ALLTOALLVC) {
    4341            0 :             std::vector<HcclAlgoType> algoTypeArr = CommConfiger::GetInstance().GetCommConfigAlgoConfig(group);
    4342              :             bool useOneLevelAlgorithm
    4343            0 :                 = (algoTypeArr[0] == HcclAlgoType::HCCL_ALGO_TYPE_NA
    4344            0 :                    && algoTypeArr[1] == HcclAlgoType::HCCL_ALGO_TYPE_PAIRWISE);
    4345            0 :             s32 meshNum = (devType == DevType::DEV_TYPE_910) ? serverNum * 2 : serverNum;
    4346            0 :             commStep = useOneLevelAlgorithm ? ((meshNum - 1) * deviceNumPerServer) : (meshNum - 1);
    4347            0 :             taskNum = ALLTOALL_DEFAULT_COM_STEP * commStep;
    4348            0 :         } else {
    4349            0 :             HCCL_ERROR("The current operator is not supported tasknum accurate evaluation.");
    4350            0 :             return HCCL_E_NOT_SUPPORT;
    4351              :         }
    4352              :     }
    4353            0 :     HCCL_INFO(
    4354              :         "[GetInterComTaskNum]op[%s], cur tasknum is[%u], commStep[%u].", sCollectiveType.c_str(), taskNum, commStep);
    4355            0 :     return HCCL_SUCCESS;
    4356              : }
    4357              : 
    4358            0 : HcclResult CalcTaskNum(
    4359              :     HcomOpParam* hcomOpParam, const u64& streamNum, const s32& deviceNumPerServer, const s32& serverNum,
    4360              :     bool multiModuleDiffDeviceNumMode, u32& taskNum, DevType devType)
    4361              : {
    4362            0 :     u32 masterTaskNum = 0;
    4363            0 :     u32 slaveTaskNum = 0;
    4364            0 :     u32 piplineTaskNum = 0;
    4365              : 
    4366            0 :     std::string sCollectiveType(hcomOpParam->opType);
    4367              : 
    4368              :     HcclResult ret;
    4369            0 :     HcclUs startut = TIME_NOW();
    4370              : 
    4371            0 :     auto iter = HCCL_OPTYPE_NAME_MAP.find(hcomOpParam->opType);
    4372            0 :     HcclCMDType hcclOpType = (iter != HCCL_OPTYPE_NAME_MAP.end()) ? iter->second : HcclCMDType::HCCL_CMD_INVALID;
    4373              : 
    4374            0 :     string algName;
    4375            0 :     bool ifAiv = false;
    4376            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    4377              :     // 获取通信域句柄
    4378            0 :     std::string group = hcomOpParam->group == nullptr ? HCCL_WORLD_GROUP : hcomOpParam->group;
    4379            0 :     CHK_RET(HcomGetCommByGroup(group.c_str(), hcclComm));
    4380              :     // 判断是否是AIV场景
    4381            0 :     void* counts = nullptr;
    4382            0 :     ret = hcclComm->HcclSelectAlg(
    4383            0 :         hcclOpType, hcomOpParam->count, counts, hcomOpParam->dataType, hcomOpParam->reduceOp, hcomOpParam->aivCoreLimit,
    4384              :         ifAiv, algName);
    4385            0 :     CHK_PRT_RET(
    4386              :         ret != HCCL_SUCCESS,
    4387              :         HCCL_ERROR(
    4388              :             "[HcomGetWorkspaceSubStreamNum] HcclSelectAlg failed, ret[%d], optype[%d], count[%llu],"
    4389              :             "dataType[%d], reduceOp[%d]",
    4390              :             ret, hcomOpParam->opType, hcomOpParam->count, hcomOpParam->dataType, hcomOpParam->reduceOp),
    4391              :         ret);
    4392            0 :     HCCL_INFO(
    4393              :         "[%s] HcclSelectAlg success ifAiv[%d] algName[%s] optype[%d] count[%llu] dataType[%d] reduceOp[%d]", __func__,
    4394              :         ifAiv, algName.c_str(), hcomOpParam->opType, hcomOpParam->count, hcomOpParam->dataType, hcomOpParam->reduceOp);
    4395              :     // AIV和非rdma场景下,task数量固定
    4396            0 :     if (ifAiv && algName.find("Rdma") == std::string::npos) {
    4397            0 :         taskNum = AIV_DEFAULT_TASK_NUM;
    4398            0 :         HCCL_INFO("[%s] GetAndSetTaskNum success taskNum[%u]", __func__, taskNum);
    4399            0 :         return HCCL_SUCCESS;
    4400              :     }
    4401              : 
    4402            0 :     if (!IsNeedCalTaskNum(hcclOpType)) {
    4403            0 :         if (hcclOpType == HCCL_CMD_SEND || hcclOpType == HCCL_CMD_RECEIVE) {
    4404            0 :             taskNum = SEND_RECEIVE_TASK_NUM;
    4405              :         } else {
    4406            0 :             taskNum = OP_DEFAULT_TASK_NUM;
    4407              :         }
    4408              :     } else {
    4409            0 :         AlgType algType;
    4410            0 :         std::string socVersionStr(hcomOpParam->socVersion);
    4411              : 
    4412              :         // 获取通信算法
    4413            0 :         CHK_RET(GetAlgType(deviceNumPerServer, serverNum, hcomOpParam->opType, socVersionStr, algType));
    4414              : 
    4415              :         // 如果在线编译没有获取到ranktable file,则返回默认task数量
    4416            0 :         if ((deviceNumPerServer == 0) && (serverNum == 0)) {
    4417            0 :             taskNum = OP_DEFAULT_TASK_NUM;
    4418              :         } else {
    4419              :             // 计算Server间pipline切分数量
    4420              :             u32 dataTypeSize;
    4421            0 :             u64 totalSize = 0;
    4422            0 :             ret = SalGetDataTypeSize(hcomOpParam->dataType, dataTypeSize);
    4423            0 :             CHK_PRT_RET(
    4424              :                 ret != HCCL_SUCCESS,
    4425              :                 HCCL_ERROR(
    4426              :                     "[Get][OpWorkspaceMemSize]op[%s]: get data size failed. ret[%d]", sCollectiveType.c_str(), ret),
    4427              :                 ret);
    4428              : 
    4429            0 :             totalSize = hcomOpParam->count * dataTypeSize;
    4430              : 
    4431              :             u64 piplineSliceNum
    4432            0 :                 = CalculatePiplineSliceNum(hcclOpType, totalSize, algType, devType, deviceNumPerServer, serverNum);
    4433              : 
    4434              :             // 计算DFX校验task数量
    4435            0 :             CHK_RET(GetDfxTaskNum(sCollectiveType, masterTaskNum));
    4436              :             // 计算与从stream同步task数量
    4437            0 :             CHK_RET(GetToSlaveStreamTaskNum(sCollectiveType, streamNum, piplineSliceNum, masterTaskNum));
    4438              :             // 计算与主stream同步task数量
    4439            0 :             CHK_RET(GetToMasterStreamTaskNum(sCollectiveType, slaveTaskNum));
    4440              :             // 计算Server间Pipline从stream和主stream同步的task数量
    4441            0 :             piplineTaskNum += (piplineSliceNum >= MIN_PIPLINE_SLICE_NUM) ?
    4442              :                                   piplineSliceNum * PIPLINE_STREAM_EVENT_NUM * COM_STEP_NUM :
    4443              :                                   0;
    4444              : 
    4445            0 :             u32 intraTaskNum = 0;
    4446            0 :             u32 interTaskNum = 0;
    4447              :             // 获取Server内通信task数量
    4448              : 
    4449            0 :             if (multiModuleDiffDeviceNumMode) {
    4450              :                 // 获取打平拓扑通信task数量
    4451            0 :                 CHK_RET(
    4452              :                     GetCombineComTaskNum(sCollectiveType, serverNum, deviceNumPerServer, intraTaskNum, interTaskNum));
    4453              :             } else {
    4454            0 :                 CHK_RET(GetIntraComTaskNum(
    4455              :                     sCollectiveType, deviceNumPerServer, streamNum, algType, intraTaskNum, totalSize));
    4456              :                 // 获取Server间通信task数量, 从stream没有server间task
    4457            0 :                 std::string group = hcomOpParam->group == nullptr ? HCCL_WORLD_GROUP : hcomOpParam->group;
    4458            0 :                 CHK_RET(
    4459              :                     GetInterComTaskNum(sCollectiveType, serverNum, deviceNumPerServer, devType, interTaskNum, group));
    4460            0 :             }
    4461              : 
    4462              :             // 计算通信task
    4463            0 :             if (piplineSliceNum >= MIN_PIPLINE_SLICE_NUM) {
    4464            0 :                 masterTaskNum += intraTaskNum * piplineSliceNum;
    4465            0 :                 slaveTaskNum += intraTaskNum * piplineSliceNum;
    4466            0 :                 piplineTaskNum += interTaskNum * piplineSliceNum;
    4467              :             } else {
    4468            0 :                 masterTaskNum += intraTaskNum + interTaskNum;
    4469            0 :                 slaveTaskNum += intraTaskNum;
    4470              :             }
    4471              :         }
    4472            0 :     }
    4473            0 :     if (taskNum == 0) {
    4474            0 :         taskNum = std::max(masterTaskNum, std::max(slaveTaskNum, piplineTaskNum));
    4475              :     }
    4476              : 
    4477            0 :     HCCL_INFO("GetAndSetTaskNum success, cost time[%lld]us taskNum[%u]", DURATION_US(TIME_NOW() - startut), taskNum);
    4478            0 :     return HCCL_SUCCESS;
    4479            0 : }
    4480              : 
    4481            0 : HcclResult CalcTaskNumV2(HcomOpParam* hcomOpParam, u32& taskNum)
    4482              : {
    4483            0 :     HcclUs startut = TIME_NOW();
    4484              : 
    4485            0 :     auto iter = HCCL_OPTYPE_NAME_MAP.find(hcomOpParam->opType);
    4486            0 :     HcclCMDType hcclOpType = (iter != HCCL_OPTYPE_NAME_MAP.end()) ? iter->second : HcclCMDType::HCCL_CMD_INVALID;
    4487              : 
    4488            0 :     if (!IsNeedCalTaskNum(hcclOpType)) {
    4489            0 :         if (hcclOpType == HCCL_CMD_SEND || hcclOpType == HCCL_CMD_RECEIVE) {
    4490            0 :             taskNum = SEND_RECEIVE_TASK_NUM;
    4491              :         } else {
    4492            0 :             taskNum = OP_DEFAULT_TASK_NUM;
    4493              :         }
    4494              :     } else {
    4495            0 :         CHK_RET(HcomCalcTaskNum(hcomOpParam, taskNum));
    4496              :     }
    4497              : 
    4498            0 :     HCCL_INFO("GetAndSetTaskNum success, cost time[%lld]us taskNum[%u]", DURATION_US(TIME_NOW() - startut), taskNum);
    4499            0 :     return HCCL_SUCCESS;
    4500              : }
    4501              : 
    4502            0 : HcclResult HcomGetMemType(
    4503              :     const char* group, const char* socVersion, bool isMalloc, u32* memType, bool* isTsMem, bool withoutImplCompile,
    4504              :     bool level2Address)
    4505              : {
    4506            0 :     DevType devType = DevType::DEV_TYPE_COUNT;
    4507            0 :     std::string socVersionStr(socVersion);
    4508            0 :     const u32 NUM_SIZE_TWO = 2;
    4509              : 
    4510            0 :     CHK_RET(hrtGetDeviceTypeBySocVersion(socVersionStr, devType));
    4511              : 
    4512            0 :     if (isMalloc) {
    4513            0 :         if (Is310PDevice()) {
    4514            0 :             if (devType == DevType::DEV_TYPE_310P3 || devType == DevType::DEV_TYPE_310P1) {
    4515            0 :                 if (level2Address) { // 310P二级地址刷新时申请内存类型为:RT_MEMORY_TS
    4516            0 :                     *isTsMem = true;
    4517            0 :                     *memType = static_cast<int>(ACL_MEM_TYPE_LOW_BAND_WIDTH);
    4518              :                 } else {
    4519            0 :                     *memType = static_cast<int>(ACL_MEM_TYPE_LOW_BAND_WIDTH);
    4520              :                 }
    4521              :             } else {
    4522            0 :                 *memType = static_cast<int>(ACL_MEM_TYPE_HIGH_BAND_WIDTH);
    4523              :             }
    4524              :         } else {
    4525            0 :             if (devType == DevType::DEV_TYPE_310P3) {
    4526            0 :                 if (level2Address) { // 310P二级地址刷新时申请内存类型为:RT_MEMORY_TS
    4527            0 :                     *isTsMem = true;
    4528            0 :                     *memType = static_cast<int>(ACL_MEM_TYPE_LOW_BAND_WIDTH)
    4529              :                                | static_cast<int>(ACL_MEM_MALLOC_NORMAL_ONLY_P2P);
    4530              :                 } else {
    4531            0 :                     *memType = static_cast<int>(ACL_MEM_TYPE_LOW_BAND_WIDTH)
    4532              :                                | static_cast<int>(ACL_MEM_MALLOC_NORMAL_ONLY_P2P);
    4533              :                 }
    4534            0 :             } else if (devType == DevType::DEV_TYPE_310P1) {
    4535            0 :                 *memType = static_cast<int>(ACL_MEM_TYPE_LOW_BAND_WIDTH);
    4536              :             } else {
    4537              :                 *memType
    4538            0 :                     = static_cast<int>(ACL_MEM_TYPE_HIGH_BAND_WIDTH) | static_cast<int>(ACL_MEM_MALLOC_NORMAL_ONLY_P2P);
    4539              :             }
    4540              :         }
    4541            0 :         return HCCL_SUCCESS;
    4542              :     }
    4543              : 
    4544            0 :     if (devType == DevType::DEV_TYPE_310P3 || devType == DevType::DEV_TYPE_310P1) {
    4545            0 :         u32 numHccsLink = 0;
    4546            0 :         u32 rankSize = 0;
    4547            0 :         if (!withoutImplCompile) {
    4548            0 :             CHK_RET(HcomGetRankSize(group, &rankSize));
    4549            0 :             CHK_RET(HcomGetHccsLinkNum(group, &numHccsLink));
    4550              :         }
    4551            0 :         if ((withoutImplCompile || !(rankSize == NUM_SIZE_TWO && numHccsLink == NUM_SIZE_TWO))) {
    4552              :             // 所有形态切换子包后,改用acl_mem类型
    4553            0 :             *memType = RT_MEMORY_P2P_DDR;
    4554              :         }
    4555              :     }
    4556              : 
    4557            0 :     return HCCL_SUCCESS;
    4558            0 : }
    4559              : 
    4560            0 : HcclResult GetDeterministic(DevType devType, u8 geDetOption, u8& deterministic)
    4561              : {
    4562            0 :     deterministic = DETERMINISTIC_DISABLE; // 默认为不支持
    4563              : 
    4564            0 :     char* mmSysGetEnvValue = nullptr;
    4565            0 :     MM_SYS_GET_ENV(MM_ENV_HCCL_DETERMINISTIC, mmSysGetEnvValue);
    4566            0 :     std::string hcclDeterministicEnv = (mmSysGetEnvValue != nullptr) ? mmSysGetEnvValue : "EmptyString";
    4567            0 :     if (hcclDeterministicEnv != "EmptyString") {
    4568              :         // 环境变量优先
    4569            0 :         std::transform(
    4570              :             hcclDeterministicEnv.begin(), hcclDeterministicEnv.end(), hcclDeterministicEnv.begin(), ::toupper);
    4571            0 :         if (hcclDeterministicEnv == "FALSE") {
    4572            0 :             deterministic = DETERMINISTIC_DISABLE;
    4573            0 :         } else if (hcclDeterministicEnv == "TRUE") {
    4574            0 :             deterministic = DETERMINISTIC_ENABLE;
    4575            0 :         } else if (hcclDeterministicEnv == "STRICT") {
    4576            0 :             CHK_PRT_RET(
    4577              :                 devType != DevType::DEV_TYPE_910B && devType != DevType::DEV_TYPE_910_93,
    4578              :                 HCCL_ERROR(
    4579              :                     "ParserHcclDeterministic: reduce order preservation is not supported for devType[%d]", devType),
    4580              :                 HCCL_E_NOT_SUPPORT);
    4581            0 :             deterministic = DETERMINISTIC_STRICT;
    4582              :         } else {
    4583            0 :             HCCL_ERROR(
    4584              :                 "[GetDeterministic] HCCL_DETERMINISTIC is set to [%s], which is incorrect. Please check",
    4585              :                 hcclDeterministicEnv.c_str());
    4586            0 :             return HCCL_E_PARA;
    4587              :         }
    4588              :     } else {
    4589              :         // 未配环境变量,检查ge option
    4590            0 :         if (geDetOption == 1) {
    4591            0 :             deterministic = DETERMINISTIC_ENABLE;
    4592            0 :         } else if (geDetOption == 2) {
    4593            0 :             CHK_PRT_RET(
    4594              :                 devType != DevType::DEV_TYPE_910B && devType != DevType::DEV_TYPE_910_93,
    4595              :                 HCCL_ERROR(
    4596              :                     "ParserHcclDeterministic: reduce order preservation is not supported for devType[%d]", devType),
    4597              :                 HCCL_E_NOT_SUPPORT);
    4598            0 :             deterministic = DETERMINISTIC_STRICT;
    4599              :         }
    4600              :     }
    4601              : 
    4602            0 :     return HCCL_SUCCESS;
    4603            0 : }
    4604              : 
    4605            0 : HcclResult HcomGenerateCclOpTag(const char* opType, s64 hcomComm, const char* group, char* sTag)
    4606              : {
    4607            0 :     CHK_PTR_NULL(group);
    4608            0 :     std::string groupName(group);
    4609            0 :     std::string tag;
    4610            0 :     GenerateCclOpTag(opType, hcomComm, groupName, tag);
    4611            0 :     int32_t sret = memcpy_s(sTag, CCL_OP_TAG_MAX_LEN, tag.c_str(), (tag.length() + 1));
    4612            0 :     CHK_PRT_RET(
    4613              :         sret != EOK,
    4614              :         HCCL_ERROR(
    4615              :             "[HcomGenerateCclOpTag][Tag]memcpy failed. ret[%d],"
    4616              :             "params:destMaxSize[%zu],count[%zu]",
    4617              :             sret, CCL_OP_TAG_MAX_LEN, (tag.length() + 1)),
    4618              :         HCCL_E_PARA);
    4619            0 :     return HCCL_SUCCESS;
    4620            0 : }
    4621              : 
    4622            0 : void HcomSetDumpDebugMode(const bool dumpDebug) { SetDumpDebugMode(dumpDebug); }
    4623              : 
    4624            0 : void HcomSetLaunchKernelMode(bool state) { SetLaunchKernelMode(state); }
    4625              : 
    4626              : HcclResult
    4627            0 : HcomTbeMemClean(int64_t addrList[], int64_t sizeList[], uint32_t count, aclrtStream stream, int32_t deviceLogicId)
    4628              : {
    4629            0 :     CHK_RET(HcclTbeMemClean(addrList, sizeList, count, stream, deviceLogicId));
    4630            0 :     return HCCL_SUCCESS;
    4631              : }
        

Generated by: LCOV version 2.0-1