LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_device - ccu_dev_mgr_imp.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 28.5 % 358 102
Test Date: 2026-07-28 12:11:00 Functions: 29.3 % 41 12

            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 "ccu_dev_mgr_imp.h"
      12              : 
      13              : #include "hccl_common.h"
      14              : #include "eid_info_mgr.h"
      15              : 
      16              : #include "ccu_comp.h"
      17              : #include "ccu_res_specs.h"
      18              : #include "ccu_res_batch_allocator.h"
      19              : 
      20              : // 支持ccu新老通信域混跑临时添加
      21              : #include "unified_platform/ccu/ccu_device/ccu_component/ccu_component.h"
      22              : #include "unified_platform/ccu/ccu_device/ccu_res_specs.h"
      23              : #include "unified_platform/ccu/ccu_device/ccu_res_batch_allocator.h"
      24              : #include "orion_adpt_utils.h"
      25              : #include "exception_handler.h"
      26              : 
      27              : /* 开源自定义算子CCU设备管理实现,当前支持新老通信域混跑,
      28              :  * 暂时改用legacy数据结构,避免反向依赖
      29              :  * #include "ccu_comp.h"
      30              :  * #include "ccu_res_specs.h"
      31              :  * #include "ccu_res_batch_allocator.h"
      32              :  */
      33              : 
      34              : // 引入主板类型查询接口,后续应根据ccu驱动提供的信息用于判断
      35              : // 当前先简化修改
      36              : #include "./ccu_res_specs.h"
      37              : #include "adapter_rts.h"
      38              : 
      39              : #include "ccu_types.h"
      40              : #include "ccu_log.h"
      41              : 
      42              : #include "dev_type.h"
      43              : 
      44              : namespace hcomm {
      45              : 
      46              : static std::unordered_map<int32_t, std::shared_ptr<CcuDrvHandle>> ccuDrvHandleMap;
      47              : static std::mutex ccuDrvHandleMutex;
      48              : static bool ccuDriverInitAgainFlag = false; // 记录每个进程CCU驱动是否重复拉起
      49              : static thread_local Hccl::HcclMainboardId mainBoardType = Hccl::HcclMainboardId::MAINBOARD_OTHERS; // 记录本卡的主板类型
      50              : 
      51            8 : inline bool CheckCcuOpenSourceEnable()
      52              : {
      53              :     // A6 不支持legacy ccu mc2,可以完全切换至开源流程
      54            8 :     auto devType = DevType::DEV_TYPE_COUNT;
      55            8 :     (void)hrtGetDeviceType(devType);
      56            8 :     return devType == DevType::DEV_TYPE_960;
      57              : }
      58              : 
      59           27 : CcuResult CcuInitFeature(const int32_t devLogicId, std::shared_ptr<CcuDrvHandle> &ccuDrvHandle)
      60              : {
      61           27 :     if (devLogicId >= static_cast<int32_t>(MAX_MODULE_DEVICE_NUM)) {
      62            0 :         HCCL_ERROR("[%s] failed, devLogicId[%d] is too large, should be less than %u.",
      63              :             __func__, devLogicId, MAX_MODULE_DEVICE_NUM);
      64            0 :         return CcuResult::CCU_E_PARA;
      65              :     }
      66              : 
      67           27 :     std::lock_guard<std::mutex> lock(ccuDrvHandleMutex);
      68              :     // ccu驱动已重复拉起失败时,直接返回,在锁保护内返回
      69           27 :     if (ccuDriverInitAgainFlag) {
      70            0 :         return CcuResult::CCU_E_DRV_BUSY;
      71              :     }
      72              : 
      73           27 :     auto iter = ccuDrvHandleMap.find(devLogicId);
      74           27 :     if (iter != ccuDrvHandleMap.end()) {
      75            0 :         ccuDrvHandle = iter->second;
      76            0 :         HCCL_RUN_INFO("[%s] devLogicId[%d] init ccu feature, handle[0x%llx].",
      77              :             __func__, devLogicId, ccuDrvHandle.get());
      78            0 :         return CcuResult::CCU_SUCCESS;
      79              :     }
      80              : 
      81           27 :     std::shared_ptr<CcuDrvHandle> drvHandle = nullptr;
      82           27 :     drvHandle.reset(new (std::nothrow) CcuDrvHandle(devLogicId));
      83           27 :     CCU_CHK_PTR_NULL(drvHandle);
      84              : 
      85           27 :     auto ret = drvHandle->Init();
      86           27 :     if (ret == CcuResult::CCU_E_DRV_BUSY) {
      87            0 :         HCCL_RUN_WARNING("[%s] failed but passed, devLogicId[%d] ccu driver has been "
      88              :             "inited by another process, this process will not try to init anymore.",
      89              :             __func__, devLogicId);
      90            0 :         ccuDriverInitAgainFlag = true; // 记录该进程ccu驱动已拉起失败
      91            0 :         drvHandle = nullptr; // 主动置空触发资源销毁,控制释放时序
      92            0 :         return ret;
      93              :     }
      94           27 :     CCU_CHK_RET(ret);
      95              : 
      96           27 :     ccuDrvHandleMap[devLogicId] = drvHandle;
      97           27 :     ccuDrvHandle = ccuDrvHandleMap[devLogicId];
      98           27 :     HCCL_RUN_INFO("[%s] devLogicId[%d] init ccu feature, handle[0x%llx].",
      99              :         __func__, devLogicId, ccuDrvHandle.get());
     100           27 :     return CcuResult::CCU_SUCCESS;
     101           27 : }
     102              : 
     103           27 : CcuResult CcuDeinitFeature(const int32_t devLogicId)
     104              : {
     105           27 :     std::lock_guard<std::mutex> lock(ccuDrvHandleMutex);
     106           27 :     auto iter = ccuDrvHandleMap.find(devLogicId);
     107           27 :     if (iter == ccuDrvHandleMap.end()) {
     108            0 :         HCCL_INFO("[%s] passed, ccu feature was not inited, devLogicId[%d].",
     109              :             __func__, devLogicId);
     110            0 :         return CcuResult::CCU_SUCCESS;
     111              :     }
     112              : 
     113           27 :     auto &ccuDrvHandle = ccuDrvHandleMap[devLogicId];
     114           27 :     if (ccuDrvHandle.use_count() == 1) {
     115           27 :         HCCL_RUN_INFO("[%s] entry, start to deinit ccu feature, "
     116              :             "handle[0x%llx] devLogicId[%d].",
     117              :             __func__, ccuDrvHandle.get(), devLogicId);
     118           27 :         ccuDrvHandle = nullptr;
     119           27 :         ccuDrvHandleMap.erase(devLogicId);
     120              :     }
     121              : 
     122           27 :     return CcuResult::CCU_SUCCESS;
     123           27 : }
     124              : 
     125            0 : CcuResult CcuGetDieEnableInfo(int32_t deviceLogicId, uint8_t dieId, bool &enableFlag)
     126              : {
     127            0 :     CHK_PRT_RET(dieId >= CCU_MAX_IODIE_NUM,
     128              :         HCCL_ERROR("[%s] failed, dieId[%u] is invalid, shoudle be in [0-%u), devLogicId[%d].",
     129              :             __func__, dieId, CCU_MAX_IODIE_NUM, deviceLogicId),
     130              :         CcuResult::CCU_E_PARA);
     131              : 
     132            0 :     const auto &dieEnableFlags = CheckCcuOpenSourceEnable() ?
     133            0 :         CcuComponent::GetInstance(deviceLogicId).GetDieEnableFlags() :
     134            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId).GetDieEnableFlags();
     135              : 
     136            0 :     enableFlag = dieEnableFlags[dieId];
     137            0 :     return CcuResult::CCU_SUCCESS;
     138              : }
     139              : 
     140              : constexpr u32 CCU_MS_DEFAULT_BLOCK_LOOP_ENGINE_REQ = 8 * 8 * 2;
     141              : constexpr u32 CCU_MS_DEFAULT_BLOCK_MS_REQ = 64 * 8 * 2;
     142              : constexpr u32 CCU_MS_DEFAULT_CKE_REQ = 32;
     143              : constexpr u32 CCU_MS_DEFAULT_BLOCK_CKE_REQ = 8 * 8 * 2;
     144              : constexpr u32 CCU_MS_DEFAULT_CONTINUOUS_XN_REQ = 400;
     145              : constexpr u32 CCU_MS_DEFAULT_GSA_REQ = 400;
     146              : constexpr u32 CCU_MS_DEFAULT_MISSIONREQ_REQ = 2;
     147           54 : inline void ConfigCcuResReqCcuMs(CcuResReq &resReq, uint8_t dieId, CcuVersion version)
     148              : {
     149           54 :     resReq.loopEngineReq[dieId] = 0;
     150           54 :     resReq.blockLoopEngineReq[dieId] = CCU_MS_DEFAULT_BLOCK_LOOP_ENGINE_REQ;
     151           54 :     resReq.msReq[dieId] = 0;
     152           54 :     resReq.blockMsReq[dieId] = CCU_MS_DEFAULT_BLOCK_MS_REQ;
     153           54 :     resReq.ckeReq[dieId] = CCU_MS_DEFAULT_CKE_REQ;
     154           54 :     resReq.blockCkeReq[dieId] = CCU_MS_DEFAULT_BLOCK_CKE_REQ;
     155           54 :     resReq.xnReq[dieId] = 0;
     156           54 :     if (version == CcuVersion::CCU_V2) {
     157            4 :         resReq.continuousXnReq[dieId] = CCU_MS_DEFAULT_CONTINUOUS_XN_REQ * 2;  // V2场景下申请2倍的Xn数量
     158            4 :         resReq.gsaReq[dieId] = 0;
     159              :     } else {
     160           50 :         resReq.continuousXnReq[dieId] = CCU_MS_DEFAULT_CONTINUOUS_XN_REQ;
     161           50 :         resReq.gsaReq[dieId] = CCU_MS_DEFAULT_GSA_REQ;
     162              :     }
     163           54 :     resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE;
     164           54 :     resReq.missionReq.req[dieId] = CCU_MS_DEFAULT_MISSIONREQ_REQ;
     165           54 : }
     166              : 
     167              : constexpr u32 CCU_SCHED_DEFAULT_BLOCK_LOOP_ENGINE_REQ = 16;
     168              : constexpr u32 CCU_SCHED_DEFAULT_BLOCK_MS_REQ = 128;
     169              : constexpr u32 CCU_SCHED_DEFAULT_CKE_REQ = 32;
     170              : constexpr u32 CCU_SCHED_DEFAULT_BLOCK_CKE_REQ = 16;
     171              : constexpr u32 CCU_SCHED_DEFAULT_CONTINUOUS_XN_REQ = 400;
     172              : constexpr u32 CCU_SCHED_DEFAULT_GSA_REQ = 400;
     173              : constexpr u32 CCU_SCHED_DEFAULT_MISSIONREQ_REQ = 2;
     174            0 : inline void ConfigCcuResReqCcuSched(CcuResReq &resReq, uint8_t dieId, CcuVersion version)
     175              : {
     176            0 :     resReq.loopEngineReq[dieId] = 0;
     177            0 :     resReq.blockLoopEngineReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_LOOP_ENGINE_REQ;
     178            0 :     resReq.msReq[dieId] = 0;
     179            0 :     resReq.blockMsReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_MS_REQ;
     180            0 :     resReq.ckeReq[dieId] = CCU_SCHED_DEFAULT_CKE_REQ;
     181            0 :     resReq.blockCkeReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_CKE_REQ;
     182            0 :     resReq.xnReq[dieId] = 0;
     183            0 :     if (version == CcuVersion::CCU_V2) {
     184            0 :         resReq.continuousXnReq[dieId] = CCU_SCHED_DEFAULT_CONTINUOUS_XN_REQ * 2;  // V2场景下申请2倍的Xn数量
     185            0 :         resReq.gsaReq[dieId] = 0;
     186              :     } else {
     187            0 :         resReq.continuousXnReq[dieId] = CCU_SCHED_DEFAULT_CONTINUOUS_XN_REQ;
     188            0 :         resReq.gsaReq[dieId] = CCU_SCHED_DEFAULT_GSA_REQ;
     189              :     }
     190              : 
     191            0 :     resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE;
     192            0 :     resReq.missionReq.req[dieId] = CCU_SCHED_DEFAULT_MISSIONREQ_REQ;
     193            0 : }
     194              : 
     195              : // CCU设备管理对集合通信提供的接口
     196           27 : CcuResult CcuAllocResHandleByInsType(int32_t deviceLogicId,
     197              :     CcuInstanceType ccuInsType, CcuResHandle &resHandle)
     198              : {
     199           27 :     if (ccuInsType >= CcuInstanceType::CCU_UNUSED) {
     200            0 :         HCCL_ERROR("[%s] failed, error ccu instance type[%d], devLogicId[%d].",
     201              :             __func__, ccuInsType, deviceLogicId);
     202            0 :         return CcuResult::CCU_E_PARA;
     203              :     }
     204              : 
     205           27 :     std::array<bool, CCU_MAX_IODIE_NUM> dieEnableFlags = {false, false};
     206           81 :     for (uint8_t dieId = 0; dieId < CCU_MAX_IODIE_NUM; dieId++) {
     207           54 :         CCU_CHK_RET(CcuGetDieEnableInfo(deviceLogicId, dieId, dieEnableFlags[dieId]));
     208              :     }
     209              : 
     210           27 :     if (!dieEnableFlags[0] && !dieEnableFlags[1]) {
     211            0 :         HCCL_ERROR("[%s] failed, all ccu dies are disable, devLogicId[%d].",
     212              :             __func__, deviceLogicId);
     213            0 :         return CcuResult::CCU_E_INTERNAL;
     214              :     }
     215              : 
     216           27 :     CcuVersion ccuVersion = CcuVersion::INVALID;
     217           27 :     CCU_CHK_RET(CcuDevMgrImp::GetCcuVersion(deviceLogicId, ccuVersion));
     218           27 :     if (ccuVersion == CcuVersion::INVALID) {
     219            0 :         HCCL_RUN_WARNING("[%s] failed, deviceLogicId[%d] ccu version is invalid, "
     220              :             "should fallback to aicpu.", __func__, deviceLogicId);
     221            0 :         return CcuResult::CCU_E_UNAVAIL;
     222              :     }
     223              : 
     224           27 :     CcuResReq resReq{};
     225           81 :     for (uint8_t dieId = 0; dieId < CCU_MAX_IODIE_NUM; dieId++) {
     226           54 :         if (!dieEnableFlags[dieId]) {
     227            0 :             continue;
     228              :         }
     229              : 
     230           54 :         if (ccuInsType == CcuInstanceType::CCU_MS) {
     231           54 :             ConfigCcuResReqCcuMs(resReq, dieId, ccuVersion);
     232              :         } else {
     233            0 :             ConfigCcuResReqCcuSched(resReq, dieId, ccuVersion);
     234              :         }
     235              :     }
     236              : 
     237           27 :     if (mainBoardType == Hccl::HcclMainboardId::MAINBOARD_OTHERS) {
     238            1 :         CCU_CHK_RET(CcuGetMainboardId(deviceLogicId, mainBoardType));
     239              :     }
     240              : 
     241           27 :     if (mainBoardType == Hccl::HcclMainboardId::MAINBOARD_PCIE_STD &&
     242              :         ccuInsType == CcuInstanceType::CCU_MS) { // 标卡环境下配置CCU_MS拦截报错
     243            0 :         HCCL_ERROR("[%s] ccuInstanceType[%d] not support in %s", __func__,
     244              :             ccuInsType, mainBoardType.Describe().c_str());
     245            0 :         return CcuResult::CCU_E_NOT_SUPPORT;
     246              :     }
     247              : 
     248           27 :     CCU_CHK_RET(CcuDevMgrImp::AllocResHandle(deviceLogicId, resReq, resHandle));
     249              : 
     250           27 :     HCCL_INFO("[%s] succeed, get res handle[%llx], devLogicId[%d]",
     251              :         __func__, resHandle, deviceLogicId);
     252           27 :     return CcuResult::CCU_SUCCESS;
     253              : }
     254              : 
     255           53 : CcuResult CcuCheckResource(const int32_t deviceLogicId, const CcuResHandle resHandle,
     256              :         CcuResRepository &resRepo)
     257              : {
     258           53 :     CCU_CHK_RET(CcuDevMgrImp::GetResource(deviceLogicId, resHandle, resRepo));
     259           53 :     return CcuResult::CCU_SUCCESS;
     260              : }
     261              : 
     262           27 : HcclResult CcuReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle resHandle)
     263              : {
     264           27 :     CHK_RET(CcuDevMgrImp::ReleaseResHandle(deviceLogicId, resHandle));
     265           27 :     return HcclResult::HCCL_SUCCESS;
     266              : }
     267              : 
     268            0 : HcclResult CcuAllocChannels(const int32_t deviceLogicId,
     269              :     const CcuChannelPara &ccuChannelPara,
     270              :     std::vector<CcuChannelInfo> &ccuChannelInfos)
     271              : {
     272            0 :     Hccl::IpAddress ipAddr{};
     273            0 :     CHK_RET(CommAddrToIpAddress(ccuChannelPara.commAddr, ipAddr)); // 为了打印信息暂时添加
     274            0 :     HCCL_INFO("[%s] new allocation request: deviceLogicId[%d], ipAddr[%s], "
     275              :         "channelnum[%u], jettyNum[%u], sqSize[%u].", __func__, deviceLogicId,
     276              :         ipAddr.Describe().c_str(), ccuChannelPara.channelNum,
     277              :         ccuChannelPara.jettyNum, ccuChannelPara.sqSize);
     278              : 
     279            0 :     uint32_t devPhyId{0};
     280            0 :     CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<uint32_t>(deviceLogicId), devPhyId));
     281              : 
     282            0 :     DevEidInfo eidInfo{};
     283            0 :     CHK_RET(EidInfoMgr::GetInstance(devPhyId)
     284              :         .GetEidInfoByAddr(ccuChannelPara.commAddr, eidInfo));
     285            0 :     const uint8_t dieId = static_cast<uint8_t>(eidInfo.dieId);
     286            0 :     const uint32_t feId = eidInfo.funcId;
     287            0 :     ChannelPara para{};
     288            0 :     para.feId = feId;
     289            0 :     para.jettyNum = ccuChannelPara.jettyNum;
     290            0 :     para.sqSize = ccuChannelPara.sqSize;
     291              : 
     292              :     HcclResult ret;
     293              :     EXCEPTION_HANDLE_BEGIN
     294            0 :     ret = CheckCcuOpenSourceEnable() ?
     295            0 :         CcuComponent::GetInstance(deviceLogicId)
     296            0 :             .AllocChannels(dieId, para, ccuChannelInfos) :
     297            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId)
     298            0 :             .AllocChannels(dieId, para, ccuChannelInfos);
     299            0 :     EXCEPTION_HANDLE_END
     300            0 :     return ret;
     301            0 : }
     302              : 
     303            0 : HcclResult CcuReleaseChannel(const int32_t deviceLogicId, const uint8_t dieId,
     304              :     const uint32_t ccuChannelId)
     305              : {
     306            0 :     HCCL_INFO("[%s] new release request: deviceLogicId[%d], dieId[%u], "
     307              :         "ccuChannelId[%u].", __func__, deviceLogicId, dieId, ccuChannelId);
     308              : 
     309              :     HcclResult ret;
     310              :     EXCEPTION_HANDLE_BEGIN
     311            0 :     ret = CheckCcuOpenSourceEnable() ?
     312            0 :         CcuComponent::GetInstance(deviceLogicId)
     313            0 :             .ReleaseChannel(dieId, ccuChannelId) :
     314            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId)
     315            0 :             .ReleaseChannel(dieId, ccuChannelId);
     316            0 :     EXCEPTION_HANDLE_END
     317            0 :     return ret;
     318              : }
     319              : 
     320              : // 以下为hcomm基础通信内部CCU流程使用的接口
     321            0 : HcclResult CcuDevMgrImp::GetCcuVersion(const int32_t deviceLogicId, CcuVersion &ccuVersion)
     322              : {
     323              :     EXCEPTION_HANDLE_BEGIN
     324            0 :     ccuVersion = CheckCcuOpenSourceEnable() ?
     325            0 :         CcuResSpecifications::GetInstance(deviceLogicId).GetCcuVersion() :
     326            0 :         Hccl::CcuResSpecifications::GetInstance(deviceLogicId).GetCcuVersion();
     327            0 :     EXCEPTION_HANDLE_END
     328            0 :     return HcclResult::HCCL_SUCCESS;
     329              : }
     330              : 
     331            0 : HcclResult CcuDevMgrImp::GetCcuResourceSpaceBufInfo(const int32_t deviceLogicId, const uint8_t dieId,
     332              :     uint64_t &addr, uint64_t &size)
     333              : {
     334              :     HcclResult ret;
     335              :     EXCEPTION_HANDLE_BEGIN
     336            0 :     ret = CheckCcuOpenSourceEnable() ?
     337            0 :         CcuComponent::GetInstance(deviceLogicId)
     338            0 :             .GetCcuResourceSpaceBufInfo(dieId, addr, size) :
     339            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId)
     340            0 :             .GetCcuResourceSpaceBufInfo(dieId, addr, size);
     341            0 :     EXCEPTION_HANDLE_END
     342            0 :     return ret;
     343              : }
     344              : 
     345            0 : HcclResult CcuDevMgrImp::GetCcuResourceSpaceTokenInfo(const int32_t deviceLogicId, const uint8_t dieId,
     346              :     uint64_t &tokenId, uint64_t &tokenValue)
     347              : {
     348              :     HcclResult ret;
     349              :     EXCEPTION_HANDLE_BEGIN
     350            0 :     ret = CheckCcuOpenSourceEnable() ?
     351            0 :         CcuComponent::GetInstance(deviceLogicId)
     352            0 :             .GetCcuResourceSpaceTokenInfo(dieId, tokenId, tokenValue) :
     353            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId)
     354            0 :             .GetCcuResourceSpaceTokenInfo(dieId, tokenId, tokenValue);
     355            0 :     EXCEPTION_HANDLE_END
     356            0 :     return ret;
     357              : }
     358              : 
     359            0 : HcclResult CcuDevMgrImp::ConfigChannel(const int32_t deviceLogicId, const uint8_t dieId,
     360              :     ChannelCfg &cfg)
     361              : {
     362              :     HcclResult ret;
     363              :     EXCEPTION_HANDLE_BEGIN
     364            0 :     ret = CheckCcuOpenSourceEnable() ?
     365            0 :         CcuComponent::GetInstance(deviceLogicId).ConfigChannel(dieId, cfg) :
     366            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId).ConfigChannel(dieId, cfg);
     367            0 :     EXCEPTION_HANDLE_END
     368            0 :     return ret;
     369              : }
     370              : 
     371            0 : HcclResult CcuDevMgrImp::GetLoopChannelId(const int32_t deviceLogicId, const uint8_t srcDieId,
     372              :     const uint8_t dstDieId, uint32_t &channIdx)
     373              : {
     374              :     HcclResult ret;
     375              :     EXCEPTION_HANDLE_BEGIN
     376            0 :     ret = CheckCcuOpenSourceEnable() ?
     377            0 :         CcuComponent::GetInstance(deviceLogicId)
     378            0 :             .GetLoopChannelId(srcDieId, dstDieId, channIdx) :
     379            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId)
     380            0 :             .GetLoopChannelId(srcDieId, dstDieId, channIdx);
     381            0 :     EXCEPTION_HANDLE_END
     382            0 :     return ret;
     383              : }
     384              : 
     385            0 : HcclResult CcuDevMgrImp::GetResource(const int32_t deviceLogicId,
     386              :     const CcuResHandle handle, CcuResRepository &ccuResRepo)
     387              : {
     388              :     HcclResult ret;
     389              :     EXCEPTION_HANDLE_BEGIN
     390            0 :     ret = CheckCcuOpenSourceEnable() ?
     391            0 :         CcuResBatchAllocator::GetInstance(deviceLogicId)
     392            0 :             .GetResource(handle, ccuResRepo) :
     393            0 :         Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId)
     394            0 :             .GetResource(handle, ccuResRepo);
     395            0 :     EXCEPTION_HANDLE_END
     396            0 :     return ret;
     397              : }
     398              : 
     399            0 : HcclResult CcuDevMgrImp::AllocResHandle(const int32_t deviceLogicId, const CcuResReq resReq,
     400              :     CcuResHandle &handle)
     401              : {
     402              :     HcclResult ret;
     403              :     EXCEPTION_HANDLE_BEGIN
     404            0 :     ret = CheckCcuOpenSourceEnable() ?
     405            0 :         CcuResBatchAllocator::GetInstance(deviceLogicId)
     406            0 :             .AllocResHandle(resReq, handle) :
     407            0 :         Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId)
     408            0 :             .AllocResHandle(resReq, handle);
     409            0 :     EXCEPTION_HANDLE_END
     410            0 :     return ret;
     411              : }
     412              : 
     413            0 : HcclResult CcuDevMgrImp::ReleaseResHandle(const int32_t deviceLogicId,
     414              :         const CcuResHandle handle)
     415              : {
     416              :     HcclResult ret;
     417              :     EXCEPTION_HANDLE_BEGIN
     418            0 :     ret = CheckCcuOpenSourceEnable() ?
     419            0 :         CcuResBatchAllocator::GetInstance(deviceLogicId)
     420            0 :             .ReleaseResHandle(handle) :
     421            0 :         Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId)
     422            0 :             .ReleaseResHandle(handle);
     423            0 :     EXCEPTION_HANDLE_END
     424            0 :     return ret;
     425              : }
     426              : 
     427            0 : HcclResult CcuDevMgrImp::AllocIns(const int32_t deviceLogicId, const uint8_t dieId,
     428              :     const uint32_t num, ResInfo &insInfo)
     429              : {
     430              :     HcclResult ret;
     431              :     EXCEPTION_HANDLE_BEGIN
     432            0 :     ret = CheckCcuOpenSourceEnable() ?
     433            0 :         CcuComponent::GetInstance(deviceLogicId).AllocIns(dieId, num, insInfo) :
     434            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId).AllocIns(dieId, num, insInfo);
     435            0 :     EXCEPTION_HANDLE_END
     436            0 :     return ret;
     437              : }
     438              : 
     439            0 : HcclResult CcuDevMgrImp::ReleaseIns(const int32_t deviceLogicId, const uint8_t dieId,
     440              :     const ResInfo &insInfo)
     441              : {
     442              :     HcclResult ret;
     443              :     EXCEPTION_HANDLE_BEGIN
     444            0 :     ret = CheckCcuOpenSourceEnable() ?
     445            0 :         CcuComponent::GetInstance(deviceLogicId).ReleaseIns(dieId, insInfo) :
     446            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId).ReleaseIns(dieId, insInfo);
     447            0 :     EXCEPTION_HANDLE_END
     448            0 :     return ret;
     449              : }
     450              : 
     451            0 : HcclResult CcuDevMgrImp::AllocCke(const int32_t deviceLogicId, const uint8_t dieId,
     452              :     const uint32_t num, std::vector<ResInfo> &ckeInfos)
     453              : {
     454              :     HcclResult ret;
     455              :     EXCEPTION_HANDLE_BEGIN
     456            0 :     ret = CheckCcuOpenSourceEnable() ?
     457            0 :         CcuComponent::GetInstance(deviceLogicId).AllocCke(dieId, num, ckeInfos) :
     458            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId).AllocCke(dieId, num, ckeInfos);
     459            0 :     EXCEPTION_HANDLE_END
     460            0 :     return ret;
     461              : }
     462              : 
     463            0 : HcclResult CcuDevMgrImp::ReleaseCke(const int32_t deviceLogicId, const uint8_t dieId,
     464              :     const std::vector<ResInfo> &ckeInfos)
     465              : {
     466              :     HcclResult ret;
     467              :     EXCEPTION_HANDLE_BEGIN
     468            0 :     ret = CheckCcuOpenSourceEnable() ?
     469            0 :         CcuComponent::GetInstance(deviceLogicId).ReleaseCke(dieId, ckeInfos) : 
     470            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId).ReleaseCke(dieId, ckeInfos);
     471            0 :     EXCEPTION_HANDLE_END
     472            0 :     return ret;
     473              : }
     474              : 
     475            0 : HcclResult CcuDevMgrImp::AllocXn(const int32_t deviceLogicId, const uint8_t dieId,
     476              :     const uint32_t num, std::vector<ResInfo>& xnInfos)
     477              : {
     478              :     HcclResult ret;
     479              :     EXCEPTION_HANDLE_BEGIN
     480            0 :     ret = CheckCcuOpenSourceEnable() ?
     481            0 :         CcuComponent::GetInstance(deviceLogicId).AllocXn(dieId, num, xnInfos) :
     482            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId).AllocXn(dieId, num, xnInfos);
     483            0 :     EXCEPTION_HANDLE_END
     484            0 :     return ret;
     485              : }
     486              : 
     487            0 : HcclResult CcuDevMgrImp::ReleaseXn(const int32_t deviceLogicId, const uint8_t dieId,
     488              :     const std::vector<ResInfo> &xnInfos)
     489              : {
     490              :     HcclResult ret;
     491              :     EXCEPTION_HANDLE_BEGIN
     492            0 :     ret = CheckCcuOpenSourceEnable() ?
     493            0 :         CcuComponent::GetInstance(deviceLogicId).ReleaseXn(dieId, xnInfos) :
     494            0 :         Hccl::CcuComponent::GetInstance(deviceLogicId).ReleaseXn(dieId, xnInfos);
     495            0 :     EXCEPTION_HANDLE_END
     496            0 :     return ret;
     497              : }
     498              : 
     499            0 : HcclResult CcuDevMgrImp::AllocWishCntXn(const int32_t deviceLogicId, const uint8_t dieId, const std::string &resGroupTag,
     500              :     uint32_t &wishCntXn)
     501              : {
     502            0 :     if (!CheckCcuOpenSourceEnable()) {
     503            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     504            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     505              :     }
     506              : 
     507            0 :     HCCL_INFO("[%s] new alloc count xn request: deviceLogicId[%d], dieId[%u], resGroupTag[%s].",
     508              :         __func__, deviceLogicId, dieId, resGroupTag.c_str());
     509            0 :     return CcuComponent::GetInstance(deviceLogicId).AllocWishCntXn(dieId, resGroupTag, wishCntXn);
     510              : }
     511              : 
     512            0 : HcclResult CcuDevMgrImp::ReleaseWishCntXn(const int32_t deviceLogicId, const uint8_t dieId,
     513              :     const std::string &resGroupTag, uint32_t wishCntXn)
     514              : {
     515            0 :     if (!CheckCcuOpenSourceEnable()) {
     516            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     517            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     518              :     }
     519              : 
     520            0 :     HCCL_INFO("[%s] new release count xn request: deviceLogicId[%d], dieId[%u], resGroupTag[%s], wishCntXn[%u].",
     521              :         __func__, deviceLogicId, dieId, resGroupTag.c_str(), wishCntXn);
     522            0 :     return CcuComponent::GetInstance(deviceLogicId).ReleaseWishCntXn(dieId, resGroupTag, wishCntXn);
     523              : }
     524              : 
     525            0 : HcclResult CcuDevMgrImp::GetCntXnBlock(const int32_t deviceLogicId, const uint8_t dieId,
     526              :     const std::string &resGroupTag, std::pair<uint32_t, uint32_t> &cntXnPair)
     527              : {
     528            0 :     if (!CheckCcuOpenSourceEnable()) {
     529            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     530            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     531              :     }
     532              : 
     533            0 :     HCCL_INFO("[%s] get count xn request: deviceLogicId[%d], dieId[%u], resGroupTag[%s].",
     534              :         __func__, deviceLogicId, dieId, resGroupTag.c_str());
     535            0 :     return CcuComponent::GetInstance(deviceLogicId).GetCntXnBlock(dieId, resGroupTag, cntXnPair);
     536              : }
     537              : 
     538            0 : HcclResult CcuDevMgrImp::GetTotalCntXn(const int32_t deviceLogicId, const uint8_t dieId,
     539              :     const std::string &resGroupTag, uint32_t &totalCntXn)
     540              : {
     541            0 :     if (!CheckCcuOpenSourceEnable()) {
     542            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     543            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     544              :     }
     545              : 
     546            0 :     HCCL_INFO("[%s] get count xn request: deviceLogicId[%d], dieId[%u], resGroupTag[%s].",
     547              :         __func__, deviceLogicId, dieId, resGroupTag.c_str());
     548            0 :     return CcuComponent::GetInstance(deviceLogicId).GetTotalCntXn(dieId, resGroupTag, totalCntXn);
     549              : }
     550              : 
     551            0 : HcclResult CcuDevMgrImp::GetMissionKey(const int32_t deviceLogicId, const uint8_t dieId,
     552              :     uint32_t &missionKey)
     553              : {
     554              :     HcclResult ret;
     555              :     EXCEPTION_HANDLE_BEGIN
     556            0 :     ret = CheckCcuOpenSourceEnable() ?
     557            0 :         CcuResSpecifications::GetInstance(deviceLogicId)
     558            0 :             .GetMissionKey(dieId, missionKey) :
     559            0 :         Hccl::CcuResSpecifications::GetInstance(deviceLogicId)
     560            0 :             .GetMissionKey(dieId, missionKey);
     561            0 :     EXCEPTION_HANDLE_END
     562            0 :     return ret;
     563              : }
     564              : 
     565            0 : HcclResult CcuDevMgrImp::GetInstructionNum(const int32_t deviceLogicId, const uint8_t dieId,
     566              :     uint32_t &instrNum)
     567              : {
     568              :     HcclResult ret;
     569              :     EXCEPTION_HANDLE_BEGIN
     570            0 :     ret = CheckCcuOpenSourceEnable() ?
     571            0 :         CcuResSpecifications::GetInstance(deviceLogicId)
     572            0 :             .GetInstructionNum(dieId, instrNum) :
     573            0 :         Hccl::CcuResSpecifications::GetInstance(deviceLogicId)
     574            0 :             .GetInstructionNum(dieId, instrNum);
     575            0 :     EXCEPTION_HANDLE_END
     576            0 :     return ret;
     577              : }
     578              : 
     579            0 : HcclResult CcuDevMgrImp::GetXnBaseAddr(const int32_t devLogicId, const uint8_t dieId,
     580              :     uint64_t& xnBaseAddr)
     581              : {
     582              :     HcclResult ret;
     583              :     EXCEPTION_HANDLE_BEGIN
     584            0 :     ret = CheckCcuOpenSourceEnable() ?
     585            0 :         CcuResSpecifications::GetInstance(devLogicId)
     586            0 :             .GetXnBaseAddr(dieId, xnBaseAddr) :
     587            0 :         Hccl::CcuResSpecifications::GetInstance(devLogicId)
     588            0 :             .GetXnBaseAddr(dieId, xnBaseAddr);
     589            0 :     EXCEPTION_HANDLE_END
     590            0 :     return ret;
     591              : }
     592            0 : HcclResult CcuDevMgrImp::GetCkeBaseAddr(const int32_t devLogicId, const uint8_t dieId,
     593              :     uint64_t& ckeBaseAddr)
     594              : {
     595            0 :     if (!CheckCcuOpenSourceEnable()) {
     596            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     597            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     598              :     }
     599              : 
     600            0 :     return CcuResSpecifications::GetInstance(devLogicId).GetCkeBaseAddr(dieId, ckeBaseAddr);
     601              : }
     602              : 
     603            0 : HcclResult CcuDevMgrImp::GetXnOffsetCcumAddrById(const int32_t devLogicId, const uint8_t dieId, uint16_t id,
     604              :     uint64_t& xnAddr)
     605              : {
     606            0 :     if (!CheckCcuOpenSourceEnable()) {
     607            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     608            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     609              :     }
     610              : 
     611            0 :     return CcuResSpecifications::GetInstance(devLogicId).GetXnOffsetCcumAddrById(dieId, id, xnAddr);
     612              : }
     613              : 
     614            0 : HcclResult CcuDevMgrImp::GetCkeOffsetCcumAddrById(const int32_t devLogicId, const uint8_t dieId, uint16_t id,
     615              :     uint64_t& ckeAddr)
     616              : {
     617            0 :     if (!CheckCcuOpenSourceEnable()) {
     618            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     619            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     620              :     }
     621              : 
     622            0 :     return CcuResSpecifications::GetInstance(devLogicId).GetCkeOffsetCcumAddrById(dieId, id, ckeAddr);
     623              : }
     624              : 
     625         1102 : HcclResult CheckDieValid(const char *funcName, const int32_t devLogicId, const uint8_t dieId,
     626              :     const std::array<bool, CCU_MAX_IODIE_NUM> &dieEnableFlags)
     627              : {
     628         1102 :     CHK_PRT_RET(dieId >= CCU_MAX_IODIE_NUM,
     629              :         HCCL_ERROR("[%s] failed, dieId[%u] is invalid, shoudle be in [0-%u), devLogicId[%d].",
     630              :             funcName, dieId, CCU_MAX_IODIE_NUM, devLogicId),
     631              :         HcclResult::HCCL_E_PARA);
     632              : 
     633         1102 :     CHK_PRT_RET(!dieEnableFlags[dieId],
     634              :         HCCL_ERROR("[%s] failed, dieId[%u] is disable, devLogicId[%d].",
     635              :             funcName, dieId, devLogicId),
     636              :         HcclResult::HCCL_E_PARA);
     637              : 
     638         1102 :     return HcclResult::HCCL_SUCCESS;
     639              : }
     640              : 
     641            0 : bool CcuIsInited(const int32_t deviceLogicId)
     642              : {
     643            0 :     HCCL_INFO("[CcuIsInited] Input params: deviceLogicId[%d]", deviceLogicId);
     644            0 :     CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     645              :         HCCL_ERROR("[CcuIsInited]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
     646              :         false);
     647              : 
     648            0 :     if (!CheckCcuOpenSourceEnable()) {
     649            0 :         return Hccl::CcuComponent::GetInstance(deviceLogicId).IsInited();
     650              :     }
     651              : 
     652            0 :     std::lock_guard<std::mutex> lock(ccuDrvHandleMutex);
     653              :     // ccu驱动已重复拉起失败时,直接返回,在锁保护内返回
     654            0 :     if (ccuDriverInitAgainFlag) {
     655            0 :         return false;
     656              :     }
     657              : 
     658            0 :     auto iter = ccuDrvHandleMap.find(deviceLogicId);
     659            0 :     if (iter == ccuDrvHandleMap.end()) {
     660            0 :         return false;
     661              :     }
     662              : 
     663            0 :     return true;
     664            0 : }
     665              : 
     666            4 : HcclResult CcuSetTaskKill(const int32_t deviceLogicId)
     667              : {
     668            4 :     HCCL_INFO("[CcuSetTaskKill] Input params: deviceLogicId[%d]", deviceLogicId);
     669              :     // 入参校验拦截
     670            4 :     CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     671              :         HCCL_ERROR("[CcuSetTaskKill]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
     672              :             HcclResult::HCCL_E_PARA);
     673              :     HcclResult ret;
     674              :     EXCEPTION_HANDLE_BEGIN
     675            2 :     ret = CheckCcuOpenSourceEnable() ?
     676            0 :         CcuComponent::GetInstance(deviceLogicId).SetTaskKill() :
     677            2 :         Hccl::CcuComponent::GetInstance(deviceLogicId).SetTaskKill();
     678            0 :     EXCEPTION_HANDLE_END
     679            2 :     return ret;
     680              : }
     681              : 
     682            4 : HcclResult CcuSetTaskKillDone(const int32_t deviceLogicId)
     683              : {
     684            4 :     HCCL_INFO("[CcuSetTaskKillDone] Input params: deviceLogicId[%d]", deviceLogicId);
     685              :     // 入参校验拦截
     686            4 :     CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     687              :         HCCL_ERROR("[CcuSetTaskKillDone]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
     688              :             HcclResult::HCCL_E_PARA);
     689              :     HcclResult ret;
     690              :     EXCEPTION_HANDLE_BEGIN
     691            2 :     ret = CheckCcuOpenSourceEnable() ?
     692            0 :         CcuComponent::GetInstance(deviceLogicId).SetTaskKillDone() :
     693            2 :         Hccl::CcuComponent::GetInstance(deviceLogicId).SetTaskKillDone();
     694            0 :     EXCEPTION_HANDLE_END
     695            2 :     return ret;
     696              : }
     697              : 
     698            4 : HcclResult CcuCleanTaskKillState(const int32_t deviceLogicId)
     699              : {
     700            4 :     HCCL_INFO("[CcuCleanTaskKillState] Input params: deviceLogicId[%u]", deviceLogicId);
     701              :     // 入参校验拦截
     702            4 :     CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     703              :         HCCL_ERROR("[CcuCleanTaskKillState]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
     704              :             HcclResult::HCCL_E_PARA);
     705              :     HcclResult ret;
     706              :     EXCEPTION_HANDLE_BEGIN
     707            2 :     ret = CheckCcuOpenSourceEnable() ?
     708            0 :         CcuComponent::GetInstance(deviceLogicId).CleanTaskKillState() :
     709            2 :         Hccl::CcuComponent::GetInstance(deviceLogicId).CleanTaskKillState();
     710            0 :     EXCEPTION_HANDLE_END
     711            2 :     return ret;
     712              : }
     713              : 
     714            4 : HcclResult CcuCleanDieCkes(const int32_t deviceLogicId, const uint8_t dieId)
     715              : {
     716            4 :     HCCL_INFO("[CcuCleanDieCkes] Input params: deviceLogicId[%u], dieId[%u]", deviceLogicId, dieId);
     717              :     // 入参校验拦截
     718            4 :     CHK_PRT_RET((deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     719              :         HCCL_ERROR("[CcuCleanDieCkes]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
     720              :             HcclResult::HCCL_E_PARA);
     721              :     HcclResult ret;
     722              :     EXCEPTION_HANDLE_BEGIN
     723            2 :     ret = CheckCcuOpenSourceEnable() ?
     724            0 :         CcuComponent::GetInstance(deviceLogicId).CleanDieCkes(dieId) :
     725            2 :         Hccl::CcuComponent::GetInstance(deviceLogicId).CleanDieCkes(dieId);
     726            0 :     EXCEPTION_HANDLE_END
     727            2 :     return ret;
     728              : }
     729              : 
     730              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1