LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/op_base/src - op_base.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 54.4 % 2977 1620
Test Date: 2026-08-04 10:52:23 Functions: 44.9 % 147 66

            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 "op_base.h"
      12              : #include <algorithm>
      13              : #include <future>
      14              : #include <map>
      15              : #include <string>
      16              : #include <hccl/hccl_types.h>
      17              : 
      18              : #include "hccl/base.h"
      19              : #include "param_check_pub.h"
      20              : #include "rank_consistentcy_checker.h"
      21              : #include "externalinput_pub.h"
      22              : #include "env_config.h"
      23              : #include "../common/src/topo/topoinfo_detect.h"
      24              : #include "../common/src/topo/topoinfo_ranktable_partition.h"
      25              : #include "../common/src/state_guard.h"
      26              : #include "sal_pub.h"
      27              : #include "profiling_manager_pub.h"
      28              : #include "adapter_prof.h"
      29              : #include "adapter_rts_common.h"
      30              : #include "device_capacity.h"
      31              : #include "mem_host_pub.h"
      32              : #include "hcom_common.h"
      33              : #include "comm_config_pub.h"
      34              : #include "kernel_tiling/kernel_tiling.h"
      35              : #include "mmpa_api.h"
      36              : #include "aicpu_operator_pub.h"
      37              : #include "../nslbdp/hccl_nslbdp.h"
      38              : #include "hccl_group.h"
      39              : #include "hostdpu/dpu_kernel_entrance.h"
      40              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
      41              : #include "hcomm_c_adpt.h"
      42              : #endif
      43              : 
      44              : #define DOUBLE_SIZE 2
      45              : 
      46              : using namespace std;
      47              : using namespace hccl;
      48              : 
      49              : typedef int32_t Callback(uint64_t, int32_t);
      50              : 
      51              : const std::string HCCL_ALLTOALL = "ALLTOALL";
      52              : const std::string HCCL_ALLTOALLV = "ALLTOALLV";
      53              : const std::string HCCL_ALLTOALLVC = "ALLTOALLVC";
      54              : 
      55          302 : HcclResult CallMsprofReportHostApi(hccl::hcclComm* hcclComm, HcclCMDType cmdType, uint64_t beginTime, u64 count,
      56              :     HcclDataType dataType, const std::string &tag)
      57              : {
      58          302 :     if (GetIfProfile()) {
      59           13 :         AlgType algType;
      60           13 :         if(cmdType == HcclCMDType::HCCL_CMD_BATCH_SEND_RECV){
      61            1 :             algType.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_PAIRWISE;
      62            1 :             algType.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_RESERVED;
      63           12 :         } else if (cmdType == HcclCMDType::HCCL_CMD_SEND || cmdType == HcclCMDType::HCCL_CMD_RECEIVE){
      64            2 :             algType.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_RESERVED;
      65            2 :             algType.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_RESERVED;
      66              :         } else {
      67           10 :             CHK_RET(hcclComm->GetAlgType(algType, cmdType));
      68              :         }
      69              : 
      70           13 :         u32 numBlocks = 0;
      71           13 :         hcclComm->GetNumBlocks(numBlocks);
      72           13 :         uint64_t groupName = hrtMsprofGetHashId(hcclComm->GetIdentifier().c_str(), hcclComm->GetIdentifier().length());    
      73           13 :         HCCL_INFO("[%s] groupName[%llu], groupNameStr[%s]", __func__, groupName, hcclComm->GetIdentifier().c_str());
      74           13 :         CHK_RET_AND_PRINT_IDE(ProfilingManagerPub::CallMsprofReportHostApi(cmdType, beginTime, count, dataType, algType,
      75              :             groupName, numBlocks), tag.c_str());
      76              :     }
      77          302 :     hcclComm->SetAivCoreLimit(0);
      78          302 :     return HCCL_SUCCESS;
      79              : }
      80              : 
      81              : thread_local s32 g_hcclDeviceId = INVALID_INT;
      82              : std::mutex g_opHcomInfosMutex{};
      83              : std::mutex g_opHcomOneSideMutex{};
      84              : 
      85          999 : HcclOpInfoCtx &GetOpHcomInfo(uint32_t devId)
      86              : {
      87          999 :     if (devId >= MAX_MODULE_DEVICE_NUM + 1) {
      88            0 :         devId = MAX_MODULE_DEVICE_NUM;
      89              :     }
      90              : 
      91              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
      92              :     // 临时方案:声明comm各类基础单例
      93              :     // 仅触发空对象声明,不执行业务动作,故不会失败
      94          999 :     (void)HcommResMgrInit(devId);
      95              : #endif
      96              : 
      97         1395 :     static HcclOpInfoCtx g_opHcomInfos[MAX_MODULE_DEVICE_NUM + 1];
      98          999 :     return g_opHcomInfos[devId];
      99              : }
     100              : 
     101              : 
     102         1134 : HcclResult HcclGetDeviceId(void)
     103              : {
     104         1134 :     if (g_hcclDeviceId == INVALID_INT) {
     105            0 :         CHK_PRT_RET(hrtGetDevice(&g_hcclDeviceId) != HCCL_SUCCESS,
     106              :             HCCL_WARNING("[HcclGetDeviceId] get fail deviceLogicId[%d]", g_hcclDeviceId), HCCL_E_INTERNAL);
     107              :     }
     108              :     u32 maxDeviceNum;
     109         1134 :     CHK_RET(GetMaxDevNum(maxDeviceNum));
     110         1134 :     CHK_PRT_RET(static_cast<u32>(g_hcclDeviceId) >= maxDeviceNum,
     111              :         HCCL_WARNING("[HcclGetDeviceId]deviceLogicId[%d] is bigger than maxDeviceNum:[%u]",
     112              :         g_hcclDeviceId, maxDeviceNum), HCCL_E_INTERNAL);
     113         1134 :     HCCL_INFO("[HcclGetDeviceId] deviceLogicId[%d] ", g_hcclDeviceId);
     114         1134 :     return HCCL_SUCCESS;
     115              : }
     116              : 
     117          145 : s32 HcclGetThreadDeviceId()
     118              : {
     119          145 :     CHK_PRT_RET(HcclGetDeviceId() != HCCL_SUCCESS, HCCL_WARNING("[HcclGetThreadDeviceId] get fail deviceLogicId[%d]",
     120              :         g_hcclDeviceId), INVALID_INT);
     121          145 :     return g_hcclDeviceId;
     122              : }
     123              : 
     124              : // 由调用者保证device id已经被set
     125          992 : HcclOpInfoCtx &GetHcclExistDeviceOpInfoCtx(void)
     126              : {
     127          992 :     std::lock_guard<std::mutex> lock(g_opHcomInfosMutex);
     128          992 :     auto &opHcomInfo = GetOpHcomInfo(g_hcclDeviceId);
     129          992 :     if (!opHcomInfo.isUsed) {
     130            7 :         HCCL_INFO("[GetHcclOpInfoCtx] Set device, use g_hcclDeviceId[%d] ", g_hcclDeviceId);
     131            7 :         auto &backUpOpHcomInfo = GetOpHcomInfo(MAX_MODULE_DEVICE_NUM);
     132            7 :         if (backUpOpHcomInfo.isUsed) {
     133            0 :             g_hcclDeviceId = MAX_MODULE_DEVICE_NUM;
     134            0 :             HCCL_INFO("[GetHcclOpInfoCtx] Used cover bottom g_hcclDeviceId[%d]", g_hcclDeviceId);
     135            0 :             return backUpOpHcomInfo;
     136              :         }
     137              :     }
     138              : 
     139          992 :     HCCL_INFO("[GetHcclExistDeviceOpInfoCtx] use g_hcclDeviceId[%d] opHcomInfos", g_hcclDeviceId);
     140          992 :     opHcomInfo.isUsed = true;
     141          992 :     return opHcomInfo;
     142          992 : }
     143              : 
     144          989 : HcclOpInfoCtx &GetHcclOpInfoCtx(void)
     145              : {
     146          989 :     if (HcclGetDeviceId() == HCCL_SUCCESS) {
     147          989 :         return GetHcclExistDeviceOpInfoCtx();
     148              :     }
     149              : 
     150            0 :     std::lock_guard<std::mutex> lock(g_opHcomInfosMutex);
     151            0 :     for (u32 i = 0; i < MAX_MODULE_DEVICE_NUM; i++) {
     152            0 :         auto &opHcomInfo = GetOpHcomInfo(i);
     153            0 :         if (opHcomInfo.isUsed) {
     154            0 :             g_hcclDeviceId = i;
     155            0 :             HCCL_INFO("[GetHcclOpInfoCtx] Not set device, Used g_hcclDeviceId[%u] ", i);
     156            0 :             return opHcomInfo;
     157              :         }
     158              :     }
     159              : 
     160            0 :     g_hcclDeviceId = MAX_MODULE_DEVICE_NUM;
     161            0 :     auto &backUpOpHcomInfo = GetOpHcomInfo(g_hcclDeviceId);
     162            0 :     backUpOpHcomInfo.isUsed = true;
     163            0 :     HCCL_INFO("[GetHcclOpInfoCtx] Used cover bottom g_hcclDeviceId[%d]", g_hcclDeviceId);
     164            0 :     return backUpOpHcomInfo;
     165            0 : }
     166              : 
     167            0 : HcclResult GetDeviceComm(uint32_t ndev, const HcclRootInfo &rootHandle, const s32 rank, const s32 logicDeviceId,
     168              :     HcclComm &comm)
     169              : {
     170              :     //给当前线程添加名字
     171            0 :     SetThreadName("Hccl_GetDevComm");
     172              : 
     173            0 :     CHK_PRT_RET(hrtSetDevice(logicDeviceId) != HCCL_SUCCESS,
     174              :         HCCL_ERROR("[GetDeviceComm] set fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
     175            0 :     HcclResult ret = HcclCommInitRootInfo(ndev, &rootHandle, rank, &comm);
     176            0 :     if (ret != HCCL_SUCCESS || comm == nullptr) {
     177            0 :         comm = nullptr;
     178            0 :         HCCL_ERROR("[GetDeviceComm] rank[%d] Get device comm failed!", rank);
     179            0 :         CHK_PRT_RET(hrtResetDevice(logicDeviceId) != HCCL_SUCCESS,
     180              :             HCCL_ERROR("[GetDeviceComm] reset fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
     181            0 :         return ret;
     182              :     }
     183            0 :     hcclComm *pComm = static_cast<hcclComm *>(comm);
     184            0 :     pComm->ResetDeviceEnable();
     185            0 :     return HCCL_SUCCESS;
     186              : }
     187              : 
     188            0 : HcclResult HcclGetCommAll(uint32_t ndev, int32_t *devices, HcclComm *comms)
     189              : {
     190              :     // 入参校验
     191            0 :     CHK_PRT_RET(ndev == 0, HCCL_ERROR("[HcclGetCommAll] ndev is invalid, ndev[%u]", ndev), HCCL_E_PARA);
     192            0 :     CHK_PTR_NULL(comms);
     193            0 :     CHK_PTR_NULL(devices);
     194              : 
     195              :     //给当前线程添加名字
     196            0 :     SetThreadName("Hccl_GetCommAll");
     197              : 
     198            0 :     CHK_PRT_RET(hrtSetDevice(devices[0]) != HCCL_SUCCESS,
     199              :         HCCL_ERROR("[HcclGetCommAll] set fail devices[0][%d]", devices[0]), HCCL_E_INTERNAL);
     200              : 
     201              :     // 获取通信域之前, 先把所有通信域设置为空
     202            0 :     for (uint32_t i = 0; i < ndev; i++) {
     203            0 :         comms[i] = nullptr;
     204              :     }
     205              : 
     206              :     HcclRootInfo rootHandle;
     207            0 :     CHK_RET(HcclGetRootInfo(&rootHandle));
     208              : 
     209            0 :     std::vector<std::unique_ptr<std::thread>> threads(ndev);
     210            0 :     for (uint32_t rankId = 0; rankId < ndev; rankId++) {
     211            0 :         threads[rankId].reset(new (std::nothrow) std::thread(&GetDeviceComm, ndev, std::ref(rootHandle), rankId,
     212            0 :             devices[rankId], std::ref(comms[rankId])));
     213            0 :         CHK_PRT_RET(!threads[rankId], HCCL_ERROR("[HcclGetCommAll]threads[%u] reset failed ", rankId), HCCL_E_INTERNAL);
     214              :     }
     215            0 :     for (uint32_t i = 0; i < ndev; i++) {
     216            0 :         threads[i]->join();
     217              :     }
     218              : 
     219              :     // 如果任何一个通信域初始化失败,将所有已经成功创建的通信域销毁
     220            0 :     bool isFailed = false;
     221            0 :     for (uint32_t i = 0; i < ndev; ++i) {
     222            0 :         if (comms[i] == nullptr) {
     223            0 :             HCCL_ERROR("[HcclGetCommAll] rank[%u] get comm failed!", i);
     224            0 :             isFailed = true;
     225            0 :             break;
     226              :         }
     227              :     }
     228            0 :     if (isFailed) {
     229            0 :         for (uint32_t i = 0; i < ndev; ++i) {
     230            0 :             if (comms[i] != nullptr) {
     231            0 :                 (void)HcclCommDestroy(comms[i]);
     232              :             }
     233              :         }
     234            0 :         return HCCL_E_INTERNAL;
     235              :     }
     236              : 
     237            0 :     CHK_PRT_RET(hrtResetDevice(devices[0]) != HCCL_SUCCESS,
     238              :         HCCL_ERROR("[HcclGetCommAll] reset fail devices[0][%d]", devices[0]), HCCL_E_INTERNAL);
     239              : 
     240            0 :     return HCCL_SUCCESS;
     241            0 : }
     242              : 
     243            0 : HcclResult GetDeviceCollComm(const s32 rank, HcclCommConfig *config, const s32 logicDeviceId,
     244              :     HcclComm &comm)
     245              : {
     246              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU)) 
     247              :     //给当前线程添加名字
     248            0 :     SetThreadName("Hccl_GetDeviceCollComm");
     249              : 
     250            0 :     CHK_PRT_RET(hrtSetDevice(logicDeviceId) != HCCL_SUCCESS,
     251              :         HCCL_ERROR("[GetDeviceCollComm] set fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
     252              : 
     253              :     HcclComm newComm;
     254            0 :     HcclResult ret = HcclCommInitCollComm(rank, &comm, config, &newComm);
     255            0 :     if (ret != HCCL_SUCCESS || newComm == nullptr) {
     256            0 :         newComm = nullptr;
     257            0 :         HcclCommDestroyV2(comm);
     258            0 :         comm = nullptr;
     259            0 :         HCCL_ERROR("[GetDeviceCollComm] rank[%d] Get device coll comm failed!", rank);
     260            0 :         CHK_PRT_RET(hrtResetDevice(logicDeviceId) != HCCL_SUCCESS,
     261              :             HCCL_ERROR("[GetDeviceCollComm] reset fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
     262            0 :         return ret;
     263              :     }
     264            0 :     comm = newComm;
     265              : #endif
     266            0 :     return HCCL_SUCCESS;
     267              : }
     268              : 
     269            0 : HcclResult HcclGetCollCommAll(uint32_t ndev, int32_t *devices, HcclComm *comms)
     270              : {
     271              :     // 入参校验
     272            0 :     CHK_PRT_RET(ndev == 0, HCCL_ERROR("[HcclGetCollCommAll] ndev is invalid, ndev[%u]", ndev), HCCL_E_PARA);
     273            0 :     CHK_PTR_NULL(comms);
     274            0 :     CHK_PTR_NULL(devices);
     275              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU)) 
     276              :     //给当前线程添加名字
     277            0 :     SetThreadName("Hccl_GetCollCommAll");
     278              : 
     279            0 :     CHK_PRT_RET(hrtSetDevice(devices[0]) != HCCL_SUCCESS,
     280              :         HCCL_ERROR("[HcclGetCollCommAll] set fail devices[0][%d]", devices[0]), HCCL_E_INTERNAL);
     281              : 
     282            0 :     constexpr HcclCommConfig *config = nullptr;
     283            0 :     std::vector<std::unique_ptr<std::thread>> threads(ndev);
     284            0 :     for (uint32_t rankId = 0; rankId < ndev; rankId++) {
     285            0 :         threads[rankId].reset(new (std::nothrow) std::thread(&GetDeviceCollComm, rankId, config,
     286            0 :             devices[rankId], std::ref(comms[rankId])));
     287            0 :         CHK_PRT_RET(!threads[rankId], HCCL_ERROR("[HcclGetCollCommAll]threads[%u] reset failed ", rankId), HCCL_E_INTERNAL);
     288              :     }
     289            0 :     for (uint32_t i = 0; i < ndev; i++) {
     290            0 :         threads[i]->join();
     291              :     }
     292              : 
     293              :     // 如果任何一个通信域转换失败,将所有已经成功创建的通信域销毁
     294            0 :     bool isFailed = false;
     295            0 :     for (uint32_t i = 0; i < ndev; ++i) {
     296            0 :         if (comms[i] == nullptr) {
     297            0 :             HCCL_ERROR("[HcclGetCollCommAll] rank[%u] get comm failed!", i);
     298            0 :             isFailed = true;
     299            0 :             break;
     300              :         }
     301              :     }
     302            0 :     if (isFailed) {
     303            0 :         for (uint32_t i = 0; i < ndev; ++i) {
     304            0 :             if (comms[i] != nullptr) {
     305            0 :                 (void)HcclCommDestroy(comms[i]);
     306              :             }
     307              :         }
     308            0 :         return HCCL_E_INTERNAL;
     309              :     }
     310              : 
     311            0 :     CHK_PRT_RET(hrtResetDevice(devices[0]) != HCCL_SUCCESS,
     312              :         HCCL_ERROR("[HcclGetCollCommAll] reset fail devices[0][%d]", devices[0]), HCCL_E_INTERNAL);
     313              : #endif
     314            0 :     return HCCL_SUCCESS;
     315            0 : }
     316              : 
     317            0 : HcclResult HcclCollCommInitAll(uint32_t ndev, int32_t *devices, HcclComm *comms)
     318              : {
     319              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU)) 
     320            0 :     HcclUs startut = TIME_NOW();
     321            0 :     std::string devicesStr;
     322            0 :     for (size_t i = 0; i < ndev; ++i) {
     323            0 :         std::string deviceStr = std::to_string(devices[i]);
     324            0 :         devicesStr += deviceStr;
     325            0 :         if (i != ndev - 1) {
     326            0 :             devicesStr += " ";
     327              :         }
     328            0 :     }
     329            0 :     HCCL_RUN_INFO("Entry-HcclCollCommInitAll, ndev:[%u], devices:[%s].", ndev, devicesStr.c_str());
     330              : 
     331            0 :     std::future<HcclResult> threadResult;
     332            0 :     std::unique_ptr<std::thread> getCommThread;
     333            0 :     getCommThread.reset(new (std::nothrow) std::thread(
     334            0 :         [=, &threadResult]() { threadResult = std::async(std::launch::async, HcclGetCollCommAll, ndev, devices, comms); }));
     335            0 :     CHK_PRT_RET(!getCommThread, HCCL_ERROR("[HcclCollCommInitAll]thread reset failed "), HCCL_E_INTERNAL);
     336            0 :     getCommThread->join();
     337              : 
     338            0 :     HcclResult ret = threadResult.get();
     339            0 :     if (ret != HCCL_SUCCESS) {
     340            0 :         for (uint32_t i = 0; i < ndev; ++i) {
     341            0 :             if (comms[i] != nullptr) {
     342            0 :                 (void)HcclCommDestroy(comms[i]);
     343            0 :                 comms[i] = nullptr;
     344              :             }
     345              :         }
     346            0 :         HCCL_ERROR("HcclCollCommInitAll failed! threadResult[%d]", ret);
     347            0 :         return ret;
     348              :     }
     349            0 :     s32 deviceLogicId = HcclGetThreadDeviceId();
     350            0 :     HCCL_RUN_INFO("HcclCollCommInitAll success, take time [%lld]us, deviceLogicId[%d].", DURATION_US(TIME_NOW() - startut),
     351              :                   deviceLogicId);
     352              : #endif
     353            0 :     return HCCL_SUCCESS;
     354            0 : }
     355              : 
     356            4 : HcclResult HcclCommInitAll(uint32_t ndev, int32_t *devices, HcclComm *comms)
     357              : {
     358            4 :     HcclUs startut = TIME_NOW();
     359            4 :     s32 deviceLogicId = 0;
     360            4 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
     361              : 
     362              :     // 入参校验
     363            4 :     CHK_PRT_RET(ndev <= 0, HCCL_ERROR("[HcclCommInitAll] ndev is invalid, ndev[%u]", ndev), HCCL_E_PARA);
     364            2 :     CHK_PTR_NULL(comms);
     365            1 :     CHK_PTR_NULL(devices);
     366              : 
     367              :     // 判断设备List中是否有重复id,报错退出
     368            0 :     set<int32_t> devSet(devices, devices + ndev);
     369            0 :     uint32_t devSetSize = devSet.size();
     370            0 :     CHK_PRT_RET((devSetSize != ndev),
     371              :         HCCL_ERROR("[HcclCommInitAll] Duplicate device id exist in the device list. devSetSize:[%u], ndev:[%u]",
     372              :         devSetSize, ndev),
     373              :         HCCL_E_PARA);
     374              : 
     375              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
     376            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
     377              :         CHK_RET(HcclCommInitAllV2(ndev, devices, comms));
     378              :         CHK_RET(HcclCollCommInitAll(ndev, devices, comms));
     379              :         return HCCL_SUCCESS;
     380              :     }());
     381              : #endif
     382            0 :     std::future<HcclResult> threadResult;
     383            0 :     std::unique_ptr<std::thread> getCommThread;
     384            0 :     getCommThread.reset(new (std::nothrow) std::thread(
     385            0 :         [=, &threadResult]() { threadResult = std::async(std::launch::async, HcclGetCommAll, ndev, devices, comms); }));
     386            0 :     CHK_PRT_RET(!getCommThread, HCCL_ERROR("[HcclCommInitAll]thread reset failed "), HCCL_E_INTERNAL);
     387            0 :     getCommThread->join();
     388              : 
     389            0 :     HcclResult ret = threadResult.get();
     390            0 :     if (ret != HCCL_SUCCESS) {
     391            0 :         for (uint32_t i = 0; i < ndev; ++i) {
     392            0 :             if (comms[i] != nullptr) {
     393            0 :                 (void)HcclCommDestroy(comms[i]);
     394            0 :                 comms[i] = nullptr;
     395              :             }
     396              :         }
     397            0 :         HCCL_ERROR("HcclCommInitAll failed! threadResult[%d]", ret);
     398            0 :         return ret;
     399              :     }
     400            0 :     HCCL_RUN_INFO("HcclCommInitAll success, take time [%lld]us, deviceLogicId[%d]", DURATION_US(TIME_NOW() - startut),
     401              :         deviceLogicId);
     402            0 :     return HCCL_SUCCESS;
     403            0 : }
     404              : 
     405              : std::unordered_map<s32, std::unordered_map<std::string, std::shared_ptr<HcclOpInfoCtx>>> g_oneSidedCommHcomInfos;
     406              : std::set<HcclComm> g_oneSidedCommSet;
     407              : 
     408              : /* 仅提供判断功能, 调用前需校验参数有效性*/
     409          235 : bool IsOneSidedComm(HcclComm comm)
     410              : {
     411          235 :     return g_oneSidedCommSet.find(comm) != g_oneSidedCommSet.end();
     412              : }
     413              : 
     414              : 
     415              : /* 仅提供判断功能, 调用前需校验参数有效性*/
     416            4 : bool IsCommNameExistInOneSidedComms(s32 deviceLogicId, const std::string &commName)
     417              : {
     418            4 :     bool exist = g_oneSidedCommHcomInfos.count(deviceLogicId) != 0 &&
     419            0 :                 g_oneSidedCommHcomInfos[deviceLogicId].count(commName) != 0;
     420            4 :     if (exist && g_oneSidedCommHcomInfos[deviceLogicId][commName]->isUsed) {
     421            0 :         return true;
     422              :     }
     423            4 :     return false;
     424              : }
     425              : 
     426            0 : HcclResult DeInitOneSidedHcomInfo(s32 deviceLogicId, const std::string &commName)
     427              : {
     428            0 :     CHK_PRT_RET(deviceLogicId == INVALID_INT,
     429              :                 HCCL_ERROR("[HcclCommDestroy][DeInitOneSidedHcomInfo] deviceLogicId is error."),
     430              :                 HCCL_E_PARA);
     431            0 :     CHK_PRT_RET(commName.empty(),
     432              :                 HCCL_ERROR("[HcclCommDestroy][DeInitOneSidedHcomInfo] commName is error."),
     433              :                 HCCL_E_PARA);
     434            0 :     g_oneSidedCommHcomInfos[deviceLogicId].erase(commName);
     435            0 :     return HCCL_SUCCESS;
     436              : }
     437              : 
     438              : /*
     439              :  * g_oneSidedCommHcomInfos 初始化
     440              :  * s32 deviceLogicId
     441              :  * const string &commName : 通信域名,用户确保全局唯一
     442              :  */
     443            0 : HcclResult InitOneSidedHcomInfo(s32 deviceLogicId, const std::string &commName)
     444              : {
     445            0 :     CHK_PRT_RET(deviceLogicId == INVALID_INT,
     446              :                 HCCL_ERROR("[InitOneSidedHcomInfo] deviceLogicId is error."),
     447              :                 HCCL_E_PARA);
     448            0 :     CHK_PRT_RET(commName.empty(),
     449              :                 HCCL_ERROR("[InitOneSidedHcomInfo] commName is error."),
     450              :                 HCCL_E_PARA);
     451              :     // comm name exit && isUsed = true
     452            0 :     bool isCommNameExist = IsCommNameExistInOneSidedComms(deviceLogicId, commName);
     453            0 :     CHK_PRT_RET(isCommNameExist, HCCL_ERROR("[Init][InitOneSidedHcomInfo] comm Name exist."), HCCL_E_PARA);
     454              :     // 确保 deviceLogicId 和 commName 的 map 已经被初始化
     455            0 :     if (g_oneSidedCommHcomInfos.find(deviceLogicId) == g_oneSidedCommHcomInfos.end()) {
     456            0 :         g_oneSidedCommHcomInfos[deviceLogicId] = {};
     457              :     }
     458              :     // comm name not exit
     459            0 :     if (g_oneSidedCommHcomInfos[deviceLogicId].count(commName) == 0) {
     460            0 :         std::shared_ptr<HcclOpInfoCtx> opBaseHcomPtr;
     461            0 :         EXCEPTION_CATCH((opBaseHcomPtr = std::make_shared<HcclOpInfoCtx>()), return HCCL_E_PARA);
     462            0 :         g_oneSidedCommHcomInfos[deviceLogicId][commName] = opBaseHcomPtr;
     463            0 :     }
     464              :     // comm name exit && isUsed = False
     465            0 :     g_oneSidedCommHcomInfos[deviceLogicId][commName]->isUsed = true;
     466            0 :     return HCCL_SUCCESS;
     467              : }
     468              : 
     469            0 : HcclOpInfoCtx &GetOneSidedOpInfoCtx(s32 deviceLogicId, const std::string &commName)
     470              : {
     471            0 :     std::shared_ptr<HcclOpInfoCtx> oneSidedHComPtr = g_oneSidedCommHcomInfos[deviceLogicId][commName];
     472            0 :     return *oneSidedHComPtr;
     473            0 : }
     474              : 
     475          239 : HcclResult CheckOpBasedHcom(HcclOpInfoCtx &opBaseHcom, const uint32_t rank, const CommConfig &commConfig)
     476              : {
     477              :     /* 防止重复调用初始化 */
     478          239 :     CHK_PRT_RET((opBaseHcom.pComm != nullptr), HCCL_ERROR("[Init][CheckOpBasedHcom]errNo[0x%016llx] rank[%u] "\
     479              :         "op_base hccl multiple initialization", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), rank), HCCL_E_UNAVAIL);
     480          237 :     const std::string commIdentifier = commConfig.GetConfigCommName();
     481          237 :     auto iter = opBaseHcom.opGroup2CommMap.find(commIdentifier);
     482          237 :     CHK_PRT_RET(iter != opBaseHcom.opGroup2CommMap.end(),
     483              :         HCCL_ERROR("[Init][CheckOpBasedHcom]errNo[0x%016llx] The comm name[%s] already exists in Group2Comm map.",
     484              :                 HCCL_ERROR_CODE(HCCL_E_PARA),
     485              :                 commIdentifier.c_str()),
     486              :         HCCL_E_PARA);
     487          237 :     return HCCL_SUCCESS;
     488          237 : }
     489              : 
     490            4 : HcclResult HcclCommInitCollComm(uint32_t rank, void **commV2, const HcclCommConfig *config, HcclComm *comm)
     491              : {
     492            4 :     CHK_PTR_NULL(comm);
     493            3 :     CHK_PTR_NULL(*commV2);
     494            3 :     *comm = nullptr;
     495            3 :     HCCL_INFO("[HcclCommInitCollComm] CollComm init start.");
     496              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
     497            3 :     HcclUs startut = TIME_NOW();
     498              : 
     499              :     // 图模式
     500            3 :     u32 rankNum = 0;
     501            3 :     CHK_RET(HcclGetRankSizeV2(*commV2, &rankNum));
     502            3 :     char commName[ROOTINFO_INDENTIFIER_MAX_LENGTH] = {};
     503            3 :     CHK_RET(HcclGetCommNameV2(*commV2, commName));
     504              :     //获取cclbuffer
     505            3 :     uintptr_t cclBufferAddr{0};
     506            3 :     std::size_t cclBufferSize{0};
     507            3 :     HcclMemType cclBufferMemType{HcclMemType::HCCL_MEM_TYPE_DEVICE};
     508            3 :     CHK_RET(HcclGetCclBuffer(*commV2, cclBufferAddr, cclBufferSize, cclBufferMemType));
     509              :     HcclMem cclBuffer;
     510            3 :     cclBuffer.size = static_cast<uint64_t>(cclBufferSize);
     511            3 :     cclBuffer.type = cclBufferMemType;
     512            3 :     cclBuffer.addr = reinterpret_cast<void*>(cclBufferAddr);
     513            3 :     HcclCommPtr hcclCommPtr = nullptr;
     514            3 :     EXCEPTION_CATCH(hcclCommPtr = make_shared<hccl::hcclComm>(cclBufferSize, cclBufferSize, commName), return HCCL_E_PTR);
     515            3 :     CommConfig commConfig(commName);
     516            3 :     HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
     517            3 :     CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
     518              : 
     519            3 :     void *rankGraph = nullptr;
     520            3 :     CHK_RET(HcclGetRankGraphV2(commV2, &rankGraph));
     521              : 
     522              :     //Collcomm初始化
     523            9 :     CHK_RET(hcclCommPtr->InitCollComm(*commV2, rankGraph, rank, cclBuffer, commName, config));
     524              : 
     525            3 :     std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
     526            3 :     opBaseHcom.opGroup2CommMap[hcclCommPtr->GetIdentifier()] = hcclCommPtr;
     527            3 :     lock.unlock();
     528              : 
     529            3 :     HcclResult ret = HcomSetGroupTopoInfo(commName, rankNum);
     530            3 :     if (ret != HCCL_SUCCESS) {
     531            1 :         HcomUnSetGroupTopoInfo(commName);
     532            1 :         std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
     533            2 :         opBaseHcom.opGroup2CommMap.erase(commName);
     534            1 :         lock.unlock();
     535            1 :         CHK_RET(ret);
     536            1 :     }
     537            2 :     *comm = static_cast<HcclComm>(hcclCommPtr.get());
     538            2 :     HCCL_RUN_INFO("[%s] success, take time [%lld]us.", __func__, DURATION_US(TIME_NOW() - startut));
     539              : #endif
     540            2 :     return HCCL_SUCCESS;
     541            3 : }
     542              : 
     543          234 : HcclResult InitCommClusterInfo(std::string &rankTableM, const uint32_t rank, const CommConfig &commConfig,
     544              :     HcclOpInfoCtx& opBaseHcom, HcclComm *comm)
     545              : {
     546          234 :     u32 rankTableSize = 0;
     547          234 :     HcclResult ret = HcomCheckRankTable(rankTableM.c_str(), rankTableSize);
     548          234 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     549              :         HCCL_ERROR("[Init][CommClusterInfo]check rankTable string error, rankTableSize [%u].",
     550              :             rankTableSize), HCCL_E_PARA);
     551              : 
     552          234 :     const std::string commIdentifier = commConfig.GetConfigCommName();
     553          234 :     opBaseHcom.pComm.reset(
     554              :         new (std::nothrow) hccl::hcclComm(
     555          468 :             commConfig.GetConfigBufferSize(), commConfig.GetConfigBufferSize(), commIdentifier, commConfig.GetConfigBufferName()));
     556          234 :     CHK_PTR_NULL(opBaseHcom.pComm);
     557              : 
     558              :     /* --------------初始化------------------------- */
     559          234 :     bool errorFlag = false;
     560              :     do {
     561          234 :         RankConsistentcyChecker::GetInstance().SetCheckCannVersionSwitch(true); // 打开CANN软件版本校验开关
     562          234 :         ret = InitOtherInfo(opBaseHcom.params, rankTableM.c_str());
     563          235 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] init other Info.",
     564              :             HCCL_ERROR_CODE(ret)), errorFlag = true);
     565              : 
     566          234 :         HCCL_INFO("rootInfo[%s]", opBaseHcom.params.id.internal);
     567              : 
     568          234 :         ret = InitWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
     569          234 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     570              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] init work flow mode error.",
     571              :                 HCCL_ERROR_CODE(ret)), errorFlag = true);
     572              : 
     573          234 :         ret = CfgGetClusterInfo(rankTableM, to_string(rank), opBaseHcom.params, opBaseHcom.rankTable,
     574          234 :             commConfig.GetConfigInterSuperPodRetryEnable());
     575          234 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     576              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx]"\
     577              :                 "info error:rank[%u]", HCCL_ERROR_CODE(ret), rank), errorFlag = true);
     578              : 
     579          233 :         ret = opBaseHcom.pComm->init(opBaseHcom.params, commConfig, opBaseHcom.rankTable);
     580          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] hcclComm init error.",
     581              :             HCCL_ERROR_CODE(ret)), errorFlag = true);
     582              : 
     583              :         /* 设置确定性计算配置 */
     584          233 :         ret = opBaseHcom.pComm->SetDeterministicConfig(commConfig.GetConfigDeterministic());
     585          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     586              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set deterministic error.", HCCL_ERROR_CODE(ret)),
     587              :             errorFlag = true);
     588              : 
     589              :         // 设置TC/SL配置
     590          233 :         ret = opBaseHcom.pComm->SetQpQosAttr(commConfig.GetConfigTrafficClass(), commConfig.GetConfigServiceLevel());
     591          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     592              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set TC and SL error or Invalid configuration parameter.",
     593              :             HCCL_ERROR_CODE(ret)), errorFlag = true);
     594          233 :         if (commConfig.GetConfigJobID() != 0) {
     595            0 :             HCCL_RUN_INFO("[NSLBDP]GetConfigJobID = %llu,GetConfigWorldRankID = %u.",
     596              :                            commConfig.GetConfigJobID(), commConfig.GetConfigWorldRankID());
     597            0 :             hcclNslbDp::GetInstance().SetGlobalCommTaskId(commConfig.GetConfigJobID());
     598            0 :             hcclNslbDp::GetInstance().SetGlobalCommNodeId(commConfig.GetConfigWorldRankID());
     599              :         }
     600              : 
     601              :         /* 设置AIV模式 */
     602          233 :         ret = opBaseHcom.pComm->SetAivModeConfig(commConfig.GetConfigAivMode());
     603          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     604              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set aivMode error.", HCCL_ERROR_CODE(ret)),
     605              :             errorFlag = true);
     606              : 
     607              :         /* 设置only AIV模式 */
     608          233 :         ret = opBaseHcom.pComm->SetOnlyAivModeConfig(commConfig.GetConfigIsOnlyAivMode());
     609          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     610              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set only aivMode error.", HCCL_ERROR_CODE(ret)),
     611              :             errorFlag = true);
     612              : 
     613              :         /* 设置AICPU */
     614          233 :         ret = opBaseHcom.pComm->SetAicpuUnfoldConfig(commConfig.GetConfigAicpuUnfold());
     615          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     616              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set aicpu error.", HCCL_ERROR_CODE(ret)),
     617              :             errorFlag = true);
     618              : 
     619              :         /* 设置HcclExecTimeOut */
     620          233 :         ret = opBaseHcom.pComm->SetExecTimeOutConfig(commConfig.GetConfigExecTimeOut());
     621          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     622              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set execTimeOut error.", HCCL_ERROR_CODE(ret)),
     623              :             errorFlag = true);
     624              :         
     625              :         /* 设置HcclAlgo */
     626          233 :         ret = opBaseHcom.pComm->SetAlgoConfig(commConfig.GetConfigHcclAlgoMap());
     627          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     628              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set hcclAlgo error.", HCCL_ERROR_CODE(ret)),
     629              :             errorFlag = true);
     630              : 
     631          466 :         ret = ShowRanktableConfigInfo(opBaseHcom.cloudFlag, opBaseHcom.params,
     632          233 :             opBaseHcom.rankTable);
     633          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     634              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] put ranktable info error.",
     635              :                 HCCL_ERROR_CODE(ret)), errorFlag = true);
     636              :         /* 设置独立算子参数 */
     637          233 :         ret = opBaseHcom.pComm->SetIndependentOpConfig(commConfig, opBaseHcom.rankTable);
     638          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     639              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set SetIndependentOpConfig error.", HCCL_ERROR_CODE(ret)),
     640              :             errorFlag = true);
     641              :         // 初始化完成的comm指针赋给出参
     642          233 :         *comm = opBaseHcom.pComm.get();
     643          233 :         std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
     644          233 :         opBaseHcom.opGroup2CommMap[opBaseHcom.pComm->GetIdentifier()] = opBaseHcom.pComm;
     645          233 :         lock.unlock();
     646              : 
     647              :         // 特殊场景,当comm name被手动配置为HCCL_WORLD_GROUP时,需要将pComm赋值到hcomInfo.pComm
     648          233 :         if (opBaseHcom.pComm->GetIdentifier() == HCCL_WORLD_GROUP) {
     649          233 :             HcomGetCtxHomInfo().pComm = opBaseHcom.pComm;
     650              :         }
     651          233 :         ret = HcomSetGroupTopoInfo(opBaseHcom.pComm->GetIdentifier().c_str(), opBaseHcom.rankTable.rankNum);
     652          233 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
     653              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set group topo info error.",
     654              :                 HCCL_ERROR_CODE(ret)), errorFlag = true);
     655          233 :         ret = opBaseHcom.pComm->InitHccpChannel(); 
     656          233 :         if (ret != HCCL_SUCCESS) { 
     657          212 :             HCCL_WARNING("InitHccp channel unsuccessful ret:[%u].", ret); 
     658              :         }                               
     659          233 :     } while (0);
     660              : 
     661          234 :     if (errorFlag) {
     662            1 :         HCCL_ERROR("[Init][CommClusterInfo]HcclCommInitClusterInfo failed, rankNum[%u], rank[%u], server[%s],"\
     663              :             "device[%d], return[0x%016llx]", opBaseHcom.rankTable.rankNum, rank,
     664              :             opBaseHcom.params.serverId.c_str(), opBaseHcom.params.logicDevId, HCCL_ERROR_CODE(ret));
     665            1 :         (void)HcclCommDestroy(opBaseHcom.pComm.get());
     666            1 :         opBaseHcom.pComm = nullptr;
     667            1 :         *comm = nullptr;
     668            1 :         return ret;
     669              :     }
     670          233 :     if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0 &&
     671            0 :         hcclNslbDp::GetInstance().InitNetCo() == HCCL_SUCCESS) {
     672            0 :         HCCL_INFO("HCCL try to entry SetGlobalRank_RankTableExit.");
     673              :         /* NSLB 填充 表1 表4 */
     674            0 :         CHK_RET(hcclNslbDp::GetInstance().SetCommInfo_RankTableExit(opBaseHcom.rankTable));
     675            0 :         hcclNslbDp::GetInstance().SetGlobalRank_RankTableExit(opBaseHcom.rankTable);
     676            0 :         hcclNslbDp::GetInstance().SendGlobalRankTable(rank);
     677              :     }
     678              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
     679          233 :     CHK_RET(opBaseHcom.pComm->InitCollCommInner(rank));
     680              : #endif
     681              :     /* 关键状态记录 */
     682          233 :     HCCL_INFO("%s success, rankNum[%u], rank[%u], server[%s], device[%d].",
     683              :         __func__, opBaseHcom.rankTable.rankNum, rank, opBaseHcom.params.serverId.c_str(),
     684              :         opBaseHcom.params.logicDevId);
     685          233 :     return HCCL_SUCCESS;
     686          234 : }
     687              : 
     688            0 : HcclResult HcclCommInitClusterInfoWrapper(struct hcclAsyncJob* job_){
     689            0 :     struct hcclCommInitRankTableAsyncJob* job = static_cast<hcclCommInitRankTableAsyncJob*>(job_);
     690            0 :     uint32_t rank = job->rank;
     691            0 :     HcclComm* comm = job->initComm;
     692            0 :     const char *clusterInfo = job->clusterInfo;
     693            0 :     s32 devId = job->devId;
     694            0 :     HCCL_DEBUG("[HcclCommInitClusterInfoWrapper] Set device devId: %d", devId);
     695            0 :     CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
     696              :         HCCL_ERROR("[HcclCommInitClusterInfoWrapper] set fail device[%d]", devId), HCCL_E_INTERNAL);
     697            0 :     HCCL_DEBUG("[HcclCommInitClusterInfoWrapper] Done Set device devId: %d", devId);
     698              :  
     699            0 :     HcclUs startut = TIME_NOW();
     700            0 :     s32 deviceLogicId = 0;
     701            0 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
     702            0 :     HCCL_RUN_INFO("Entry-%s: clusterInfo[%s], rank[%u], deviceLogicId[%d].",
     703              :         __func__, clusterInfo, rank, deviceLogicId);
     704              :     // 入参合法性校验
     705            0 :     CHK_PTR_NULL(clusterInfo);
     706            0 :     CHK_PTR_NULL(comm);
     707              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
     708            0 :     HCCLV2_FUNC_RUN(
     709              :     [&]() -> HcclResult {
     710              :         void *commV2 = nullptr;
     711              :         CHK_RET(HcclCommInitClusterInfoV2(clusterInfo, rank, &commV2));
     712              :         constexpr HcclCommConfig *config = nullptr; // 未配置为默认加速模式
     713              :         HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
     714              :         if (ret != HCCL_SUCCESS) {
     715              :             HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
     716              :             CHK_RET(HcclCommDestroyV2(commV2));
     717              :             commV2 = nullptr;
     718              :             *comm = nullptr;
     719              :             return ret;
     720              :         }
     721              :         return HCCL_SUCCESS;
     722              :     }());
     723              : #endif
     724            0 :     HcclResult ret = InitExternalInput();
     725            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init external input error.",
     726              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
     727            0 :     ret = InitEnvConfig();
     728            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.",
     729              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
     730              :  
     731            0 :     std::string identifier = HCCL_WORLD_GROUP;
     732            0 :     CommConfig commConfig(identifier);
     733            0 :     std::string rankTableM;
     734            0 :     std::string realFilePath;
     735            0 :     ret = HcomLoadRanktableFile(clusterInfo, rankTableM, realFilePath);
     736            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     737              :         HCCL_ERROR("[Init][HcclCommInitClusterInfoWrapper]errNo[0x%016llx], clusterInfo[%s], rank[%u], "
     738              :         "load rankTable error.", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), clusterInfo, rank), HCCL_E_INTERNAL);
     739              :  
     740            0 :     HCCL_INFO("%s success, clusterInfoRealPath[%s].", __func__, realFilePath.c_str());
     741              :  
     742            0 :     HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
     743            0 :     CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
     744              :  
     745            0 :     CHK_RET(InitCommClusterInfo(rankTableM, rank, commConfig, opBaseHcom, comm));
     746              :  
     747              :     /* 关键状态记录 */
     748            0 :     HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, clusterInfo[%s], rank[%u], deviceLogicId[%d].",
     749              :         __func__, DURATION_US(TIME_NOW() - startut), clusterInfo, rank, deviceLogicId);
     750            0 :     return HCCL_SUCCESS;
     751            0 : }
     752              : 
     753          236 : HcclResult HcclCommInitClusterInfo(const char *clusterInfo, uint32_t rank, HcclComm *comm)
     754              : {
     755          236 :     if(hcclGroupDepth > 0){
     756            0 :         HcclResult ret = HCCL_SUCCESS;
     757            0 :         std::shared_ptr<struct hcclCommInitRankTableAsyncJob> job;
     758            0 :         EXCEPTION_CATCH((job = std::make_shared<struct hcclCommInitRankTableAsyncJob>()), return HCCL_E_PARA);
     759            0 :         job->clusterInfo = clusterInfo;
     760            0 :         job->rank = rank;
     761            0 :         job->initComm = comm;
     762            0 :         s32 devId = 0;
     763            0 :         CHK_RET(HcclDeviceRefresh(devId));
     764            0 :         job->devId = devId;
     765            0 :         ret = commInitTaskAppend(job, HcclCommInitClusterInfoWrapper, comm);
     766            0 :         return ret;
     767            0 :     }
     768          236 :     HcclUs startut = TIME_NOW();
     769          236 :     s32 deviceLogicId = 0;
     770          236 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
     771          235 :     HCCL_RUN_INFO("Entry-%s: clusterInfo[%s], rank[%u], deviceLogicId[%d].",
     772              :         __func__, clusterInfo, rank, deviceLogicId);
     773              :     // 入参合法性校验
     774          235 :     CHK_PTR_NULL(clusterInfo);
     775          234 :     CHK_PTR_NULL(comm);
     776              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
     777          233 :     HCCLV2_FUNC_RUN(
     778              :         [&]() -> HcclResult {
     779              :             void *commV2 = nullptr;
     780              :             CHK_RET(HcclCommInitClusterInfoV2(clusterInfo, rank, &commV2));
     781              :             constexpr HcclCommConfig *config = nullptr; // 未配置为默认加速模式
     782              :             HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
     783              :             if (ret != HCCL_SUCCESS) {
     784              :                 HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
     785              :                 CHK_RET(HcclCommDestroyV2(commV2));
     786              :                 commV2 = nullptr;
     787              :                 *comm = nullptr;
     788              :                 return ret;
     789              :             }
     790              :             return HCCL_SUCCESS;
     791              :         }());
     792              : #endif
     793          233 :     HcclResult ret = InitExternalInput();
     794          233 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init external input error.",
     795              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
     796          233 :     ret = InitEnvConfig();
     797          233 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.",
     798              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
     799              : 
     800          233 :     std::string identifier = HCCL_WORLD_GROUP;
     801          233 :     CommConfig commConfig(identifier);
     802          233 :     std::string rankTableM;
     803          233 :     std::string realFilePath;
     804          233 :     ret = HcomLoadRanktableFile(clusterInfo, rankTableM, realFilePath);
     805          233 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     806              :         HCCL_ERROR("[Init][HcclCommInitClusterInfo]errNo[0x%016llx], clusterInfo[%s], rank[%u], "
     807              :         "load rankTable error.", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), clusterInfo, rank), HCCL_E_INTERNAL);
     808              : 
     809          231 :     HCCL_INFO("%s success, clusterInfoRealPath[%s].", __func__, realFilePath.c_str());
     810              : 
     811          231 :     HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
     812          231 :     CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
     813              : 
     814          230 :     CHK_RET(InitCommClusterInfo(rankTableM, rank, commConfig, opBaseHcom, comm));
     815              : 
     816              :     /* 关键状态记录 */
     817          229 :     HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, clusterInfo[%s], rank[%u], deviceLogicId[%d].",
     818              :         __func__, DURATION_US(TIME_NOW() - startut), clusterInfo, rank, deviceLogicId);
     819          229 :     return HCCL_SUCCESS;
     820          233 : }
     821              : 
     822            0 : HcclResult HcclCommInitClusterInfoMemConfig(const char *rankTableString, uint32_t rank,
     823              :     HcclCommConfig *config, HcclComm *comm)
     824              : {
     825            0 :     HcclUs startut = TIME_NOW();
     826            0 :     s32 deviceLogicId = 0;
     827            0 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
     828              : 
     829              :     // 入参合法性校验
     830            0 :     CHK_PTR_NULL(rankTableString);
     831            0 :     CHK_PTR_NULL(config);
     832            0 :     CHK_PTR_NULL(config->hcclCommName);
     833            0 :     CHK_PTR_NULL(comm);
     834              : 
     835            0 :     HCCL_RUN_INFO("Entry-%s: rankTableString[%s], rank[%u], deviceLogicId[%d].",
     836              :         __func__, rankTableString, rank, deviceLogicId);
     837              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
     838            0 :     HCCLV2_FUNC_RUN(
     839              :         [&]() -> HcclResult {
     840              :             void *commV2 = nullptr;
     841              :             CHK_RET(HcclCommInitClusterInfoMemConfigV2(rankTableString, rank, config, &commV2));
     842              :             HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
     843              :             if (ret != HCCL_SUCCESS) {
     844              :                 HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
     845              :                 CHK_RET(HcclCommDestroyV2(commV2));
     846              :                 commV2 = nullptr;
     847              :                 *comm = nullptr;
     848              :                 return ret;
     849              :             }
     850              :             return HCCL_SUCCESS;
     851              :         }());
     852              : #endif
     853            0 :     HcclResult ret = InitExternalInput();
     854            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     855              :         HCCL_ERROR("[%s]errNo[0x%016llx] init external input error", __func__, HCCL_ERROR_CODE(ret)),
     856              :         HCCL_E_PARA);
     857            0 :     ret = InitEnvConfig();
     858            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     859              :     HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.", __func__, HCCL_ERROR_CODE(ret)),
     860              :         HCCL_E_PARA);
     861              : 
     862            0 :     CHK_PRT_RET(strlen(config->hcclCommName) == 0,
     863              :         HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig] hcclCommName is error."),
     864              :         HCCL_E_PARA);
     865              : 
     866            0 :     std::string rankTableM(rankTableString);
     867            0 :     std::string identifier = config->hcclCommName;
     868            0 :     CommConfig commConfig(identifier);
     869            0 :     HCCL_RUN_INFO("Entry-%s: %s", "hcclCommName", identifier.c_str());
     870              : 
     871              :     /* 读取用户配置 */
     872            0 :     ret = commConfig.Load(config);
     873            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     874              :         HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig]errNo[0x%016llx] load comm config failed.",
     875              :         HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
     876              : 
     877            0 :     CHK_PRT_RET(deviceLogicId == INVALID_INT,
     878              :         HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig] deviceLogicId is error."),
     879              :         HCCL_E_PARA);
     880              : 
     881            0 :     bool isCommNameExist = IsCommNameExistInOneSidedComms(deviceLogicId, identifier);
     882            0 :     CHK_PRT_RET(isCommNameExist, HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig] comm Name exist."), HCCL_E_PARA);
     883              : 
     884            0 :     CHK_RET(InitOneSidedHcomInfo(deviceLogicId, identifier));
     885              : 
     886            0 :     const std::string commIdentifier = commConfig.GetConfigCommName();
     887            0 :     HcclOpInfoCtx &oneSidedHCom = GetOneSidedOpInfoCtx(deviceLogicId, commIdentifier);
     888              : 
     889            0 :     AddOneSidedIdentifier(identifier);
     890              : 
     891            0 :     ret = InitCommClusterInfo(rankTableM, rank, commConfig, oneSidedHCom, comm);
     892            0 :     if (ret != HCCL_SUCCESS) {
     893            0 :         HCCL_ERROR("[Init][HcclCommInitClusterInfoMemConfig] InitCommClusterInfo failed");
     894            0 :         DeleteOneSidedIdentifier(identifier);
     895            0 :         DeInitOneSidedHcomInfo(deviceLogicId, identifier);
     896            0 :         return ret;
     897              :     }
     898              : 
     899            0 :     g_oneSidedCommSet.insert(*comm);
     900              : 
     901              :     /* 关键状态记录 */
     902            0 :     HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, rankTableString[%s], rank[%u], deviceLogicId[%d].",
     903              :         __func__, DURATION_US(TIME_NOW() - startut), rankTableString, rank, deviceLogicId);
     904            0 :     return HCCL_SUCCESS;
     905            0 : }
     906              : 
     907            0 : HcclResult HcclCommInitClusterInfoConfigWrapper(struct hcclAsyncJob* job_){
     908            0 :     struct hcclCommInitRankTableConfigAsyncJob* job = static_cast<hcclCommInitRankTableConfigAsyncJob*>(job_);
     909            0 :     uint32_t rank = job->rank;
     910            0 :     HcclComm* comm = job->initComm;
     911            0 :     const char *clusterInfo = job->clusterInfo;
     912            0 :     HcclCommConfig *config = job->config;
     913            0 :     s32 devId = job->devId;
     914            0 :     HCCL_DEBUG("[HcclCommInitClusterInfoConfigWrapper] Set device devId: %d", devId);
     915            0 :     CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
     916              :         HCCL_ERROR("[HcclCommInitClusterInfoConfigWrapper] set fail device[%d]", devId), HCCL_E_INTERNAL);
     917            0 :     HCCL_DEBUG("[HcclCommInitClusterInfoConfigWrapper] Done Set device devId: %d", devId);
     918              :  
     919            0 :     HcclUs startut = TIME_NOW();
     920            0 :     s32 deviceLogicId = 0;
     921            0 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
     922            0 :     HCCL_RUN_INFO("Entry-%s: clusterInfo[%s], rank[%u], deviceLogicId[%d].",
     923              :         __func__, clusterInfo, rank, deviceLogicId);
     924              :     // 入参合法性校验
     925            0 :     CHK_PTR_NULL(clusterInfo);
     926            0 :     CHK_PTR_NULL(comm);
     927              :  
     928              :     // 检查配置参数是否为空
     929            0 :     RPT_INPUT_ERR(config == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
     930              :         std::vector<std::string>({"HcclCommInitClusterInfoConfigWrapper", "nullptr", "config", "non-null pointer"}));
     931            0 :     CHK_SMART_PTR_NULL(config);
     932              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
     933            0 :     const char *socNamePtr = aclrtGetSocName();
     934            0 :     CHK_PTR_NULL(socNamePtr);
     935            0 :     HCCLV2_FUNC_RUN(
     936              :         [&]() -> HcclResult {
     937              :             void *commV2 = nullptr;
     938              :             CHK_RET(HcclCommInitClusterInfoConfigV2(clusterInfo, rank, config, &commV2));
     939              :             HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
     940              :             if (ret != HCCL_SUCCESS) {
     941              :                 HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
     942              :                 CHK_RET(HcclCommDestroyV2(commV2));
     943              :                 commV2 = nullptr;
     944              :                 *comm = nullptr;
     945              :                 return ret;
     946              :             }
     947              :             return HCCL_SUCCESS;
     948              :         }(),
     949              :         socNamePtr);
     950              : #endif
     951            0 :     HcclResult ret = InitExternalInput();
     952            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init external input error.",
     953              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
     954            0 :     ret = InitEnvConfig();
     955            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.",
     956              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
     957              :  
     958            0 :     std::string identifier = HCCL_WORLD_GROUP;
     959            0 :     CommConfig commConfig(identifier);
     960            0 :     ret = commConfig.Load(config);
     961            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     962              :         HCCL_ERROR("[%s]errNo[0x%016llx] load comm config failed.",
     963              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
     964              :  
     965            0 :     std::string rankTableM;
     966            0 :     std::string realFilePath;
     967            0 :     ret = HcomLoadRanktableFile(clusterInfo, rankTableM, realFilePath);
     968            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     969              :         HCCL_ERROR("[Init][HcclCommInitClusterInfoConfigWrapper]errNo[0x%016llx] clusterInfo[%s] rank[%u] "
     970              :         "load rankTable error.", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), clusterInfo, rank), HCCL_E_INTERNAL);
     971              :  
     972            0 :     HCCL_INFO("%s success, clusterInfoRealPath[%s].", __func__, realFilePath.c_str());
     973              :  
     974            0 :     HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
     975            0 :     CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
     976              :  
     977            0 :     CHK_RET(InitCommClusterInfo(rankTableM, rank, commConfig, opBaseHcom, comm));
     978              :  
     979              :     // 记录groupName和UDI的映射
     980            0 :     HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
     981              :  
     982              :     /* 关键状态记录 */
     983            0 :     HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, clusterInfo[%s], rank[%u], deviceLogicId[%d].",
     984              :         __func__, DURATION_US(TIME_NOW() - startut), clusterInfo, rank, deviceLogicId);
     985            0 :     return HCCL_SUCCESS;
     986            0 : }
     987              : 
     988           10 : HcclResult HcclCommInitClusterInfoConfig(const char *clusterInfo, uint32_t rank, HcclCommConfig *config,
     989              :     HcclComm *comm)
     990              : {
     991           10 :     if(hcclGroupDepth > 0){
     992            0 :         HcclResult ret = HCCL_SUCCESS;
     993            0 :         std::shared_ptr<struct hcclCommInitRankTableConfigAsyncJob> job;
     994            0 :         EXCEPTION_CATCH((job = std::make_shared<struct hcclCommInitRankTableConfigAsyncJob>()), return HCCL_E_PARA);
     995            0 :         job->clusterInfo = clusterInfo;
     996            0 :         job->rank = rank;
     997            0 :         job->config = config;
     998            0 :         job->initComm = comm;
     999            0 :         s32 devId = 0;
    1000            0 :         CHK_RET(HcclDeviceRefresh(devId));
    1001            0 :         job->devId = devId;
    1002            0 :         ret = commInitTaskAppend(job, HcclCommInitClusterInfoConfigWrapper, comm);
    1003            0 :         return ret;
    1004            0 :     }
    1005           10 :     HcclUs startut = TIME_NOW();
    1006           10 :     s32 deviceLogicId = 0;
    1007           10 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    1008            9 :     HCCL_RUN_INFO("Entry-%s: clusterInfo[%s], rank[%u], deviceLogicId[%d].", 
    1009              :         __func__, clusterInfo, rank, deviceLogicId);
    1010              :     // 入参合法性校验
    1011            9 :     CHK_PTR_NULL(clusterInfo);
    1012            8 :     CHK_PTR_NULL(comm);
    1013              : 
    1014              :     // 检查配置参数是否为空
    1015            7 :     RPT_INPUT_ERR(config == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),
    1016              :         std::vector<std::string>({"HcclCommInitClusterInfoConfig", "nullptr", "config", "non-null pointer"}));
    1017            7 :     CHK_SMART_PTR_NULL(config);
    1018              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    1019            7 :     HCCLV2_FUNC_RUN(
    1020              :         [&]() -> HcclResult {
    1021              :             void *commV2 = nullptr;
    1022              :             CHK_RET(HcclCommInitClusterInfoConfigV2(clusterInfo, rank, config, &commV2));
    1023              :             HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
    1024              :             if (ret != HCCL_SUCCESS) {
    1025              :                 HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
    1026              :                 CHK_RET(HcclCommDestroyV2(commV2));
    1027              :                 commV2 = nullptr;
    1028              :                 *comm = nullptr;
    1029              :                 return ret;    
    1030              :             }
    1031              :             return HCCL_SUCCESS;
    1032              :         }());
    1033              : #endif
    1034            7 :     HcclResult ret = InitExternalInput();
    1035            7 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init external input error.",
    1036              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1037            7 :     ret = InitEnvConfig();
    1038            7 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.",
    1039              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1040              : 
    1041            7 :     std::string identifier = HCCL_WORLD_GROUP;
    1042            7 :     CommConfig commConfig(identifier);
    1043            7 :     ret = commConfig.Load(config);
    1044            7 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1045              :         HCCL_ERROR("[%s]errNo[0x%016llx] load comm config failed.",
    1046              :         __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1047              : 
    1048            6 :     std::string rankTableM;
    1049            6 :     std::string realFilePath;
    1050            6 :     ret = HcomLoadRanktableFile(clusterInfo, rankTableM, realFilePath);
    1051            6 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1052              :         HCCL_ERROR("[Init][HcclCommInitClusterInfoConfig]errNo[0x%016llx] clusterInfo[%s] rank[%u] "
    1053              :         "load rankTable error.", HCCL_ERROR_CODE(HCCL_E_UNAVAIL), clusterInfo, rank), HCCL_E_INTERNAL);
    1054              : 
    1055            5 :     HCCL_INFO("%s success, clusterInfoRealPath[%s].", __func__, realFilePath.c_str());
    1056              : 
    1057            5 :     HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
    1058            5 :     CHK_RET(CheckOpBasedHcom(opBaseHcom, rank, commConfig));
    1059              : 
    1060            4 :     CHK_RET(InitCommClusterInfo(rankTableM, rank, commConfig, opBaseHcom, comm));
    1061              : 
    1062              :     // 记录groupName和UDI的映射
    1063            4 :     HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
    1064              : 
    1065              :     /* 关键状态记录 */
    1066            4 :     HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, clusterInfo[%s], rank[%u], deviceLogicId[%d].", 
    1067              :         __func__, DURATION_US(TIME_NOW() - startut), clusterInfo, rank, deviceLogicId);
    1068            4 :     return HCCL_SUCCESS;
    1069            7 : }
    1070              : 
    1071            1 : HcclResult HcclCreateSubCommConfigInner(hccl::hcclComm *globalComm, uint32_t rankNum, uint32_t *rankIds,
    1072              :     uint32_t subCommRankId, CommConfig &commConfig, HcclComm *subComm)
    1073              : {
    1074            1 :     HcclResult ret = HCCL_SUCCESS;
    1075            1 :     HcclCommParams globalParams{};
    1076            1 :     RankTable_t globalRankTable{};
    1077            1 :     CHK_RET(globalComm->GetCommParams(globalParams));
    1078            1 :     CHK_RET(globalComm->GetCommRankTable(globalRankTable));
    1079              : 
    1080            1 :     HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
    1081              : 
    1082            1 :     const std::string commIdentifier = commConfig.GetConfigCommName();
    1083            1 :     auto iter = opBaseHcom.opGroup2CommMap.find(commIdentifier);
    1084            1 :     CHK_PRT_RET(iter != opBaseHcom.opGroup2CommMap.end(),
    1085              :         HCCL_ERROR("[%s]errNo[0x%016llx]The comm name[%s] already exists in Group2Comm map.",
    1086              :             __func__, HCCL_ERROR_CODE(HCCL_E_PARA), commIdentifier.c_str()),
    1087              :         HCCL_E_PARA);
    1088              : 
    1089            1 :     std::shared_ptr<hccl::hcclComm> pComm;
    1090            1 :     pComm.reset(new (std::nothrow) hccl::hcclComm(
    1091            2 :             commConfig.GetConfigBufferSize(), commConfig.GetConfigBufferSize(), commIdentifier, commConfig.GetConfigBufferName()));
    1092            1 :     CHK_PTR_NULL(pComm);
    1093              : 
    1094            1 :     bool errorFlag = false;
    1095            1 :     hccl::HcclCommParams subParams{};
    1096            1 :     hccl::RankTable_t subRankTable{};
    1097              :     do {
    1098            1 :         RankConsistentcyChecker::GetInstance().SetCheckCannVersionSwitch(true); // 打开CANN软件版本校验开关
    1099              : 
    1100            1 :         std::unique_ptr<TopoinfoRanktablePartition> pTopoPartition;
    1101            1 :         pTopoPartition.reset(new (std::nothrow) hccl::TopoinfoRanktablePartition(globalParams, globalRankTable));
    1102            1 :         CHK_SMART_PTR_NULL(pTopoPartition);
    1103            1 :         CHK_RET(pTopoPartition->GenerateSubRankTable(rankNum, rankIds, subRankTable));
    1104            1 :         CHK_RET(pTopoPartition->GenerateSubParams(subRankTable, subCommRankId, subParams));
    1105              : 
    1106            1 :         std::string rankTableM = "";
    1107            1 :         CHK_RET(pTopoPartition->GetRankTableStr(subRankTable, rankTableM));
    1108              : 
    1109            1 :         ret = InitOtherInfo(subParams, rankTableM.c_str());
    1110            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] init other Info.",
    1111              :             __func__, HCCL_ERROR_CODE(ret)), errorFlag = true);
    1112            1 :         ret = pComm->init(subParams, commConfig, subRankTable);
    1113            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] hcclComm init error.",
    1114              :             __func__, HCCL_ERROR_CODE(ret)), errorFlag = true);
    1115            1 :         HCCL_INFO("[HcclCreateSubCommConfigInner]comm id[%s]", subParams.id.internal);
    1116              : 
    1117              :         /* 设置确定性计算配置 */
    1118            1 :         ret = pComm->SetDeterministicConfig(commConfig.GetConfigDeterministic());
    1119            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1120              :             HCCL_ERROR("[%s]errNo[0x%016llx] set deterministic error.", __func__, HCCL_ERROR_CODE(ret)),
    1121              :             errorFlag = true);
    1122              : 
    1123              :         // 设置TC/SL配置
    1124            1 :         ret = pComm->SetQpQosAttr(commConfig.GetConfigTrafficClass(), commConfig.GetConfigServiceLevel());
    1125            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]errNo[0x%016llx] set TC and SL error",
    1126              :             __func__, HCCL_ERROR_CODE(ret)), errorFlag = true);
    1127            1 :         if (commConfig.GetConfigJobID() != 0) {
    1128            0 :             HCCL_RUN_INFO("[NSLBDP]GetConfigJobID = %llu,GetConfigWorldRankID = %u.",
    1129              :                            commConfig.GetConfigJobID(), commConfig.GetConfigWorldRankID());
    1130            0 :             hcclNslbDp::GetInstance().SetGlobalCommTaskId(commConfig.GetConfigJobID());
    1131            0 :             hcclNslbDp::GetInstance().SetGlobalCommNodeId(commConfig.GetConfigWorldRankID());
    1132              :         }
    1133              :         /* 设置AIV模式 */
    1134            1 :         ret = pComm->SetAivModeConfig(commConfig.GetConfigAivMode());
    1135            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1136              :             HCCL_ERROR("[%s]errNo[0x%016llx] set aivMode error.", __func__, HCCL_ERROR_CODE(ret)),
    1137              :             errorFlag = true);
    1138              : 
    1139              :         /* 设置only AIV模式 */
    1140            1 :         ret = pComm->SetOnlyAivModeConfig(commConfig.GetConfigIsOnlyAivMode());
    1141            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1142              :             HCCL_ERROR("[%s]errNo[0x%016llx] set only aivMode error.", __func__, HCCL_ERROR_CODE(ret)),
    1143              :             errorFlag = true);
    1144              : 
    1145              :         /* 设置AICPU */
    1146            1 :         ret = pComm->SetAicpuUnfoldConfig(commConfig.GetConfigAicpuUnfold());
    1147            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1148              :             HCCL_ERROR("[%s]errNo[0x%016llx] set aicpu error.", __func__, HCCL_ERROR_CODE(ret)),
    1149              :             errorFlag = true);
    1150              :         
    1151              :         /* 设置HcclExecTimeOut */
    1152            1 :         ret = pComm->SetExecTimeOutConfig(commConfig.GetConfigExecTimeOut());
    1153            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1154              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set execTimeOut error.", HCCL_ERROR_CODE(ret)),
    1155              :             errorFlag = true);
    1156              :         
    1157              :         /* 设置HcclAlgo */
    1158            1 :         ret = pComm->SetAlgoConfig(commConfig.GetConfigHcclAlgoMap());
    1159            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1160              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set hcclAlgo error.", HCCL_ERROR_CODE(ret)),
    1161              :             errorFlag = true);
    1162              : 
    1163            1 :         ret = InitWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
    1164            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1165              :             HCCL_ERROR("[%s]errNo[0x%016llx] init workflow mode error.", __func__, HCCL_ERROR_CODE(ret)),
    1166              :             errorFlag = true);
    1167              : 
    1168            1 :         ret = DisplayRanktableInfo(subRankTable);
    1169            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1170              :             HCCL_ERROR("[%s]errNo[0x%016llx] print ranktable info error.", __func__, HCCL_ERROR_CODE(ret)),
    1171              :             errorFlag = true);
    1172              : 
    1173              :         /* 设置独立算子参数 */
    1174            1 :         ret = pComm->SetIndependentOpConfig(commConfig, subRankTable);
    1175            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1176              :             HCCL_ERROR("[%s] errNo[0x%016llx] set SetIndependentOpConfig error.", __func__, HCCL_ERROR_CODE(ret)),
    1177              :             errorFlag = true);
    1178              :         // 初始化完成的comm指针赋给出参
    1179            1 :         *subComm = pComm.get();
    1180            1 :         std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
    1181            1 :         opBaseHcom.opGroup2CommMap[pComm->GetIdentifier()] = pComm;
    1182            1 :         lock.unlock();
    1183              : 
    1184            1 :         ret = HcomSetGroupTopoInfo(pComm->GetIdentifier().c_str(), rankNum);
    1185            1 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1186              :             HCCL_ERROR("[%s]errNo[0x%016llx] set group topo info error.", __func__, HCCL_ERROR_CODE(ret)),
    1187              :             errorFlag = true);
    1188            1 :         ret = pComm->InitHccpChannel(); 
    1189            1 :         if (ret != HCCL_SUCCESS) { 
    1190            0 :             HCCL_WARNING("InitHccp channel unsuccessful ret:[%u].", ret); 
    1191              :         }                       
    1192            1 :     } while(0);
    1193              : 
    1194            1 :     if (errorFlag) {
    1195            0 :         HCCL_ERROR("[%s]Create sub communication failed, return[0x%016llx], " \
    1196              :             "rankNum[%u], subCommRankId[%u], sub commm identifier[%s], server[%s], logicDevId[%d]",
    1197              :             __func__, HCCL_ERROR_CODE(ret), rankNum, subCommRankId, commIdentifier.c_str(),
    1198              :             GetLocalServerId(subParams.serverId).c_str(), subParams.logicDevId);
    1199            0 :         (void)HcclCommDestroy(pComm.get());
    1200            0 :         return ret;
    1201              :     }
    1202            1 :     std::string identifier = pComm->GetIdentifier();
    1203              : 
    1204              :     /* NSLB 填充 表1 */
    1205            1 :     CHK_RET(hcclNslbDp::GetInstance().SetCommInfo_NoRankTable(subRankTable, identifier));
    1206            1 :     hcclNslbDp::GetInstance().SendTableFir(subCommRankId);
    1207              : 
    1208            1 :     HCCL_RUN_INFO("%s success, sub commm identifier[%s], rankNum[%u], rank[%u], server[%s], device[%d].",
    1209              :         __func__, commIdentifier.c_str(), subRankTable.rankNum, subCommRankId,
    1210              :         subParams.serverId.c_str(), subParams.logicDevId);
    1211            1 :     return HCCL_SUCCESS;
    1212            1 : }
    1213              : 
    1214            1 : HcclResult SubCommIsOneSidedComm(HcclComm *comm)
    1215              : {
    1216            1 :     if (IsOneSidedComm(*comm)) {
    1217            0 :         HCCL_ERROR("[%s]errNo[0x%016llx] oneSidedComm does not support create sub comm.",
    1218              :             __func__, HCCL_ERROR_CODE(HCCL_E_NOT_SUPPORT));
    1219            0 :         return HCCL_E_NOT_SUPPORT;
    1220              :     }
    1221            1 :     return HCCL_SUCCESS;
    1222              : }
    1223              : 
    1224            9 : HcclResult HcclCreateSubCommConfig(HcclComm *comm, uint32_t rankNum, uint32_t *rankIds,
    1225              :     uint64_t subCommId, uint32_t subCommRankId, HcclCommConfig *config, HcclComm *subComm)
    1226              : {
    1227            9 :     HcclUs startut = TIME_NOW();
    1228            9 :     s32 deviceLogicId = 0;
    1229            9 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    1230            8 :     HCCL_RUN_INFO("Entry-%s: rankNum[%u], rank[%u], deviceLogicId[%d]",
    1231              :         __func__, rankNum, subCommRankId, deviceLogicId);
    1232            8 :     CHK_SMART_PTR_NULL(subComm);
    1233            7 :     if (*subComm != nullptr) {
    1234            0 :         HCCL_WARNING("[%s]The value pointed by output param subComm is not nullptr. " \
    1235              :             "Please be ware of possible memory leak.", __func__);
    1236              :     }
    1237            7 :     CHK_PRT_RET(rankIds == nullptr && subCommId == INVALID_SUBCOMM_ID,
    1238              :         HCCL_RUN_INFO("[HCCL_TRACE]HcclCreateSubCommConfig return, rankIds is nullptr and subCommId is 0xFFFFFFFF, " \
    1239              :             "this device is not in the sub comm, deviceLogicId[%u].", deviceLogicId), HCCL_SUCCESS);
    1240            6 :     CHK_PRT_RET(rankIds == nullptr || subCommId == INVALID_SUBCOMM_ID,
    1241              :         HCCL_ERROR("[%s]errNo[0x%016llx] " \
    1242              :             "rankIds[%p] is nullptr xor subCommId[%llu] is invalid. " \
    1243              :             "The two parameters should only be both valid or both invalid.",
    1244              :             __func__, HCCL_ERROR_CODE(HCCL_E_PARA), rankIds, subCommId), HCCL_E_PARA);
    1245              : 
    1246            4 :     HcclResult ret = HCCL_SUCCESS;
    1247              :     // 入参合法性校验
    1248            4 :     CHK_PRT_RET((rankNum == 0), HCCL_ERROR("[%s]errNo[0x%016llx] Rank num cannot be zero.",
    1249              :         __func__, HCCL_ERROR_CODE(HCCL_E_PARA)), HCCL_E_PARA);
    1250            3 :     CHK_PRT_RET((subCommRankId >= rankNum), HCCL_ERROR("[%s]errNo[0x%016llx] subCommRankId[%u] should be less " \
    1251              :         "than rankNum[%u].", __func__, HCCL_ERROR_CODE(HCCL_E_PARA), subCommRankId, rankNum), HCCL_E_PARA);
    1252              : 
    1253           22 :     RPT_INPUT_ERR(config == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    1254              :         std::vector<std::string>({"HcclCreateSubCommConfig", "nullptr", "config", "non-null pointer"}));
    1255            2 :     CHK_SMART_PTR_NULL(config);
    1256            1 :     CHK_SMART_PTR_NULL(comm);
    1257            1 :     CHK_RET(SubCommIsOneSidedComm(comm));
    1258              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    1259            1 :     HCCLV2_FUNC_RUN(
    1260              :         [&]() -> HcclResult {
    1261              :             hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(*comm);
    1262              :             CHK_PTR_NULL(hcclComm);
    1263              :             void* commV2 = hcclComm->GetCommunicatorV2();
    1264              :             CHK_PTR_NULL(commV2);
    1265              :             void* subCommV2 = nullptr;
    1266              :             CHK_RET(HcclCreateSubCommConfigV2(&commV2, rankNum, rankIds, subCommId, subCommRankId, config, &subCommV2));
    1267              :             HcclResult ret = HcclCommInitCollComm(subCommRankId, &subCommV2, config, subComm);
    1268              :             if (ret != HCCL_SUCCESS) {
    1269              :                 HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed. Destroy subCommV2");
    1270              :                 CHK_RET(HcclCommDestroyV2(subCommV2));
    1271              :                 subCommV2 = nullptr;
    1272              :                 *subComm = nullptr;
    1273              :                 return ret;    
    1274              :             }
    1275              :             return HCCL_SUCCESS;
    1276              :         }());
    1277              : #endif
    1278            1 :     ret = InitExternalInput();
    1279            1 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1280              :         HCCL_ERROR("[%s]errNo[0x%016llx] init external input error", __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1281            1 :     ret = InitEnvConfig();
    1282            1 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1283              :         HCCL_ERROR("[%s]errNo[0x%016llx] init environment config error.", __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1284              : 
    1285            1 :     hccl::hcclComm *globalComm = static_cast<hccl::hcclComm*>(*comm);
    1286            1 :     CHK_PTR_NULL(globalComm);
    1287              : 
    1288            1 :     std::string identifier = globalComm->GetIdentifier() + "_sub_" + to_string(subCommId);
    1289            1 :     CommConfig commConfig(identifier);
    1290            1 :     ret = commConfig.Load(config);
    1291            1 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1292              :         HCCL_ERROR("[%s]errNo[0x%016llx] load comm config failed.", __func__, HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1293              : 
    1294            1 :     CHK_RET(HcclCreateSubCommConfigInner(globalComm, rankNum, rankIds, subCommRankId, commConfig, subComm));
    1295              : 
    1296              :     // 记录groupName和UDI的映射
    1297            1 :     HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
    1298              : 
    1299              :     /* 关键状态记录 */
    1300            1 :     HCCL_RUN_INFO("[HCCL_TRACE]%s success, take time [%lld]us, " \
    1301              :         "sub commm identifier[%s], rankNum[%u], rank[%u], deviceLogicId[%d]",
    1302              :         __func__, DURATION_US(TIME_NOW() - startut), commConfig.GetConfigCommName().c_str(),
    1303              :         rankNum, subCommRankId, deviceLogicId);
    1304            1 :     return HCCL_SUCCESS;
    1305            1 : }
    1306              : 
    1307           16 : HcclResult HcclGetRootInfo(HcclRootInfo *rootInfo)
    1308              : {
    1309           16 :     HcclUs startut = TIME_NOW();
    1310           16 :     s32 deviceLogicId = 0;
    1311           16 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    1312              : 
    1313              :     // input check
    1314           16 :     CHK_PTR_NULL(rootInfo);
    1315           15 :     HCCL_RUN_INFO("Entry-HcclGetRootInfo:rootInfo[%p], deviceLogicId[%d] ", rootInfo, deviceLogicId);
    1316              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    1317           15 :     HCCLV2_FUNC_RUN(HcclGetRootInfoV2(rootInfo));
    1318              : #endif
    1319              :     // get commId from env
    1320           15 :     CHK_RET(InitExternalInput());
    1321           15 :     CHK_RET(InitEnvConfig());
    1322              : 
    1323              :     HcclRootHandle rootHandle;
    1324           15 :     std::shared_ptr<TopoInfoDetect> topoDetectServer;
    1325           15 :     EXCEPTION_CATCH((topoDetectServer = std::make_shared<TopoInfoDetect>()),
    1326              :         return HCCL_E_MEMORY);
    1327           15 :     HcclResult ret = topoDetectServer->SetupServer(rootHandle);
    1328           15 :         CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s][%s]%s failed, ret[%u]",
    1329              :             LOG_KEYWORDS_INIT_GROUP.c_str(), LOG_KEYWORDS_RANKTABLE_DETECT.c_str(), __func__, ret), ret);
    1330              : 
    1331              :     if (sizeof(HcclRootHandle) > HCCL_ROOT_INFO_BYTES) {
    1332              :         HCCL_ERROR("[Get][RootInfo]hccl root info overflow. max length: %u, actual:%zu, identifier[%s]",
    1333              :             HCCL_ROOT_INFO_BYTES, sizeof(HcclRootHandle), rootHandle.identifier);
    1334              :         return HCCL_E_INTERNAL;
    1335              :     } else {
    1336           13 :         s32 sRet = memcpy_s(rootInfo->internal, HCCL_ROOT_INFO_BYTES, &rootHandle, sizeof(HcclRootHandle));
    1337           13 :         CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[Get][RootInfo]memcpy root info fail. errorno[%d] "\
    1338              :             "params:destMaxSize[%u], count[%u]", sRet, HCCL_ROOT_INFO_BYTES,
    1339              :             sizeof(HcclRootHandle)), HCCL_E_MEMORY);
    1340              :     }
    1341              : 
    1342           13 :     HcclOpInfoCtx& opBaseInfo = GetHcclOpInfoCtx();
    1343           13 :     EXCEPTION_CATCH(opBaseInfo.hcclCommTopoInfoDetectServer.insert({rootHandle.identifier, topoDetectServer}),
    1344              :         return HCCL_E_MEMORY);
    1345              :     /* 首节点诊断信息记录 */
    1346           13 :     HCCL_RUN_INFO("[HCCL_TRACE]HcclGetRootInfo success, take time [%lld]us, identifier[%s]",
    1347              :         DURATION_US(TIME_NOW() - startut), rootHandle.identifier);
    1348           13 :     return HCCL_SUCCESS;
    1349           15 : }
    1350              : 
    1351            0 : HcclResult GetSelfClusterInfo(const HcclBasicRankInfo &rankInfo, HcclCommParams &params)
    1352              : {
    1353            0 :     params.deviceType = rankInfo.deviceType;
    1354            0 :     params.rank = rankInfo.rank;
    1355            0 :     params.userRank = rankInfo.rank;
    1356            0 :     params.logicDevId = rankInfo.deviceLogicID;
    1357            0 :     params.totalRanks = rankInfo.rankSize;
    1358            0 :     params.serverId = rankInfo.hostIP.GetReadableAddress();
    1359              : 
    1360            0 :     return HCCL_SUCCESS;
    1361              : }
    1362              : 
    1363            5 : HcclResult HcclGetCommName(HcclComm commHandle, char *commName)
    1364              : {
    1365            5 :     CHK_PTR_NULL(commHandle);
    1366            4 :     CHK_PTR_NULL(commName);
    1367              : #if  (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    1368            3 :     HCCLV2_FUNC_RUN(
    1369              :     [&]() -> HcclResult {
    1370              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(commHandle);
    1371              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    1372              :         CHK_PTR_NULL(commV2);
    1373              :         CHK_RET(HcclGetCommNameV2(commV2, commName));
    1374              :         return HCCL_SUCCESS;
    1375              :     }());
    1376              : #endif
    1377            3 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(commHandle);
    1378            3 :     s32 ret = strncpy_s(commName, ROOTINFO_INDENTIFIER_MAX_LENGTH, hcclComm->GetIdentifier().c_str(),
    1379            6 :         hcclComm->GetIdentifier().size());
    1380            3 :     CHK_PRT_RET(ret != EOK, HCCL_ERROR("HcclGetCommName str copy fail. return[%d]", ret), HCCL_E_INTERNAL);
    1381            3 :     HCCL_INFO("HcclGetCommName input handle=%p commName=%s", commHandle, commName);
    1382            3 :     return HCCL_SUCCESS;
    1383              : }
    1384              : 
    1385            5 : HcclResult HcclGetCommHandle(const char *commName, std::shared_ptr<hccl::hcclComm> &comm)
    1386              : {
    1387            5 :     CHK_PTR_NULL(commName);
    1388            3 :     std::string group(commName);
    1389              : 
    1390            3 :     s32 deviceLogicId = 0;
    1391            3 :     HcclResult ret = HCCL_SUCCESS;
    1392            3 :     ret = hrtGetDevice(&deviceLogicId);
    1393            9 :     if (ret == HCCL_SUCCESS && IsCommNameExistInOneSidedComms(deviceLogicId, commName)) {
    1394            0 :         HcclOpInfoCtx &oneSidedHcom = GetOneSidedOpInfoCtx(deviceLogicId, commName);
    1395            0 :         comm = oneSidedHcom.pComm;
    1396            0 :         return HCCL_SUCCESS;
    1397              :     }
    1398              : 
    1399            3 :     HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
    1400            3 :     std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
    1401            3 :     auto iter = opBaseHcom.opGroup2CommMap.find(group);
    1402            3 :     if (iter == opBaseHcom.opGroup2CommMap.end()) {
    1403            3 :         HCCL_WARNING("please check the group name is correct, group=%s", commName);
    1404            3 :         return HCCL_E_PARA;
    1405              :     } else {
    1406            0 :         comm = iter->second;
    1407              :     }
    1408            0 :     return HCCL_SUCCESS;
    1409            3 : }
    1410              : 
    1411            3 : HcclResult HcclCommGetHandleWithName(const char* commName, HcclComm* comm)
    1412              : {
    1413            3 :     CHK_PTR_NULL(commName);
    1414            2 :     CHK_PTR_NULL(comm);
    1415            1 :     std::string group(commName);
    1416              : 
    1417            1 :     s32 deviceLogicId = 0;
    1418            1 :     HcclResult ret = HCCL_SUCCESS;
    1419            1 :     ret = hrtGetDevice(&deviceLogicId);
    1420            3 :     if (ret == HCCL_SUCCESS && IsCommNameExistInOneSidedComms(deviceLogicId, commName)) {
    1421            0 :         HcclOpInfoCtx &oneSidedHcom = GetOneSidedOpInfoCtx(deviceLogicId, commName);
    1422            0 :         *comm = static_cast<HcclComm>(oneSidedHcom.pComm.get());
    1423            0 :         return HCCL_SUCCESS;
    1424              :     }
    1425              : 
    1426            1 :     HcclOpInfoCtx &opBaseHcom = GetHcclOpInfoCtx();
    1427            1 :     std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
    1428            1 :     auto iter = opBaseHcom.opGroup2CommMap.find(group);
    1429            1 :     if (iter == opBaseHcom.opGroup2CommMap.end()) {
    1430            1 :         HCCL_ERROR("please check the group name is correct, group=%s", commName);
    1431            1 :         return HCCL_E_PARA;
    1432              :     } else {
    1433            0 :         *comm = static_cast<HcclComm>(iter->second.get());
    1434              :     }
    1435            0 :     return HCCL_SUCCESS;
    1436            1 : }
    1437              : 
    1438            0 : HcclResult HcclGetCommConnections(const HcclRootHandle &rootHandle, const std::string &identifier,
    1439              :     HcclCommConnections &commConnections)
    1440              : {
    1441            0 :     HcclOpInfoCtx& opBaseInfo = GetHcclOpInfoCtx();
    1442            0 :     auto iterServer = opBaseInfo.hcclCommTopoInfoDetectServer.find(rootHandle.identifier);
    1443            0 :     if (iterServer == opBaseInfo.hcclCommTopoInfoDetectServer.end()) {
    1444            0 :         commConnections.isRoot = false;
    1445              :     } else {
    1446            0 :         commConnections.isRoot = true;
    1447            0 :         CHK_RET(iterServer->second->GetServerConnections(commConnections.serverConnections));
    1448              :     }
    1449              : 
    1450            0 :     auto iterAgent = opBaseInfo.hcclCommTopoInfoDetectAgent.find(identifier);
    1451            0 :     if (iterAgent == opBaseInfo.hcclCommTopoInfoDetectAgent.end()) {
    1452            0 :         HCCL_ERROR("hccl get agent connections failed, identifier=%s", identifier.c_str());
    1453            0 :         return HCCL_E_PARA;
    1454              :     } else {
    1455            0 :         CHK_RET(iterAgent->second->GetAgentConnection(commConnections.agentConnection));
    1456              :     }
    1457            0 :     return HCCL_SUCCESS;
    1458              : }
    1459              : 
    1460          467 : void HcclCloseCommConnections(const std::string &identifier)
    1461              : {
    1462          467 :     HcclOpInfoCtx& opBaseInfo = GetHcclOpInfoCtx();
    1463          467 :     EXCEPTION_CATCH(opBaseInfo.hcclCommTopoInfoDetectServer.erase(identifier), return);
    1464          467 :     EXCEPTION_CATCH(opBaseInfo.hcclCommTopoInfoDetectAgent.erase(identifier), return);
    1465          467 :     return;
    1466              : }
    1467              : 
    1468            0 : HcclResult SetupHierarchical(const u32 nRanks, const u32 rank, const HcclRootHandle &rootHandle,
    1469              :     std::shared_ptr<TopoInfoDetect> &topoDetectAgent, std::shared_ptr<TopoInfoDetect> &topoDetectMember,
    1470              :     HcclRankHandle& groupLeader)
    1471              : {
    1472              :     HcclResult ret;
    1473              :     HcclRankHandle rankHandle;
    1474            0 :     std::vector<HcclIpAddress> whitelist;
    1475            0 :     std::shared_ptr<TopoInfoDetect> topoDetectGroupLeader;
    1476            0 :     EXCEPTION_CATCH((topoDetectGroupLeader = std::make_shared<TopoInfoDetect>()), return HCCL_E_MEMORY);
    1477              : 
    1478            0 :     CHK_PTR_NULL(topoDetectAgent);
    1479              : 
    1480            0 :     ret = topoDetectAgent->PrepareHandle(rankHandle, whitelist);
    1481            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1482              :         "prepare rank handle error", HCCL_ERROR_CODE(ret)), ret);
    1483              : 
    1484            0 :     CommConfig commConfig;
    1485            0 :     ret = topoDetectAgent->SetupAgent(nRanks, rank, rootHandle, rankHandle, commConfig); // member connect to root
    1486            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1487              :         "setup topo detect error", HCCL_ERROR_CODE(ret)), ret);
    1488              : 
    1489            0 :     ret = topoDetectAgent->GetGroupLeader(groupLeader);  // get group leader  此时group leader未监听
    1490            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1491              :         "get group leader info error", HCCL_ERROR_CODE(ret)), ret);
    1492              : 
    1493            0 :     std::shared_ptr<HcclSocket> agentConnRoot;
    1494            0 :     ret = topoDetectAgent->GetAgentConnection(agentConnRoot);
    1495            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1496              :             "get agent connection ptr error", HCCL_ERROR_CODE(ret)), ret);
    1497              :     // 判读当前rank是否被选为GroupLeader
    1498            0 :     if (std::strcmp(groupLeader.ip, rankHandle.ip) == 0 && (groupLeader.rankId == rank)) {
    1499            0 :         HCCL_RUN_INFO("[Init][CommRootInfo][SetupHierarchical]rank[%u] is group leader", rank);
    1500            0 :         CHK_PTR_NULL(topoDetectGroupLeader);
    1501            0 :         std::shared_ptr<HcclSocket> groupLeaderConnRoot;
    1502              : 
    1503              :         //保留下Agent->Server的Socket
    1504            0 :         ret = topoDetectAgent->GetAgentConnection(groupLeaderConnRoot);
    1505            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1506              :             "get group leader connection ptr error", HCCL_ERROR_CODE(ret)), ret);
    1507              : 
    1508              :         // 开启GroupLeader监听
    1509            0 :         ret = topoDetectGroupLeader->GroupLeaderListen(rankHandle, whitelist); // rank bind one local port
    1510            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1511              :         "rank bind port error", HCCL_ERROR_CODE(ret)), ret);
    1512              : 
    1513              :         //传给root 监听的端口
    1514            0 :         ret = topoDetectAgent ->SendGroupLeaderPort(groupLeaderConnRoot, rankHandle);
    1515            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1516              :         "setup group leader error", HCCL_ERROR_CODE(ret)), ret);
    1517              : 
    1518            0 :         HCCL_RUN_INFO("rankHandle.port[%u]", rankHandle.port);
    1519              : 
    1520            0 :         ret = topoDetectGroupLeader->GroupLeaderAccept(rankHandle, whitelist, groupLeaderConnRoot);
    1521            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1522              :             "setup group leader error", HCCL_ERROR_CODE(ret)), ret);
    1523            0 :     }
    1524            0 :     ret = topoDetectAgent->SetupRank(agentConnRoot);
    1525            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1526              :         "set up rank to get newest grpleader error", HCCL_ERROR_CODE(ret)), ret);
    1527            0 :     ret = topoDetectAgent->GetGroupLeader(groupLeader);  // get group leader 此时group leader已监听 更新groupLeader 准备连接groupLeader
    1528            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1529              :         "get group leader info error", HCCL_ERROR_CODE(ret)), ret);
    1530            0 :     CHK_PTR_NULL(topoDetectMember);
    1531            0 :     ret = topoDetectMember->SetupGroupMember(nRanks, rank, groupLeader);    // group member connect to group leader
    1532            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][SetupHierarchical]errNo[0x%016llx] " \
    1533              :         "setup group member error", HCCL_ERROR_CODE(ret)), ret);
    1534              : 
    1535            0 :     return HCCL_SUCCESS;
    1536            0 : }
    1537              : 
    1538            0 : HcclResult GetTopoDetectInfo(hccl::HcclCommParams &params, RankTable_t &rankTable,
    1539              :     HcclBasicRankInfo &localRankInfo, const HcclRootHandle &rootHandle,
    1540              :     std::shared_ptr<TopoInfoDetect> &topoDetectAgent, std::shared_ptr<TopoInfoDetect> &topoDetectMember)
    1541              : {
    1542            0 :     HcclResult ret = HCCL_SUCCESS;
    1543            0 :     ret = topoDetectMember->GetCluterInfo(rankTable);
    1544            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]errNo[0x%016llx] " \
    1545              :         "GetCluterInfo error", HCCL_ERROR_CODE(ret)), ret);
    1546              : 
    1547            0 :     ret = topoDetectMember->GetLocalRankInfo(localRankInfo);
    1548            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]errNo[0x%016llx] "\
    1549              :         "GetLocalRankInfo error.", HCCL_ERROR_CODE(ret)), ret);
    1550              : 
    1551            0 :     ret = GetSelfClusterInfo(localRankInfo, params);
    1552            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]errNo[0x%016llx] "\
    1553              :         "GetRankInfo error.", HCCL_ERROR_CODE(ret)), ret);
    1554              : 
    1555            0 :     ret = topoDetectMember->WaitComplete(rootHandle);
    1556            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]errNo[0x%016llx] "\
    1557              :         "wait complete topo detect error", HCCL_ERROR_CODE(ret)), ret);
    1558              : 
    1559            0 :     ret = topoDetectAgent->GetAgentListenSocket(params.commPortConfig);
    1560            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1561              :         HCCL_ERROR("[Init][CommRootInfo][GetTopoDetectInfo]HcclGetCommListenSockets failed."), ret);
    1562              : 
    1563            0 :     return HCCL_SUCCESS;
    1564              : }
    1565              : 
    1566            0 : HcclResult InitCommRootInfo(const u32 nRanks, const u32 rank, const HcclRootHandle &rootHandle,
    1567              :     const CommConfig &commConfig, HcclComm *comm)
    1568              : {
    1569            0 :     HcclResult ret = HCCL_SUCCESS;
    1570            0 :     bool errorFlag = false;
    1571            0 :     std::shared_ptr<hccl::hcclComm> pComm;
    1572            0 :     HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
    1573            0 :     const std::string commIdentifier = commConfig.GetConfigCommName();
    1574            0 :     auto iter = opBaseHcom.opGroup2CommMap.find(commIdentifier);
    1575            0 :     CHK_PRT_RET(
    1576              :         iter != opBaseHcom.opGroup2CommMap.end(),
    1577              :         HCCL_ERROR("[Init][InitCommRootInfo]errNo[0x%016llx] The comm name[%s] already exists in Group2Comm map.",
    1578              :         HCCL_ERROR_CODE(HCCL_E_PARA), commIdentifier.c_str()),
    1579              :         HCCL_E_PARA
    1580              :     );
    1581            0 :     hccl::HcclCommParams params;
    1582            0 :     RankTable_t rankTable;
    1583            0 :     HcclBasicRankInfo localRankInfo;
    1584              : 
    1585              :     DevType devType;
    1586            0 :     CHK_RET(hrtGetDeviceType(devType));
    1587            0 :     bool retryEnable = devType == DevType::DEV_TYPE_910_93 && !commConfig.GetConfigAivMode() && (
    1588            0 :         commConfig.GetConfigInterServerRetryEnable() || commConfig.GetConfigInterSuperPodRetryEnable());
    1589            0 :     HCCL_INFO("[InitCommRootInfo] retryEnable is [%d]", retryEnable);
    1590              : 
    1591              :     do {
    1592            0 :         RankConsistentcyChecker::GetInstance().SetCheckCannVersionSwitch(true); // 打开CANN软件版本校验开关
    1593            0 :         pComm.reset(new hccl::hcclComm(commConfig.GetConfigBufferSize(), commConfig.GetConfigBufferSize(),
    1594            0 :             commIdentifier, commConfig.GetConfigBufferName()));
    1595            0 :         CHK_SMART_PTR_NULL(pComm);
    1596              : 
    1597            0 :         std::shared_ptr<TopoInfoDetect> topoDetectAgent;
    1598            0 :         EXCEPTION_CATCH((topoDetectAgent = std::make_shared<TopoInfoDetect>()), return HCCL_E_MEMORY);
    1599            0 :         topoDetectAgent->SetIsInterSuperPodRetryEnable(commConfig.GetConfigInterSuperPodRetryEnable());
    1600              :         // 32k 作为agent开启阈值
    1601            0 :         if (nRanks > TOPO_HIERARCHICAL_ENABLE_THRESHOLD ) {
    1602            0 :             HCCL_RUN_INFO("[Init][CommRootInfo][Hierarchical]nRanks[%u] entry hierarchical topo detect.", nRanks);
    1603              : 
    1604            0 :             std::shared_ptr<TopoInfoDetect> topoDetectMember;
    1605            0 :             EXCEPTION_CATCH((topoDetectMember = std::make_shared<TopoInfoDetect>()), return HCCL_E_MEMORY);
    1606            0 :             topoDetectMember->SetIsInterSuperPodRetryEnable(commConfig.GetConfigInterSuperPodRetryEnable());
    1607              : 
    1608              :             HcclRankHandle groupLeader;
    1609            0 :             ret = SetupHierarchical(nRanks, rank, rootHandle, topoDetectAgent, topoDetectMember, groupLeader);
    1610            0 :             CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo]errNo[0x%016llx] setup " \
    1611              :                 "hierarchical error", HCCL_ERROR_CODE(ret)), errorFlag = true);
    1612              : 
    1613            0 :             ret = GetTopoDetectInfo(params, rankTable, localRankInfo, groupLeader, topoDetectAgent, topoDetectMember);
    1614            0 :             CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][Hierarchical]errNo[0x%016llx] setup " \
    1615              :                 "GetTopoDetectInfo error", HCCL_ERROR_CODE(ret)), errorFlag = true);
    1616            0 :         } else {
    1617            0 :             HCCL_RUN_INFO("[Init][CommRootInfo][Flat]nRanks[%u] entry flat topo detect.", nRanks);
    1618              : 
    1619            0 :             ret = topoDetectAgent->SetupAgent(nRanks, rank, rootHandle, rootHandle, commConfig);
    1620            0 :             CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][Flat]errNo[0x%016llx] " \
    1621              :                 "setup flat topo detect error", HCCL_ERROR_CODE(ret)), errorFlag = true);
    1622            0 :             ret = GetTopoDetectInfo(params, rankTable, localRankInfo, rootHandle, topoDetectAgent, topoDetectAgent);
    1623            0 :             CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfo][Flat]errNo[0x%016llx] setup " \
    1624              :                 "GetTopoDetectInfo error", HCCL_ERROR_CODE(ret)), errorFlag = true);
    1625              :         }
    1626              : 
    1627              :         /* 初始化hccl comm */
    1628              : 
    1629            0 :         CHK_RET(DisplayRanktableInfo(rankTable));
    1630              : 
    1631            0 :         if (retryEnable) {
    1632            0 :             EXCEPTION_CATCH(opBaseHcom.hcclCommTopoInfoDetectAgent.insert({ commIdentifier, topoDetectAgent }),
    1633              :                 return HCCL_E_MEMORY);
    1634            0 :             ret = HcclGetCommConnections(rootHandle, commIdentifier, params.commConnections);
    1635            0 :             CHK_PRT_BREAK(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][RootInfo]HcclGetCommConnections failed."),
    1636              :                 errorFlag = true);
    1637              :         } else {
    1638            0 :             ret = topoDetectAgent->Teardown();
    1639            0 :             CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1640              :                 HCCL_ERROR("[Init][RootInfo]errNo[0x%016llx] Teardown topo detect error", HCCL_ERROR_CODE(ret)),
    1641              :                 errorFlag = true);
    1642              :         }
    1643              : 
    1644            0 :         ret = InitWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
    1645            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1646              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] init work flow mode error", HCCL_ERROR_CODE(ret)),
    1647              :             errorFlag = true);
    1648              : 
    1649            0 :         ret = InitOtherInfo(params, nullptr);
    1650            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1651              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] init other Info", HCCL_ERROR_CODE(ret)),
    1652              :             errorFlag = true);
    1653              : 
    1654            0 :         HCCL_INFO("rootInfo[%s], params.logiceDevice[%d]", params.id.internal, params.logicDevId);
    1655            0 :         ret = pComm->init(params, commConfig, rankTable);
    1656            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1657              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] hcclComm init error", HCCL_ERROR_CODE(ret)),
    1658              :             errorFlag = true);
    1659              : 
    1660              :         /* 设置确定性计算配置 */
    1661            0 :         ret = pComm->SetDeterministicConfig(commConfig.GetConfigDeterministic());
    1662            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1663              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set deterministic error", HCCL_ERROR_CODE(ret)),
    1664              :             errorFlag = true);
    1665              : 
    1666              :         // 设置TC/SL配置
    1667            0 :         ret = pComm->SetQpQosAttr(commConfig.GetConfigTrafficClass(), commConfig.GetConfigServiceLevel());
    1668            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1669              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set TC and SL error or Invalid configuration parameter.",
    1670              :             HCCL_ERROR_CODE(ret)), errorFlag = true);
    1671            0 :         if (commConfig.GetConfigJobID() != 0) {
    1672            0 :             HCCL_RUN_INFO("[NSLBDP]GetConfigJobID = %llu,GetConfigWorldRankID = %u.",
    1673              :                            commConfig.GetConfigJobID(), commConfig.GetConfigWorldRankID());
    1674            0 :             hcclNslbDp::GetInstance().SetGlobalCommTaskId(commConfig.GetConfigJobID());
    1675            0 :             hcclNslbDp::GetInstance().SetGlobalCommNodeId(commConfig.GetConfigWorldRankID());
    1676              :         }
    1677              : 
    1678              :         // 设置HCCL QOS配置
    1679            0 :             ret = pComm->SetHcclQos(commConfig.GetConfigHcclQos());
    1680            0 :             CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1681              :                 HCCL_ERROR("[%s]errNo[0x%016llx] set hccl qos error.", __func__, HCCL_ERROR_CODE(ret)),
    1682              :             errorFlag = true);
    1683              : 
    1684              :         /* 设置AIV模式 */
    1685            0 :         ret = pComm->SetAivModeConfig(commConfig.GetConfigAivMode());
    1686            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1687              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set aivMode error.", HCCL_ERROR_CODE(ret)),
    1688              :             errorFlag = true);
    1689              : 
    1690              :         /* 设置only AIV模式 */
    1691            0 :         ret = pComm->SetOnlyAivModeConfig(commConfig.GetConfigIsOnlyAivMode());
    1692            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1693              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set only aivMode error.", HCCL_ERROR_CODE(ret)),
    1694              :             errorFlag = true);
    1695              : 
    1696              :         /* 设置AICPU */
    1697            0 :         ret = pComm->SetAicpuUnfoldConfig(commConfig.GetConfigAicpuUnfold());
    1698            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1699              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set aicpu error.", HCCL_ERROR_CODE(ret)),
    1700              :             errorFlag = true);
    1701              : 
    1702              :         /* 设置独立算子参数 */
    1703            0 :         ret = pComm->SetIndependentOpConfig(commConfig, rankTable);
    1704            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1705              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set SetIndependentOpConfig error.", HCCL_ERROR_CODE(ret)),
    1706              :             errorFlag = true);
    1707              :         
    1708              :         /* 设置HcclExecTimeOut */
    1709            0 :         ret = pComm->SetExecTimeOutConfig(commConfig.GetConfigExecTimeOut());
    1710            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1711              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] set execTimeOut error.", HCCL_ERROR_CODE(ret)),
    1712              :             errorFlag = true);
    1713              :         
    1714              :         /* 设置HcclAlgo */
    1715            0 :         ret = pComm->SetAlgoConfig(commConfig.GetConfigHcclAlgoMap());
    1716            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1717              :             HCCL_ERROR("[Init][CommClusterInfo]errNo[0x%016llx] set hcclAlgo error.", HCCL_ERROR_CODE(ret)),
    1718              :             errorFlag = true);
    1719              : 
    1720              :         // 初始化完成的comm指针赋给出参
    1721            0 :         *comm = pComm.get();
    1722            0 :         std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
    1723            0 :         opBaseHcom.opGroup2CommMap[pComm->GetIdentifier()] = pComm;
    1724            0 :         lock.unlock();
    1725              : 
    1726              :         // 特殊场景,当comm name被手动配置为HCCL_WORLD_GROUP时,需要将pComm赋值到hcomInfo.pComm
    1727            0 :         if (pComm->GetIdentifier() == HCCL_WORLD_GROUP) {
    1728            0 :             HcomGetCtxHomInfo().pComm = pComm;
    1729              :         }
    1730              : 
    1731            0 :         ret = HcomSetGroupTopoInfo(pComm->GetIdentifier().c_str(), nRanks);
    1732            0 :         CHK_PRT_BREAK(ret != HCCL_SUCCESS,
    1733              :             HCCL_ERROR("[InitCommRootInfo]errNo[0x%016llx] setGroupTopoInfo error", HCCL_ERROR_CODE(ret)),
    1734              :             errorFlag = true);
    1735              : 
    1736            0 :         ret = pComm->InitHccpChannel(); 
    1737            0 :         if (ret != HCCL_SUCCESS) { 
    1738            0 :             HCCL_WARNING("InitHccp channel unsuccessful ret:[%u].", ret); 
    1739              :         }
    1740            0 :         if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
    1741              :             DevType nslb_devType;
    1742            0 :             CHK_RET(hrtGetDeviceType(nslb_devType));
    1743            0 :             if (nslb_devType == DevType::DEV_TYPE_910_93) {
    1744            0 :                 hcclNslbDp::GetInstance().SetDeviceType();
    1745              :             }
    1746            0 :             if (hcclNslbDp::GetInstance().InitNetCo() == HCCL_SUCCESS) {
    1747            0 :                 std::string identifier_nslb = commIdentifier;
    1748            0 :                 hcclNslbDp::GetInstance().InitCmmDesc(identifier_nslb);
    1749            0 :                 HCCL_INFO("nslb_InitCommRootInfo rankTable.rankList.size:[%zu], identifier_nslb[%s].",
    1750              :                         rankTable.rankList.size(), identifier_nslb.c_str());
    1751            0 :                 hcclNslbDp::GetInstance().SetGlobalCommRankTable_RootInfo(rankTable, localRankInfo, pComm->GetRankLists(), identifier_nslb, nRanks, rank);
    1752            0 :                 hcclNslbDp::GetInstance().SetGlobalDisRankTable(localRankInfo);
    1753            0 :             } else {
    1754            0 :                 HCCL_WARNING("nslbdp try to init hccp failed.");
    1755              :             }
    1756              :         }
    1757            0 :     } while (0);
    1758              : 
    1759            0 :     std::string defaultIdentifier = rootHandle.identifier;
    1760            0 :     bool serverExist = opBaseHcom.hcclCommTopoInfoDetectServer.find(defaultIdentifier)
    1761            0 :         != opBaseHcom.hcclCommTopoInfoDetectServer.end();
    1762            0 :     if (defaultIdentifier.compare(commIdentifier) != 0 && retryEnable && serverExist) {
    1763            0 :         EXCEPTION_CATCH(opBaseHcom.hcclCommTopoInfoDetectServer.insert({commIdentifier,
    1764              :             opBaseHcom.hcclCommTopoInfoDetectServer[defaultIdentifier]}), return HCCL_E_MEMORY);
    1765            0 :         EXCEPTION_CATCH(opBaseHcom.hcclCommTopoInfoDetectServer.erase(defaultIdentifier), return HCCL_E_MEMORY);
    1766            0 :         HCCL_INFO("[InitCommRootInfo] replace key of topoDetectServer from [%s] to [%s]",
    1767              :             defaultIdentifier.c_str(), commIdentifier.c_str());
    1768            0 :     } else if (!retryEnable && serverExist) {
    1769            0 :         EXCEPTION_CATCH(opBaseHcom.hcclCommTopoInfoDetectServer.erase(defaultIdentifier), return HCCL_E_MEMORY);
    1770            0 :         HCCL_INFO("[InitCommRootInfo] close topoDetectServer identifier[%s]", commIdentifier.c_str());
    1771              :     }
    1772              : 
    1773            0 :     if (errorFlag) {
    1774            0 :         HCCL_ERROR("[InitCommRootInfo]Init failed, return[0x%016llx], rankNum[%u], rank[%u], "\
    1775              :             "rootInfo identifier[%s], server[%s], logicDevId[%d]", HCCL_ERROR_CODE(ret), nRanks, rank,
    1776              :             commIdentifier.c_str(), GetLocalServerId(params.serverId).c_str(), params.logicDevId);
    1777            0 :         (void)HcclCommDestroy(pComm.get());
    1778            0 :         return ret;
    1779              :     }
    1780              : 
    1781            0 :     HCCL_INFO("[InitCommRootInfo]Init success, rankNum[%u], rank[%u], rootInfo identifier[%s], server[%s], "
    1782              :               "logicDevId[%d]",
    1783              :         nRanks, rank, commIdentifier.c_str(), params.serverId.c_str(), params.logicDevId);
    1784              : 
    1785            0 :     return HCCL_SUCCESS;
    1786            0 : }
    1787              : 
    1788            4 : HcclResult HcclCommInitRootInfoInner(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank, HcclComm *comm)
    1789              : {
    1790            4 :     HcclUs startut = TIME_NOW();
    1791            4 :     s32 deviceLogicId = 0;
    1792            4 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    1793              : 
    1794            4 :     CHK_PRT_RET((nRanks == 0), HCCL_ERROR("[Init][CommRootInfoInner]errNo[0x%016llx] nRanks[%u] should "\
    1795              :         "be greater than 0.", HCCL_ERROR_CODE(HCCL_E_PARA), nRanks), HCCL_E_PARA);
    1796              : 
    1797            3 :     CHK_PRT_RET((rank >= nRanks), HCCL_ERROR("[Init][CommRootInfoInner]errNo[0x%016llx] rank[%u] should "\
    1798              :         "be less than nRanks[%u].", HCCL_ERROR_CODE(HCCL_E_PARA), rank, nRanks), HCCL_E_PARA);
    1799              : 
    1800            2 :     CHK_SMART_PTR_NULL(comm);
    1801            1 :     CHK_SMART_PTR_NULL(rootInfo);
    1802              : 
    1803              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    1804            0 :     HCCLV2_FUNC_RUN(
    1805              :         [&]() -> HcclResult {
    1806              :             void *commV2 = nullptr;
    1807              :             std::string fooidentifier;
    1808              :             CHK_RET(HcclCommInitRootInfoV2(nRanks, rootInfo, rank, &commV2, fooidentifier));
    1809              :             constexpr HcclCommConfig *config = nullptr; // 未配置为默认加速模式
    1810              :             HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
    1811              :             if (ret != HCCL_SUCCESS) {
    1812              :                 HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
    1813              :                 CHK_RET(HcclCommDestroyV2(commV2));
    1814              :                 commV2 = nullptr;
    1815              :                 *comm = nullptr;
    1816              :                 return ret; 
    1817              :             }
    1818              :             return HCCL_SUCCESS;
    1819              :         }());
    1820              : #endif
    1821              : 
    1822            0 :     HcclResult ret = InitExternalInput();
    1823            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfoInner]errNo[0x%016llx] init "\
    1824              :         "external input error", HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1825            0 :     ret = InitEnvConfig();
    1826            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1827              :         HCCL_ERROR("[Init][CommRootInfoInner]errNo[0x%016llx] init environment config error.",
    1828              :         HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1829              : 
    1830              :     HcclRootHandle rootHandle;
    1831            0 :     s32 sRet = memcpy_s(&rootHandle, sizeof(HcclRootHandle), rootInfo->internal, sizeof(HcclRootHandle));
    1832            0 :     CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[Init][RootInfoInner]memcpy root info fail. errorno[%d] "\
    1833              :         "params:destMaxSize[%u], count[%u]", sRet, sizeof(HcclRootHandle),
    1834              :         sizeof(HcclRootHandle)), HCCL_E_MEMORY);
    1835            0 :     rootHandle.identifier[ROOTINFO_INDENTIFIER_MAX_LENGTH - 1] = '\0';
    1836              : 
    1837              :     /* 接口交互信息日志 */
    1838            0 :     HCCL_RUN_INFO("Entry-HcclCommInitRootInfoInner:ranks[%u], rank[%u], rootinfo: host ip[%s] port[%u] "\
    1839              :         "nicDeploy[%d] identifier[%s], deviceLogicId[%d]", nRanks, rank, rootHandle.ip, rootHandle.port,
    1840              :         rootHandle.nicDeploy, rootHandle.identifier, deviceLogicId);
    1841              : 
    1842            0 :     CommConfig commConfig(rootHandle.identifier);
    1843              : 
    1844              :     /* --------------初始化------------------------- */
    1845            0 :     HCCL_INFO("HCCL nslbdp entry InitCommRootInfo.");
    1846            0 :     ret = InitCommRootInfo(nRanks, rank, rootHandle, commConfig, comm);
    1847            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1848              :         HCCL_ERROR("[Init][CommRootInfoConfig]errNo[0x%016llx]HcclCommInitRootInfo failed.",
    1849              :         HCCL_ERROR_CODE(ret)),
    1850              :         ret);
    1851              : 
    1852              :     // 记录groupName和UDI的映射
    1853            0 :     HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
    1854            0 :     if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
    1855              :         /* NSLB 发送 */
    1856            0 :         HCCL_INFO("hcclNslbDp entry Table FIVE rank[%u]", rank);
    1857            0 :         hcclNslbDp::GetInstance().SendGlobalDisRankTable();
    1858              :     }
    1859              : 
    1860              :     /* 关键状态记录 */
    1861            0 :     HCCL_RUN_INFO("[HCCL_TRACE]HcclCommInitRootInfoInner success, take time [%lld]us, rankNum[%u], rank[%u]",
    1862              :         DURATION_US(TIME_NOW() - startut), nRanks, rank);
    1863            0 :     return HCCL_SUCCESS;
    1864            0 : }
    1865              : 
    1866            0 : HcclResult HcclCommInitRootInfoInnerWrapper(struct hcclAsyncJob* job_)
    1867              : {
    1868            0 :     struct hcclCommInitAsyncJob* job = static_cast<hcclCommInitAsyncJob*>(job_);
    1869            0 :     uint32_t nRanks = job->nRanks;
    1870            0 :     const HcclRootInfo* rootInfo = job->rootInfo;
    1871            0 :     uint32_t rank = job->rank;
    1872            0 :     HcclComm* comm = job->initComm;
    1873            0 :     s32 devId = job->devId;
    1874            0 :     HCCL_DEBUG("[HcclCommInitRootInfoInnerWrapper] Set device devId: %d", devId);
    1875            0 :     CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
    1876              :         HCCL_ERROR("[HcclCommInitRootInfo] set fail device[%d]", devId), HCCL_E_INTERNAL);
    1877              :  
    1878            0 :     HcclResult ret = HCCL_SUCCESS;        
    1879            0 :     ret = HcclCommInitRootInfoInner(nRanks, rootInfo, rank, comm);
    1880            0 :     return ret;
    1881              : }
    1882              : 
    1883            4 : HcclResult HcclCommInitRootInfo(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank, HcclComm *comm)
    1884              : {
    1885            4 :     HCCL_INFO("hcclGroupDepth=[%d]", hcclGroupDepth);
    1886            4 :     HcclResult ret = HCCL_SUCCESS;
    1887            4 :     if(hcclGroupDepth > 0){
    1888            0 :         std::shared_ptr<struct hcclCommInitAsyncJob> job;
    1889            0 :         EXCEPTION_CATCH((job = std::make_shared<struct hcclCommInitAsyncJob>()), return HCCL_E_PARA);
    1890            0 :         job->nRanks = nRanks;
    1891            0 :         job->rootInfo = rootInfo;
    1892            0 :         job->rank = rank;
    1893            0 :         job->initComm = comm;
    1894            0 :         s32 devId = 0;
    1895            0 :         CHK_RET(HcclDeviceRefresh(devId));
    1896            0 :         job->devId = devId;
    1897            0 :         ret = commInitTaskAppend(job, HcclCommInitRootInfoInnerWrapper, comm);
    1898            0 :         return ret;
    1899            0 :     }
    1900            4 :     ret = HcclCommInitRootInfoInner(nRanks, rootInfo, rank, comm);
    1901            4 :     return ret;
    1902              : }
    1903              : 
    1904            5 : HcclResult HcclCommInitRootInfoConfigInner(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank,
    1905              :     const HcclCommConfig *config, HcclComm *comm)
    1906              : {
    1907            5 :     HcclUs startut = TIME_NOW();
    1908            5 :     s32 deviceLogicId = 0;
    1909            5 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    1910              : 
    1911              :     // 检查配置参数是否为空
    1912           25 :     RPT_INPUT_ERR(config == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    1913              :         std::vector<std::string>({"HcclCommInitRootInfoConfigInner", "nullptr", "config", "non-null pointer"}));
    1914              : 
    1915            5 :     CHK_PRT_RET((nRanks == 0),
    1916              :         HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] nRanks[%u] should be greater than 0.",
    1917              :         HCCL_ERROR_CODE(HCCL_E_PARA), nRanks),
    1918              :         HCCL_E_PARA);
    1919              : 
    1920            4 :     CHK_PRT_RET((rank >= nRanks),
    1921              :         HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] rank[%u] should be less than nRanks[%u].",
    1922              :         HCCL_ERROR_CODE(HCCL_E_PARA), rank, nRanks),
    1923              :         HCCL_E_PARA);
    1924              : 
    1925            3 :     CHK_PTR_NULL(comm);
    1926            2 :     CHK_SMART_PTR_NULL(rootInfo);
    1927              : 
    1928              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    1929            1 :     HCCLV2_FUNC_RUN(
    1930              :         [&]() -> HcclResult {
    1931              :             void *commV2 = nullptr;
    1932              :             CHK_RET(HcclCommInitRootInfoConfigV2(nRanks, rootInfo, rank, config, &commV2));
    1933              :             HcclResult ret = HcclCommInitCollComm(rank, &commV2, config, comm);
    1934              :             if (ret != HCCL_SUCCESS) {
    1935              :                 HCCL_ERROR("[HcclCommInitCollComm]HcclCommInitCollComm failed.Destroy comv2");
    1936              :                 CHK_RET(HcclCommDestroyV2(commV2));
    1937              :                 commV2 = nullptr;
    1938              :                 *comm = nullptr;
    1939              :                 return ret; 
    1940              :             }
    1941              :             return HCCL_SUCCESS;
    1942              :         }());
    1943              : #endif
    1944              : 
    1945            1 :     HcclResult ret = InitExternalInput();
    1946            1 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] init "\
    1947              :         "external input error", HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1948            1 :     ret = InitEnvConfig();
    1949            1 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] init "\
    1950              :         "environment config error", HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1951              : 
    1952              :     HcclRootHandle rootHandle;
    1953            1 :     s32 sRet = memcpy_s(&rootHandle, sizeof(HcclRootHandle), rootInfo->internal, sizeof(HcclRootHandle));
    1954            1 :     CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[Init][RootInfo]memcpy root info fail. errorno[%d] "\
    1955              :         "params:destMaxSize[%u], count[%u]", sRet, sizeof(HcclRootHandle),
    1956              :         sizeof(HcclRootHandle)), HCCL_E_MEMORY);
    1957            1 :     rootHandle.identifier[ROOTINFO_INDENTIFIER_MAX_LENGTH - 1] = '\0';
    1958              : 
    1959              :     /* 读取用户配置 */
    1960            1 :     CommConfig commConfig(rootHandle.identifier);
    1961            1 :     ret = commConfig.Load(config);
    1962            1 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1963              :         HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx] load comm config failed.",
    1964              :         HCCL_ERROR_CODE(ret)), HCCL_E_PARA);
    1965              : 
    1966              :     /* 接口交互信息日志 */
    1967            0 :     HCCL_RUN_INFO("Entry-HcclCommInitRootInfoConfigInner:ranks[%u], rank[%u], rootinfo: host ip[%s] "\
    1968              :         "port[%u] nicDeploy[%d] identifier[%s], deviceLogicId[%d]", nRanks, rank, rootHandle.ip,
    1969              :         rootHandle.port, rootHandle.nicDeploy, commConfig.GetConfigCommName().c_str(), deviceLogicId);
    1970              : 
    1971              :     /* --------------初始化------------------------- */
    1972            0 :     ret = InitCommRootInfo(nRanks, rank, rootHandle, commConfig, comm);
    1973            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    1974              :         HCCL_ERROR("[Init][CommRootInfoConfigInner]errNo[0x%016llx]HcclCommInitRootInfoConfigInner failed.",
    1975              :         HCCL_ERROR_CODE(ret)),
    1976              :         ret);
    1977              : 
    1978            0 :     if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
    1979              :         /* NSLB 发送 */
    1980            0 :         HCCL_INFO("hcclNslbDp-sendTable 5 rank[%u]", rank);
    1981            0 :         hcclNslbDp::GetInstance().SendGlobalDisRankTable();
    1982              :     }
    1983              : 
    1984              :     // 记录groupName和UDI的映射
    1985            0 :     HCCL_PROFILER_ADD_GROUP_UDI(commConfig.GetConfigCommName(), commConfig.GetConfigUdi());
    1986              : 
    1987            0 :     HCCL_RUN_INFO("[HCCL_TRACE]HcclCommInitRootInfoConfigInner success, take time [%lld]us, "\
    1988              :         "rankNum[%u], rank[%u]", DURATION_US(TIME_NOW() - startut), nRanks, rank);
    1989              : 
    1990            0 :     return HCCL_SUCCESS;
    1991            1 : }
    1992              : 
    1993            0 : HcclResult HcclCommInitRootInfoConfigInnerWrapper(struct hcclAsyncJob* job_){
    1994            0 :     struct hcclCommInitConfigAsyncJob* job = static_cast<hcclCommInitConfigAsyncJob*>(job_);
    1995            0 :     uint32_t nRanks = job->nRanks;
    1996            0 :     const HcclRootInfo* rootInfo = job->rootInfo;
    1997            0 :     uint32_t rank = job->rank;
    1998            0 :     HcclComm* comm = job->initComm;
    1999            0 :     const HcclCommConfig* config = job->config;
    2000            0 :     s32 devId = job->devId;
    2001            0 :     HCCL_DEBUG("[HcclCommInitRootInfoConfigInnerWrapper] Set device devId: %d", devId);
    2002            0 :     CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
    2003              :         HCCL_ERROR("[HcclCommInitRootInfoConfigInnerWrapper] set fail device[%d]", devId), HCCL_E_INTERNAL);
    2004              :  
    2005            0 :     HcclResult ret = HCCL_SUCCESS;        
    2006            0 :     ret = HcclCommInitRootInfoConfigInner(nRanks, rootInfo, rank, config, comm);
    2007            0 :     return ret;
    2008              : }
    2009              : 
    2010            5 : HcclResult HcclCommInitRootInfoConfig(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank,
    2011              :     const HcclCommConfig *config, HcclComm *comm)
    2012              : {
    2013            5 :     HcclResult ret = HCCL_SUCCESS;
    2014            5 :     HCCL_INFO("hcclGroupDepth=[%d]", hcclGroupDepth);
    2015            5 :     if(hcclGroupDepth > 0){
    2016            0 :         std::shared_ptr<struct hcclCommInitConfigAsyncJob> job;
    2017            0 :         EXCEPTION_CATCH((job = std::make_shared<struct hcclCommInitConfigAsyncJob>()), return HCCL_E_PARA);
    2018            0 :         job->nRanks = nRanks;
    2019            0 :         job->rootInfo = rootInfo;
    2020            0 :         job->rank = rank;
    2021            0 :         job->initComm = comm;
    2022            0 :         job->config = config;
    2023            0 :         s32 devId = 0;
    2024            0 :         CHK_RET(HcclDeviceRefresh(devId));
    2025            0 :         job->devId = devId;
    2026            0 :         ret = commInitTaskAppend(job, HcclCommInitRootInfoConfigInnerWrapper, comm);
    2027            0 :         return ret;
    2028            0 :     }
    2029            5 :     ret = HcclCommInitRootInfoConfigInner(nRanks, rootInfo, rank, config, comm);
    2030            5 :     return ret;
    2031              : }
    2032              : 
    2033            3 : HcclResult HcclSetConfig(HcclConfig config, HcclConfigValue configValue)
    2034              : {
    2035            3 :     if (config == HCCL_DETERMINISTIC) {
    2036              :     #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    2037            3 :         HCCLV2_FUNC_RUN(HcclSetConfigV2(config, configValue));
    2038              :     #endif
    2039            3 :         char* mmSysGetEnvValue = nullptr;
    2040            3 :         MM_SYS_GET_ENV(MM_ENV_HCCL_DETERMINISTIC, mmSysGetEnvValue);
    2041            3 :         std::string hcclDeterministicEnv = (mmSysGetEnvValue != nullptr) ? mmSysGetEnvValue : "EmptyString";
    2042            3 :         if (hcclDeterministicEnv == "EmptyString") {
    2043            3 :             if (configValue.value != DETERMINISTIC_STRICT && configValue.value != DETERMINISTIC_ENABLE &&
    2044            1 :                 configValue.value != DETERMINISTIC_DISABLE) {
    2045            0 :                 HCCL_ERROR("[HcclSetConfig] HCCL_DETERMINISTIC is only support 0, 1 or 2");
    2046            0 :                 return HCCL_E_PARA;
    2047              :             } else {
    2048              :                 DevType devType;
    2049            4 :                 CHK_RET(hrtGetDeviceType(devType));
    2050            3 :                 if (configValue.value == DETERMINISTIC_STRICT && devType != DevType::DEV_TYPE_910B) {
    2051            1 :                     HCCL_ERROR("[HcclSetConfig] configValue[%d], reduce order preservation is not supported for"
    2052              :                         " devType[%d]", configValue.value, devType);
    2053            1 :                     return HCCL_E_NOT_SUPPORT;
    2054              :                 }
    2055            2 :                 CHK_RET(SetDeterministic(configValue.value));
    2056            2 :                 HCCL_INFO("[HcclSetConfig] Set HCCL_DETERMINISTIC to %u", configValue.value);
    2057              :             }
    2058              :         } else {
    2059            0 :             HCCL_WARNING("[HcclSetConfig] HCCL_DETERMINISTIC has been set by Env, so will not be reset again");
    2060            0 :             return HCCL_SUCCESS;
    2061              :         }
    2062            2 :         HcclOpInfoCtx& opBaseInfo = GetHcclOpInfoCtx();
    2063              :         // 遍历所有的通信域设置其确定性计算配置参数
    2064            2 :         for (auto it = opBaseInfo.opGroup2CommMap.begin(); it != opBaseInfo.opGroup2CommMap.end(); it++) {
    2065            0 :             CHK_RET(it->second->SetDeterministicConfig(configValue.value));
    2066              :         }
    2067            3 :         }
    2068            2 :     return HCCL_SUCCESS;
    2069              : }
    2070              : 
    2071            4 : HcclResult HcclGetConfig(HcclConfig config, HcclConfigValue *configValue)
    2072              : {
    2073            4 :     CHK_PTR_NULL(configValue);
    2074            3 :     if (config == HCCL_DETERMINISTIC) {
    2075              :     #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    2076            3 :         HCCLV2_FUNC_RUN(HcclGetConfigV2(config, configValue));
    2077              :     #endif
    2078            3 :         configValue->value = static_cast<int32_t>(GetExternalInputHcclDeterministicV2());
    2079            3 :         HCCL_INFO("[HcclGetConfig] HCCL_DETERMINISTIC is [%d]", configValue->value);
    2080              :     }
    2081            3 :     return HCCL_SUCCESS;
    2082              : }
    2083              : 
    2084          317 : HcclResult HcclSetIfProfile()
    2085              : {
    2086          317 :     bool ifOpbase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
    2087          317 :     bool state = ProfilingManagerPub::GetAllState();
    2088          317 :     SetIfProfile((!ifOpbase) || (!state));
    2089          317 :     return HCCL_SUCCESS;
    2090              : }
    2091              : 
    2092          289 : void HcclResetIfProfile()
    2093              : {
    2094          289 :     SetIfProfile(true);
    2095          289 : }
    2096              : 
    2097           28 : HcclResult HcclBroadcastInner(void *buf, uint64_t count, HcclDataType dataType, uint32_t root, HcclComm comm,
    2098              :                          aclrtStream stream)
    2099              : {
    2100              :     // 入参合法性校验
    2101           28 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return broadcast success"), HCCL_SUCCESS);
    2102           27 :     RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2103              :         std::vector<std::string>({"HcclBroadcastInner", "nullptr", "stream", "non-null pointer"}));
    2104           27 :     CHK_PTR_NULL(stream);
    2105           47 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2106              :         std::vector<std::string>({"HcclBroadcastInner", "nullptr", "comm", "non-null pointer"}));
    2107           27 :     CHK_PTR_NULL(comm);
    2108           46 :     RPT_INPUT_ERR(buf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2109              :         std::vector<std::string>({"HcclBroadcastInner", "nullptr", "buf", "non-null pointer"}));
    2110           26 :     CHK_PTR_NULL(buf);
    2111              :     
    2112              :     // Group特性
    2113           25 :     if (hcclGroupDepth > 0) {
    2114              :         struct hcclOpInfo info;
    2115            1 :         info.coll = HcclCMDType::HCCL_CMD_BROADCAST;
    2116            1 :         info.sendbuff = buf;
    2117            1 :         info.sendCount = count;
    2118            1 :         info.sendType = dataType;
    2119            1 :         info.recvType = dataType;
    2120            1 :         info.op = HCCL_REDUCE_SUM;
    2121            1 :         info.root = root;
    2122            1 :         info.comm = comm;
    2123            1 :         info.stream = stream;
    2124            1 :         CHK_RET(taskAppend(comm, info));
    2125            1 :         HCCL_INFO("[HcclBroadcast] Finish taskAppend, count [%d] dataType [%s] root [%u]", count, GetDataTypeEnumStr(dataType).c_str(), root);
    2126            1 :         return HCCL_SUCCESS;
    2127              :     }
    2128              : 
    2129           24 :     HcclUs startut = TIME_NOW();
    2130              :     bool isCapture;
    2131           24 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    2132           24 :     uint64_t modelId = 0xFFFFFFFF;
    2133           24 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    2134           24 :     if (!isCapture) {
    2135           23 :         HcclSetIfProfile();
    2136              :     }
    2137           24 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2138              : 
    2139              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    2140           24 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    2141              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2142              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    2143              :         CHK_PTR_NULL(commV2);
    2144              :         CHK_RET(HcclBroadcastV2(buf, count, dataType, root, commV2, stream));
    2145              :         return HCCL_SUCCESS;
    2146              :     }());
    2147              : #endif
    2148           24 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2149           24 :     const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
    2150           24 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    2151           24 :     s32 threadID = SalGetTid();
    2152           24 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    2153              :     // 同通信域同算子复用tag
    2154           24 :     const string tag = "Broadcast_" + hcclComm->GetIdentifier();
    2155              : 
    2156           24 :     CHK_RET(HcomCheckOpParam(tag.c_str(), count, dataType, stream));
    2157              : 
    2158           24 :     HcomCollOpInfo opInfo = {"", buf, buf, count, dataType, root, HCCL_REDUCE_RESERVED};
    2159              : 
    2160           24 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    2161           24 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
    2162              : 
    2163           24 :     CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, root), tag.c_str());
    2164              : 
    2165              :     /* 接口交互信息日志 */
    2166              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    2167           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    2168           23 :         s32 deviceLogicId = 0;
    2169           23 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    2170              : 
    2171           23 :         u32 localRank = INVALID_VALUE_RANKID;
    2172           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    2173              : 
    2174           23 :         s32 streamId = 0;
    2175           23 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    2176              : 
    2177           23 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    2178              :             "tag[%s], buf[%p], count[%llu], dataType[%s], root[%u], localRank[%u], streamId[%d], deviceLogicId[%d]",
    2179           46 :             tag.c_str(), buf, count, GetDataTypeEnumStr(dataType).c_str(), root, localRank, streamId, deviceLogicId);
    2180              : 
    2181           23 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    2182           46 :         std::string logInfo = "Entry-HcclBroadcastInner:" + std::string(stackLogBuffer) +
    2183           69 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    2184           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    2185           23 :     }
    2186              : 
    2187           23 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    2188              : 
    2189           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->CreateOpBasedResources(HcclCMDType::HCCL_CMD_BROADCAST, tag, opInfo), tag.c_str());
    2190              : 
    2191           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(buf), tag.c_str());
    2192              : 
    2193           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->BroadcastOutPlace(tag, buf, count, dataType, root, stream), tag.c_str());
    2194              : 
    2195           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_BROADCAST, beginTime, count, dataType, tag));
    2196           23 :     if (!isCapture) {
    2197           22 :         HcclResetIfProfile();
    2198              :     }
    2199           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    2200              : 
    2201           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    2202           23 :         HcclUs endut = TIME_NOW();
    2203              :         /* 关键状态记录 */
    2204           23 :         std::string endInfo = "HcclBroadcastInner:success,take time: " +
    2205           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    2206           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    2207           23 :     }
    2208           23 :     std::string identifier = hcclComm->GetIdentifier();
    2209           23 :     AlgType nslbAlgType;
    2210           23 :     CHK_RET(hcclComm->GetAlgType(nslbAlgType, HcclCMDType::HCCL_CMD_BROADCAST));
    2211              : 
    2212           23 :     if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
    2213            0 :         AlgTypeLevel1 algValue = nslbAlgType.algoLevel1;
    2214            0 :         uint8_t nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel1AlgType(algValue);
    2215              :         DevType devType;
    2216            0 :         CHK_RET(hrtGetDeviceType(devType));
    2217            0 :         if (devType == DevType::DEV_TYPE_910_93) {
    2218            0 :             AlgTypeLevel2 algValue2 = nslbAlgType.algoLevel2;
    2219            0 :             nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel2AlgType(algValue2);
    2220              :         }
    2221              :         // NSLB 填充 表6
    2222            0 :         hcclNslbDp::GetInstance().SetNslbDpRootRank(HcclCMDType::HCCL_CMD_BROADCAST, root, identifier, nslbAlg);
    2223              :     }
    2224           23 :     return HCCL_SUCCESS;
    2225           24 : }
    2226              : 
    2227           30 : HcclResult HcclReduceScatterInner(void *sendBuf, void *recvBuf, uint64_t recvCount, HcclDataType dataType,
    2228              :                              HcclReduceOp op, HcclComm comm, aclrtStream stream)
    2229              : {    
    2230              :     // 入参合法性校验
    2231           30 :     CHK_PRT_RET(recvCount == 0, HCCL_WARNING("input recvCount is 0, return ReduceScatter success"), HCCL_SUCCESS);
    2232           29 :     RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2233              :         std::vector<std::string>({"HcclReduceScatterInner", "nullptr", "stream", "non-null pointer"}));
    2234           29 :     CHK_PTR_NULL(stream);
    2235           49 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2236              :         std::vector<std::string>({"HcclReduceScatterInner", "nullptr", "comm", "non-null pointer"}));
    2237           29 :     CHK_PTR_NULL(comm);
    2238           48 :     RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2239              :         std::vector<std::string>({"HcclReduceScatterInner", "nullptr", "sendBuf", "non-null pointer"}));
    2240           28 :     CHK_PTR_NULL(sendBuf);
    2241           47 :     RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2242              :         std::vector<std::string>({"HcclReduceScatterInner", "nullptr", "recvBuf", "non-null pointer"}));
    2243           27 :     CHK_PTR_NULL(recvBuf);
    2244              : 
    2245              :     // Group特性
    2246           26 :     if (hcclGroupDepth > 0) {
    2247              :         struct hcclOpInfo info;
    2248            1 :         info.coll = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    2249            1 :         info.sendbuff = sendBuf;
    2250            1 :         info.recvbuff = recvBuf;
    2251            1 :         info.recvCount = recvCount;
    2252            1 :         info.sendType = dataType;
    2253            1 :         info.recvType = dataType;
    2254            1 :         info.op = op;
    2255            1 :         info.comm = comm;
    2256            1 :         info.stream = stream;
    2257            1 :         CHK_RET(taskAppend(comm, info));
    2258            1 :         HCCL_INFO("[HcclReduceScatter] Finish taskAppend, count [%d] dataType [%s]", recvCount, GetDataTypeEnumStr(dataType).c_str());
    2259            1 :             return HCCL_SUCCESS;
    2260              :     }
    2261              : 
    2262           25 :     HcclUs startut = TIME_NOW();
    2263              :     bool isCapture;
    2264           25 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    2265           25 :     uint64_t modelId = 0xFFFFFFFF;
    2266           25 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    2267           25 :     if (!isCapture) {
    2268           24 :         HcclSetIfProfile();
    2269              :     }
    2270           25 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2271              : 
    2272              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    2273           25 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    2274              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2275              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    2276              :         CHK_PTR_NULL(commV2);
    2277              :         CHK_RET(HcclReduceScatterV2(sendBuf, recvBuf, recvCount, dataType, op, commV2, stream));
    2278              :         return HCCL_SUCCESS;
    2279              :     }());
    2280              : #endif
    2281           25 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2282           25 :     const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
    2283           25 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    2284           25 :     s32 threadID = SalGetTid();
    2285           25 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    2286              :     // 同通信域同算子复用tag
    2287           25 :     const string tag = "ReduceScatter_" + hcclComm->GetIdentifier();
    2288              : 
    2289           25 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), recvCount, dataType, stream), tag.c_str());
    2290              : 
    2291           72 :     CHK_RET_AND_PRINT_IDE(HcomCheckReductionOp("HcclReduceScatterInner", op), tag.c_str());
    2292              :     DevType devType;
    2293           24 :     CHK_RET(hrtGetDeviceType(devType));
    2294           24 :     CHK_RET_AND_PRINT_IDE(HcomCheckReduceDataType(dataType, op, devType), tag.c_str());
    2295              : 
    2296              :     /* 接口交互信息日志 */
    2297              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    2298           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    2299           23 :         s32 deviceLogicId = 0;
    2300           23 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    2301              : 
    2302           23 :         u32 localRank = INVALID_VALUE_RANKID;
    2303           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    2304              : 
    2305           23 :         s32 streamId = 0;
    2306           23 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    2307              : 
    2308           46 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    2309              :             "tag[%s], sendBuf[%p], recvBuf[%p], recvCount[%llu], dataType[%s], op[%s], "
    2310              :             "localRank[%u], streamId[%d], deviceLogicId[%d]",
    2311           69 :             tag.c_str(), sendBuf, recvBuf, recvCount, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
    2312              :             localRank, streamId, deviceLogicId);
    2313              : 
    2314           23 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    2315           46 :         std::string logInfo = "Entry-HcclReduceScatterInner:" + std::string(stackLogBuffer) +
    2316           69 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    2317           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    2318           23 :     }
    2319              : 
    2320           23 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    2321              : 
    2322           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
    2323              : 
    2324           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    2325              : 
    2326           23 :     CHK_RET_AND_PRINT_IDE(SetOverFlowAddr(hcclComm), tag.c_str());
    2327              : 
    2328           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->ReduceScatterOutPlace(tag, sendBuf, recvBuf, recvCount, dataType, op, stream),
    2329              :                           tag.c_str());
    2330           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_REDUCE_SCATTER, beginTime, recvCount,
    2331              :         dataType, tag));
    2332           23 :     if (!isCapture) {
    2333           22 :         HcclResetIfProfile();
    2334              :     }
    2335           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    2336              : 
    2337           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    2338           23 :         HcclUs endut = TIME_NOW();
    2339              :         /* 关键状态记录 */
    2340           23 :         std::string endInfo = "HcclReduceScatterInner:success,take time: " +
    2341           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    2342           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    2343           23 :     }
    2344              : 
    2345           23 :     return HCCL_SUCCESS;
    2346           25 : }
    2347              : 
    2348           34 : HcclResult HcclReduceScatterVInner(void *sendBuf, const void *sendCounts, const void *sendDispls,
    2349              :     void *recvBuf, uint64_t recvCount, HcclDataType dataType, HcclReduceOp op, HcclComm comm, aclrtStream stream)
    2350              : {
    2351              :     // 入参合法性校验
    2352           34 :     RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2353              :         std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "stream", "non-null pointer"}));
    2354           34 :     CHK_PTR_NULL(stream);
    2355           54 :     RPT_INPUT_ERR(sendCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2356              :         std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "sendCounts", "non-null pointer"}));
    2357           34 :     CHK_PTR_NULL(sendCounts);
    2358           53 :     RPT_INPUT_ERR(sendDispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2359              :         std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "sendDispls", "non-null pointer"}));
    2360           33 :     CHK_PTR_NULL(sendDispls);
    2361           52 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2362              :         std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "comm", "non-null pointer"}));
    2363           32 :     CHK_PTR_NULL(comm);
    2364           31 :     if (UNLIKELY(recvCount > 0 && recvBuf == nullptr)) {
    2365           21 :         RPT_INPUT_ERR(true, "EI0003",\
    2366              :         std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2367              :         std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "recvBuf", "non-null pointer"}));
    2368            1 :         CHK_PTR_NULL(recvBuf);
    2369              :     }
    2370              : 
    2371              :     // Group特性
    2372           30 :     if (hcclGroupDepth > 0) {
    2373              :         struct hcclOpInfo info;
    2374            1 :         info.coll = HcclCMDType::HCCL_CMD_REDUCE_SCATTER_V;
    2375            1 :         info.sendbuff = sendBuf;
    2376            1 :         info.recvbuff = recvBuf;
    2377            1 :         info.sendCounts = sendCounts;
    2378            1 :         info.sdispls = sendDispls;
    2379            1 :         info.recvCount = recvCount;
    2380            1 :         info.sendType = dataType;
    2381            1 :         info.recvType = dataType;
    2382            1 :         info.op = op;
    2383            1 :         info.comm = comm;
    2384            1 :         info.stream = stream;
    2385            1 :         CHK_RET(taskAppend(comm, info));
    2386            1 :         HCCL_INFO("[HcclReduceScatterV] Finish taskAppend, recvCount [%d] dataType [%s]", recvCount, GetDataTypeEnumStr(dataType).c_str());
    2387            1 :             return HCCL_SUCCESS;
    2388              :     }
    2389              : 
    2390           29 :     HcclUs startut = TIME_NOW();
    2391              :     bool isCapture;
    2392           29 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    2393           29 :     uint64_t modelId = 0xFFFFFFFF;
    2394           29 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    2395           29 :     if (!isCapture) {
    2396           28 :         HcclSetIfProfile();
    2397              :     }
    2398           29 :     s32 threadID = SalGetTid();
    2399           29 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    2400           29 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2401              : 
    2402              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    2403           29 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    2404              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2405              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    2406              :         CHK_PTR_NULL(commV2);
    2407              :         CHK_RET(HcclReduceScatterVV2(sendBuf, const_cast<void*>(sendCounts), const_cast<void*>(sendDispls), recvBuf, recvCount, dataType, op, commV2, stream));
    2408              :         return HCCL_SUCCESS;
    2409              :     }());
    2410              : #endif
    2411           29 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2412           29 :     const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
    2413              :     // 同通信域同算子复用tag
    2414           29 :     const string tag = "ReduceScatterV_" + hcclComm->GetIdentifier();
    2415              : 
    2416           29 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), recvCount, dataType, stream), tag.c_str());
    2417              : 
    2418           84 :     CHK_RET_AND_PRINT_IDE(HcomCheckReductionOp("HcclReduceScatterVInner", op), tag.c_str());
    2419              :     DevType devType;
    2420           28 :     CHK_RET(hrtGetDeviceType(devType));
    2421           28 :     CHK_RET_AND_PRINT_IDE(HcomCheckReduceDataType(dataType, op, devType), tag.c_str());
    2422              : 
    2423           27 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    2424           27 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
    2425           27 :     u32 userRank = INVALID_VALUE_RANKID;
    2426           27 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(userRank), tag.c_str());
    2427           27 :     CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, userRank), tag.c_str());
    2428              : 
    2429           27 :     u64 maxCount = 0;
    2430           27 :     u64 inputCount = 0;
    2431           27 :     u64* counts = static_cast<u64 *>(const_cast<void*>(sendCounts));
    2432           61 :     for (u32 i = 0; i < rankSize; i++) {
    2433           34 :         CHK_PRT_RET(counts[i] > SYS_MAX_COUNT,
    2434              :             HCCL_ERROR("HcclReduceScatterVInner sendCounts[%u][%llu] is invalid.(bigger than MAX count[%llu])",
    2435              :                 i, counts[i], SYS_MAX_COUNT),
    2436              :             HCCL_E_PARA);
    2437           34 :         inputCount += counts[i];
    2438           34 :         maxCount = std::max(maxCount, counts[i]);
    2439              :     }
    2440           27 :     CHK_PRT_RET(inputCount == 0, HCCL_WARNING("The inputCount is 0, this ReduceScatter v has no task to execute, "
    2441              :         "returning success."), HCCL_SUCCESS);
    2442           46 :     RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    2443              :         std::vector<std::string>({"HcclReduceScatterVInner", "nullptr", "sendBuf", "non-null pointer"}));
    2444           26 :     CHK_PTR_NULL(sendBuf);
    2445              : 
    2446              :     /* 接口交互信息日志 */
    2447              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    2448           25 :     if (GetExternalInputHcclEnableEntryLog()) {
    2449           25 :         s32 deviceLogicId = 0;
    2450           25 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    2451              : 
    2452           25 :         u32 localRank = INVALID_VALUE_RANKID;
    2453           25 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    2454              : 
    2455           25 :         s32 streamId = 0;
    2456           25 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    2457              : 
    2458           50 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    2459              :             "tag[%s], sendBuf[%p], recvBuf[%p], sendCounts[%p], sendDispls[%p], recvCount[%llu], dataType[%s], op[%s], "
    2460              :             "localRank[%u], streamId[%d], deviceLogicId[%d]",
    2461              :             tag.c_str(), sendBuf, recvBuf, sendCounts, sendDispls, recvCount,
    2462           75 :             GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(), localRank, streamId, deviceLogicId);
    2463              : 
    2464           25 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    2465           50 :         std::string logInfo = "Entry-HcclReduceScatterVInner:" + std::string(stackLogBuffer) +
    2466           75 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    2467           25 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    2468           25 :     }
    2469              : 
    2470           50 :     PrintCountsAndDispls(rankSize, sendCounts, sendDispls, tag.c_str());
    2471              : 
    2472           25 :     CheckCountsAndDispls(rankSize, sendCounts, sendDispls, tag.c_str());
    2473              : 
    2474           25 :     const u64 countOfThisRank = static_cast<const u64 *>(sendCounts)[userRank];
    2475           25 :     CHK_PRT_RET(recvCount != countOfThisRank,
    2476              :         HCCL_ERROR("[HcclReduceScatterVInner] input recvCount[%llu] is not equal to sendCounts[%u][%llu]", recvCount,
    2477              :         userRank, countOfThisRank),
    2478              :         HCCL_E_PARA);
    2479              : 
    2480           23 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    2481              : 
    2482           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
    2483              : 
    2484           23 :     if (recvBuf != nullptr) {
    2485           23 :         CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    2486              :     }
    2487              : 
    2488           23 :     CHK_RET_AND_PRINT_IDE(SetOverFlowAddr(hcclComm), tag.c_str());
    2489              : 
    2490           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->ReduceScatterVOutPlace(tag, sendBuf, recvBuf, sendCounts, sendDispls, recvCount,
    2491              :                         dataType, op, stream), tag.c_str());
    2492              : 
    2493           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_REDUCE_SCATTER_V, beginTime, maxCount,
    2494              :         dataType, tag));
    2495           23 :     if (!isCapture) {
    2496           22 :         HcclResetIfProfile();
    2497              :     }
    2498           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    2499              : 
    2500           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    2501           23 :         HcclUs endut = TIME_NOW();
    2502              :         /* 关键状态记录 */
    2503           23 :         std::string endInfo = "HcclReduceScatterVInner:success,take time: " +
    2504           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    2505           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    2506           23 :     }
    2507              : 
    2508           23 :     return HCCL_SUCCESS;
    2509           29 : }
    2510              : 
    2511           29 : HcclResult CheckScatterInputPara(HcclComm comm, void *recvBuf)
    2512              : {
    2513              :     // 入参合法性校验
    2514           49 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    2515              :         std::vector<std::string>({"HcclScatterInner", "nullptr", "comm", "non-null pointer"}));
    2516           29 :     CHK_PTR_NULL(comm);
    2517           48 :     RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    2518              :         std::vector<std::string>({"HcclScatterInner", "nullptr", "recvBuf", "non-null pointer"}));
    2519           28 :     CHK_PTR_NULL(recvBuf);
    2520              : 
    2521           27 :     return HCCL_SUCCESS;
    2522              : }
    2523              : 
    2524           30 : HcclResult HcclScatterInner(void *sendBuf, void *recvBuf, uint64_t recvCount, HcclDataType dataType, uint32_t root,
    2525              :     HcclComm comm, aclrtStream stream)
    2526              : {   
    2527              :     // 入参合法性校验
    2528           30 :     CHK_PRT_RET(recvCount == 0, HCCL_WARNING("input recvCount is 0, return scatter success"), HCCL_SUCCESS);
    2529           29 :     CHK_RET(CheckScatterInputPara(comm, recvBuf));
    2530           27 :     CHK_PTR_NULL(stream);
    2531              : 
    2532              :     // Group特性
    2533           27 :     if (hcclGroupDepth > 0) {
    2534              :         struct hcclOpInfo info;
    2535            1 :         info.coll = HcclCMDType::HCCL_CMD_SCATTER;
    2536            1 :         info.sendbuff = sendBuf;
    2537            1 :         info.recvbuff = recvBuf;
    2538            1 :         info.recvCount = recvCount;
    2539            1 :         info.sendType = dataType;
    2540            1 :         info.recvType = dataType;
    2541            1 :         info.root = root;
    2542            1 :         info.comm = comm;
    2543            1 :         info.stream = stream;
    2544            1 :         CHK_RET(taskAppend(comm, info));
    2545            1 :         HCCL_INFO("[HcclScatter] Finish taskAppend, recvCount [%d] dataType [%s]", recvCount, GetDataTypeEnumStr(dataType).c_str());
    2546            1 :             return HCCL_SUCCESS;
    2547              :     }
    2548              : 
    2549           26 :     HcclUs startut = TIME_NOW();
    2550              :     bool isCapture;
    2551           26 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    2552           26 :     uint64_t modelId = 0xFFFFFFFF;
    2553           26 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    2554           26 :     if (!isCapture) {
    2555           25 :         HcclSetIfProfile();
    2556              :     }
    2557           26 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2558              : 
    2559              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    2560           26 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    2561              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2562              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    2563              :         CHK_PTR_NULL(commV2);
    2564              :         CHK_RET(HcclScatterV2(sendBuf, recvBuf, recvCount, dataType, root, commV2, stream));
    2565              :         return HCCL_SUCCESS;
    2566              :     }());
    2567              : #endif
    2568           26 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2569           26 :     const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
    2570           26 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    2571           26 :     s32 threadID = SalGetTid();
    2572           26 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    2573           26 :     u32 commRank = INVALID_VALUE_RANKID;
    2574           26 :     CHK_RET(hcclComm->GetUserRank(commRank));
    2575           26 :     if (commRank == root) { // 本rank为root节点,send_buff不为空
    2576           45 :         RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    2577              :             std::vector<std::string>({"HcclScatterInner", "nullptr", "sendBuf", "non-null pointer"}));
    2578           25 :         CHK_PTR_NULL(sendBuf);
    2579              :     }
    2580              : 
    2581              :     // 同通信域同算子复用tag
    2582           25 :     const string tag = "Scatter_" + hcclComm->GetIdentifier();
    2583              : 
    2584           25 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), recvCount, dataType, stream), tag.c_str());
    2585              : 
    2586           24 :     HcomCollOpInfo opInfo = {"", sendBuf, recvBuf, recvCount, dataType, root};
    2587              : 
    2588           24 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    2589           24 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
    2590              : 
    2591           24 :     CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, root), tag.c_str());
    2592              : 
    2593              :     /* 接口交互信息日志 */
    2594              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    2595           24 :     if (GetExternalInputHcclEnableEntryLog()) {
    2596           24 :         s32 deviceLogicId = 0;
    2597           24 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    2598              : 
    2599           24 :         u32 localRank = INVALID_VALUE_RANKID;
    2600           24 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    2601              : 
    2602           24 :         s32 streamId = 0;
    2603           24 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    2604              : 
    2605           24 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    2606              :             "tag[%s], sendBuf[%p], recvBuf[%p], recvCount[%llu], dataType[%s], root[%u], localRank[%u], streamId[%d], deviceLogicId[%d]",
    2607           48 :             tag.c_str(), sendBuf, recvBuf, recvCount, GetDataTypeEnumStr(dataType).c_str(), root, localRank, streamId, deviceLogicId);
    2608              : 
    2609           24 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    2610           48 :         std::string logInfo = "Entry-HcclScatterInner:" + std::string(stackLogBuffer) +
    2611           72 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    2612           24 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    2613           24 :     }
    2614              : 
    2615           24 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    2616              : 
    2617           24 :     CHK_RET_AND_PRINT_IDE(hcclComm->CreateOpBasedResources(HcclCMDType::HCCL_CMD_SCATTER, tag, opInfo), tag.c_str());
    2618              : 
    2619           24 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    2620              : 
    2621           24 :     CHK_RET_AND_PRINT_IDE(hcclComm->ScatterOutPlace(tag, sendBuf, recvBuf, recvCount, dataType, root, stream),
    2622              :                           tag.c_str());
    2623              : 
    2624           24 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_SCATTER, beginTime, recvCount, dataType,
    2625              :         tag));
    2626           24 :     if (!isCapture) {
    2627           23 :         HcclResetIfProfile();
    2628              :     }
    2629           24 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    2630              : 
    2631           24 :     if (GetExternalInputHcclEnableEntryLog()) {
    2632           24 :         HcclUs endut = TIME_NOW();
    2633              :         /* 关键状态记录 */
    2634           24 :         std::string endInfo = "HcclScatterInner:success,take time: " +
    2635           48 :             std::to_string(DURATION_US(endut - startut).count()) + " us, tag: " + tag;
    2636           24 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    2637           24 :     }
    2638           24 :     std::string identifier = hcclComm->GetIdentifier();
    2639           24 :     AlgType algType;
    2640           24 :     CHK_RET(hcclComm->GetAlgType(algType, HcclCMDType::HCCL_CMD_SCATTER));
    2641              : 
    2642           24 :     if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
    2643              :         DevType nslb_devType;
    2644            0 :         CHK_RET(hrtGetDeviceType(nslb_devType));
    2645            0 :         AlgTypeLevel1 algValue = algType.algoLevel1;
    2646            0 :         uint8_t nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel1AlgType(algValue);
    2647            0 :         if (nslb_devType == DevType::DEV_TYPE_910_93) {
    2648            0 :             AlgTypeLevel2 algValue2 = algType.algoLevel2;
    2649            0 :             nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel2AlgType(algValue2);
    2650              :         }
    2651              :         // NSLB 填充 表6
    2652            0 :         hcclNslbDp::GetInstance().SetNslbDpRootRank(HcclCMDType::HCCL_CMD_SCATTER, root, identifier, nslbAlg);
    2653              :     }
    2654           24 :     return HCCL_SUCCESS;
    2655           26 : }
    2656              : 
    2657           29 : HcclResult HcclAllGatherInner(void *sendBuf, void *recvBuf, uint64_t sendCount, HcclDataType dataType,
    2658              :                          HcclComm comm, aclrtStream stream)
    2659              : {
    2660              :     // 入参合法性校验
    2661           29 :     CHK_PRT_RET(sendCount == 0, HCCL_WARNING("input sendCount is 0, return HcclAllGatherInner success"), HCCL_SUCCESS);
    2662           48 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2663              :         std::vector<std::string>({"HcclAllGatherInner", "nullptr", "comm", "non-null pointer"}));
    2664           28 :     CHK_PTR_NULL(comm);
    2665           47 :     RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2666              :         std::vector<std::string>({"HcclAllGatherInner", "nullptr", "sendBuf", "non-null pointer"}));
    2667           27 :     CHK_PTR_NULL(sendBuf);
    2668           46 :     RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2669              :         std::vector<std::string>({"HcclAllGatherInner", "nullptr", "recvBuf", "non-null pointer"}));
    2670           26 :     CHK_PTR_NULL(recvBuf);
    2671           25 :     RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2672              :         std::vector<std::string>({"HcclAllGatherInner", "nullptr", "stream", "non-null pointer"}));
    2673           25 :     CHK_PTR_NULL(stream);
    2674              : 
    2675              :     // Group特性
    2676           25 :     if (hcclGroupDepth > 0) {
    2677              :         struct hcclOpInfo info;
    2678            1 :         info.coll = HcclCMDType::HCCL_CMD_ALLGATHER;
    2679            1 :         info.sendbuff = sendBuf;
    2680            1 :         info.recvbuff = recvBuf;
    2681            1 :         info.sendCount = sendCount;
    2682            1 :         info.sendType = dataType;
    2683            1 :         info.recvType = dataType;
    2684            1 :         info.comm = comm;
    2685            1 :         info.stream = stream;
    2686            1 :         CHK_RET(taskAppend(comm, info));
    2687            1 :         HCCL_INFO("[HcclAllGather] Finish taskAppend, sendCount [%d] dataType [%s]", sendCount, GetDataTypeEnumStr(dataType).c_str());
    2688            1 :             return HCCL_SUCCESS;
    2689              :     }
    2690              : 
    2691           24 :     HcclUs startut = TIME_NOW();
    2692              :     bool isCapture;
    2693           24 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    2694           24 :     uint64_t modelId = 0xFFFFFFFF;
    2695           24 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    2696           24 :     if (!isCapture) {
    2697           23 :         HcclSetIfProfile();
    2698              :     }
    2699           24 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2700              : 
    2701              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    2702           24 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    2703              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2704              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    2705              :         CHK_PTR_NULL(commV2);
    2706              :         CHK_RET(HcclAllGatherV2(sendBuf, recvBuf, sendCount, dataType, commV2, stream));
    2707              :         return HCCL_SUCCESS;
    2708              :     }());
    2709              : #endif
    2710           24 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2711           24 :     const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
    2712           24 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    2713           24 :     s32 threadID = SalGetTid();
    2714           24 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    2715              :     // 同通信域同算子复用tag
    2716           24 :     const std::string tag = "AllGather_" + hcclComm->GetIdentifier();
    2717           24 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), sendCount, dataType, stream), tag.c_str());
    2718              : 
    2719              :     /* 接口交互信息日志 */
    2720              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    2721           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    2722           23 :         s32 deviceLogicId = 0;
    2723           23 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    2724              : 
    2725           23 :         u32 localRank = INVALID_VALUE_RANKID;
    2726           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    2727              : 
    2728           23 :         s32 streamId = 0;
    2729           23 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    2730              : 
    2731           23 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    2732              :             "tag[%s], sendBuf[%p], recvBuf[%p], sendCount[%llu], dataType[%s], localRank[%u], streamId[%d], "
    2733              :             "deviceLogicId[%d]",
    2734           46 :             tag.c_str(), sendBuf, recvBuf, sendCount, GetDataTypeEnumStr(dataType).c_str(), localRank, streamId, deviceLogicId);
    2735              : 
    2736           23 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    2737           46 :         std::string logInfo = "Entry-HcclAllGatherInner:" + std::string(stackLogBuffer) +
    2738           69 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    2739           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    2740           23 :     }
    2741              : 
    2742           23 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    2743              : 
    2744           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
    2745              : 
    2746           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    2747              : 
    2748           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->AllGatherOutPlace(tag, sendBuf, recvBuf, sendCount, dataType, stream), tag.c_str());
    2749           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLGATHER, beginTime, sendCount, dataType,
    2750              :         tag));
    2751           23 :     if (!isCapture) {
    2752           22 :         HcclResetIfProfile();
    2753              :     }
    2754           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    2755              : 
    2756           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    2757           23 :         HcclUs endut = TIME_NOW();
    2758              :         /* 关键状态记录 */
    2759           23 :         std::string endInfo = "HcclAllGatherInner:success,take time: " +
    2760           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    2761           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    2762           23 :     }
    2763              : 
    2764           23 :     return HCCL_SUCCESS;
    2765           24 : }
    2766              : 
    2767           33 : HcclResult HcclAllGatherVInner(void *sendBuf, uint64_t sendCount, void *recvBuf,
    2768              :     const void *recvCounts, const void *recvDispls, HcclDataType dataType, HcclComm comm, aclrtStream stream)
    2769              : {
    2770              :     // 入参合法性校验
    2771           53 :     RPT_INPUT_ERR(recvCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2772              :         std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "recvCounts", "non-null pointer"}));
    2773           33 :     CHK_PTR_NULL(recvCounts);
    2774           52 :     RPT_INPUT_ERR(recvDispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2775              :         std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "recvDispls", "non-null pointer"}));
    2776           32 :     CHK_PTR_NULL(recvDispls);
    2777           51 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2778              :         std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "comm", "non-null pointer"}));
    2779           31 :     CHK_PTR_NULL(comm);
    2780           30 :     RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2781              :         std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "stream", "non-null pointer"}));
    2782           30 :     CHK_PTR_NULL(stream);
    2783           30 :     if (UNLIKELY(sendCount > 0 && sendBuf == nullptr)) {
    2784           21 :             RPT_INPUT_ERR(true, "EI0003",\
    2785              :             std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    2786              :             std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "sendBuf", "non-null pointer"}));
    2787            1 :             CHK_PTR_NULL(sendBuf);
    2788              :     }
    2789              : 
    2790              :     // Group特性
    2791           29 :     if (hcclGroupDepth > 0) {
    2792              :         struct hcclOpInfo info;
    2793            1 :         info.coll = HcclCMDType::HCCL_CMD_ALLGATHER_V;
    2794            1 :         info.sendbuff = sendBuf;
    2795            1 :         info.recvbuff = recvBuf;
    2796            1 :         info.sendCount = sendCount;
    2797            1 :         info.recvCounts = recvCounts;
    2798            1 :         info.rdispls = recvDispls;
    2799            1 :         info.sendType = dataType;
    2800            1 :         info.recvType = dataType;
    2801            1 :         info.comm = comm;
    2802            1 :         info.stream = stream;
    2803            1 :         CHK_RET(taskAppend(comm, info));
    2804            1 :         HCCL_INFO("[HcclAllGatherV] Finish taskAppend, sendCount [%d] dataType [%s]", sendCount, GetDataTypeEnumStr(dataType).c_str());
    2805            1 :             return HCCL_SUCCESS;
    2806              :     }
    2807              : 
    2808           28 :     HcclUs startut = TIME_NOW();
    2809              :     bool isCapture;
    2810           28 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    2811           28 :     uint64_t modelId = 0xFFFFFFFF;
    2812           28 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    2813           28 :     if (!isCapture) {
    2814           27 :         HcclSetIfProfile();
    2815              :     }
    2816           28 :     s32 threadID = SalGetTid();
    2817           28 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    2818           28 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2819              : 
    2820              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    2821           28 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    2822              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2823              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    2824              :         CHK_PTR_NULL(commV2);
    2825              :         CHK_RET(HcclAllGatherVV2(sendBuf, sendCount, recvBuf, const_cast<void*>(recvCounts), const_cast<void*>(recvDispls), dataType, commV2, stream));
    2826              :         return HCCL_SUCCESS;
    2827              :     }());
    2828              : #endif
    2829           28 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2830           28 :     const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
    2831              :     // 同通信域同算子复用tag
    2832           28 :     const std::string tag = "AllGatherV_" + hcclComm->GetIdentifier();
    2833           28 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), sendCount, dataType, stream), tag.c_str());
    2834              : 
    2835           27 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    2836           27 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
    2837           27 :     u32 userRank = INVALID_VALUE_RANKID;
    2838           27 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(userRank), tag.c_str());
    2839           27 :     CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, userRank), tag.c_str());
    2840              : 
    2841           27 :     u64 maxCount = 0;
    2842           27 :     u64 outputCount = 0;
    2843           27 :     u64* counts = static_cast<u64 *>(const_cast<void*>(recvCounts));
    2844           61 :     for (u32 i = 0; i < rankSize; i++) {
    2845           34 :         CHK_PRT_RET(counts[i] > SYS_MAX_COUNT,
    2846              :             HCCL_ERROR("HcclAllGatherVInner recvCounts[%u][%llu] is invalid.(bigger than MAX count[%llu])",
    2847              :                 i, counts[i], SYS_MAX_COUNT),
    2848              :             HCCL_E_PARA);
    2849           34 :         outputCount += counts[i];
    2850           34 :         maxCount = std::max(maxCount, counts[i]);
    2851              :     }
    2852           27 :     CHK_PRT_RET(outputCount == 0, HCCL_WARNING("The outputCount is 0, this AllGatherV has no task to execute, "
    2853              :         "returning success."), HCCL_SUCCESS);
    2854           46 :     RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    2855              :         std::vector<std::string>({"HcclAllGatherVInner", "nullptr", "recvBuf", "non-null pointer"}));
    2856           26 :     CHK_PTR_NULL(recvBuf);
    2857              : 
    2858              :     /* 接口交互信息日志 */
    2859              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    2860           25 :     if (GetExternalInputHcclEnableEntryLog()) {
    2861           25 :         u32 localRank = INVALID_VALUE_RANKID;
    2862           25 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    2863              : 
    2864           25 :         s32 streamId = 0;
    2865           25 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    2866              : 
    2867           25 :         s32 deviceLogicId = 0;
    2868           25 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    2869              : 
    2870           25 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    2871              :             "tag[%s], sendBuf[%p], recvBuf[%p], sendCount[%llu], recvCounts[%u], recvDispls[%u], "
    2872              :             "dataType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
    2873              :             tag.c_str(), sendBuf, recvBuf, sendCount, recvCounts, recvDispls,
    2874           50 :             GetDataTypeEnumStr(dataType).c_str(), localRank, streamId, deviceLogicId);
    2875              : 
    2876           25 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    2877           50 :         std::string logInfo = "Entry-HcclAllGatherVInner:" + std::string(stackLogBuffer) +
    2878           75 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    2879           25 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    2880           25 :     }
    2881              : 
    2882           50 :     PrintCountsAndDispls(rankSize, recvCounts, recvDispls, tag.c_str());
    2883              : 
    2884           25 :     CheckCountsAndDispls(rankSize, recvCounts, recvDispls, tag.c_str());
    2885              : 
    2886           25 :     const u64 countOfThisRank = static_cast<const u64*>(recvCounts)[userRank];
    2887           25 :     CHK_PRT_RET(sendCount != countOfThisRank,
    2888              :         HCCL_ERROR("[HcclAllGatherVInner] input sendCount[%llu] is not equal to recvCounts[%u][%llu]", sendCount,
    2889              :         userRank, countOfThisRank),
    2890              :         HCCL_E_PARA);
    2891              : 
    2892           23 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    2893              : 
    2894           23 :     if(sendBuf != nullptr) {
    2895           23 :         CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
    2896              :     }
    2897              : 
    2898           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    2899              : 
    2900           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->AllGatherVOutPlace(tag, sendBuf, recvBuf, sendCount, recvCounts, recvDispls,
    2901              :         dataType, stream), tag.c_str());
    2902              : 
    2903           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLGATHER_V, beginTime, maxCount, dataType, tag));
    2904           23 :     if (!isCapture) {
    2905           22 :         HcclResetIfProfile();
    2906              :     }
    2907           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    2908              : 
    2909           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    2910           23 :         HcclUs endut = TIME_NOW();
    2911              :         /* 关键状态记录 */
    2912           23 :         std::string endInfo = "HcclAllGatherVInner:success,take time: " +
    2913           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    2914           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    2915           23 :     }
    2916              : 
    2917           23 :     return HCCL_SUCCESS;
    2918           28 : }
    2919              : 
    2920           28 : HcclResult HcclSendInner(void* sendBuf, uint64_t count, HcclDataType dataType, uint32_t destRank,
    2921              :                     HcclComm comm, aclrtStream stream)
    2922              : {
    2923              :     // 入参合法性校验
    2924           28 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return HcclSendInner success."), HCCL_SUCCESS);
    2925           27 :     CHK_PTR_NULL(comm);
    2926           26 :     CHK_PTR_NULL(sendBuf);
    2927           25 :     CHK_PTR_NULL(stream);
    2928           25 :     CHK_RET(HcomCheckCount(count));
    2929              : 
    2930              :     // Group特性
    2931           25 :     if (hcclGroupDepth > 0) {
    2932            1 :         HCCL_INFO("[HcclSendInner] groupDepth[%d]", hcclGroupDepth);
    2933              :         struct hcclOpInfo info;
    2934            1 :         info.coll = HcclCMDType::HCCL_CMD_SEND;
    2935            1 :         info.sendbuff = sendBuf;
    2936            1 :         info.sendCount = count;
    2937            1 :         info.sendType = dataType;
    2938            1 :         info.root = destRank;
    2939            1 :         info.comm = comm;
    2940            1 :         info.stream = stream;
    2941            1 :         CHK_RET(taskAppend(comm, info));
    2942            1 :         HCCL_INFO("[HcclSend] Finish taskAppend, count [%lld] dataType [%s] destRank [%u]", count, GetDataTypeEnumStr(dataType).c_str(), destRank);
    2943            1 :         return HCCL_SUCCESS;
    2944              :     }
    2945              : 
    2946           24 :     HcclUs startut = TIME_NOW();
    2947              :     bool isCapture;
    2948           24 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    2949           24 :     uint64_t modelId = 0xFFFFFFFF;
    2950           24 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    2951           24 :     if (!isCapture) {
    2952           23 :         HcclSetIfProfile();
    2953              :     }
    2954           24 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    2955              : 
    2956              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    2957           24 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    2958              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2959              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    2960              :         CHK_PTR_NULL(commV2);
    2961              :         CHK_RET(HcclSendV2(sendBuf, count, dataType, destRank, commV2, stream));
    2962              :         return HCCL_SUCCESS;
    2963              :     }());
    2964              : #endif
    2965           24 :     CHK_RET(HcomCheckDataType(dataType));
    2966           24 :     s32 streamId = 0;
    2967           24 :     CHK_RET(hrtGetStreamId(stream, streamId));
    2968              : 
    2969           24 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    2970           24 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    2971           24 :     s32 threadID = SalGetTid();
    2972           24 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    2973              :     // 同算子复用tag,为实现通信域复用,根据srRank和dstRank构造Tag
    2974           24 :     u32 localRank = INVALID_VALUE_RANKID;
    2975           24 :     CHK_RET(hcclComm->GetGroupRank(localRank));
    2976              : 
    2977           48 :     const string tag = "worldCommSendRecv_" + std::to_string(localRank) + "_" + std::to_string(destRank) + "_" +
    2978           72 :         hcclComm->GetIdentifier();
    2979              : 
    2980           24 :     HcomCollOpInfo opInfo = {"", sendBuf, sendBuf, count, dataType, 0, HCCL_REDUCE_RESERVED};
    2981              :     /* 接口交互信息日志 */
    2982              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    2983           24 :     if (GetExternalInputHcclEnableEntryLog()) {
    2984           24 :         s32 deviceLogicId = 0;
    2985           24 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    2986              : 
    2987           24 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    2988              :             "tag[%s], sendBuf[%p], count[%llu], dataType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
    2989           48 :             tag.c_str(), sendBuf, count, GetDataTypeEnumStr(dataType).c_str(), localRank, streamId, deviceLogicId);
    2990              : 
    2991           24 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    2992           48 :         std::string logInfo = "Entry-HcclSendInner:" + std::string(stackLogBuffer) +
    2993           72 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    2994           24 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    2995           24 :     }
    2996              : 
    2997           24 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    2998              : 
    2999           24 :     CHK_RET_AND_PRINT_IDE(hcclComm->CreateOpBasedResources(HcclCMDType::HCCL_CMD_SEND, tag, opInfo), tag.c_str());
    3000              : 
    3001           24 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
    3002              : 
    3003           24 :     CHK_RET_AND_PRINT_IDE(hcclComm->SendOutPlace(tag, sendBuf, count, dataType, destRank, stream), tag.c_str());
    3004           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_SEND, beginTime, count, dataType, tag));
    3005           23 :     if (!isCapture) {
    3006           22 :         HcclResetIfProfile();
    3007              :     }
    3008           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    3009              : 
    3010           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    3011           23 :         HcclUs endut = TIME_NOW();
    3012              :         /* 关键状态记录 */
    3013           23 :         std::string endInfo = "HcclSendInner:success,take time: " +
    3014           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    3015           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    3016           23 :     }
    3017              : 
    3018           23 :     return HCCL_SUCCESS;
    3019           24 : }
    3020              : 
    3021           28 : HcclResult HcclRecvInner(void* recvBuf, uint64_t count, HcclDataType dataType, uint32_t srcRank,
    3022              :                     HcclComm comm, aclrtStream stream)
    3023              : {
    3024              :     // 入参合法性校验
    3025           28 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return HcclRecvInner success."), HCCL_SUCCESS);
    3026           27 :     CHK_PTR_NULL(comm);
    3027           26 :     CHK_PTR_NULL(recvBuf);
    3028           25 :     CHK_PTR_NULL(stream);
    3029           25 :     CHK_RET(HcomCheckCount(count));
    3030              : 
    3031              :     // Group特性
    3032           25 :     if (hcclGroupDepth > 0) {
    3033            1 :         HCCL_INFO("[HcclRecvInner] groupDepth[%d]", hcclGroupDepth);
    3034              :         struct hcclOpInfo info;
    3035            1 :         info.coll = HcclCMDType::HCCL_CMD_RECEIVE;
    3036            1 :         info.recvbuff = recvBuf;
    3037            1 :         info.recvCount = count;
    3038            1 :         info.recvType = dataType;
    3039            1 :         info.root = srcRank;
    3040            1 :         info.comm = comm;
    3041            1 :         info.stream = stream;
    3042            1 :         CHK_RET(taskAppend(comm, info));
    3043            1 :         HCCL_INFO("[HcclRecv] Finish taskAppend, count [%d] dataType [%s] srcRank [%u]", count, GetDataTypeEnumStr(dataType).c_str(), srcRank);
    3044            1 :             return HCCL_SUCCESS;
    3045              :     }
    3046              : 
    3047           24 :     HcclUs startut = TIME_NOW();
    3048              :     bool isCapture;
    3049           24 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    3050           24 :     uint64_t modelId = 0xFFFFFFFF;
    3051           24 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    3052           24 :     if (!isCapture) {
    3053           23 :         HcclSetIfProfile();
    3054              :     }
    3055           24 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    3056              : 
    3057              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    3058           24 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    3059              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3060              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    3061              :         CHK_PTR_NULL(commV2);
    3062              :         CHK_RET(HcclRecvV2(recvBuf, count, dataType, srcRank, commV2, stream));
    3063              :         return HCCL_SUCCESS;
    3064              :     }());
    3065              : #endif
    3066           24 :     CHK_RET(HcomCheckDataType(dataType));
    3067           24 :     s32 streamId = 0;
    3068           24 :     CHK_RET(hrtGetStreamId(stream, streamId));
    3069              : 
    3070           24 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3071           24 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    3072           24 :     s32 threadID = SalGetTid();
    3073           24 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    3074              :     // 同算子复用tag,为实现通信域复用,根据srRank和dstRank构造Tag
    3075           24 :     u32 localRank = INVALID_VALUE_RANKID;
    3076           24 :     CHK_RET(hcclComm->GetGroupRank(localRank));
    3077              : 
    3078           48 :     const string tag = "worldCommSendRecv_" + std::to_string(srcRank) + "_" + std::to_string(localRank) + "_" +
    3079           72 :         hcclComm->GetIdentifier();
    3080              : 
    3081           24 :     HcomCollOpInfo opInfo = {"", recvBuf, recvBuf, count, dataType, 0, HCCL_REDUCE_RESERVED};
    3082              :     /* 接口交互信息日志 */
    3083              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    3084           24 :     if (GetExternalInputHcclEnableEntryLog()) {
    3085           24 :         s32 deviceLogicId = 0;
    3086           24 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    3087              : 
    3088           24 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    3089              :             "tag[%s], recvBuf[%p], count[%llu], dataType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
    3090           48 :             tag.c_str(), recvBuf, count, GetDataTypeEnumStr(dataType).c_str(), localRank, streamId, deviceLogicId);
    3091              : 
    3092           24 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    3093           48 :         std::string logInfo = "Entry-HcclRecvInner:" + std::string(stackLogBuffer) +
    3094           72 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    3095           24 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    3096           24 :     }
    3097              : 
    3098           24 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    3099              : 
    3100           24 :     CHK_RET_AND_PRINT_IDE(hcclComm->CreateOpBasedResources(HcclCMDType::HCCL_CMD_RECEIVE, tag, opInfo), tag.c_str());
    3101              : 
    3102           24 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    3103              : 
    3104           24 :     CHK_RET_AND_PRINT_IDE(hcclComm->ReceiveOutPlace(tag, recvBuf, count, dataType, srcRank, stream), tag.c_str());
    3105           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_RECEIVE, beginTime, count, dataType, tag));
    3106           23 :     if (!isCapture) {
    3107           22 :         HcclResetIfProfile();
    3108              :     }
    3109           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    3110              : 
    3111           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    3112           23 :         HcclUs endut = TIME_NOW();
    3113              :         /* 关键状态记录 */
    3114           23 :         std::string endInfo = "HcclRecvInner:success,take time: " +
    3115           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    3116           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    3117           23 :     }
    3118              : 
    3119           23 :     return HCCL_SUCCESS;
    3120           24 : }
    3121              : 
    3122            0 : HcclResult HcclOneSidedCommDestroy(HcclComm comm, s32 deviceLogicId, HcclUs startut)
    3123              : {
    3124            0 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    3125            0 :     std::string group = hcclComm->GetIdentifier();
    3126            0 :     CHK_PRT_RET(group.empty(),
    3127              :                 HCCL_ERROR("[HcclCommDestroy][HcclOneSidedCommDestroy] commName is error."),
    3128              :                 HCCL_E_PARA);
    3129            0 :     HCCL_RUN_INFO("Entry-%s: deviceLogicId[%d], commName[%s]",
    3130              :                   __func__, deviceLogicId, group.c_str());
    3131              : 
    3132              :     #if (!defined(HCCD)) && (!defined(CCL_KERNEL_AICPU))
    3133            0 :     HcclResult ret = hcclComm->DeinitOneSidedService();
    3134            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    3135              :                 HCCL_ERROR("[HcclCommDestroy][HcclOneSidedCommDestroy] Deinit one sided service"
    3136              :                 " failed, commName[%s].", group.c_str()),
    3137              :                 ret);
    3138              :     #endif
    3139              : 
    3140            0 :     HcclOpInfoCtx &opBaseHcom = GetOneSidedOpInfoCtx(deviceLogicId, hcclComm->GetIdentifier());
    3141              : 
    3142            0 :     g_oneSidedCommSet.erase(comm);
    3143            0 :     DeleteOneSidedIdentifier(group);
    3144              : 
    3145            0 :     std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
    3146            0 :     auto iter = opBaseHcom.opGroup2CommMap.find(group);
    3147            0 :     if (iter != opBaseHcom.opGroup2CommMap.end()) {
    3148            0 :         EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
    3149            0 :         HcclCloseCommConnections(group);
    3150              :     } else {
    3151            0 :         HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(),
    3152              :             deviceLogicId);
    3153            0 :         return HCCL_E_PARA;
    3154              :     }
    3155              : 
    3156            0 :     opBaseHcom.isUsed = false;
    3157            0 :     CHK_RET(DeInitOneSidedHcomInfo(deviceLogicId, group));
    3158              : 
    3159            0 :     HcclUs endut = TIME_NOW();
    3160              :     /* 关键状态记录 */
    3161            0 :     HCCL_USER_CRITICAL_LOG("op_base comm destroy complete, take time [%lld]us, group[%s], deviceLogicId[%d]",
    3162              :         DURATION_US(endut - startut), group.c_str(), deviceLogicId);
    3163              : 
    3164            0 :     return HCCL_SUCCESS;
    3165            0 : }
    3166              : 
    3167          235 : static HcclResult ResetDevice(hccl::hcclComm* hcclComm)
    3168              : {
    3169          235 :     s32 logicDeviceId = 0;
    3170          235 :     CHK_RET(hcclComm->GetDeviceId(logicDeviceId));
    3171          234 :     g_hcclDeviceId = logicDeviceId;
    3172          234 :     if (hcclComm->IsNeedResetDevice()) {
    3173            0 :         HCCL_RUN_INFO("op_base com destroy, com is not global com");
    3174            0 :         HCCL_RUN_INFO("[HcclCommDestroy] reset logicDeviceId[%d]", logicDeviceId);
    3175            0 :         CHK_PRT_RET(hrtResetDevice(logicDeviceId) != HCCL_SUCCESS,
    3176              :             HCCL_ERROR("[HcclCommDestroy] reset fail logicDeviceId[%d]", logicDeviceId), HCCL_E_INTERNAL);
    3177              :     }
    3178          234 :     return HCCL_SUCCESS;
    3179              : }
    3180              : 
    3181            0 : HcclResult HcclCommDestroyWrapper(struct hcclAsyncJob* job_){
    3182            0 :     struct hcclCommDestroyAsyncJob* job = static_cast<hcclCommDestroyAsyncJob*>(job_);
    3183            0 :     HcclComm comm = job->initComm;
    3184            0 :     s32 devId = job->devId;
    3185            0 :     HCCL_DEBUG("[HcclCommDestroyWrapper] Set device devId: %d", devId);
    3186            0 :     CHK_PRT_RET(hrtSetDevice(devId) != HCCL_SUCCESS,
    3187              :         HCCL_ERROR("[HcclCommDestroyWrapper] set fail"), HCCL_E_INTERNAL);
    3188            0 :     HCCL_DEBUG("[HcclCommDestroyWrapper] Done Set device devId: %d", devId);
    3189              :  
    3190            0 :     HCCL_RUN_INFO("Entry-%s: op_base comm destroy begin", __func__);
    3191              :  
    3192            0 :     HcclUs startut = TIME_NOW();
    3193            0 :     s32 deviceLogicId = 0;
    3194            0 :     HcclResult ret = HcclDeviceRefresh(deviceLogicId);
    3195            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclCommDestroy] Get device fail, comm=%p", comm), ret);
    3196            0 :     CHK_PRT_RET(comm == nullptr, HCCL_WARNING("[Destroy][HcclComm]An empty comm given, skip destroy."), HCCL_SUCCESS);
    3197              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    3198            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    3199              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3200              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    3201              :         CHK_PTR_NULL(commV2);
    3202              :         CHK_RET(HcclCommDestroyV2(commV2)); // 临时处理,dpustream的销毁要在其他资源销毁前完成。待新方案CpuThread上库后,原dpuStream删除可以恢复顺序
    3203              :         string group = hcclComm->GetIdentifier();
    3204              :         HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
    3205              :         std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
    3206              :         auto iter = opBaseHcom.opGroup2CommMap.find(group);
    3207              :         if (iter != opBaseHcom.opGroup2CommMap.end()) {
    3208              :             EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
    3209              :         } else {
    3210              :             HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(), deviceLogicId);
    3211              :             return HCCL_E_PARA;
    3212              :         }
    3213              :         return HCCL_SUCCESS;
    3214              :     }());
    3215              : #endif
    3216            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3217            0 :     HcclCommState state = hcclComm->GetState();
    3218            0 :     if (state == HcclCommState::INUSE) {
    3219            0 :         HCCL_WARNING("[HcclCommDestroy] comm is in use, please try again later");
    3220            0 :         return HCCL_E_AGAIN;
    3221              :     }
    3222            0 :     hcclComm->DeinitZeroCopyMemoryAgent();
    3223            0 :     HCCL_RUN_INFO("[HcclCommDestroy] comm state is %s", HcclCommStateToString(state));
    3224              :  
    3225            0 :     CHK_RET(hcclComm->SetStopFlag(true));
    3226            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
    3227            0 :     CHK_RET(ResetDevice(hcclComm));
    3228              :  
    3229            0 :     if (IsOneSidedComm(comm)) {
    3230            0 :         return HcclOneSidedCommDestroy(comm, deviceLogicId, startut);
    3231              :     }
    3232              :  
    3233            0 :     HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
    3234            0 :     string group;
    3235            0 :     if (comm == opBaseHcom.pComm.get()) {
    3236            0 :         group = opBaseHcom.pComm->GetIdentifier();
    3237            0 :         opBaseHcom.pComm = nullptr;
    3238            0 :         HcclCloseCommConnections(group);
    3239              :     } else {
    3240            0 :         HCCL_RUN_INFO("com is not global com");
    3241            0 :         group = hcclComm->GetIdentifier();
    3242              :     }
    3243              :  
    3244              :     // 特殊场景,当comm name被手动配置为HCCL_WORLD_GROUP时,需要将hcomInfo.pComm设为nullptr
    3245            0 :     if (hcclComm->GetIdentifier() == HCCL_WORLD_GROUP) {
    3246            0 :         HcomGetCtxHomInfo().pComm = nullptr;
    3247              :     }
    3248              :  
    3249            0 :     HcomUnSetGroupTopoInfo(group.c_str());
    3250              :  
    3251            0 :     std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
    3252            0 :     auto iter = opBaseHcom.opGroup2CommMap.find(group);
    3253            0 :     if (iter != opBaseHcom.opGroup2CommMap.end()) {
    3254            0 :         EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
    3255            0 :         HcclCloseCommConnections(group);
    3256              :     } else {
    3257            0 :         HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(), deviceLogicId);
    3258            0 :         return HCCL_E_PARA;
    3259              :     }
    3260              :  
    3261            0 :     if (ProfilingManagerPub::GetAllState()) {
    3262            0 :         ProfilingManagerPub::ClearStoragedProfilingInfo();
    3263              :     }
    3264              :  
    3265            0 :     HcclUs endut = TIME_NOW();
    3266              :  
    3267              :     // 删除groupName和UDI的映射
    3268            0 :     HCCL_PROFILER_DEL_GROUP_UDI(group);
    3269              :  
    3270              :     /* 关键状态记录 */
    3271            0 :     HCCL_RUN_INFO("op_base comm destroy complete, take time [%lld]us, group[%s], deviceLogicId[%d].",
    3272              :         DURATION_US(endut - startut), group.c_str(), deviceLogicId);
    3273            0 :     return HCCL_SUCCESS;
    3274            0 : }
    3275              : 
    3276          303 : HcclResult HcclCommDestroy(HcclComm comm)
    3277              : {
    3278          303 :     if(hcclGroupDepth > 0){
    3279            0 :         std::shared_ptr<struct hcclCommDestroyAsyncJob> job;
    3280            0 :         EXCEPTION_CATCH((job = std::make_shared<struct hcclCommDestroyAsyncJob>()), return HCCL_E_PARA);
    3281            0 :         job->initComm = comm;
    3282            0 :         s32 devId = 0;
    3283            0 :         HcclResult ret = HcclDeviceRefresh(devId);
    3284            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Group][HcclCommDestroy] Get device fail, comm=%p", comm), ret);
    3285            0 :         job->devId = devId;
    3286            0 :         ret = commInitTaskAppend(job, HcclCommDestroyWrapper, &comm);
    3287            0 :         return ret;
    3288            0 :     }
    3289          303 :     HCCL_RUN_INFO("Entry-%s: op_base comm destroy begin", __func__);
    3290              : 
    3291          303 :     HcclUs startut = TIME_NOW();
    3292          303 :     s32 deviceLogicId = 0;
    3293          303 :     HcclResult ret = HcclDeviceRefresh(deviceLogicId);
    3294          303 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclCommDestroy] Get device fail, comm=%p", comm), ret);
    3295          302 :     CHK_PRT_RET(comm == nullptr, HCCL_WARNING("[Destroy][HcclComm]An empty comm given, skip destroy."), HCCL_SUCCESS);
    3296              :     
    3297              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    3298          235 :     HCCLV2_FUNC_RUN(
    3299              :         [&]() -> HcclResult {
    3300              :             hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3301              :             // 先拷贝orion通信域地址,避免coll comm销毁后无法获取
    3302              :             HcclComm commV2 = hcclComm->GetCommunicatorV2();
    3303              :             CHK_RET(HcclCommDestroyV2(commV2)); // 临时处理,dpustream的销毁要在其他资源销毁前完成。待新方案CpuThread上库后,原dpuStream删除可以恢复顺序
    3304              :             string group = hcclComm->GetIdentifier();
    3305              :             HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
    3306              :             std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
    3307              :             auto iter = opBaseHcom.opGroup2CommMap.find(group);
    3308              :             if (iter != opBaseHcom.opGroup2CommMap.end()) {
    3309              :                 EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
    3310              :             } else {
    3311              :                 HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(), deviceLogicId);
    3312              :                 return HCCL_E_PARA;
    3313              :             }
    3314              :             return HCCL_SUCCESS;
    3315              :         }());
    3316              : #endif
    3317          235 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3318          235 :     HcclCommState state = hcclComm->GetState();
    3319          235 :     if (state == HcclCommState::INUSE) {
    3320            0 :         HCCL_WARNING("[HcclCommDestroy] comm is in use, please try again later");
    3321            0 :         return HCCL_E_AGAIN;
    3322              :     }
    3323          235 :     hcclComm->DeinitZeroCopyMemoryAgent();
    3324          235 :     HCCL_RUN_INFO("[HcclCommDestroy] comm state is %s", HcclCommStateToString(state));
    3325          235 :     CHK_RET(hcclComm->RealeaseShareCCLbuffer());
    3326          235 :     CHK_RET(hcclComm->SetStopFlag(true));
    3327          235 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
    3328          235 :     CHK_RET(ResetDevice(hcclComm));
    3329              : 
    3330          234 :     std::unique_lock<std::mutex> oneSideLock(g_opHcomOneSideMutex);
    3331          234 :     if (IsOneSidedComm(comm)) {
    3332            0 :         return HcclOneSidedCommDestroy(comm, deviceLogicId, startut);
    3333              :     }
    3334          234 :     oneSideLock.unlock();
    3335              : 
    3336          234 :     HcclOpInfoCtx& opBaseHcom = GetHcclOpInfoCtx();
    3337          234 :     string group;
    3338          234 :     if (comm == opBaseHcom.pComm.get()) {
    3339          233 :         group = opBaseHcom.pComm->GetIdentifier();
    3340          233 :         opBaseHcom.pComm = nullptr;
    3341          233 :         HcclCloseCommConnections(group);
    3342              :     } else {
    3343            1 :         HCCL_RUN_INFO("com is not global com");
    3344            1 :         group = hcclComm->GetIdentifier();
    3345              :     }
    3346              : 
    3347              :     // 特殊场景,当comm name被手动配置为HCCL_WORLD_GROUP时,需要将hcomInfo.pComm设为nullptr
    3348          234 :     if (hcclComm->GetIdentifier() == HCCL_WORLD_GROUP) {
    3349          233 :         HcomGetCtxHomInfo().pComm = nullptr;
    3350              :     }
    3351              : 
    3352          234 :     HcomUnSetGroupTopoInfo(group.c_str());
    3353              : 
    3354          234 :     std::unique_lock<std::mutex> lock(opBaseHcom.opGroupMapMutex);
    3355          234 :     auto iter = opBaseHcom.opGroup2CommMap.find(group);
    3356          234 :     if (iter != opBaseHcom.opGroup2CommMap.end()) {
    3357          234 :         EXCEPTION_CATCH(opBaseHcom.opGroup2CommMap.erase(group), return HCCL_E_MEMORY);
    3358          234 :         HcclCloseCommConnections(group);
    3359              :     } else {
    3360            0 :         HCCL_ERROR("[HcclCommDestroy] comm is not exist, comm=%p, group=%s, deviceLogicId=%d", comm, group.c_str(), deviceLogicId);
    3361            0 :         return HCCL_E_PARA;
    3362              :     }
    3363              : 
    3364          234 :     if (ProfilingManagerPub::GetAllState()) {
    3365          234 :         ProfilingManagerPub::ClearStoragedProfilingInfo();
    3366              :     }
    3367              : 
    3368          234 :     HcclUs endut = TIME_NOW();
    3369              : 
    3370              :     // 删除groupName和UDI的映射
    3371          234 :     HCCL_PROFILER_DEL_GROUP_UDI(group);
    3372              : 
    3373              :     /* 关键状态记录 */
    3374          234 :     HCCL_RUN_INFO("op_base comm destroy complete, take time [%lld]us, group[%s], deviceLogicId[%d].",
    3375              :         DURATION_US(endut - startut), group.c_str(), deviceLogicId);
    3376              : 
    3377          234 :     return HCCL_SUCCESS;
    3378          234 : }
    3379              : 
    3380              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    3381            0 : static HcclConfigTypeOpExpansionMode OpExpansionModeValueToModeEnum(const uint32_t value)
    3382              : {
    3383            0 :     constexpr uint32_t defaultMode = 0;
    3384            0 :     constexpr uint32_t hostTsMode = 1;
    3385            0 :     constexpr uint32_t aicpuTsMode = 2;
    3386            0 :     constexpr uint32_t aivMode = 3;
    3387            0 :     constexpr uint32_t aivOnlyMode = 4;
    3388            0 :     constexpr uint32_t ccuMsMode = 5;
    3389            0 :     constexpr uint32_t ccuSchedMode = 6;
    3390            0 :     constexpr uint32_t aicpuMode = 7;
    3391              : 
    3392            0 :     switch(value) {
    3393            0 :         case defaultMode:
    3394            0 :             return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_CCU_SCHED;
    3395            0 :         case hostTsMode:
    3396            0 :             return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_HOST_TS;
    3397            0 :         case aicpuTsMode:
    3398              :         case aicpuMode:
    3399            0 :             return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_AI_CPU;
    3400            0 :         case ccuMsMode:
    3401            0 :             return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_CCU_MS;
    3402            0 :         case ccuSchedMode:
    3403            0 :             return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_CCU_SCHED;
    3404            0 :         case aivMode:
    3405            0 :             return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_AIV;
    3406            0 :         case aivOnlyMode:
    3407            0 :             return HcclOpExpansionMode::HCCL_OP_EXPANSION_AIV_ONLY;
    3408            0 :         default:
    3409            0 :             break;
    3410              :     }
    3411              : 
    3412            0 :     return HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_INVALID;
    3413              : }
    3414              : #endif
    3415              : 
    3416            1 : HcclResult HcclConfigGetInfo(HcclComm comm, HcclConfigType cfgType,
    3417              :     uint32_t infoLen, void *info)
    3418              : {
    3419              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    3420            1 :     CHK_PTR_NULL(comm);
    3421            1 :     CHK_PTR_NULL(info);
    3422              : 
    3423            1 :     if (cfgType != HcclConfigType::HCCL_CONFIG_TYPE_OP_EXPANSION_MODE) {
    3424            0 :         HCCL_ERROR("[%s] cfgType[%d] is invalid.", __func__, cfgType);
    3425            0 :         return HcclResult::HCCL_E_PARA;
    3426              :     }
    3427              : 
    3428            1 :     constexpr size_t infoExpectedLen = sizeof(HcclConfigTypeOpExpansionMode);
    3429            1 :     if (static_cast<size_t>(infoLen) != infoExpectedLen) {
    3430            0 :         HCCL_ERROR("[%s] cfgType[%d] infoLen[%u] is not equal to expected[%zu].",
    3431              :             __func__, cfgType, infoLen, infoExpectedLen);
    3432            0 :         return HcclResult::HCCL_E_PARA;
    3433              :     }
    3434              : 
    3435            1 :     auto *hcclComm = static_cast<hccl::hcclComm *>(comm);
    3436            1 :     auto *collComm = hcclComm->GetCollComm();
    3437            1 :     CHK_PTR_NULL(collComm);
    3438            0 :     auto *myRank = collComm->GetMyRank();
    3439            0 :     CHK_PTR_NULL(myRank);
    3440            0 :     const uint32_t opExpansionModeValue = myRank->GetOpExpansionMode();
    3441            0 :     const auto opExpansionMode = OpExpansionModeValueToModeEnum(opExpansionModeValue);
    3442            0 :     if (opExpansionMode == HcclOpExpansionMode::HCCL_OP_EXPANSION_MODE_INVALID) {
    3443            0 :         HCCL_ERROR("[%s] unknown expansion mode[%d].", __func__, opExpansionMode);
    3444            0 :         return HcclResult::HCCL_E_INTERNAL;
    3445              :     }
    3446              : 
    3447            0 :     auto *modeInfo = static_cast<HcclConfigTypeOpExpansionMode *>(info);
    3448            0 :     *modeInfo = opExpansionMode;
    3449            0 :     return HcclResult::HCCL_SUCCESS;
    3450              : #endif
    3451              : 
    3452              :     HCCL_ERROR("[%s] is not support for hccd or kernel.", __func__);
    3453              :     return HcclResult::HCCL_E_NOT_SUPPORT;
    3454              : }
    3455              : 
    3456          235 : HcclResult HcclGenerateCommId(hccl::HcclCommParams &params)
    3457              : {
    3458          235 :     s32 sRet = memset_s(params.id.internal, HCCL_ROOT_INFO_BYTES, 0, sizeof(params.id.internal));
    3459          235 :     CHK_PRT_RET(sRet != EOK, HCCL_ERROR("[GenerateCommId]memory set error. return[%d].", sRet), HCCL_E_PARA);
    3460              : 
    3461              :     HcclRootInfo uniqueId;
    3462          235 :     std::string group;
    3463          235 :     CHK_RET(hcclComm::GetUniqueId(&uniqueId));
    3464              : 
    3465          235 :     if (!params.isHeterogComm) {
    3466          235 :         group = "hccl_world_group";
    3467              :     } else {
    3468            0 :         group = "hccl_heterog_group";
    3469              :     }
    3470              : 
    3471          235 :     sRet = snprintf_s(params.id.internal, HCCL_ROOT_INFO_BYTES, HCCL_ROOT_INFO_BYTES - 1, "%s%s%s",
    3472              :         uniqueId.internal, "-", group.c_str());
    3473          235 :     CHK_PRT_RET(sRet == -1, HCCL_ERROR("[GenerateCommId]errNo[0x%016llx] sal snprintf_s error",
    3474              :         HCCL_ERROR_CODE(HCCL_E_INTERNAL)), HCCL_E_INTERNAL);
    3475          235 :     HCCL_INFO("params.id.internal [%s]", params.id.internal);
    3476          235 :     return HCCL_SUCCESS;
    3477          235 : }
    3478              : 
    3479          235 : HcclResult InitOtherInfo(hccl::HcclCommParams &params, const char *rankTable)
    3480              : {
    3481              :     // 记录版本信息
    3482          235 :     std::string curVersion = GetExternalInputCannVersion();
    3483          235 :     CHK_RET(RankConsistentcyChecker::GetInstance().RecordVerInfo(curVersion));
    3484              : 
    3485              :     // ranktableCRC计算
    3486          235 :     if (rankTable == nullptr) {
    3487            0 :         HCCL_INFO("rank table is null, rankTableCrc is 0.");
    3488              :     } else {
    3489          235 :         HcclResult ret = HcomCalcCRC(params, rankTable);
    3490          235 :         CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[Init][OtherInfo]errNo[0x%016llx] calc ranktable crc error",
    3491              :             HCCL_ERROR_CODE(HCCL_E_INTERNAL)), HCCL_E_INTERNAL);
    3492              :     }
    3493              : 
    3494              :     // 生成通信域标识符
    3495          235 :     HcclResult ret = HcclGenerateCommId(params);
    3496          235 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    3497              :         HCCL_ERROR("[Init][OtherInfo]errNo[0x%016llx] generate CommId error, params: dest[%p]",
    3498              :             HCCL_ERROR_CODE(HCCL_E_INTERNAL), params.id.internal), HCCL_E_INTERNAL);
    3499          235 :     return HCCL_SUCCESS;
    3500          235 : }
    3501              : 
    3502            0 : HcclResult ReduceScatterLoop(const std::string &tag, void *inputPtr, void *outputPtr, const u64 &count,
    3503              :                              HcclDataType dataType, HcclReduceOp op, hccl::hcclComm *hcclComm, rtStream_t stream)
    3504              : {
    3505              :     HcclResult ret;
    3506            0 :     void *commInputPtr = nullptr;
    3507            0 :     void *commOutputPtr = nullptr;
    3508              :     u64 commInputSize, commOutputSize;
    3509              : 
    3510            0 :     CHK_RET(hcclComm->GetInCCLbuffer(commInputPtr, commInputSize));
    3511              : 
    3512            0 :     CHK_RET(hcclComm->GetOutCCLbuffer(commOutputPtr, commOutputSize));
    3513              : 
    3514              :     u32 unitSize;
    3515            0 :     CHK_RET(SalGetDataTypeSize(dataType, unitSize));
    3516              : 
    3517            0 :     char *curInputPtr = static_cast<char *>(inputPtr);
    3518            0 :     char *curOutputPtr = static_cast<char *>(outputPtr);
    3519            0 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    3520            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    3521              : 
    3522            0 :     CHK_PRT_RET(rankSize * unitSize == 0, HCCL_ERROR("The result of rankSize * unitSize is 0"), HCCL_E_PARA);
    3523            0 :     u64 maxCountPerLoop = commInputSize / (rankSize * unitSize); // 中转内存单次最多能够接受的output count
    3524            0 :     u64 curCount = 0;
    3525              : 
    3526            0 :     for (u64 countLeft = count, inputOffset = 0, outputOffset = 0; countLeft > 0; countLeft -= curCount) {
    3527            0 :         curInputPtr += inputOffset;
    3528            0 :         curOutputPtr += outputOffset;
    3529            0 :         HCCL_INFO("-OP_BASE-ReduceScatterLoop:inputOffset[%llu], outputOffset[%llu]", inputOffset, outputOffset);
    3530              :         // 判断剩余数据量对应的input size是否大于中转input size
    3531            0 :         curCount = ((countLeft * unitSize * rankSize) > commInputSize) ? maxCountPerLoop : countLeft;
    3532            0 :         u64 curSize = curCount * unitSize; // 单位:字节
    3533              : 
    3534            0 :         for (u32 i = 0; i < rankSize; i++) {
    3535              :             // 拷贝input上每个slice的数据到中转内存,源端每个slice的size固定为output的size
    3536            0 :             ret = hrtMemAsyncCopy(static_cast<char *>(commInputPtr) + curSize * i, curSize,
    3537            0 :                 curInputPtr + count * unitSize * i, curSize, HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE,
    3538              :                 stream);
    3539            0 :             CHK_PRT_RET(ret != HCCL_SUCCESS,
    3540              :                 HCCL_ERROR("[Loop][ReduceScatter]In OP_BASE inputbuffer transit,[%u]slice memcopy "\
    3541              :                     "failed", i), HCCL_E_MEMORY);
    3542              :         }
    3543              : 
    3544            0 :         ret = hcclComm->ReduceScatter(tag, commInputPtr, commOutputPtr, curCount, dataType, op, stream);
    3545              : 
    3546            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS,
    3547              :             HCCL_ERROR("[Loop][ReduceScatter]errNo[0x%016llx] op_base hcclComm ReduceScatter error, "\
    3548              :             "tag[%s], input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s]",
    3549              :             HCCL_ERROR_CODE(ret), tag.c_str(), commInputPtr, commOutputPtr, curCount,
    3550              :             GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str()), ret);
    3551              : 
    3552            0 :         CHK_RET(hrtMemAsyncCopy(curOutputPtr, curSize, commOutputPtr, curSize,
    3553              :             HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE, stream));
    3554              : 
    3555            0 :         CHK_PRT_RET((curCount == 0), HCCL_ERROR("[Loop][ReduceScatter]In OP_BASE curCount is zero"), HCCL_E_PARA);
    3556            0 :         inputOffset = curSize;
    3557            0 :         outputOffset = curSize;
    3558              :     }
    3559              : 
    3560            0 :     return HCCL_SUCCESS;
    3561              : }
    3562              : 
    3563              : // 获取算子所需workspace memory大小[byte]
    3564            0 : HcclResult HcclGetOpBasedMemSize(const HcclCMDType &opType, u64 &size,
    3565              :     const HcomCollOpInfo &opInfo)
    3566              : {
    3567            0 :     u64 opMemSize = 0;
    3568              : 
    3569            0 :     if (opType == HcclCMDType::HCCL_CMD_REDUCE_SCATTER) {
    3570              :         // ReduceScatter 算子所需memory大小为 GetExternalInputCCLBuffSize()
    3571              :         DevType devType;
    3572            0 :         CHK_RET(hrtGetDeviceType(devType));
    3573            0 :         if (IsSupportSDMAReduce(opInfo.inputAddr, opInfo.outputAddr, opInfo.dataType, opInfo.reduceOp) &&
    3574            0 :             IsSupportRDMAReduce(opInfo.dataType, opInfo.reduceOp) && devType == DevType::DEV_TYPE_910B) {
    3575            0 :                 opMemSize = 0;
    3576              :             } else {
    3577            0 :                 opMemSize = GetExternalInputCCLBuffSize();
    3578              :             }
    3579              :     } else {
    3580            0 :         opMemSize = 0;
    3581              :     }
    3582            0 :     size = HCCL_WORKSPACE_MEM_32_KB + opMemSize;
    3583            0 :     HCCL_INFO("workspace memory size: op[%d], memory size[%llu]", opType, size);
    3584            0 :     return HCCL_SUCCESS;
    3585              : }
    3586              : 
    3587           30 : HcclResult HcclAlltoAllInner(const void *sendBuf, uint64_t sendCount, HcclDataType sendType, const void *recvBuf,
    3588              :     uint64_t recvCount, HcclDataType recvType, HcclComm comm, aclrtStream stream)
    3589              : {
    3590              :     // 入参校验
    3591           30 :     CHK_PRT_RET(sendCount == 0 && recvCount == 0,
    3592              :         HCCL_WARNING("sendCount and recvCount are both 0, return AllToAll success"), HCCL_SUCCESS);
    3593           49 :     RPT_INPUT_ERR(sendBuf == nullptr, "EI0003",\
    3594              :         std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    3595              :         std::vector<std::string>({"HcclAlltoAllInner", "nullptr", "sendBuf", "non-null pointer"}));
    3596           29 :     CHK_PTR_NULL(sendBuf);
    3597           48 :     RPT_INPUT_ERR(recvBuf == nullptr, "EI0003",\
    3598              :         std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    3599              :         std::vector<std::string>({"HcclAlltoAllInner", "nullptr", "recvBuf", "non-null pointer"}));
    3600           28 :     CHK_PTR_NULL(recvBuf);
    3601           27 :     CHK_PRT_RET(sendCount != recvCount,
    3602              :         HCCL_ERROR("sendCount[%lu] and recvCount[%lu] are not equal, please check params",
    3603              :             sendCount, recvCount), HCCL_E_PARA);
    3604           26 :     CHK_PRT_RET(sendType != recvType,
    3605              :         HCCL_ERROR("sendType[%s] and recvType[%s] are not equal, please check params",
    3606              :             GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str()), HCCL_E_PARA);
    3607              : 
    3608           25 :     RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    3609              :         std::vector<std::string>({"HcclAlltoAllInner", "nullptr", "stream", "non-null pointer"}));
    3610           25 :     CHK_PTR_NULL(stream);
    3611           45 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    3612              :         std::vector<std::string>({"HcclAlltoAllInner", "nullptr", "comm", "non-null pointer"}));
    3613           25 :     CHK_PTR_NULL(comm);
    3614           24 :     CHK_PRT_RET(sendBuf == recvBuf,
    3615              :         HCCL_ERROR("[HcclAlltoAllInner] sendBuf and recvBuf cannot be same."), HCCL_E_PARA);
    3616              : 
    3617              :     // Group特性
    3618           24 :     if (hcclGroupDepth > 0) {
    3619              :         struct hcclOpInfo info;
    3620            1 :         info.coll = HcclCMDType::HCCL_CMD_ALLTOALL;
    3621            1 :         info.sendbuff = const_cast<void *>(sendBuf);
    3622            1 :         info.recvbuff = const_cast<void *>(recvBuf);
    3623            1 :         info.sendCount = sendCount;
    3624            1 :         info.recvCount = recvCount;
    3625            1 :         info.comm = comm;
    3626            1 :         info.stream = stream;
    3627            1 :         CHK_RET(taskAppend(comm, info));
    3628            1 :         HCCL_INFO("[HcclAlltoAll] Finish taskAppend, sendCount [%d] sendType [%s] recvCount [%d] recvType [%s]", sendCount, GetDataTypeEnumStr(sendType).c_str(), recvCount, GetDataTypeEnumStr(recvType).c_str());
    3629            1 :             return HCCL_SUCCESS;
    3630              :     }
    3631              :     
    3632           23 :     HcclUs startut = TIME_NOW();
    3633              :     bool isCapture;
    3634           23 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    3635           23 :     uint64_t modelId = 0xFFFFFFFF;
    3636           23 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    3637           23 :     if (!isCapture) {
    3638           22 :         HcclSetIfProfile();
    3639              :     }
    3640              : 
    3641           23 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    3642              : 
    3643              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    3644           23 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    3645              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3646              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    3647              :         CHK_PTR_NULL(commV2);
    3648              :         CHK_RET(HcclAlltoAllV2(sendBuf, sendCount, sendType, recvBuf, recvCount, recvType, commV2, stream));
    3649              :         return HCCL_SUCCESS;
    3650              :     }());
    3651              : #endif
    3652           23 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3653           23 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    3654           23 :     s32 threadID = SalGetTid();
    3655           23 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    3656           23 :     const std::string tag = HCCL_ALLTOALL + "_" + hcclComm->GetIdentifier();
    3657           23 :     CHK_RET(HcomCheckOpParam(tag.c_str(), 0, sendType, stream));
    3658           23 :     CHK_RET(HcomCheckDataType(recvType));
    3659              :     // 接口交互信息日志
    3660              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    3661           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    3662           23 :         s32 deviceLogicId = 0;
    3663           23 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    3664              : 
    3665           23 :         u32 localRank = INVALID_VALUE_RANKID;
    3666           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    3667              : 
    3668           23 :         s32 streamId = 0;
    3669           23 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    3670              : 
    3671           46 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    3672              :             "tag[%s], sendCount[%llu], recvCount[%llu], sendType[%s], recvType[%s], localRank[%u], streamId[%d], "
    3673              :             "deviceLogicId[%d]",
    3674           69 :             tag.c_str(), sendCount, recvCount, GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str(),
    3675              :             localRank, streamId, deviceLogicId);
    3676              : 
    3677           23 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    3678           46 :         std::string logInfo = "Entry-HcclAlltoAllInner:" + std::string(stackLogBuffer) +
    3679           69 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    3680           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    3681           23 :     }
    3682              : 
    3683           23 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    3684              : 
    3685           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
    3686           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    3687              : 
    3688           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAll(sendBuf, sendCount, sendType, recvBuf, recvCount, recvType, stream, tag),
    3689              :                           tag.c_str());
    3690           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLTOALL, beginTime, sendCount, sendType,
    3691              :         tag));
    3692           23 :     if (!isCapture) {
    3693           22 :         HcclResetIfProfile();
    3694              :     }
    3695           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    3696              : 
    3697           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    3698           23 :         HcclUs endut = TIME_NOW();
    3699           23 :         std::string endInfo = "HcclAlltoAllInner:success,take time: " +
    3700           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    3701           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    3702           23 :     }
    3703              : 
    3704           23 :     return HCCL_SUCCESS;
    3705           23 : }
    3706              : 
    3707              : // sendBuf & recvBuf为device mem, 其它为host mem
    3708           34 : HcclResult HcclAlltoAllVInner(const void *sendBuf, const void *sendCounts, const void *sdispls, HcclDataType sendType,
    3709              :                          const void *recvBuf, const void *recvCounts, const void *rdispls, HcclDataType recvType,
    3710              :                          HcclComm comm, aclrtStream stream)
    3711              : {
    3712              :     // 入参校验
    3713           54 :     RPT_INPUT_ERR(sendCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3714              :         std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "sendCounts", "non-null pointer"}));
    3715           34 :     CHK_PTR_NULL(sendCounts);
    3716           53 :     RPT_INPUT_ERR(sdispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3717              :         std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "sdispls", "non-null pointer"}));
    3718           33 :     CHK_PTR_NULL(sdispls);
    3719           52 :     RPT_INPUT_ERR(recvCounts == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3720              :         std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "recvCounts", "non-null pointer"}));
    3721           32 :     CHK_PTR_NULL(recvCounts);
    3722           51 :     RPT_INPUT_ERR(rdispls == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3723              :         std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "rdispls", "non-null pointer"}));
    3724           31 :     CHK_PTR_NULL(rdispls);
    3725           30 :     RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3726              :         std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "stream", "non-null pointer"}));
    3727           30 :     CHK_PTR_NULL(stream);
    3728           50 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3729              :         std::vector<std::string>({"HcclAlltoAllVInner", "nullptr", "comm", "non-null pointer"}));
    3730           30 :     CHK_PTR_NULL(comm);
    3731              : 
    3732              :     // Group特性
    3733           29 :     if (hcclGroupDepth > 0) {
    3734              :         struct hcclOpInfo info;
    3735            1 :         info.coll = HcclCMDType::HCCL_CMD_ALLTOALLV;
    3736            1 :         info.sendbuff = const_cast<void *>(sendBuf);
    3737            1 :         info.recvbuff = const_cast<void *>(recvBuf);
    3738            1 :         info.sendCounts = sendCounts;
    3739            1 :         info.recvCounts = recvCounts;
    3740            1 :         info.sdispls = sdispls;
    3741            1 :         info.rdispls = rdispls;
    3742            1 :         info.sendType = sendType;
    3743            1 :         info.recvType = recvType;
    3744            1 :         info.comm = comm;
    3745            1 :         info.stream = stream;
    3746            1 :         CHK_RET(taskAppend(comm, info));
    3747            1 :         HCCL_INFO("[HcclAlltoAllV] Finish taskAppend, sendType [%s] recvType [%s]", GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str());
    3748            1 :             return HCCL_SUCCESS;
    3749              :     }
    3750              : 
    3751           28 :     HcclUs startut = TIME_NOW();
    3752              :     bool isCapture;
    3753           28 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    3754           28 :     uint64_t modelId = 0xFFFFFFFF;
    3755           28 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    3756           28 :     if (!isCapture) {
    3757           27 :         HcclSetIfProfile();
    3758              :     }
    3759           28 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    3760              : 
    3761              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    3762           28 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    3763              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3764              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    3765              :         CHK_PTR_NULL(commV2);
    3766              :         CHK_RET(HcclAlltoAllVV2(sendBuf, sendCounts, sdispls, sendType, recvBuf, recvCounts, rdispls, recvType, commV2, stream));
    3767              :         return HCCL_SUCCESS;
    3768              :     }());
    3769              : #endif
    3770           28 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3771           28 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    3772           28 :     s32 threadID = SalGetTid();
    3773           28 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    3774           28 :     u32 rankSize = 0;
    3775           28 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    3776           28 :     CHK_RET(HcomCheckAlltoAllVExternalMem(sendBuf, sendCounts, recvBuf, recvCounts, rankSize));
    3777              : 
    3778           25 :     const std::string tag = HCCL_ALLTOALLV + "_" + hcclComm->GetIdentifier();
    3779           25 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), 0, sendType, stream), tag.c_str());
    3780           25 :     CHK_RET_AND_PRINT_IDE(HcomCheckDataType(recvType), tag.c_str());
    3781              :     /* 接口交互信息日志 */
    3782              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    3783           25 :     if (GetExternalInputHcclEnableEntryLog()) {
    3784           25 :         s32 deviceLogicId = 0;
    3785           25 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    3786              : 
    3787           25 :         u32 localRank = INVALID_VALUE_RANKID;
    3788           25 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    3789              : 
    3790           25 :         s32 streamId = 0;
    3791           25 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    3792              : 
    3793           50 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    3794              :             "tag[%s], sendBuf[%p], recvBuf[%p], sendCounts[%p], recvCounts[%p], sendType[%s], "
    3795              :             "recvType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
    3796           50 :             tag.c_str(), sendBuf, recvBuf, sendCounts, recvCounts, GetDataTypeEnumStr(sendType).c_str(),
    3797           50 :             GetDataTypeEnumStr(recvType).c_str(), localRank, streamId, deviceLogicId);
    3798              : 
    3799           25 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    3800           50 :         std::string logInfo = "Entry-HcclAlltoAllVInner:" + std::string(stackLogBuffer) +
    3801           75 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    3802           25 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    3803           25 :     }
    3804              : 
    3805           25 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    3806              : 
    3807           25 :     if (sendBuf != nullptr) {
    3808           25 :         CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
    3809              :     }
    3810           25 :     if (recvBuf != nullptr) {
    3811           25 :         CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    3812              :     }
    3813              : 
    3814           25 :     if (!GetExternalInputHcclEnableFfts()) {
    3815           24 :         CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAllV(sendBuf, sendCounts, sdispls, sendType, recvBuf,
    3816              :             recvCounts, rdispls, recvType, stream, tag), tag.c_str());
    3817              :     } else {
    3818            1 :         CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAllVOutPlace(sendBuf, sendCounts, sdispls, sendType, recvBuf,
    3819              :             recvCounts, rdispls, recvType, stream, tag), tag.c_str());
    3820              :     }
    3821              : 
    3822           25 :     u64 sendCount = 0;
    3823           57 :     for (u32 i = 0; i < rankSize; i++) {
    3824           32 :         sendCount += *(static_cast<const u64 *>(sendCounts) + i);
    3825              :     }
    3826           25 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLTOALLV, beginTime, sendCount, sendType, tag));
    3827           25 :     if (!isCapture) {
    3828           24 :         HcclResetIfProfile();
    3829              :     }
    3830           25 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    3831              : 
    3832           25 :     if (GetExternalInputHcclEnableEntryLog()) {
    3833           25 :         HcclUs endut = TIME_NOW();
    3834              :         /* 关键状态记录 */
    3835           25 :         std::string endInfo = "HcclAlltoAllVInner:success,take time: " +
    3836           50 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    3837           25 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    3838           25 :     }
    3839              : 
    3840           25 :     return HCCL_SUCCESS;
    3841           28 : }
    3842              : 
    3843            1 : HcclResult HcclAlltoAllVCInner(const void *sendBuf, const void *sendCountMatrix,
    3844              :     HcclDataType sendType, const void *recvBuf, HcclDataType recvType,
    3845              :     HcclComm comm, rtStream_t stream)
    3846              : {
    3847              :     // 参数校验
    3848            1 :     RPT_INPUT_ERR(sendCountMatrix == nullptr, "EI0003",\
    3849              :         std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3850              :         std::vector<std::string>({"HcclAlltoAllVCInner", "nullptr", "sendCountMatrix", "non-null pointer"}));
    3851            1 :     CHK_PTR_NULL(sendCountMatrix);
    3852            1 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3853              :         std::vector<std::string>({"HcclAlltoAllVCInner", "nullptr", "comm", "non-null pointer"}));
    3854            1 :     CHK_PTR_NULL(comm);
    3855            1 :     RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3856              :         std::vector<std::string>({"HcclAlltoAllVCInner", "nullptr", "stream", "non-null pointer"}));    
    3857            1 :     CHK_PTR_NULL(stream);
    3858              : 
    3859              :     // Group特性
    3860            1 :     if (hcclGroupDepth > 0) {
    3861              :         struct hcclOpInfo info;
    3862            1 :         info.coll = HcclCMDType::HCCL_CMD_ALLTOALLVC;
    3863            1 :         info.sendbuff = const_cast<void *>(sendBuf);
    3864            1 :         info.recvbuff = const_cast<void *>(recvBuf);
    3865            1 :         info.sendCounts = sendCountMatrix;
    3866            1 :         info.sendType = sendType;
    3867            1 :         info.recvType = recvType;
    3868            1 :         info.comm = comm;
    3869            1 :         info.stream = stream;
    3870            1 :         CHK_RET(taskAppend(comm, info));
    3871            1 :         HCCL_INFO("[HcclAlltoAllVC] Finish taskAppend, sendType [%s] recvType [%s]", GetDataTypeEnumStr(sendType).c_str(), GetDataTypeEnumStr(recvType).c_str());
    3872            1 :             return HCCL_SUCCESS;
    3873              :     }
    3874              :     
    3875            0 :     HcclUs startut = TIME_NOW();
    3876              :     bool isCapture;
    3877            0 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    3878            0 :     uint64_t modelId = 0xFFFFFFFF;
    3879            0 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    3880            0 :     if (!isCapture) {
    3881            0 :         HcclSetIfProfile();
    3882              :     }
    3883            0 :     s32 threadID = SalGetTid();
    3884            0 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    3885            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    3886              : 
    3887              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    3888            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    3889              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3890              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    3891              :         CHK_PTR_NULL(commV2);
    3892              :         CHK_RET(HcclAlltoAllVCV2(sendBuf, sendCountMatrix, sendType, recvBuf, recvType, commV2, stream));
    3893              :         return HCCL_SUCCESS;
    3894              :     }());
    3895              : #endif
    3896            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    3897            0 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    3898              : 
    3899            0 :     u32 rankSize = 0;
    3900            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    3901            0 :     u32 rank = 0;
    3902            0 :     hcclComm->GetUserRank(rank);
    3903            0 :     u32 userRank = 0;
    3904            0 :     hcclComm->GetGroupRank(userRank);
    3905              : 
    3906            0 :     CHK_RET(HcomCheckAlltoAllVCExternalMem(sendBuf, sendCountMatrix, recvBuf, rankSize, rank));
    3907            0 :     const std::string tag = HCCL_ALLTOALLVC + "_" + hcclComm->GetIdentifier();
    3908            0 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), 0, sendType, stream), tag.c_str());
    3909            0 :     CHK_RET_AND_PRINT_IDE(HcomCheckDataType(recvType), tag.c_str());
    3910              : 
    3911              :     /* 接口交互信息日志 */
    3912              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    3913            0 :     if (GetExternalInputHcclEnableEntryLog()) {
    3914              :         u64 sendCountMatrixHash;
    3915            0 :         HcomGetHashFromSendCountMatrix(sendCountMatrixHash, sendCountMatrix, rankSize, tag);
    3916              : 
    3917            0 :         s32 deviceLogicId = 0;
    3918            0 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    3919              : 
    3920            0 :         u32 localRank = INVALID_VALUE_RANKID;
    3921            0 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    3922              : 
    3923            0 :         s32 streamId = 0;
    3924            0 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    3925              : 
    3926            0 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    3927              :             "tag[%s], sendBuf[%p], sendCountMatrixHash[%llu], sendType[%s], recvBuf[%p], "
    3928              :             "recvType[%s], localRank[%u], streamId[%d], deviceLogicId[%d]",
    3929            0 :             tag.c_str(), sendBuf, sendCountMatrixHash, GetDataTypeEnumStr(sendType).c_str(), recvBuf,
    3930            0 :             GetDataTypeEnumStr(recvType).c_str(), localRank, streamId, deviceLogicId);
    3931              : 
    3932            0 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    3933            0 :         std::string logInfo = "Entry-HcclAlltoAllVCInner:" + std::string(stackLogBuffer) +
    3934            0 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    3935            0 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    3936            0 :     }
    3937              : 
    3938            0 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    3939              : 
    3940            0 :     if (sendBuf != nullptr) {
    3941            0 :         CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
    3942              :     }
    3943            0 :     if (recvBuf != nullptr) {
    3944            0 :         CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    3945              :     }
    3946              : 
    3947            0 :     if (!GetExternalInputHcclEnableFfts()) {
    3948            0 :         CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAllVC(sendBuf, sendCountMatrix, sendType, recvBuf, recvType, stream, tag),
    3949              :             tag.c_str());
    3950              :     } else {
    3951            0 :         CHK_RET_AND_PRINT_IDE(hcclComm->AlltoAllVCOutPlace(sendBuf, sendCountMatrix, sendType, recvBuf,
    3952              :             recvType, stream, tag), tag.c_str());
    3953              :     }
    3954            0 :     u64 sendCount = 0;
    3955            0 :     for (u32 i = 0; i < rankSize; i++) {
    3956            0 :         sendCount += *(static_cast<const u64 *>(sendCountMatrix) + userRank * rankSize + i);
    3957              :     }
    3958            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_ALLTOALLVC, beginTime, sendCount, sendType,
    3959              :         tag));
    3960            0 :     if (!isCapture) {
    3961            0 :         HcclResetIfProfile();
    3962              :     }
    3963            0 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    3964              : 
    3965            0 :     if (GetExternalInputHcclEnableEntryLog()) {
    3966            0 :         HcclUs endut = TIME_NOW();
    3967              :         /* 关键状态记录 */
    3968            0 :         std::string endInfo = "HcclAlltoAllVCInner:success,take time: " +
    3969            0 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    3970            0 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    3971            0 :     }
    3972              : 
    3973            0 :     return HCCL_SUCCESS;
    3974            0 : }
    3975              : 
    3976           29 : HcclResult HcclReduceInner(void *sendBuf, void *recvBuf, uint64_t count, HcclDataType dataType, HcclReduceOp op,
    3977              :                       uint32_t root, HcclComm comm, aclrtStream stream)
    3978              : {
    3979              :     // 入参合法性校验
    3980           29 :     CHK_PRT_RET(count == 0, HCCL_WARNING("input count is 0, return reduce success"), HCCL_SUCCESS);
    3981           48 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3982              :         std::vector<std::string>({"HcclReduceInner", "nullptr", "comm", "non-null pointer"}));
    3983           28 :     CHK_PTR_NULL(comm);
    3984           47 :     RPT_INPUT_ERR(sendBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3985              :         std::vector<std::string>({"HcclReduceInner", "nullptr", "sendBuf", "non-null pointer"}));
    3986           27 :     CHK_PTR_NULL(sendBuf);
    3987           46 :     RPT_INPUT_ERR(recvBuf == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3988              :         std::vector<std::string>({"HcclReduceInner", "nullptr", "recvBuf", "non-null pointer"}));
    3989           26 :     CHK_PTR_NULL(recvBuf);
    3990           25 :     RPT_INPUT_ERR(stream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "value"}),\
    3991              :         std::vector<std::string>({"HcclReduceInner", "nullptr", "stream", "non-null pointer"}));    
    3992           25 :     CHK_PTR_NULL(stream);
    3993              : 
    3994              :     // Group特性
    3995           25 :     if (hcclGroupDepth > 0) {
    3996              :         struct hcclOpInfo info;
    3997            1 :         info.coll = HcclCMDType::HCCL_CMD_REDUCE;
    3998            1 :         info.sendbuff = sendBuf;
    3999            1 :         info.recvbuff = recvBuf;
    4000            1 :         info.sendCount = count;
    4001            1 :         info.sendType = dataType;
    4002            1 :         info.recvType = dataType;
    4003            1 :         info.comm = comm;
    4004            1 :         info.stream = stream;
    4005            1 :         CHK_RET(taskAppend(comm, info));
    4006            1 :         HCCL_INFO("[HcclReduce] Finish taskAppend, count [%d] dataType [%s]", count, GetDataTypeEnumStr(dataType).c_str());
    4007            1 :             return HCCL_SUCCESS;
    4008              :     }
    4009              : 
    4010           24 :     HcclUs startut = TIME_NOW();
    4011              :     bool isCapture;
    4012           24 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    4013           24 :     uint64_t modelId = 0xFFFFFFFF;
    4014           24 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    4015           24 :     if (!isCapture) {
    4016           23 :         HcclSetIfProfile();
    4017              :     }
    4018           24 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    4019              : 
    4020              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4021           24 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    4022              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4023              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    4024              :         CHK_PTR_NULL(commV2);
    4025              :         CHK_RET(HcclReduceV2(sendBuf, recvBuf, count, dataType, op, root, commV2, stream));
    4026              :         return HCCL_SUCCESS;
    4027              :     }());
    4028              : #endif
    4029           24 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4030           24 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    4031           24 :     s32 threadID = SalGetTid();
    4032           24 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    4033              :     // 同通信域同算子复用tag
    4034           24 :     const string tag = "Reduce_" + hcclComm->GetIdentifier();
    4035           24 :     CHK_RET_AND_PRINT_IDE(HcomCheckOpParam(tag.c_str(), count, dataType, stream), tag.c_str());
    4036              : 
    4037           69 :     CHK_RET_AND_PRINT_IDE(HcomCheckReductionOp("HcclReduceInner", op), tag.c_str());
    4038              :     DevType devType;
    4039           23 :     CHK_RET(hrtGetDeviceType(devType));
    4040           23 :     CHK_RET_AND_PRINT_IDE(HcomCheckReduceDataType(dataType, op, devType), tag.c_str());
    4041              : 
    4042           23 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    4043           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
    4044           23 :     CHK_RET_AND_PRINT_IDE(HcomCheckUserRank(rankSize, root), tag.c_str());
    4045              : 
    4046              :     /* 接口交互信息日志 */
    4047              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    4048           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    4049           23 :         s32 deviceLogicId = 0;
    4050           23 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    4051              : 
    4052           23 :         u32 localRank = INVALID_VALUE_RANKID;
    4053           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    4054              : 
    4055           23 :         s32 streamId = 0;
    4056           23 :         CHK_RET_AND_PRINT_IDE(hrtGetStreamId(stream, streamId), tag.c_str());
    4057              : 
    4058           46 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    4059              :             "tag[%s], sendBuf[%p], recvBuf[%p], count[%llu], dataType[%s], op[%s], root[%u], "
    4060              :             "localRank[%u], streamId[%d], deviceLogicId[%d]",
    4061           69 :             tag.c_str(), sendBuf, recvBuf, count, GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(),
    4062              :             root, localRank, streamId, deviceLogicId);
    4063              : 
    4064           23 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    4065           46 :         std::string logInfo = "Entry-HcclReduceInner:" + std::string(stackLogBuffer) +
    4066           69 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    4067           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    4068           23 :     }
    4069              : 
    4070           23 :     CHK_RET_AND_PRINT_IDE(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE), tag.c_str());
    4071              : 
    4072           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(sendBuf), tag.c_str());
    4073              : 
    4074           23 :     CHK_RET_AND_PRINT_IDE(PrintMemoryAttr(recvBuf), tag.c_str());
    4075              : 
    4076           23 :     CHK_RET_AND_PRINT_IDE(SetOverFlowAddr(hcclComm), tag.c_str());
    4077              : 
    4078           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->ReduceOutPlace(tag, sendBuf, recvBuf, count, dataType, op, root, stream),
    4079              :                               tag.c_str());
    4080              : 
    4081           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_REDUCE, beginTime, count, dataType, tag));
    4082           23 :     if (!isCapture) {
    4083           22 :         HcclResetIfProfile();
    4084              :     }
    4085           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    4086              : 
    4087           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    4088           23 :         HcclUs endut = TIME_NOW();
    4089              :         /* 关键状态记录 */
    4090           23 :         std::string endInfo = "HcclReduceInner:success,take time: " +
    4091           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    4092           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    4093           23 :     }
    4094           23 :     std::string identifier = hcclComm->GetIdentifier();
    4095           23 :     AlgType algType;
    4096           23 :     CHK_RET(hcclComm->GetAlgType(algType, HcclCMDType::HCCL_CMD_REDUCE));
    4097              : 
    4098           23 :     if (hcclNslbDp::GetInstance().GetGlobalCommTaskId() != 0) {
    4099            0 :         AlgTypeLevel1 algValue = algType.algoLevel1;
    4100            0 :         uint8_t nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel1AlgType(algValue);
    4101            0 :         if (devType == DevType::DEV_TYPE_910_93) {
    4102            0 :             AlgTypeLevel2 algValue2 = algType.algoLevel2;
    4103            0 :             nslbAlg = hcclNslbDp::GetInstance().GetNslbLevel2AlgType(algValue2);
    4104              :         }
    4105              :         // NSLB 填充 表6
    4106            0 :         hcclNslbDp::GetInstance().SetNslbDpRootRank(HcclCMDType::HCCL_CMD_REDUCE, root, identifier, nslbAlg);
    4107              :     }
    4108           23 :     return HCCL_SUCCESS;
    4109           24 : }
    4110              : 
    4111            0 : HcclResult ReduceLoop(const std::string &tag, void *inputPtr, void *outputPtr, const u64 count,
    4112              :     HcclDataType dataType, HcclReduceOp op, const u32 root, hccl::hcclComm *hcclComm, rtStream_t stream)
    4113              : {
    4114            0 :     HcclSetIfProfile();
    4115              : 
    4116            0 :     void *commInputPtr = nullptr;
    4117            0 :     void *commOutputPtr = nullptr;
    4118              :     u64 commInputSize, commOutputSize;
    4119              : 
    4120              :     HcclResult ret;
    4121            0 :     CHK_RET(hcclComm->GetInCCLbuffer(commInputPtr, commInputSize));
    4122            0 :     CHK_PTR_NULL(commInputPtr);
    4123              : 
    4124            0 :     CHK_RET(hcclComm->GetOutCCLbuffer(commOutputPtr, commOutputSize));
    4125            0 :     CHK_PTR_NULL(commOutputPtr);
    4126              : 
    4127              :     u32 unitSize;
    4128            0 :     CHK_RET(SalGetDataTypeSize(dataType, unitSize));
    4129              : 
    4130            0 :     char *curInputPtr = static_cast<char *>(inputPtr);
    4131            0 :     char *curOutputPtr = static_cast<char *>(outputPtr);
    4132            0 :     u64 inputOffset = 0;
    4133            0 :     u64 outputOffset = 0;
    4134            0 :     u64 countLeft = count;
    4135              : 
    4136            0 :     while (countLeft > 0) {
    4137            0 :         curInputPtr += inputOffset;
    4138            0 :         curOutputPtr += outputOffset;
    4139            0 :         HCCL_DEBUG("-OP_BASE-ReduceLoop:inputOffset[%llu], outputOffset[%llu]", inputOffset, outputOffset);
    4140            0 :         u64 curCount = ((countLeft * unitSize) > commInputSize) ? (commInputSize / unitSize) : countLeft; // 单次执行操作的数据量
    4141            0 :         u64 curSize = curCount * unitSize; // 单位 byte
    4142              : 
    4143            0 :         HCCL_DEBUG("-OP_BASE-ReduceLoop:curInputPtr[%p], curOutputPtr[%p], curCount[%llu], curSize[%llu]",
    4144              :             curInputPtr, curOutputPtr, curCount, curSize);
    4145              : 
    4146            0 :         u32 commRank = INVALID_VALUE_RANKID;
    4147            0 :         CHK_RET(hcclComm->GetUserRank(commRank));
    4148              : 
    4149            0 :         CHK_RET(hrtMemAsyncCopy(commInputPtr, curSize, curInputPtr, curSize,
    4150              :             HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE, stream));
    4151              : 
    4152              :         /* 入参的正确性由HCCL确保 */
    4153            0 :         ret = hcclComm->Reduce(tag, commInputPtr, commOutputPtr, curCount, dataType, op, root, stream);
    4154            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS,
    4155              :             HCCL_ERROR("[Loop][Reduce]errNo[0x%016llx] op_base hcclComm reduce error, tag[%s], "\
    4156              :             "input_ptr[%p], output_ptr[%p], count[%llu], data_type[%s], op[%s], root[%u]",
    4157              :             HCCL_ERROR_CODE(ret), tag.c_str(), commInputPtr, commOutputPtr, curCount,
    4158              :             GetDataTypeEnumStr(dataType).c_str(), GetReduceOpEnumStr(op).c_str(), root), ret);
    4159              : 
    4160            0 :         if (commRank == root) { // 只root rank需要把数据从中转内存拷贝出去
    4161            0 :             CHK_RET(hrtMemAsyncCopy(curOutputPtr, curSize, commOutputPtr, curSize,
    4162              :                 HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_DEVICE, stream));
    4163              :         }
    4164              : 
    4165            0 :         countLeft -= curCount;
    4166            0 :         inputOffset = curSize;
    4167            0 :         outputOffset = curSize;
    4168              :     }
    4169              : 
    4170            0 :     return HCCL_SUCCESS;
    4171              : }
    4172              : 
    4173              : /*
    4174              :  * **********************************************************************
    4175              :  * 单算子GatherAllToAllV的函数接口,目前不对外开放,仅图模式动态shape使用
    4176              :  * **********************************************************************
    4177              :  */
    4178            0 : HcclResult HcclGatherAlltoAllV(HcomGatherAllToAllVParams params, HcclComm comm, aclrtStream stream)
    4179              : {
    4180            0 :     HcclUs startut = TIME_NOW();
    4181            0 :     CHK_PTR_NULL(comm);
    4182            0 :     CHK_PTR_NULL(params.addrInfoCountPerRank);
    4183            0 :     CHK_PTR_NULL(params.recvcounts);
    4184            0 :     CHK_PTR_NULL(params.gatheredbuf);
    4185            0 :     CHK_PTR_NULL(params.rdispls);
    4186              : 
    4187            0 :     const u32 NUM_TWO = 2;
    4188            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4189            0 :     u32 rankSize = 0;
    4190            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    4191              : 
    4192              :     // 同通信域同算子复用tag
    4193            0 :     const string tag = "Reduce_" + hcclComm->GetIdentifier();
    4194              : 
    4195            0 :     std::vector<u64> addrInfoCountPerRank(rankSize, 0);
    4196            0 :     CHK_RET_AND_PRINT_IDE(hrtMemSyncCopy(addrInfoCountPerRank.data(), rankSize * sizeof(u64),
    4197              :         params.addrInfoCountPerRank, rankSize * sizeof(u64),
    4198              :         HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_HOST), tag.c_str());
    4199            0 :     u64 blockNum = 0;
    4200            0 :     for (u32 index = 0; index < rankSize; index++) {
    4201            0 :         blockNum += addrInfoCountPerRank[index];
    4202              :     }
    4203            0 :     if (blockNum != 0) {
    4204            0 :         CHK_PTR_NULL(params.addrInfo);
    4205              :     }
    4206            0 :     std::vector<u64> addrInfo(blockNum * NUM_TWO, 0);
    4207            0 :     CHK_RET_AND_PRINT_IDE(hrtMemSyncCopy(addrInfo.data(), addrInfo.size() * sizeof(u64), params.addrInfo,
    4208              :         addrInfo.size() * sizeof(u64), HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_DEVICE_TO_HOST), tag.c_str());
    4209              : 
    4210              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    4211            0 :     if (GetExternalInputHcclEnableEntryLog()) {
    4212            0 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    4213              :         "tag[%s]", tag.c_str());
    4214              : 
    4215            0 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    4216            0 :         std::string logInfo = "Entry-HcclGatherAlltoAllV:" + std::string(stackLogBuffer);
    4217            0 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(logInfo), tag.c_str());
    4218            0 :     }
    4219              : 
    4220              :     // 执行gather
    4221            0 :     u64 sendCounts = static_cast<u64>(rankSize);
    4222            0 :     u64 sdispls = static_cast<u64>(rankSize);
    4223              : 
    4224              :     // step1 gather
    4225            0 :     GatherPara gatherPara;
    4226            0 :     gatherPara.addrInfo = addrInfo;
    4227            0 :     gatherPara.rankSize = rankSize;
    4228            0 :     gatherPara.addrInfoCountPerRank = addrInfoCountPerRank;
    4229            0 :     gatherPara.addrLength = params.addrLength;
    4230            0 :     CHK_RET_AND_PRINT_IDE(RunGather(&sendCounts, &sdispls, params.gatheredbuf, gatherPara), tag.c_str());
    4231              : 
    4232              :     // step2 alltoallv
    4233            0 :     CHK_RET_AND_PRINT_IDE(HcclAlltoAllVInner(params.gatheredbuf, &sendCounts, &sdispls, params.recvtype, params.recvbuf,
    4234              :         params.recvcounts, params.rdispls, params.recvtype, comm, stream), tag.c_str());
    4235              : 
    4236            0 :     if (GetExternalInputHcclEnableEntryLog()) {
    4237            0 :         HcclUs endut = TIME_NOW();
    4238            0 :         std::string endInfo = "HcclGatherAlltoAllV:success,take time: " +
    4239            0 :             std::to_string(DURATION_US(endut - startut).count()) + " us," + std::string(stackLogBuffer);
    4240            0 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    4241            0 :     }
    4242              : 
    4243            0 :     return HCCL_SUCCESS;
    4244            0 : }
    4245              : 
    4246              : /*
    4247              :  * **********************************************************************
    4248              :  * 单算子GatherAllToAllV step1 执行gather,出参作为step2的入参
    4249              :  * **********************************************************************
    4250              :  */
    4251            0 : HcclResult RunGather(u64 *sendCounts, u64 *sdispls, void *sendDevBuf, GatherPara &gatherPara)
    4252              : {
    4253            0 :     u64 memSize = 0;
    4254            0 :     const u32 GATHER_THREAD_NUM = 16;
    4255            0 :     const u32 NUM_TWO = 2;
    4256            0 :     u64 perThreadCount = gatherPara.addrInfo.size() / NUM_TWO / GATHER_THREAD_NUM;
    4257            0 :     std::vector<u64> perThreadCounts(GATHER_THREAD_NUM, perThreadCount);
    4258            0 :     perThreadCounts[GATHER_THREAD_NUM - 1] =
    4259            0 :         gatherPara.addrInfo.size() / NUM_TWO - perThreadCount * (GATHER_THREAD_NUM - 1);
    4260            0 :     std::vector<u64> offset(GATHER_THREAD_NUM, 0);
    4261            0 :     if (gatherPara.addrLength == -1) { // 数据包长度不一样的情况
    4262            0 :         u32 offsetIndex = 0;
    4263            0 :         for (u32 index = 1; index < gatherPara.addrInfo.size(); index += NUM_TWO) { // 由于是二元组,单数为数据包的长度,每个循环+2
    4264              :             /* 如果数据包数量小于线程数量则offset全置为0 */
    4265            0 :             if (perThreadCount != 0 && index / NUM_TWO % perThreadCount == 0 && offsetIndex < GATHER_THREAD_NUM) {
    4266              :                 /* 条件1:当累加的数量达到perThreadCount时往offset中填入累加值,即可计算出前面thread产生的offset值 */
    4267              :                 /* 条件2:由于第0个thread的offset为0,后面的线程的offset为前面线程处理数据量的累加,因此对最后一个值弃之不用 */
    4268            0 :                 offset[offsetIndex] = memSize;
    4269            0 :                 offsetIndex++;
    4270              :             }
    4271            0 :             memSize += gatherPara.addrInfo[index];
    4272              :         }
    4273              :     } else {
    4274            0 :         memSize = gatherPara.addrInfo.size() / NUM_TWO * gatherPara.addrInfo[1];
    4275            0 :         for (u32 index = 0; index < GATHER_THREAD_NUM; index++) {
    4276            0 :             offset[index] = index * perThreadCount * gatherPara.addrInfo[1];
    4277              :         }
    4278              :     }
    4279              : 
    4280              :     // 多线程拷贝
    4281            0 :     HostMem tmpHostMem = HostMem::alloc(memSize);
    4282            0 :     CHK_PTR_NULL(tmpHostMem.ptr());
    4283            0 :     std::vector<std::unique_ptr<std::thread>> threads(GATHER_THREAD_NUM);
    4284            0 :     for (u32 num = 0; num < GATHER_THREAD_NUM; num++) {
    4285              :         OpBaseMemPara memPara;
    4286            0 :         memPara.beginIndex = num * perThreadCount * NUM_TWO;
    4287            0 :         memPara.count = perThreadCounts[num];
    4288            0 :         memPara.tmpMemSize = memSize;
    4289            0 :         threads[num].reset(new (std::nothrow) std::thread(&GatherMemCopyThread, tmpHostMem.ptr(),
    4290            0 :             offset[num], std::ref(gatherPara.addrInfo), memPara));
    4291            0 :         CHK_PRT_RET(!threads[num], HCCL_ERROR("[Exec][EnqueueGatherAlltoAllV]threads[%u] reset "\
    4292              :             "failed ", num), HCCL_E_INTERNAL);
    4293              :     }
    4294              : 
    4295              :     // 构造入参
    4296            0 :     auto ret = memset_s(sendCounts, gatherPara.rankSize * sizeof(u64), 0, gatherPara.rankSize * sizeof(u64));
    4297            0 :     CHK_PRT_RET(ret != EOK, HCCL_ERROR("[Exec][EnqueueGatherAlltoAllV] mem set failed, count[%lld]",
    4298              :         gatherPara.rankSize * sizeof(u64)), HCCL_E_SYSCALL);
    4299            0 :     u64 prevNum = 0;
    4300            0 :     u64 nextNum = 0;
    4301            0 :     for (u32 index = 0; index < gatherPara.addrInfoCountPerRank.size(); index++) {
    4302            0 :         nextNum += gatherPara.addrInfoCountPerRank[index];
    4303            0 :         for (u64 i = NUM_TWO * prevNum; i < NUM_TWO * nextNum; i += NUM_TWO) {
    4304            0 :             *(sendCounts + index) += gatherPara.addrInfo[i + 1];
    4305              :         }
    4306            0 :         prevNum = nextNum;
    4307              :     }
    4308              : 
    4309            0 :     ret = memset_s(sdispls, gatherPara.rankSize * sizeof(u64), 0, gatherPara.rankSize * sizeof(u64));
    4310            0 :     CHK_PRT_RET(ret != EOK, HCCL_ERROR("[Exec][EnqueueGatherAlltoAllV] mem set failed, count[%lld]",
    4311              :         gatherPara.rankSize * sizeof(u64)), HCCL_E_SYSCALL);
    4312            0 :     u64 displ = 0;
    4313            0 :     for (u32 i = 0; i < gatherPara.rankSize; i++) {
    4314            0 :         *(sdispls + i) = displ;
    4315            0 :         displ += *(sendCounts + i);
    4316              :     }
    4317              : 
    4318              :     // 等待线程执行完毕
    4319            0 :     for (u32 num = 0; num < GATHER_THREAD_NUM; num++) {
    4320            0 :         threads[num]->join();
    4321              :     }
    4322              : 
    4323            0 :     CHK_RET(hrtMemSyncCopy(sendDevBuf, memSize, tmpHostMem.ptr(), memSize,
    4324              :         HcclRtMemcpyKind::HCCL_RT_MEMCPY_KIND_HOST_TO_DEVICE));
    4325            0 :     return HCCL_SUCCESS;
    4326            0 : }
    4327              : 
    4328              : /*
    4329              :  * **********************************************************************
    4330              :  * 单算子GatherAllToAllV gather多线程拷贝
    4331              :  * **********************************************************************
    4332              :  */
    4333            0 : void GatherMemCopyThread(void *baseAddr, u64 offset, std::vector<u64> &addrInfo, OpBaseMemPara memCpyPara)
    4334              : {
    4335              :     //给当前线程添加名字
    4336            0 :     SetThreadName("Hccl_GatherCopy");
    4337              : 
    4338            0 :     void *addr = nullptr;
    4339            0 :     const u32 NUM_TWO = 2;
    4340            0 :     u64 length = 0;
    4341            0 :     auto destMax = [&]()-> u64 {
    4342            0 :         return memCpyPara.tmpMemSize < offset ? 0 : memCpyPara.tmpMemSize - offset;
    4343            0 :     };
    4344              : 
    4345            0 :     for (u32 index = 0; index < memCpyPara.count; index++) {
    4346            0 :         addr = reinterpret_cast<void *>(addrInfo[memCpyPara.beginIndex + NUM_TWO * index]);
    4347            0 :         length = addrInfo[memCpyPara.beginIndex + index * NUM_TWO + 1];
    4348            0 :         if (memcpy_s(static_cast<s8 *>(baseAddr) + offset, destMax(), addr, length) != EOK) {
    4349            0 :             HCCL_ERROR("[MemCopy][GatherAlltoAllV] mem copy failed, destMax[%llu], count[%llu]",
    4350              :                 memCpyPara.tmpMemSize - offset, length);
    4351            0 :             return;
    4352              :         }
    4353            0 :         offset += length;
    4354              :     }
    4355              : }
    4356              : 
    4357              : /*
    4358              :  * **********************************************************************
    4359              :  * 获取HCCL错误
    4360              :  * **********************************************************************
    4361              :  */
    4362            1 : HcclResult HcclGetCommAsyncError(HcclComm comm, HcclResult *asyncError)
    4363              : {
    4364           21 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4365              :         std::vector<std::string>({"HcclCommGetAsyncError", "nullptr", "comm", "non-null pointer"}));
    4366            1 :     CHK_PTR_NULL(comm);
    4367            0 :     CHK_PTR_NULL(asyncError);
    4368              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4369            0 :     HCCLV2_FUNC_RUN(HcclGetCommAsyncErrorV2());
    4370              : #endif
    4371            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4372            0 :     CHK_RET(hcclComm->CommCheckErrorCqe(*asyncError));
    4373            0 :     if (*asyncError == HCCL_SUCCESS) {
    4374            0 :         CHK_RET(hcclComm->CommCheckOpInconsistentError(*asyncError));
    4375              :     } 
    4376            0 :     return HCCL_SUCCESS;
    4377              : }
    4378              : 
    4379              : /*
    4380              :  * **********************************************************************
    4381              :  * HCCL提供错误码到字符串的转换
    4382              :  * **********************************************************************
    4383              :  */
    4384           22 : const char *HcclGetErrorString(HcclResult code)
    4385              : {
    4386           22 :     if (code < HcclResult::HCCL_SUCCESS || code >= HcclResult::HCCL_E_RESERVED) {
    4387            0 :         return "unknown error";
    4388              :     }
    4389            0 :     static const std::map<HcclResult, std::string> errorMap = {{HCCL_SUCCESS, "no error"},
    4390            0 :         {HCCL_E_PARA, "parameter error"}, {HCCL_E_PTR, "empty pointer"},
    4391            0 :         {HCCL_E_MEMORY, "memory error"}, {HCCL_E_INTERNAL, "internal error"},
    4392            0 :         {HCCL_E_NOT_SUPPORT, "not support feature"}, {HCCL_E_NOT_FOUND, "not found specific resource"},
    4393            0 :         {HCCL_E_UNAVAIL, "resource unavailable"}, {HCCL_E_SYSCALL, "call system interface error"},
    4394            0 :         {HCCL_E_TIMEOUT, "timeout"}, {HCCL_E_OPEN_FILE_FAILURE, "open file fail"},
    4395            0 :         {HCCL_E_TCP_CONNECT, "tcp connect fail"}, {HCCL_E_ROCE_CONNECT, "roce connect fail"},
    4396            0 :         {HCCL_E_TCP_TRANSFER, "tcp transfer fail"}, {HCCL_E_ROCE_TRANSFER, "roce transfer fail"},
    4397            0 :         {HCCL_E_RUNTIME, "call runtime api fail"}, {HCCL_E_DRV, "call driver api fail"},
    4398            0 :         {HCCL_E_PROFILING, "call profiling api fail"}, {HCCL_E_CCE, "call cce api fail"},
    4399            0 :         {HCCL_E_NETWORK, "call network api fail"}, {HCCL_E_AGAIN, "try again"},
    4400            0 :         {HCCL_E_REMOTE, "error cqe"}, {HCCL_E_SUSPENDING, "error communicator suspending"},
    4401           49 :             {HCCL_E_OPRETRY_FAIL, "retry constraint"}, {HCCL_E_OOM, "out of memory"}};
    4402              : 
    4403           22 :     auto it = errorMap.find(code);
    4404           22 :     if (it != errorMap.end()) {
    4405           22 :         return it->second.c_str();
    4406              :     } else {
    4407            0 :         return "unknown err";
    4408              :     }
    4409            1 : }
    4410              : 
    4411              : /*
    4412              :  * 配置溢出检测地址
    4413              :  */
    4414           92 : HcclResult SetOverFlowAddr(hccl::hcclComm *hcclComm)
    4415              : {
    4416           92 :     std::vector<void *> globalWorkSpaceAddr;
    4417           92 :     CHK_RET(hcclComm->SetGlobalWorkSpace(globalWorkSpaceAddr));
    4418           92 :     return HCCL_SUCCESS;
    4419           92 : }
    4420              : 
    4421              : #ifdef __cplusplus
    4422              : extern "C" {
    4423              : #endif // __cplusplus
    4424            0 : HcclResult HcclCreateComResource(const char *commName, u32 streamMode, void** commContext)
    4425              : {
    4426            0 :     RPT_INPUT_ERR(commName == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4427              :         std::vector<std::string>({"HcclCreateComResource", "nullptr", "commName", "non-null pointer"}));
    4428              : 
    4429            0 :     RPT_INPUT_ERR(commContext == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4430              :         std::vector<std::string>({"HcclCreateComResource", "nullptr", "commContext", "non-null pointer"}));
    4431              :     // 切换线程后获取不到hcom上下文,需重新刷新一次线程操作的deviceid
    4432            0 :     s32 deviceLogicId = 0;
    4433            0 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    4434            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    4435            0 :     CHK_RET(HcomGetCommByGroup(commName, hcclComm));
    4436            0 :     HcclComm comm = hcclComm.get();
    4437            0 :     CHK_RET(HcclCreateComResourceByComm(comm, streamMode, true, commContext));
    4438            0 :     return HCCL_SUCCESS;
    4439            0 : }
    4440              : 
    4441              : #ifdef __cplusplus
    4442              : }
    4443              : #endif // __cplusplus
    4444              : 
    4445            0 : HcclResult HcclCreateComResourceByComm(HcclComm comm, u32 streamMode, bool isOpbaseMode,
    4446              :     void** commContext, bool isMC2, void* mc2Tiling)
    4447              : {
    4448            0 :     HcclUs startut = TIME_NOW();
    4449            0 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4450              :         std::vector<std::string>({"HcclCreateComResource", "nullptr", "comm", "non-null pointer"}));
    4451              : 
    4452            0 :     RPT_INPUT_ERR(commContext == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4453              :         std::vector<std::string>({"HcclCreateComResource", "nullptr", "commContext", "non-null pointer"}));
    4454              : 
    4455              :     // 同通信域同算子复用tag
    4456            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4457            0 :     u32 moduleNum = hcclComm->GetModuleNum();
    4458              :     // mc2算子更改tag
    4459              :     DevType devType;
    4460            0 :     CHK_RET(hrtGetDeviceType(devType));
    4461            0 :     string commIdentifier = hcclComm->GetIdentifier();
    4462            0 :     string tag = "CreatecomResource_" + commIdentifier;
    4463            0 :     std::string algConfigMc2 = "";
    4464            0 :     if (isMC2 && devType == DevType::DEV_TYPE_910B &&
    4465              :         (moduleNum > HCCL_DEVICE_NUM_ONE)) {
    4466            0 :         tag += HCCL_MC2_MULTISERVER_SUFFIX;
    4467              :         const void *tilingList[MAX_HCOM_NUM];
    4468              :         uint32_t tilingNum;
    4469            0 :         CHK_RET(HcclGetInitTilingList(mc2Tiling, tilingList, tilingNum));
    4470            0 :         const Mc2HcommCfg *tiling = static_cast<const Mc2HcommCfg *>(tilingList[0]);
    4471            0 :         if (tiling != nullptr && string(tiling->groupName) == commIdentifier) {
    4472            0 :             algConfigMc2 = string(tiling->algConfig);
    4473              :         }
    4474              :     }
    4475              : 
    4476              :     // A2 MC2引擎默认为AICPU
    4477            0 :     if (isMC2) {
    4478            0 :         CHK_RET(hcclComm->SetAicpuCommEngine(true));
    4479              :     }
    4480              : 
    4481            0 :     if (LIKELY(hcclComm->GetCommResource(tag, commContext))) {
    4482            0 :         return HCCL_SUCCESS;
    4483              :     }
    4484              : 
    4485              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    4486            0 :     if (GetExternalInputHcclEnableEntryLog()) {
    4487            0 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U, "tag[%s], commContext[%p]", tag.c_str(),
    4488              :             commContext);
    4489            0 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    4490              :     }
    4491            0 :     const std::lock_guard<std::mutex> lock(hcclComm->operatorlock_);
    4492              : 
    4493            0 :     u32 localRank = INVALID_VALUE_RANKID;
    4494            0 :     CHK_RET(hcclComm->GetUserRank(localRank));
    4495              : 
    4496            0 :     if (GetExternalInputHcclEnableEntryLog()) {
    4497              :         /* 接口交互信息日志 */
    4498            0 :         std::string logInfo = "Entry-HcclCreateComResource:localRank[" + std::to_string(localRank)
    4499            0 :             + "]" + std::string(stackLogBuffer);
    4500            0 :         CHK_RET(hcclComm->SaveTraceInfo(logInfo));
    4501            0 :     }
    4502              : 
    4503              :     // SetWorkflowMode性能开销hrtGetDevice,0.11us
    4504            0 :     HcclUs middleut0 = TIME_NOW();
    4505            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
    4506            0 :     HcclUs middleut1 = TIME_NOW();
    4507              :     rtStream_t stream;
    4508            0 :     CHK_RET(hcclComm->Mc2AiCpuStreamAllocAndGet(streamMode, stream));
    4509            0 :     CHK_RET(hcclComm->CreateCommResource(tag, stream, isOpbaseMode, commContext, algConfigMc2));
    4510              : 
    4511            0 :     if (GetExternalInputHcclEnableEntryLog()) {
    4512            0 :         HcclUs endut = TIME_NOW();
    4513              :         /* 关键状态记录 */
    4514              :         std::string endInfo = "HcclCreateComResource success, HcclCreateComResource take time ["
    4515            0 :             + std::to_string(DURATION_US(endut - startut).count()) + "]us, CreateComResource take time ["
    4516            0 :             + std::to_string(DURATION_US(endut - middleut1).count()) + "]us, SetWorkflowMode take time ["
    4517            0 :             + std::to_string(DURATION_US(middleut1 - middleut0).count()) + "]us, localRank["
    4518            0 :             + std::to_string(localRank) + "] " + std::string(stackLogBuffer);
    4519            0 :         CHK_RET(hcclComm->SaveTraceInfo(endInfo));
    4520            0 :     }
    4521              : 
    4522            0 :     return HCCL_SUCCESS;
    4523            0 : }
    4524              : 
    4525           50 : void PrintCountsAndDispls(const u32 length, const void *counts, const void *displs, const std::string &tag)
    4526              : {
    4527              :     // 打印counts和displs
    4528           50 :     const u64 *countsPtr = static_cast<const u64 *>(counts);
    4529           50 :     const u64 *displsPtr = static_cast<const u64 *>(displs);
    4530           50 :     if (HcclCheckLogLevel(DLOG_DEBUG)) {
    4531           50 :         std::ostringstream countsStream;
    4532           50 :         std::ostringstream displsStream;
    4533           50 :         countsStream << "[ ";
    4534           50 :         displsStream << "[ ";
    4535          114 :         for (u32 i = 0; i < length; ++i) {
    4536           64 :             countsStream << countsPtr[i] << " ";
    4537           64 :             displsStream << displsPtr[i] << " ";
    4538              :         }
    4539           50 :         countsStream << "]";
    4540           50 :         displsStream << "]";
    4541           50 :         HCCL_DEBUG("[PrintCountsAndDispls]tag[%s], counts%s", tag.c_str(), countsStream.str().c_str());
    4542           50 :         HCCL_DEBUG("[PrintCountsAndDispls]tag[%s], displs%s", tag.c_str(), displsStream.str().c_str());
    4543           50 :     }
    4544           50 : }
    4545              : 
    4546           50 : void CheckCountsAndDispls(const u32 length, const void *counts, const void *displs, const std::string &tag)
    4547              : {
    4548              :     // 校验counts和displs是否匹配
    4549           50 :     const u64 *countsPtr = static_cast<const u64 *>(counts);
    4550           50 :     const u64 *displsPtr = static_cast<const u64 *>(displs);
    4551           50 :     u64 displsCal = 0;
    4552              : 
    4553          114 :     for (u32 i = 0; i < length; i++) {
    4554           64 :         if (displsCal != displsPtr[i]) {
    4555            0 :             HCCL_WARNING("[CheckCountsAndDispls]tag[%s], displs[%u]: [%llu] memory is discontinuous.",
    4556              :                 tag.c_str(), i, displsPtr[i]);
    4557              :         }
    4558              : 
    4559           64 :         displsCal = displsCal + countsPtr[i];
    4560              :     }
    4561           50 : }
    4562              : 
    4563              : #ifdef __cplusplus
    4564              : extern "C" {
    4565              : #endif // __cplusplus
    4566            0 : HcclResult HcclGetAicpuOpStreamNotify(const char *commName, rtStream_t* opstream, void** aicpuNotify)
    4567              : {
    4568            0 :     RPT_INPUT_ERR(commName == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4569              :         std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "commName", "non-null pointer"}));
    4570              : 
    4571            0 :     RPT_INPUT_ERR(opstream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4572              :         std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "opstream", "non-null pointer"}));
    4573              : 
    4574            0 :     RPT_INPUT_ERR(aicpuNotify == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4575              :         std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "aicpuNotify", "non-null pointer"}));
    4576              :     // 切换线程后获取不到hcom上下文,需重新刷新一次线程操作的deviceid
    4577            0 :     s32 deviceLogicId = 0;
    4578            0 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    4579            0 :     std::shared_ptr<hccl::hcclComm> hcclComm;
    4580            0 :     CHK_RET(HcomGetCommByGroup(commName, hcclComm));
    4581              : 
    4582            0 :     CHK_RET(hcclComm->GetAicpuOpStreamNotify(opstream, 1, aicpuNotify));
    4583            0 :     return HCCL_SUCCESS;
    4584            0 : }
    4585              : 
    4586            0 : HcclResult HcclGetAicpuOpStreamAndNotify(HcclComm comm, rtStream_t* opstream, u8 aicpuNotifyNum, void** aicpuNotify)
    4587              : {
    4588            0 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4589              :         std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "comm", "non-null pointer"}));
    4590              : 
    4591            0 :     RPT_INPUT_ERR(opstream == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4592              :         std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "opstream", "non-null pointer"}));
    4593              : 
    4594            0 :     RPT_INPUT_ERR(aicpuNotify == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4595              :         std::vector<std::string>({"HcclGetAicpuOpStream", "nullptr", "aicpuNotify", "non-null pointer"}));
    4596              :     // 切换线程后获取不到hcom上下文,需重新刷新一次线程操作的deviceid
    4597            0 :     s32 deviceLogicId = 0;
    4598            0 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    4599              :  #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4600            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    4601              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4602              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    4603              :         CHK_PTR_NULL(commV2);
    4604              :         CHK_RET(HcclGetAicpuOpStreamAndNotifyV2(commV2, opstream, aicpuNotifyNum, aicpuNotify));
    4605              :         return HCCL_SUCCESS;
    4606              :     }());
    4607              : #endif
    4608            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4609              : 
    4610            0 :     CHK_RET(hcclComm->GetAicpuOpStreamNotify(opstream, aicpuNotifyNum, aicpuNotify));
    4611            0 :     return HCCL_SUCCESS;
    4612              : }
    4613              : #ifdef __cplusplus
    4614              : }
    4615              : #endif // __cplusplus
    4616              : 
    4617            0 : HcclResult HcclBatchSendRecvGroup(HcclSendRecvItem* sendRecvInfo, uint32_t itemNum, HcclComm comm, aclrtStream stream)
    4618              : {
    4619            0 :     HcclUs startut = TIME_NOW();
    4620              :     bool isCapture;
    4621            0 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    4622            0 :     uint64_t modelId = 0xFFFFFFFF;
    4623            0 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    4624            0 :     if (!isCapture) {
    4625            0 :         HcclSetIfProfile();
    4626              :     }
    4627            0 :     s32 threadID = SalGetTid();
    4628            0 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    4629            0 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    4630              : 
    4631              :     // 入参校验
    4632            0 :     CHK_PTR_NULL(comm);
    4633            0 :     CHK_PTR_NULL(stream);
    4634              : 
    4635            0 :     CHK_PTR_NULL(sendRecvInfo);
    4636            0 :     CHK_PRT_RET((itemNum == 0), HCCL_WARNING("[BatchSendRecvGroup] taskList itemNum is zero."), HCCL_SUCCESS);
    4637              : 
    4638            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4639            0 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    4640              :     // 若任务不同,也复用tag
    4641            0 :     const string tag = "worldBatchSendRecvGroup_" + hcclComm->GetIdentifier();
    4642            0 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    4643            0 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
    4644            0 :     u32 rankId = INVALID_VALUE_RANKID;
    4645            0 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetGroupRank(rankId), tag.c_str());
    4646              : 
    4647              :     /* 记录接口交互信息日志 */
    4648              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    4649            0 :     if (GetExternalInputHcclEnableEntryLog()) {
    4650            0 :         s32 deviceLogicId = 0;
    4651            0 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    4652              : 
    4653            0 :         u32 localRank = INVALID_VALUE_RANKID;
    4654            0 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    4655              : 
    4656            0 :         s32 streamId = 0;
    4657            0 :         CHK_RET(hrtGetStreamId(stream, streamId));
    4658              : 
    4659            0 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    4660              :             "tag[%s], itemNum[%u], localRank[%u], streamId[%d], deviceLogicId[%d]", tag.c_str(), itemNum, localRank, streamId, deviceLogicId);
    4661              : 
    4662            0 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    4663            0 :         std::string logInfo = "Entry-HcclBatchSendRecvGroup:" + std::string(stackLogBuffer) +
    4664            0 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    4665            0 :         CHK_RET(hcclComm->SaveTraceInfo(logInfo));
    4666            0 :     }
    4667              : 
    4668            0 :     for (u32 i = 0; i < itemNum; i++) {
    4669            0 :         CHK_PTR_NULL((sendRecvInfo + i)->buf);
    4670            0 :         CHK_RET(HcomCheckDataType((sendRecvInfo + i)->dataType));
    4671            0 :         CHK_RET(HcomCheckCount((sendRecvInfo + i)->count));
    4672            0 :         CHK_RET(HcomCheckUserRank(rankSize, (sendRecvInfo + i)->remoteRank));
    4673            0 :         if (GetExternalInputHcclEnableEntryLog()) {
    4674              :             char stackLogBuffer[LOG_TMPBUF_SIZE];
    4675            0 :             s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    4676              :                 "SendRecvItem : SendRecvType[%d], remoteRank[%u], count[%llu], dataType[%d], buf[%p].",
    4677            0 :                 (sendRecvInfo + i)->sendRecvType, (sendRecvInfo + i)->remoteRank, (sendRecvInfo + i)->count,
    4678            0 :                 (sendRecvInfo + i)->dataType, (sendRecvInfo + i)->buf);
    4679            0 :             CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    4680            0 :             std::string logInfo = "[HcclBatchSendRecvGroup]" + std::string(stackLogBuffer);
    4681            0 :             CHK_RET(hcclComm->SaveTraceInfo(logInfo));
    4682            0 :         }
    4683              :     }
    4684              : 
    4685            0 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
    4686            0 :     HCCL_INFO("About to enter BatchSendRecv, itemNum[%u]", itemNum);
    4687            0 :     CHK_RET_AND_PRINT_IDE(hcclComm->BatchSendRecv(tag, sendRecvInfo, itemNum, stream), tag.c_str());
    4688            0 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_BATCH_SEND_RECV, beginTime, sendRecvInfo->count,
    4689              :         sendRecvInfo->dataType, tag));
    4690            0 :     if (!isCapture) {
    4691            0 :         HcclResetIfProfile();
    4692              :     }
    4693            0 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    4694              : 
    4695            0 :     if (GetExternalInputHcclEnableEntryLog()) {
    4696            0 :         HcclUs endut = TIME_NOW();
    4697              :         /* 关键状态记录 */
    4698            0 :         std::string endInfo = "HcclBatchSendRecvGroup:success,take time: " +
    4699            0 :             std::to_string(DURATION_US(endut - startut).count()) + " us, tag: " + tag;
    4700            0 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    4701            0 :     }
    4702              : 
    4703            0 :     return HCCL_SUCCESS;
    4704            0 : }
    4705              : 
    4706           26 : HcclResult HcclBatchSendRecvInner(HcclSendRecvItem* sendRecvInfo, uint32_t itemNum, HcclComm comm, aclrtStream stream)
    4707              : {
    4708              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4709           26 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    4710              :         CHK_PTR_NULL(comm);
    4711              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4712              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    4713              :         CHK_PTR_NULL(commV2);
    4714              :         CHK_RET(HcclBatchSendRecvV2(sendRecvInfo, itemNum, commV2, stream));
    4715              :         return HCCL_SUCCESS;
    4716              :     }());
    4717              : #endif
    4718           26 :     HcclUs startut = TIME_NOW();
    4719              :     bool isCapture;
    4720           26 :     aclmdlRICaptureStatus captureStatus = aclmdlRICaptureStatus::ACL_MODEL_RI_CAPTURE_STATUS_NONE;
    4721           26 :     uint64_t modelId = 0xFFFFFFFF;
    4722           26 :     CHK_PRT(GetCaptureInfo(stream, captureStatus, modelId, isCapture));
    4723           26 :     if (!isCapture) {
    4724           25 :         HcclSetIfProfile();
    4725              :     }
    4726           26 :     s32 threadID = SalGetTid();
    4727           26 :     ProfilingManagerPub::SetThreadCaptureStatus(threadID, isCapture);
    4728           26 :     uint64_t beginTime = hrtMsprofSysCycleTime();
    4729              : 
    4730              :     // 入参校验
    4731           26 :     CHK_PTR_NULL(comm);
    4732           25 :     CHK_PTR_NULL(stream);
    4733              : 
    4734           25 :     CHK_PTR_NULL(sendRecvInfo);
    4735           24 :     CHK_PRT_RET((itemNum == 0), HCCL_WARNING("[BatchSendRecv] taskList itemNum is zero."), HCCL_SUCCESS);
    4736              : 
    4737           23 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4738           23 :     StateGuard<hccl::hcclComm, HcclCommState> guard(hcclComm, HcclCommState::INUSE);
    4739              :     // 若任务不同,也复用tag
    4740           23 :     const string tag = "worldBatchSendRecv_" + hcclComm->GetIdentifier();
    4741           23 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    4742           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetRankSize(rankSize), tag.c_str());
    4743           23 :     u32 rankId = INVALID_VALUE_RANKID;
    4744           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->GetGroupRank(rankId), tag.c_str());
    4745              : 
    4746              :     /* 记录接口交互信息日志 */
    4747              :     char stackLogBuffer[LOG_TMPBUF_SIZE];
    4748           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    4749           23 :         s32 deviceLogicId = 0;
    4750           23 :         CHK_RET(HcclDeviceRefresh(deviceLogicId));
    4751              : 
    4752           23 :         u32 localRank = INVALID_VALUE_RANKID;
    4753           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->GetUserRank(localRank), tag.c_str());
    4754              : 
    4755           23 :         s32 streamId = 0;
    4756           23 :         CHK_RET(hrtGetStreamId(stream, streamId));
    4757              : 
    4758           23 :         s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    4759              :             "tag[%s], itemNum[%u], localRank[%u], streamId[%d], deviceLogicId[%d]", tag.c_str(), itemNum, localRank, streamId, deviceLogicId);
    4760              : 
    4761           23 :         CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    4762           46 :         std::string logInfo = "Entry-HcclBatchSendRecvInner:" + std::string(stackLogBuffer) +
    4763           69 :             ", capture status[" + to_string(captureStatus) + "], model id[" + to_string(modelId) + "].";
    4764           23 :         CHK_RET(hcclComm->SaveTraceInfo(logInfo));
    4765           23 :     }
    4766              : 
    4767           46 :     for (u32 i = 0; i < itemNum; i++) {
    4768              :         // 支持数据量为0的场景,buf为空的item跳过
    4769           23 :         if ((sendRecvInfo + i)->buf == nullptr) {
    4770            0 :             continue;
    4771              :         }
    4772           23 :         CHK_RET(HcomCheckDataType((sendRecvInfo + i)->dataType));
    4773           23 :         CHK_RET(HcomCheckCount((sendRecvInfo + i)->count));
    4774           23 :         CHK_RET(HcomCheckUserRank(rankSize, (sendRecvInfo + i)->remoteRank));
    4775           23 :         if (GetExternalInputHcclEnableEntryLog()) {
    4776              :             char stackLogBuffer[LOG_TMPBUF_SIZE];
    4777           46 :             s32 ret = snprintf_s(stackLogBuffer, LOG_TMPBUF_SIZE, LOG_TMPBUF_SIZE - 1U,
    4778              :                 "SendRecvItem : SendRecvType[%d], remoteRank[%u], count[%llu], dataType[%d], buf[%p].",
    4779           23 :                 (sendRecvInfo + i)->sendRecvType, (sendRecvInfo + i)->remoteRank, (sendRecvInfo + i)->count,
    4780           23 :                 (sendRecvInfo + i)->dataType, (sendRecvInfo + i)->buf);
    4781           23 :             CHK_PRT_CONT(ret == -1, HCCL_WARNING("Failed to build log info, tag[%s].", tag.c_str()));
    4782           23 :             std::string logInfo = "[HcclBatchSendRecvInner]" + std::string(stackLogBuffer);
    4783           23 :             CHK_RET(hcclComm->SaveTraceInfo(logInfo));
    4784           23 :         }
    4785              :     }
    4786              : 
    4787           23 :     CHK_RET(SetWorkflowMode(HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE));
    4788           23 :     CHK_RET_AND_PRINT_IDE(hcclComm->BatchSendRecv(tag, sendRecvInfo, itemNum, stream), tag.c_str());
    4789           23 :     CHK_RET(CallMsprofReportHostApi(hcclComm, HcclCMDType::HCCL_CMD_BATCH_SEND_RECV, beginTime, sendRecvInfo->count,
    4790              :         sendRecvInfo->dataType, tag));
    4791           23 :     if (!isCapture) {
    4792           22 :         HcclResetIfProfile();
    4793              :     }
    4794           23 :     ProfilingManagerPub::DeleteThreadCaptureStatus(threadID);
    4795              : 
    4796           23 :     if (GetExternalInputHcclEnableEntryLog()) {
    4797           23 :         HcclUs endut = TIME_NOW();
    4798              :         /* 关键状态记录 */
    4799           23 :         std::string endInfo = "HcclBatchSendRecvInner:success,take time: " +
    4800           46 :             std::to_string(DURATION_US(endut - startut).count()) + " us, tag: " + tag;
    4801           23 :         CHK_RET_AND_PRINT_IDE(hcclComm->SaveTraceInfo(endInfo), tag.c_str());
    4802           23 :     }
    4803              : 
    4804           23 :     return HCCL_SUCCESS;
    4805           23 : }
    4806              : 
    4807         2095 : HcclResult HcclDeviceRefresh(s32 &deviceLogicId)
    4808              : {
    4809         2095 :     HcclResult ret = hrtGetDeviceRefresh(&g_hcclDeviceId);
    4810         2095 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
    4811              :         HCCL_ERROR("[Get][DeviceRefresh]errNo[0x%016llx] g_hcclDeviceId[%d]"
    4812              :         "get device refresh error.", ret, g_hcclDeviceId), ret);
    4813         2079 :     deviceLogicId = g_hcclDeviceId;
    4814         2079 :     return HCCL_SUCCESS;
    4815              : }
    4816              : 
    4817              : #ifdef __cplusplus
    4818              : extern "C" {
    4819              : #endif // __cplusplus
    4820            0 : int32_t HcclTaskRegister(HcclComm comm, const char *msgTag, Callback cb)
    4821              : {
    4822            0 :     HCCL_INFO("[HcclTaskRegister] start to register task");
    4823              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4824            0 :     CHK_PTR_NULL(comm);
    4825            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4826            0 :     HcclComm commV2 = hcclComm->GetCommunicatorV2();
    4827              :     HcclResult ret;
    4828            0 :     if (commV2 != nullptr) {
    4829            0 :         ret =  HcclTaskRegisterV2(commV2, msgTag, cb);
    4830            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclTaskRegister] TaskRegisterV2 failed, ret[0x%016llx]",
    4831              :             HCCL_ERROR_CODE(ret)), ret);
    4832              :     } else {
    4833            0 :         std::string commId = hcclComm->GetIdentifier();
    4834            0 :         CHK_RET(HcclCheckTaskServiceExist(commId, g_hcclDeviceId));
    4835            0 :         ret = g_taskServiceMap[commId][g_hcclDeviceId]->TaskRegister(msgTag, cb);
    4836            0 :         CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclTaskRegister] TaskRegister failed, ret[0x%016llx]",
    4837              :             HCCL_ERROR_CODE(ret)), ret);
    4838            0 :         return HCCL_SUCCESS;
    4839            0 :     }
    4840              :     uint32_t dpuStreamId;
    4841            0 :     CHK_PTR_NULL(commV2);
    4842            0 :     ret = HcclGetDpuSteamIdV2(commV2, dpuStreamId);
    4843            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclTaskRegister] GetDpuSteamIdV2 failed, ret[0x%016llx]",
    4844              :         HCCL_ERROR_CODE(ret)), ret);
    4845            0 :     hccl::CollComm *collComm = hcclComm->GetCollComm();
    4846            0 :     CHK_PTR_NULL(collComm);
    4847            0 :     collComm->GetHcclCommDfx()->SetDpuStreamId(dpuStreamId);
    4848            0 :     auto profCallback = collComm->GetHcclCommDfx()->GetDpuCallback();
    4849            0 :     CHK_PTR_NULL(profCallback);
    4850            0 :     ret = HcclTaskRegisterProfV2(commV2, profCallback);
    4851            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[HcclTaskRegister] TaskProfRegister failed, ret[0x%016llx]",
    4852              :         HCCL_ERROR_CODE(ret)), ret);
    4853            0 :     return ret;
    4854              : 
    4855              : #endif
    4856              :     return HCCL_E_NOT_SUPPORT;
    4857            0 : }
    4858              : 
    4859            0 : int32_t HcclTaskUnRegister(HcclComm comm,  const char *msgTag)
    4860              : {
    4861            0 :     HCCL_INFO("[HcclTaskUnRegister] start to register task");
    4862              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4863            0 :     CHK_PTR_NULL(comm);
    4864            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4865            0 :     HcclComm commV2 = hcclComm->GetCommunicatorV2();
    4866            0 :     if (commV2 != nullptr) {
    4867            0 :         return HcclTaskUnRegisterV2(commV2, msgTag);
    4868              :     } else {
    4869            0 :         std::string commId = hcclComm->GetIdentifier();
    4870            0 :         CHK_RET(HcclCheckTaskServiceExist(commId, g_hcclDeviceId));
    4871            0 :         return g_taskServiceMap[commId][g_hcclDeviceId]->TaskUnRegister(msgTag);
    4872            0 :     }
    4873              : #endif
    4874              :     return HCCL_E_NOT_SUPPORT;
    4875              : }
    4876              : 
    4877            0 : HcclResult HcclGetTopoDesc(HcclComm comm, HcclTopoDescs *topoDescs, uint32_t topoSize)
    4878              : {
    4879              :     // 入参合法性校验
    4880            0 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4881              :         std::vector<std::string>({"HcclGetTopoDesc", "nullptr", "comm", "non-null pointer"}));
    4882              : 
    4883            0 :     RPT_INPUT_ERR(topoDescs == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    4884              :         std::vector<std::string>({"HcclGetTopoDesc", "nullptr", "topoDescs", "non-null pointer"}));
    4885              : 
    4886            0 :     s32 deviceLogicId = 0;
    4887            0 :     CHK_RET(HcclDeviceRefresh(deviceLogicId));
    4888              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4889            0 :     HCCLV2_FUNC_RUN(HcclGetTopoDescV2());
    4890              : #endif
    4891            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4892            0 :     CHK_RET(hcclComm->GetTopoDesc(topoDescs, topoSize));
    4893              : 
    4894            0 :     return HCCL_SUCCESS;
    4895              : }
    4896              : 
    4897            2 : HcclResult HcclCommSuspend(HcclComm comm)
    4898              : {
    4899              :     // 入参校验
    4900            2 :     CHK_PTR_NULL(comm);
    4901              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4902            1 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    4903              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4904              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    4905              :         CHK_PTR_NULL(commV2);
    4906              :         CHK_RET(HcclCommSuspendV2(commV2));
    4907              :         return HCCL_SUCCESS;
    4908              :     }());
    4909              : #endif
    4910            1 :     HcclUs startut = TIME_NOW();
    4911            1 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    4912            1 :     CHK_RET(hcclComm->Suspend());
    4913            1 :     HcclUs endut = TIME_NOW();
    4914            1 :     HCCL_RUN_INFO("HcclCommSuspend:success, take time:[%lld]us, comm[%s]",
    4915              :         DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str());
    4916            1 :     return HCCL_SUCCESS;
    4917              : }
    4918              : 
    4919              : static std::unordered_map<std::string, pair<HcclCommStateCallback, void*>> g_resumeCallBack;
    4920              : static std::mutex g_callBackMtx; // 保护 g_resumeCallBack
    4921            5 : HcclResult HcclCommRegCommStateCallback(const char *regName, HcclCommStateCallback cb, void *args)
    4922              : {
    4923            5 :     CHK_PTR_NULL(regName);
    4924            4 :     CHK_PTR_NULL(cb);
    4925            3 :     CHK_PTR_NULL(args);
    4926              : 
    4927            2 :     constexpr uint32_t MAX_REG_NAME_LEN = 160;
    4928            2 :     const uint32_t nameLen = strlen(regName);
    4929            2 :     CHK_PRT_RET((nameLen == 0 || nameLen >= MAX_REG_NAME_LEN),
    4930              :         HCCL_ERROR("[%s]Invalid regName, valid length is (0, %u)", __func__, MAX_REG_NAME_LEN), HCCL_E_PARA);
    4931              :     {
    4932            2 :         std::lock_guard<std::mutex> lock(g_callBackMtx);
    4933            4 :         g_resumeCallBack[regName] = std::make_pair(cb, args);
    4934            2 :     }
    4935            2 :     HCCL_RUN_INFO("[%s]Register commStateCallBack success, regName[%s], args[%p].", __func__, regName, args);
    4936            2 :     return HCCL_SUCCESS;
    4937              : }
    4938              : 
    4939              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4940            2 : HcclResult HcclCommResumePostCallback(HcclComm comm) {
    4941            2 :     std::lock_guard<std::mutex> lock(g_callBackMtx);
    4942            4 :     for(const auto& [regName, cbPair] : g_resumeCallBack) {
    4943            2 :         HcclCommStateCallback cb = cbPair.first;
    4944            2 :         void* args = cbPair.second;
    4945            2 :         CHK_RET(cb(comm, HcclCommStatePhase::HCCL_COMM_STATE_PHASE_RESUME_POST, args));
    4946            2 :         HCCL_RUN_INFO("[%s]COMM_STATE_RESUME_POST, regName[%s], args[%p] callback success.", __func__, regName, args);
    4947              :     }
    4948            2 :     return HCCL_SUCCESS;
    4949            2 : }
    4950              : #endif
    4951              : 
    4952            2 : HcclResult HcclCommResume(HcclComm comm)
    4953              : {
    4954              :     // 入参校验
    4955            2 :     CHK_PTR_NULL(comm);
    4956              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4957            1 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    4958              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    4959              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    4960              :         CHK_PTR_NULL(commV2);
    4961              :         CHK_RET(HcclCommResumeV2(commV2));
    4962              : 
    4963              :         CHK_RET(hcclComm->Resume());
    4964              :         CHK_RET(HcclCommResumePostCallback(comm));
    4965              : 
    4966              :         return HCCL_SUCCESS;
    4967              :     }());
    4968              : #endif
    4969            1 :     HcclUs startut = TIME_NOW();
    4970            1 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    4971            1 :     CHK_RET(hcclComm->Resume());
    4972            1 :     HcclUs endut = TIME_NOW();
    4973            1 :     HCCL_RUN_INFO("HcclCommResume:success, take time:[%lld]us, comm[%s]",
    4974              :         DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str());
    4975            1 :     return HCCL_SUCCESS;
    4976              : }
    4977              : 
    4978            1 : uint32_t HcclGetCommConfigCapability()
    4979              : {
    4980              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4981            1 :     HCCLV2_FUNC_RUN(HcclGetCommConfigCapabilityV2());
    4982              : #endif
    4983              :     // RESERVED在枚举中是最后一个,返回RESERVED说明它前面所有的配置项都支持
    4984            1 :     return static_cast<uint32_t>(HCCL_COMM_CONFIG_RESERVED);
    4985              : }
    4986              : 
    4987            3 : HcclResult HcclCommSetMemoryRange(HcclComm comm, void *baseVirPtr, size_t size, size_t alignment, uint64_t flags)
    4988              : {
    4989              :     // 入参校验
    4990            3 :     CHK_PTR_NULL(comm);
    4991            2 :     CHK_PTR_NULL(baseVirPtr);
    4992              : 
    4993              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    4994            1 :     HCCLV2_FUNC_RUN(HcclCommSetMemoryRangeV2(comm, baseVirPtr, size, alignment, flags));
    4995              :     
    4996              : #endif
    4997              : 
    4998            1 :     HcclUs startut = TIME_NOW();
    4999            1 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5000            1 :     CHK_RET(hcclComm->SetMemoryRange(baseVirPtr, size, alignment, flags));
    5001            1 :     HcclUs endut = TIME_NOW();
    5002            1 :     HCCL_RUN_INFO("HcclCommSetMemoryRange:success, take time:[%lld]us, comm[%s] basePtr[%p] size[%lu] alignment[%lu] flags[%lu]",
    5003              :         DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str(), baseVirPtr, size, alignment, flags);
    5004            1 :     return HCCL_SUCCESS;
    5005              : }
    5006              : 
    5007            3 : HcclResult HcclCommUnsetMemoryRange(HcclComm comm, void *baseVirPtr)
    5008              : {
    5009              :     // 入参校验
    5010            3 :     CHK_PTR_NULL(comm);
    5011            2 :     CHK_PTR_NULL(baseVirPtr);
    5012              : 
    5013              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5014            1 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    5015              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    5016              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    5017              :         CHK_PTR_NULL(commV2);
    5018              :         CHK_RET(HcclCommUnsetMemoryRangeV2(commV2, baseVirPtr));
    5019              :         return HCCL_SUCCESS;
    5020              :     }());
    5021              : #endif
    5022              : 
    5023            1 :     HcclUs startut = TIME_NOW();
    5024            1 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5025            1 :     CHK_RET(hcclComm->UnsetMemoryRange(baseVirPtr));
    5026            1 :     HcclUs endut = TIME_NOW();
    5027            1 :     HCCL_RUN_INFO("HcclCommUnsetMemoryRange:success, take time:[%lld]us, comm[%s] basePtr[%p]",
    5028              :         DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str(), baseVirPtr);
    5029            1 :     return HCCL_SUCCESS;
    5030              : }
    5031              : 
    5032            4 : HcclResult HcclCommActivateCommMemory(HcclComm comm, void *virPtr, size_t size, size_t offset, void* handle, uint64_t flags)
    5033              : {
    5034              :     // 入参校验
    5035            4 :     CHK_PTR_NULL(comm);
    5036            3 :     CHK_PTR_NULL(virPtr);
    5037            2 :     CHK_PTR_NULL(handle);
    5038              : 
    5039              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5040            1 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    5041              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    5042              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    5043              :         CHK_PTR_NULL(commV2);
    5044              :         CHK_RET(HcclCommActivateCommMemoryV2(commV2, virPtr, size, offset, handle, flags));
    5045              :         return HCCL_SUCCESS;
    5046              :     }());
    5047              : #endif
    5048              : 
    5049            1 :     HcclUs startut = TIME_NOW();
    5050            1 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5051            1 :     CHK_RET(hcclComm->ActivateCommMemory(virPtr, size, offset, handle, flags));
    5052            1 :     HcclUs endut = TIME_NOW();
    5053            1 :     HCCL_RUN_INFO("HcclCommActivateCommMemory:success, take time:[%lld]us, comm[%s] virPtr[%p] size[%lu] offset[%lu] "
    5054              :         "handle[%p] flags[%lu]", DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str(), virPtr, size,
    5055              :         offset, handle, flags);
    5056            1 :     return HCCL_SUCCESS;
    5057              : }
    5058              : 
    5059            3 : HcclResult HcclCommDeactivateCommMemory(HcclComm comm, void *virPtr)
    5060              : {
    5061              :     // 入参校验
    5062            3 :     CHK_PTR_NULL(comm);
    5063            2 :     CHK_PTR_NULL(virPtr);
    5064              : 
    5065              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5066            1 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    5067              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    5068              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    5069              :         CHK_PTR_NULL(commV2);
    5070              :         CHK_RET(HcclCommDeactivateCommMemoryV2(commV2, virPtr));
    5071              :         return HCCL_SUCCESS;
    5072              :     }());
    5073              : #endif
    5074              : 
    5075            1 :     HcclUs startut = TIME_NOW();
    5076            1 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5077            1 :     CHK_RET(hcclComm->DeactivateCommMemory(virPtr));
    5078            1 :     HcclUs endut = TIME_NOW();
    5079            1 :     HCCL_RUN_INFO("HcclCommDeactivateCommMemory:success, take time:[%lld]us, comm[%s] virPtr[%p]",
    5080              :         DURATION_US(endut - startut).count(), hcclComm->GetIdentifier().c_str(), virPtr);
    5081            1 :     return HCCL_SUCCESS;
    5082              : }
    5083              : 
    5084            4 : HcclResult HcclCommWorkingDevNicSet(HcclComm comm, uint32_t *ranks, bool *useBackup, uint32_t nRanks)
    5085              : {
    5086              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5087            4 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    5088              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    5089              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    5090              :         CHK_PTR_NULL(commV2);
    5091              :         CHK_RET(HcclCommWorkingDevNicSetV2(commV2, ranks, useBackup, nRanks));
    5092              :         return HCCL_SUCCESS;
    5093              :     }());
    5094              : #endif
    5095           24 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5096              :         std::vector<std::string>({"HcclCommWorkingDevNicSet", "nullptr", "comm", "non-null pointer"}));
    5097            4 :     CHK_PTR_NULL(comm);
    5098            3 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5099            3 :     u32 localRank = INVALID_VALUE_RANKID;
    5100            3 :     (void) hcclComm->GetUserRank(localRank);
    5101            3 :     HCCL_RUN_INFO("Entry-HcclCommWorkingDevNicSet, comm[%s], rank[%u], nRanks[%u] need to switch nic",
    5102              :         hcclComm->GetIdentifier().c_str(), localRank, nRanks);
    5103              : 
    5104           23 :     RPT_INPUT_ERR(ranks == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5105              :         std::vector<std::string>({"HcclCommWorkingDevNicSet", "nullptr", "ranks", "non-null pointer"}));
    5106            3 :     CHK_PTR_NULL(ranks);
    5107           22 :     RPT_INPUT_ERR(useBackup == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5108              :         std::vector<std::string>({"HcclCommWorkingDevNicSet", "nullptr", "useBackup", "non-null pointer"}));
    5109            2 :     CHK_PTR_NULL(useBackup);
    5110            1 :     HcclResult ret = hcclComm->SwitchNic(nRanks, ranks, useBackup);
    5111            1 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("HcclCommWorkingDevNicSet fail, comm[%s], rank[%u], ret[%u]",
    5112              :         hcclComm->GetIdentifier().c_str(), localRank, ret), ret);
    5113              : 
    5114            1 :     HCCL_RUN_INFO("HcclCommWorkingDevNicSet success, comm[%s], rank[%u], nRanks[%u] switch nic success.",
    5115              :         hcclComm->GetIdentifier().c_str(), localRank, nRanks);
    5116            1 :     return HCCL_SUCCESS;
    5117              : }
    5118              : 
    5119            0 : HcclResult HcclCommRegister(HcclComm comm, void* addr, uint64_t size, void **handle, uint32_t flag)
    5120              : {
    5121              :     // 入参校验
    5122            0 :     CHK_PTR_NULL(comm);
    5123            0 :     CHK_PTR_NULL(addr);
    5124            0 :     CHK_PTR_NULL(handle);
    5125            0 :     CHK_PRT_RET(size == 0, HCCL_ERROR("[%s] size is 0, please check size value", __func__), HCCL_E_PARA);
    5126              : 
    5127            0 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5128            0 :     CHK_RET(hcclComm->RegisterCommUserMem(addr, size, handle));
    5129            0 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    5130            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    5131            0 :     CHK_RET(HcomSetGroupTopoInfo(hcclComm->GetIdentifier().c_str(), rankSize));
    5132            0 :     HCCL_RUN_INFO("[%s]Register mem success, group[%s], handle ptr[%p], size[%llu]", __func__,
    5133              :         hcclComm->GetIdentifier().c_str(), *handle, size);
    5134            0 :     return HCCL_SUCCESS;
    5135              : }
    5136              : 
    5137            0 : HcclResult HcclCommDeregister(HcclComm comm, void* handle)
    5138              : {
    5139              :     // 入参校验
    5140            0 :     CHK_PTR_NULL(comm);
    5141            0 :     CHK_PTR_NULL(handle);
    5142            0 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5143            0 :     CHK_RET(hcclComm->DeregisterCommUserMem(handle));
    5144            0 :     u32 rankSize = INVALID_VALUE_RANKSIZE;
    5145            0 :     CHK_RET(hcclComm->GetRankSize(rankSize));
    5146            0 :     CHK_RET(HcomSetGroupTopoInfo(hcclComm->GetIdentifier().c_str(), rankSize));
    5147            0 :     HCCL_RUN_INFO("[%s]Deregister mem success, group[%s], handle ptr[%p]", __func__,
    5148              :         hcclComm->GetIdentifier().c_str(), handle);
    5149            0 :     return HCCL_SUCCESS;
    5150              : }
    5151              : 
    5152            0 : HcclResult HcclCommExchangeMem(HcclComm comm, void* handle, uint32_t* peerRanks, uint32_t peerRankNum)
    5153              : {
    5154            0 :     HcclUs startut = TIME_NOW();
    5155              :     // 入参校验
    5156            0 :     CHK_PTR_NULL(comm);
    5157            0 :     CHK_PTR_NULL(handle);
    5158            0 :     CHK_PTR_NULL(peerRanks);
    5159            0 :     CHK_PRT_RET((peerRankNum == 0 || peerRankNum > MAX_RANK_NUM_A3),
    5160              :         HCCL_ERROR("[%s]Invalid peerRankNum, valid range is (0, %u], peerRankNum[%u]",
    5161              :             __func__, MAX_RANK_NUM_A3, peerRankNum), HCCL_E_PARA);
    5162            0 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5163            0 :     std::vector<u32> peerRanksVec(peerRanks, peerRanks + peerRankNum);
    5164            0 :     CHK_RET(hcclComm->ExchangeCommUserMem(handle, peerRanksVec));
    5165            0 :     HCCL_RUN_INFO("[%s] success, take time [%lld]us, group[%s]", __func__, DURATION_US(TIME_NOW() - startut),
    5166              :         hcclComm->GetIdentifier().c_str());
    5167            0 :     return HCCL_SUCCESS;
    5168            0 : }
    5169              : 
    5170            0 : HcclResult CommGetLocalCCLBuf(HcclComm comm, void **addr, uint64_t *size)
    5171              : {
    5172            0 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5173              :         std::vector<std::string>({"CommGetLocalCCLBuf", "nullptr", "comm", "non-null pointer"}));
    5174            0 :     CHK_PTR_NULL(comm);
    5175            0 :     RPT_INPUT_ERR(addr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5176              :         std::vector<std::string>({"CommGetLocalCCLBuf", "nullptr", "addr", "non-null pointer"}));
    5177            0 :     CHK_PTR_NULL(addr);
    5178            0 :     RPT_INPUT_ERR(size == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5179              :         std::vector<std::string>({"CommGetLocalCCLBuf", "nullptr", "size", "non-null pointer"}));
    5180            0 :     CHK_PTR_NULL(size);
    5181              : 
    5182            0 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5183            0 :     HcclResult ret = hcclComm->GetLocalCCLBuf(addr, size);
    5184            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("CommGetLocalCCLBuf fail, comm[%s]",
    5185              :         hcclComm->GetIdentifier().c_str()), ret);
    5186              : 
    5187            0 :     HCCL_RUN_INFO("CommGetLocalCCLBuf success, comm[%s]", hcclComm->GetIdentifier().c_str());
    5188            0 :     return HCCL_SUCCESS;
    5189              : }
    5190              : 
    5191            0 : HcclResult CommGetRemoteCCLBuf(HcclComm comm, uint32_t remoteRank, void **addr, uint64_t *size)
    5192              : {
    5193            0 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5194              :         std::vector<std::string>({"CommGetRemoteCCLBuf", "nullptr", "comm", "non-null pointer"}));
    5195            0 :     CHK_PTR_NULL(comm);
    5196            0 :     RPT_INPUT_ERR(addr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5197              :         std::vector<std::string>({"CommGetRemoteCCLBuf", "nullptr", "addr", "non-null pointer"}));
    5198            0 :     CHK_PTR_NULL(addr);
    5199            0 :     RPT_INPUT_ERR(size == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5200              :         std::vector<std::string>({"CommGetRemoteCCLBuf", "nullptr", "size", "non-null pointer"}));
    5201            0 :     CHK_PTR_NULL(size);
    5202              : 
    5203            0 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5204            0 :     HcclResult ret = hcclComm->GetRemoteCCLBuf(remoteRank, addr, size);
    5205            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("CommGetRemoteCCLBuf fail, comm[%s], remoteRank[%u]",
    5206              :         hcclComm->GetIdentifier().c_str(), remoteRank), ret);
    5207              : 
    5208            0 :     HCCL_RUN_INFO("CommGetRemoteCCLBuf success, comm[%s], remoteRank[%u]", hcclComm->GetIdentifier().c_str(), remoteRank);
    5209            0 :     return HCCL_SUCCESS;
    5210              : }
    5211            0 : HcclResult CommGetKFCWorkSpace(HcclComm comm, void **addr, uint64_t *size)
    5212              : {
    5213            0 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5214              :         std::vector<std::string>({"CommGetKFCWorkSpace", "nullptr", "comm", "non-null pointer"}));
    5215            0 :     CHK_PTR_NULL(comm);
    5216            0 :     RPT_INPUT_ERR(addr == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5217              :         std::vector<std::string>({"CommGetKFCWorkSpace", "nullptr", "addr", "non-null pointer"}));
    5218            0 :     CHK_PTR_NULL(addr);
    5219            0 :     RPT_INPUT_ERR(size == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5220              :         std::vector<std::string>({"CommGetKFCWorkSpace", "nullptr", "size", "non-null pointer"}));
    5221            0 :     CHK_PTR_NULL(size);
    5222              : 
    5223            0 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5224            0 :     HcclResult ret = hcclComm->GetKFCWorkSpace(addr, size);
    5225            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("CommGetKFCWorkSpace fail, comm[%s]",
    5226              :         hcclComm->GetIdentifier().c_str()), ret);
    5227              : 
    5228            0 :     HCCL_RUN_INFO("CommGetKFCWorkSpace success, comm[%s]", hcclComm->GetIdentifier().c_str());
    5229            0 :     return HCCL_SUCCESS;
    5230              : }
    5231            0 : HcclResult CommGetCCLBufSizeCfg(HcclComm comm, uint64_t *cclBufSize)
    5232              : {
    5233            0 :     RPT_INPUT_ERR(comm == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5234              :         std::vector<std::string>({"CommGetCCLBufSizeCfg", "nullptr", "comm", "non-null pointer"}));
    5235            0 :     CHK_PTR_NULL(comm);
    5236            0 :     RPT_INPUT_ERR(cclBufSize == nullptr, "EI0003", std::vector<std::string>({"ccl_op", "value", "parameter", "expect"}),\
    5237              :         std::vector<std::string>({"CommGetCCLBufSizeCfg", "nullptr", "cclBufSize", "non-null pointer"}));
    5238            0 :     CHK_PTR_NULL(cclBufSize);
    5239              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5240            0 :     const char *socNamePtr = aclrtGetSocName();
    5241            0 :     CHK_PTR_NULL(socNamePtr);
    5242            0 :     HCCLV2_FUNC_RUN([&]() -> HcclResult {
    5243              :         hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    5244              :         HcclComm commV2 = hcclComm->GetCommunicatorV2();
    5245              :         CHK_PTR_NULL(commV2);
    5246              :         CHK_RET(CommGetCCLBufSizeCfgV2(commV2, cclBufSize));
    5247              :         return HCCL_SUCCESS;
    5248              :     }());
    5249              : #endif
    5250            0 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5251            0 :     uint64_t buffSize = 0;
    5252            0 :     if (0 == hcclComm->GetConfigInCCLbufferSize()) {
    5253            0 :         buffSize = GetExternalInputCCLBuffSize();
    5254              :     }else {
    5255            0 :         buffSize = hcclComm->GetConfigInCCLbufferSize();
    5256              :     }
    5257            0 :     *cclBufSize = buffSize;
    5258            0 :     HCCL_RUN_INFO("CommGetCCLBufSizeCfg success, comm[%s], size[%u]", hcclComm->GetIdentifier().c_str(), buffSize);
    5259            0 :     return HCCL_SUCCESS;
    5260              : }
    5261              : 
    5262              : enum HcclCommSymWindowInnerFlag {
    5263              :     HCCL_COMM_SYM_WINDOW_FLAG_DEFAULT = 0,
    5264              :     HCCL_COMM_SYM_WINDOW_FLAG_COLL_SYMMETRIC = 1
    5265              : };
    5266              : 
    5267              : std::unordered_map<HcclCommSymWindow, HcclComm> winHandle2comm;
    5268              : std::mutex g_winHandleMtx; // 保护 winHandle2comm
    5269              : 
    5270            0 : HcclResult HcclCommSymWinRegister(HcclComm comm, void* addr, uint64_t size, HcclCommSymWindow *winHandle, uint32_t flag)
    5271              : {
    5272              :     // 入参校验
    5273            0 :     CHK_PTR_NULL(comm);
    5274            0 :     CHK_PTR_NULL(addr);
    5275            0 :     CHK_PTR_NULL(winHandle);
    5276            0 :     CHK_PRT_RET(size == 0, HCCL_ERROR("[%s] size is 0, please check size value", __func__), HCCL_E_PARA);
    5277            0 :     if (flag == HCCL_COMM_SYM_WINDOW_FLAG_COLL_SYMMETRIC) {
    5278            0 :         hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5279              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5280            0 :         if (hcclComm->IsCommunicatorV2()) {
    5281            0 :             hccl::CollComm *collComm = hcclComm->GetCollComm();
    5282            0 :             CHK_PTR_NULL(collComm);
    5283            0 :             CHK_RET(collComm->RegisterWindow(addr, size, winHandle));
    5284              :         } else {
    5285              : #endif
    5286            0 :             CHK_RET(hcclComm->RegisterWindow(addr, size, winHandle));
    5287              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5288              :         }
    5289              : #endif
    5290            0 :         HCCL_RUN_INFO("[%s]WindowRegister mem success, group[%s], handle ptr[%p], size[%llu]", __func__,
    5291              :             hcclComm->GetIdentifier().c_str(), *winHandle, size);
    5292              :         {
    5293            0 :             std::lock_guard<std::mutex> lock(g_winHandleMtx);
    5294            0 :             winHandle2comm[*winHandle] = comm;
    5295            0 :         }
    5296            0 :     } else if (flag == HCCL_COMM_SYM_WINDOW_FLAG_DEFAULT) {
    5297            0 :         HCCL_ERROR("[HcclCommSymWinRegister]flag: 0 is not supported yet.");
    5298            0 :         return HCCL_E_PARA;
    5299              :     }else {
    5300            0 :         HCCL_ERROR("[HcclCommSymWinRegister]Invalid flag[%u], must be 0 or 1", flag);
    5301            0 :         return HCCL_E_PARA;
    5302              :     }
    5303            0 :     return HCCL_SUCCESS;
    5304              : }
    5305              : 
    5306            0 : HcclResult HcclCommSymWinDeregister(HcclCommSymWindow winHandle)
    5307              : {
    5308              :     // 入参校验
    5309            0 :     CHK_PTR_NULL(winHandle);
    5310            0 :     HcclComm comm = nullptr;
    5311            0 :     std::lock_guard<std::mutex> lock(g_winHandleMtx);
    5312            0 :     auto it = winHandle2comm.find(winHandle);
    5313            0 :     if (it == winHandle2comm.end()) {
    5314            0 :         HCCL_ERROR("[HcclCommSymWinDeregister]Window handle[%p] is not registered.", winHandle);
    5315            0 :         return HCCL_E_PARA;
    5316              :     }
    5317            0 :     comm = it->second;
    5318            0 :     CHK_PTR_NULL(comm);
    5319            0 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5320              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5321            0 :     if (hcclComm->IsCommunicatorV2()) {
    5322            0 :         hccl::CollComm *collComm = hcclComm->GetCollComm();
    5323            0 :         CHK_PTR_NULL(collComm);
    5324            0 :         CHK_RET(collComm->DeregisterWindow(winHandle));
    5325              :     } else {
    5326              : #endif
    5327            0 :         CHK_RET(hcclComm->DeregisterWindow(winHandle));
    5328              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5329              :     }
    5330              : #endif
    5331            0 :     winHandle2comm.erase(it);
    5332            0 :     HCCL_RUN_INFO("[%s]WindowDeregister mem success, group[%s]", __func__, hcclComm->GetIdentifier().c_str());
    5333            0 :     return HCCL_SUCCESS;
    5334            0 : }
    5335              : 
    5336            1 : HcclResult HcclCommSymWinGet(HcclComm comm, void *ptr, size_t size, HcclCommSymWindow *winHandle, size_t *offset)
    5337              : {
    5338              :     // 入参校验
    5339            1 :     CHK_PTR_NULL(comm);
    5340            1 :     CHK_PTR_NULL(ptr);
    5341            1 :     CHK_PTR_NULL(winHandle);
    5342            1 :     CHK_PTR_NULL(offset);
    5343            1 :     CHK_PRT_RET(size == 0, HCCL_ERROR("[%s] size is 0, please check size value", __func__), HCCL_E_PARA);
    5344              : 
    5345            1 :     hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
    5346              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5347            1 :     if (hcclComm->IsCommunicatorV2()) {
    5348            0 :         hccl::CollComm *collComm = hcclComm->GetCollComm();
    5349            0 :         CHK_PTR_NULL(collComm);
    5350            0 :         CHK_RET(collComm->GetCommSymWin(ptr, size, winHandle, offset));
    5351              :     } else {
    5352              : #endif
    5353            1 :         CHK_RET(hcclComm->GetCommSymWin(ptr, size, winHandle, offset));
    5354              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
    5355              :     }
    5356              : #endif
    5357            1 :     HCCL_DEBUG("[%s]GetCommSymWin success, group[%s], handle ptr[%p], offset[%llu], size[%llu]", __func__,
    5358              :         hcclComm->GetIdentifier().c_str(), *winHandle, *offset, size);
    5359            1 :     return HCCL_SUCCESS;
    5360              : }
    5361              : 
    5362            0 : HcclResult HcclGetCcuTaskInfo(HcclComm comm, void *tilingData, void *ccuTaskGroup)
    5363              : {
    5364            0 :     CHK_PTR_NULL(comm);
    5365            0 :     CHK_PTR_NULL(tilingData);
    5366            0 :     CHK_PTR_NULL(ccuTaskGroup);
    5367              : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU)) 
    5368            0 :     hccl::hcclComm* hcclComm = static_cast<hccl::hcclComm *>(comm);
    5369            0 :     comm = hcclComm->GetCommunicatorV2();
    5370            0 :     CHK_PTR_NULL(comm);
    5371            0 :     CHK_RET(HcclGetCcuTaskInfoLegacy(comm, tilingData, ccuTaskGroup));
    5372              : #endif
    5373            0 :     return HCCL_SUCCESS;
    5374              : }
    5375              : 
    5376              : #ifdef __cplusplus
    5377              : }
    5378              : #endif // __cplusplus
        

Generated by: LCOV version 2.0-1