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: 42.1 % 463 195
Test Date: 2026-08-18 17:47:01 Functions: 41.0 % 61 25

            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_legacy.h"
      23              : #include "unified_platform/ccu/ccu_device/ccu_res_batch_allocator_legacy.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              : #include "ccu_res_desc.h"
      42              : 
      43              : #include "dev_type.h"
      44              : 
      45              : namespace hcomm {
      46              : 
      47              : static std::unordered_map<int32_t, std::shared_ptr<CcuDrvHandle>> ccuDrvHandleMap;
      48              : static std::mutex ccuDrvHandleMutex;
      49              : static bool ccuDriverInitAgainFlag = false; // 记录每个进程CCU驱动是否重复拉起
      50              : static thread_local Hccl::HcclMainboardId mainBoardType = Hccl::HcclMainboardId::MAINBOARD_OTHERS; // 记录本卡的主板类型
      51              : 
      52           11 : inline bool CheckCcuOpenSourceEnable()
      53              : {
      54              :     // A6 不支持legacy ccu mc2,可以完全切换至开源流程
      55           11 :     auto devType = DevType::DEV_TYPE_COUNT;
      56           11 :     (void)hrtGetDeviceType(devType);
      57           11 :     return devType == DevType::DEV_TYPE_960;
      58              : }
      59              : 
      60           69 : CcuResult CcuInitFeature(const int32_t devLogicId, std::shared_ptr<CcuDrvHandle>& ccuDrvHandle)
      61              : {
      62           69 :     if (devLogicId >= static_cast<int32_t>(MAX_MODULE_DEVICE_NUM)) {
      63            0 :         HCCL_ERROR(
      64              :             "[%s] failed, devLogicId[%d] is too large, should be less than %u.", __func__, devLogicId,
      65              :             MAX_MODULE_DEVICE_NUM);
      66            0 :         return CcuResult::CCU_E_PARA;
      67              :     }
      68              : 
      69           69 :     std::lock_guard<std::mutex> lock(ccuDrvHandleMutex);
      70              :     // ccu驱动已重复拉起失败时,直接返回,在锁保护内返回
      71           69 :     if (ccuDriverInitAgainFlag) {
      72            0 :         return CcuResult::CCU_E_DRV_BUSY;
      73              :     }
      74              : 
      75           69 :     auto iter = ccuDrvHandleMap.find(devLogicId);
      76           69 :     if (iter != ccuDrvHandleMap.end()) {
      77            0 :         ccuDrvHandle = iter->second;
      78            0 :         HCCL_RUN_INFO("[%s] devLogicId[%d] init ccu feature, handle[%p].", __func__, devLogicId, ccuDrvHandle.get());
      79            0 :         return CcuResult::CCU_SUCCESS;
      80              :     }
      81              : 
      82           69 :     std::shared_ptr<CcuDrvHandle> drvHandle = nullptr;
      83           69 :     drvHandle.reset(new (std::nothrow) CcuDrvHandle(devLogicId));
      84           69 :     CCU_CHK_PTR_NULL(drvHandle);
      85              : 
      86           69 :     auto ret = drvHandle->Init();
      87           69 :     if (ret == CcuResult::CCU_E_DRV_BUSY) {
      88            0 :         HCCL_RUN_WARNING(
      89              :             "[%s] failed but passed, devLogicId[%d] ccu driver has been "
      90              :             "inited by another process, this process will not try to init anymore.",
      91              :             __func__, devLogicId);
      92            0 :         ccuDriverInitAgainFlag = true; // 记录该进程ccu驱动已拉起失败
      93            0 :         drvHandle = nullptr;           // 主动置空触发资源销毁,控制释放时序
      94            0 :         return ret;
      95              :     }
      96           69 :     CCU_CHK_RET(ret);
      97              : 
      98           68 :     ccuDrvHandleMap[devLogicId] = drvHandle;
      99           68 :     ccuDrvHandle = ccuDrvHandleMap[devLogicId];
     100           68 :     HCCL_RUN_INFO("[%s] devLogicId[%d] init ccu feature, handle[%p].", __func__, devLogicId, ccuDrvHandle.get());
     101           68 :     return CcuResult::CCU_SUCCESS;
     102           69 : }
     103              : 
     104           68 : CcuResult CcuDeinitFeature(const int32_t devLogicId)
     105              : {
     106           68 :     std::lock_guard<std::mutex> lock(ccuDrvHandleMutex);
     107           68 :     auto iter = ccuDrvHandleMap.find(devLogicId);
     108           68 :     if (iter == ccuDrvHandleMap.end()) {
     109            0 :         HCCL_INFO("[%s] passed, ccu feature was not inited, devLogicId[%d].", __func__, devLogicId);
     110            0 :         return CcuResult::CCU_SUCCESS;
     111              :     }
     112              : 
     113           68 :     auto& ccuDrvHandle = ccuDrvHandleMap[devLogicId];
     114           68 :     if (ccuDrvHandle.use_count() == 1) {
     115           68 :         HCCL_RUN_INFO(
     116              :             "[%s] entry, start to deinit ccu feature, "
     117              :             "handle[%p] devLogicId[%d].",
     118              :             __func__, ccuDrvHandle.get(), devLogicId);
     119           68 :         ccuDrvHandle = nullptr;
     120           68 :         ccuDrvHandleMap.erase(devLogicId);
     121              :     }
     122              : 
     123           68 :     return CcuResult::CCU_SUCCESS;
     124           68 : }
     125              : 
     126            0 : CcuResult CcuGetDieEnableInfo(int32_t deviceLogicId, uint8_t dieId, bool& enableFlag)
     127              : {
     128            0 :     CHK_PRT_RET(
     129              :         dieId >= CCU_MAX_IODIE_NUM,
     130              :         HCCL_ERROR(
     131              :             "[%s] failed, dieId[%u] is invalid, should be in [0-%u), devLogicId[%d].", __func__, dieId,
     132              :             CCU_MAX_IODIE_NUM, deviceLogicId),
     133              :         CcuResult::CCU_E_PARA);
     134              : 
     135            0 :     const auto& dieEnableFlags = CheckCcuOpenSourceEnable() ?
     136            0 :                                      CcuComponent::GetInstance(deviceLogicId).GetDieEnableFlags() :
     137            0 :                                      Hccl::CcuComponent::GetInstance(deviceLogicId).GetDieEnableFlags();
     138              : 
     139            0 :     enableFlag = dieEnableFlags[dieId];
     140            0 :     return CcuResult::CCU_SUCCESS;
     141              : }
     142              : 
     143              : // 查询指定 die 上各资源类型可分配的总量
     144            2 : CcuResult CcuGetLoopEngineNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num)
     145              : {
     146            2 :     CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxLoopEngineNum(deviceLogicId, dieId, num));
     147            2 :     return CcuResult::CCU_SUCCESS;
     148              : }
     149              : 
     150            2 : CcuResult CcuGetMsNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num)
     151              : {
     152            2 :     CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxMsNum(deviceLogicId, dieId, num));
     153            2 :     return CcuResult::CCU_SUCCESS;
     154              : }
     155              : 
     156            2 : CcuResult CcuGetCkeNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num)
     157              : {
     158            2 :     CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxCkeNum(deviceLogicId, dieId, num));
     159            2 :     return CcuResult::CCU_SUCCESS;
     160              : }
     161              : 
     162            2 : CcuResult CcuGetXnNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num)
     163              : {
     164            2 :     CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxXnNum(deviceLogicId, dieId, num));
     165            2 :     return CcuResult::CCU_SUCCESS;
     166              : }
     167              : 
     168            2 : CcuResult CcuGetGsaNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num)
     169              : {
     170            2 :     CCU_CHK_RET(CcuDevMgrImp::GetAllocatableMaxGsaNum(deviceLogicId, dieId, num));
     171            2 :     return CcuResult::CCU_SUCCESS;
     172              : }
     173              : 
     174            2 : CcuResult CcuGetInstructionNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num)
     175              : {
     176            2 :     CCU_CHK_RET(CcuDevMgrImp::GetResSpecsInstructionNum(deviceLogicId, dieId, num));
     177            2 :     return CcuResult::CCU_SUCCESS;
     178              : }
     179              : 
     180            2 : CcuResult CcuGetMissionNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num)
     181              : {
     182            2 :     CCU_CHK_RET(CcuDevMgrImp::GetResSpecsMissionNum(deviceLogicId, dieId, num));
     183            2 :     return CcuResult::CCU_SUCCESS;
     184              : }
     185              : 
     186            0 : HcclResult CcuGetMainboardType(uint32_t deviceLogicId, Hccl::HcclMainboardId& hcclMainboardId)
     187              : {
     188            0 :     CHK_RET(CcuGetMainboardId(deviceLogicId, hcclMainboardId));
     189            0 :     return HcclResult::HCCL_SUCCESS;
     190              : }
     191              : 
     192              : // 单个描述符的资源数量映射到 CcuResReq 的 block 字段
     193          122 : static CcuResult FillResReqByResDesc(CcuResReq& resReq, uint8_t dieId, const CcuResDesc& desc)
     194              : {
     195          122 :     uint32_t num = 0;
     196          122 :     CCU_CHK_RET(desc.QueryResNum(ResType::LOOP, num));
     197          122 :     resReq.blockLoopEngineReq[dieId] = num;
     198          122 :     CCU_CHK_RET(desc.QueryResNum(ResType::MS, num));
     199          122 :     resReq.blockMsReq[dieId] = num;
     200          122 :     CCU_CHK_RET(desc.QueryResNum(ResType::CKE, num));
     201          122 :     resReq.blockCkeReq[dieId] = num;
     202          122 :     CCU_CHK_RET(desc.QueryResNum(ResType::XN, num));
     203          122 :     resReq.blockXnReq[dieId] = num;
     204          122 :     CCU_CHK_RET(desc.QueryResNum(ResType::GSA, num));
     205          122 :     resReq.blockGsaReq[dieId] = num;
     206              : 
     207          122 :     resReq.loopEngineReq[dieId] = 0;
     208          122 :     resReq.msReq[dieId] = 0;
     209          122 :     resReq.ckeReq[dieId] = 0;
     210          122 :     resReq.xnReq[dieId] = 0;
     211          122 :     resReq.gsaReq[dieId] = 0;
     212          122 :     return CcuResult::CCU_SUCCESS;
     213              : }
     214              : 
     215              : // 查询各 die 是否启用;若全部未启用则返回错误
     216           61 : static CcuResult CheckEnabledDies(int32_t deviceLogicId, std::array<bool, CCU_MAX_IODIE_NUM>& dieEnableFlags)
     217              : {
     218           61 :     dieEnableFlags = {false, false};
     219          183 :     for (uint8_t dieId = 0; dieId < CCU_MAX_IODIE_NUM; dieId++) {
     220          122 :         CCU_CHK_RET(CcuGetDieEnableInfo(deviceLogicId, dieId, dieEnableFlags[dieId]));
     221              :     }
     222              : 
     223           61 :     if (!dieEnableFlags[0] && !dieEnableFlags[1]) {
     224            0 :         HCCL_ERROR("[%s] failed, all ccu dies are disable, devLogicId[%d].", __func__, deviceLogicId);
     225            0 :         return CcuResult::CCU_E_INTERNAL;
     226              :     }
     227           61 :     return CcuResult::CCU_SUCCESS;
     228              : }
     229              : 
     230              : // 根据资源描述符数组构造 CcuResReq:
     231              : // 跳过未启用 die;block 字段由各 die 的 resDesc 填充;
     232              : // missionReq 取所有 die 的最大值,再统一回填到各启用 die
     233           61 : static CcuResult BuildResReqByDescs(
     234              :     const CcuResDesc* descs[], uint32_t descNum, const std::array<bool, CCU_MAX_IODIE_NUM>& dieEnableFlags,
     235              :     int32_t deviceLogicId, CcuResReq& resReq)
     236              : {
     237           61 :     resReq = CcuResReq{};
     238           61 :     resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE;
     239              : 
     240           61 :     uint32_t maxMissionReq = 0;
     241          183 :     for (uint32_t i = 0; i < descNum; i++) {
     242          122 :         if (descs[i] == nullptr) {
     243            0 :             HCCL_ERROR("[%s] failed, descs[%u] is nullptr, devLogicId[%d].", __func__, i, deviceLogicId);
     244            0 :             return CcuResult::CCU_E_PARA;
     245              :         }
     246          122 :         uint8_t dieId = 0;
     247          122 :         dieId = static_cast<uint8_t>(descs[i]->dieId);
     248          122 :         if (dieId >= CCU_MAX_IODIE_NUM) {
     249            0 :             HCCL_ERROR("[%s] failed, dieId[%u] is invalid, devLogicId[%d].", __func__, dieId, deviceLogicId);
     250            0 :             return CcuResult::CCU_E_PARA;
     251              :         }
     252              : 
     253              :         // 不跳过未启用的die,如果die未启用,但请求资源,在分配资源时检查返回错误
     254          122 :         CCU_CHK_RET(FillResReqByResDesc(resReq, dieId, *descs[i]));
     255          122 :         uint32_t missionNum = 0;
     256          122 :         CCU_CHK_RET(descs[i]->QueryResNum(ResType::MISSION, missionNum));
     257          122 :         if (missionNum > maxMissionReq) {
     258           61 :             maxMissionReq = missionNum;
     259              :         }
     260              :     }
     261              : 
     262           61 :     if (maxMissionReq > 0) {
     263          183 :         for (uint8_t dieId = 0; dieId < CCU_MAX_IODIE_NUM; dieId++) {
     264          122 :             if (dieEnableFlags[dieId]) {
     265          122 :                 resReq.missionReq.req[dieId] = maxMissionReq;
     266              :             }
     267              :         }
     268              :     }
     269           61 :     return CcuResult::CCU_SUCCESS;
     270              : }
     271              : 
     272              : CcuResult
     273           61 : CcuAllocResHandleByResDescs(int32_t deviceLogicId, const CcuResDesc* descs[], uint32_t descNum, CcuResHandle& resHandle)
     274              : {
     275           61 :     if (descs == nullptr || descNum == 0 || descNum > hcomm::CCU_MAX_IODIE_NUM) {
     276            0 :         HCCL_ERROR(
     277              :             "[%s] failed, invalid descs[%p] descNum[%u], devLogicId[%d].", __func__, descs, descNum, deviceLogicId);
     278            0 :         return CcuResult::CCU_E_PARA;
     279              :     }
     280              : 
     281           61 :     std::array<bool, CCU_MAX_IODIE_NUM> dieEnableFlags = {false, false};
     282           61 :     CCU_CHK_RET(CheckEnabledDies(deviceLogicId, dieEnableFlags));
     283              : 
     284           61 :     CcuResReq resReq{};
     285           61 :     CCU_CHK_RET(BuildResReqByDescs(descs, descNum, dieEnableFlags, deviceLogicId, resReq));
     286              : 
     287           61 :     if (mainBoardType == Hccl::HcclMainboardId::MAINBOARD_OTHERS) {
     288            1 :         CCU_CHK_RET(CcuGetMainboardId(deviceLogicId, mainBoardType));
     289              :     }
     290              : 
     291           61 :     CCU_CHK_RET(CcuDevMgrImp::AllocResHandle(deviceLogicId, resReq, resHandle));
     292              : 
     293           61 :     HCCL_INFO(
     294              :         "[%s] succeed, get res handle[%llx], devLogicId[%d], descNum[%u]", __func__, resHandle, deviceLogicId, descNum);
     295           61 :     return CcuResult::CCU_SUCCESS;
     296              : }
     297              : 
     298              : constexpr u32 CCU_MS_DEFAULT_BLOCK_LOOP_ENGINE_REQ = 8 * 8 * 2;
     299              : constexpr u32 CCU_MS_DEFAULT_BLOCK_MS_REQ = 64 * 8 * 2;
     300              : constexpr u32 CCU_MS_DEFAULT_BLOCK_CKE_REQ = 32 + 8 * 8 * 2;
     301              : constexpr u32 CCU_MS_DEFAULT_BLOCK_XN_REQ = 400;
     302              : constexpr u32 CCU_MS_DEFAULT_GSA_REQ = 400;
     303              : constexpr u32 CCU_MS_DEFAULT_MISSIONREQ_REQ = 2;
     304            8 : inline void ConfigCcuResReqCcuMs(CcuResReq& resReq, uint8_t dieId, CcuVersion version)
     305              : {
     306            8 :     resReq.loopEngineReq[dieId] = 0;
     307            8 :     resReq.blockLoopEngineReq[dieId] = CCU_MS_DEFAULT_BLOCK_LOOP_ENGINE_REQ;
     308            8 :     resReq.msReq[dieId] = 0;
     309            8 :     resReq.blockMsReq[dieId] = CCU_MS_DEFAULT_BLOCK_MS_REQ;
     310            8 :     resReq.ckeReq[dieId] = 0;
     311            8 :     resReq.blockCkeReq[dieId] = CCU_MS_DEFAULT_BLOCK_CKE_REQ;
     312            8 :     resReq.xnReq[dieId] = 0;
     313            8 :     resReq.gsaReq[dieId] = 0;
     314            8 :     if (version == CcuVersion::CCU_V2) {
     315            0 :         resReq.blockXnReq[dieId] = CCU_MS_DEFAULT_BLOCK_XN_REQ * 2; // V2场景下申请2倍的Xn数量
     316            0 :         resReq.blockGsaReq[dieId] = 0;
     317              :     } else {
     318            8 :         resReq.blockXnReq[dieId] = CCU_MS_DEFAULT_BLOCK_XN_REQ;
     319            8 :         resReq.blockGsaReq[dieId] = CCU_MS_DEFAULT_GSA_REQ;
     320              :     }
     321            8 :     resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE;
     322            8 :     resReq.missionReq.req[dieId] = CCU_MS_DEFAULT_MISSIONREQ_REQ;
     323            8 : }
     324              : 
     325              : constexpr u32 CCU_SCHED_DEFAULT_BLOCK_LOOP_ENGINE_REQ = 16;
     326              : constexpr u32 CCU_SCHED_DEFAULT_BLOCK_MS_REQ = 128;
     327              : constexpr u32 CCU_SCHED_DEFAULT_BLOCK_CKE_REQ = 32 + 16;
     328              : constexpr u32 CCU_SCHED_DEFAULT_BLOCK_XN_REQ = 400;
     329              : constexpr u32 CCU_SCHED_DEFAULT_GSA_REQ = 400;
     330              : constexpr u32 CCU_SCHED_DEFAULT_MISSIONREQ_REQ = 2;
     331            4 : inline void ConfigCcuResReqCcuSched(CcuResReq& resReq, uint8_t dieId, CcuVersion version)
     332              : {
     333            4 :     resReq.loopEngineReq[dieId] = 0;
     334            4 :     resReq.blockLoopEngineReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_LOOP_ENGINE_REQ;
     335            4 :     resReq.msReq[dieId] = 0;
     336            4 :     resReq.blockMsReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_MS_REQ;
     337            4 :     resReq.ckeReq[dieId] = 0;
     338            4 :     resReq.blockCkeReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_CKE_REQ;
     339            4 :     resReq.xnReq[dieId] = 0;
     340            4 :     resReq.gsaReq[dieId] = 0;
     341            4 :     if (version == CcuVersion::CCU_V2) {
     342            0 :         resReq.blockXnReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_XN_REQ * 2; // V2场景下申请2倍的Xn数量
     343            0 :         resReq.blockGsaReq[dieId] = 0;
     344              :     } else {
     345            4 :         resReq.blockXnReq[dieId] = CCU_SCHED_DEFAULT_BLOCK_XN_REQ;
     346            4 :         resReq.blockGsaReq[dieId] = CCU_SCHED_DEFAULT_GSA_REQ;
     347              :     }
     348              : 
     349            4 :     resReq.missionReq.reqType = MissionReqType::FUSION_MULTIPLE_DIE;
     350            4 :     resReq.missionReq.req[dieId] = CCU_SCHED_DEFAULT_MISSIONREQ_REQ;
     351            4 : }
     352              : 
     353              : // CCU设备管理对集合通信提供的接口
     354            6 : CcuResult CcuAllocResHandleByInsType(int32_t deviceLogicId, CcuInstanceType ccuInsType, CcuResHandle& resHandle)
     355              : {
     356            6 :     if (ccuInsType >= CcuInstanceType::CCU_UNUSED) {
     357            0 :         HCCL_ERROR("[%s] failed, error ccu instance type[%d], devLogicId[%d].", __func__, ccuInsType, deviceLogicId);
     358            0 :         return CcuResult::CCU_E_PARA;
     359              :     }
     360              : 
     361            6 :     std::array<bool, CCU_MAX_IODIE_NUM> dieEnableFlags = {false, false};
     362           18 :     for (uint8_t dieId = 0; dieId < CCU_MAX_IODIE_NUM; dieId++) {
     363           12 :         CCU_CHK_RET(CcuGetDieEnableInfo(deviceLogicId, dieId, dieEnableFlags[dieId]));
     364              :     }
     365              : 
     366            6 :     if (!dieEnableFlags[0] && !dieEnableFlags[1]) {
     367            0 :         HCCL_ERROR("[%s] failed, all ccu dies are disable, devLogicId[%d].", __func__, deviceLogicId);
     368            0 :         return CcuResult::CCU_E_INTERNAL;
     369              :     }
     370              : 
     371            6 :     CcuVersion ccuVersion = CcuVersion::INVALID;
     372            6 :     CCU_CHK_RET(CcuDevMgrImp::GetCcuVersion(deviceLogicId, ccuVersion));
     373            6 :     if (ccuVersion == CcuVersion::INVALID) {
     374            0 :         HCCL_RUN_WARNING(
     375              :             "[%s] failed, deviceLogicId[%d] ccu version is invalid, "
     376              :             "should fallback to aicpu.",
     377              :             __func__, deviceLogicId);
     378            0 :         return CcuResult::CCU_E_UNAVAIL;
     379              :     }
     380              : 
     381            6 :     CcuResReq resReq{};
     382           18 :     for (uint8_t dieId = 0; dieId < CCU_MAX_IODIE_NUM; dieId++) {
     383           12 :         if (!dieEnableFlags[dieId]) {
     384            0 :             continue;
     385              :         }
     386              : 
     387           12 :         if (ccuInsType == CcuInstanceType::CCU_MS) {
     388            8 :             ConfigCcuResReqCcuMs(resReq, dieId, ccuVersion);
     389              :         } else {
     390            4 :             ConfigCcuResReqCcuSched(resReq, dieId, ccuVersion);
     391              :         }
     392              :     }
     393              : 
     394            6 :     if (mainBoardType == Hccl::HcclMainboardId::MAINBOARD_OTHERS) {
     395            0 :         CCU_CHK_RET(CcuGetMainboardId(deviceLogicId, mainBoardType));
     396              :     }
     397              : 
     398            6 :     if (mainBoardType == Hccl::HcclMainboardId::MAINBOARD_PCIE_STD
     399            6 :         && ccuInsType == CcuInstanceType::CCU_MS) { // 标卡环境下配置CCU_MS拦截报错
     400            0 :         HCCL_ERROR(
     401              :             "[%s] ccuInstanceType[%d] not support in %s", __func__, ccuInsType, mainBoardType.Describe().c_str());
     402            0 :         return CcuResult::CCU_E_NOT_SUPPORT;
     403              :     }
     404              : 
     405            6 :     CCU_CHK_RET(CcuDevMgrImp::AllocResHandle(deviceLogicId, resReq, resHandle));
     406              : 
     407            6 :     HCCL_INFO("[%s] succeed, get res handle[%p], devLogicId[%d]", __func__, resHandle, deviceLogicId);
     408            6 :     return CcuResult::CCU_SUCCESS;
     409              : }
     410              : 
     411          122 : CcuResult CcuCheckResource(const int32_t deviceLogicId, const CcuResHandle resHandle, CcuResRepository& resRepo)
     412              : {
     413          122 :     CCU_CHK_RET(CcuDevMgrImp::GetResource(deviceLogicId, resHandle, resRepo));
     414          122 :     return CcuResult::CCU_SUCCESS;
     415              : }
     416              : 
     417           67 : HcclResult CcuReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle resHandle)
     418              : {
     419           67 :     CHK_RET(CcuDevMgrImp::ReleaseResHandle(deviceLogicId, resHandle));
     420           67 :     return HcclResult::HCCL_SUCCESS;
     421              : }
     422              : 
     423            0 : HcclResult CcuAllocChannels(
     424              :     const int32_t deviceLogicId, const CcuChannelPara& ccuChannelPara, std::vector<CcuChannelInfo>& ccuChannelInfos)
     425              : {
     426            0 :     Hccl::IpAddress ipAddr{};
     427            0 :     CHK_RET(CommAddrToIpAddress(ccuChannelPara.commAddr, ipAddr)); // 为了打印信息暂时添加
     428            0 :     HCCL_INFO(
     429              :         "[%s] new allocation request: deviceLogicId[%d], ipAddr[%s], "
     430              :         "channelnum[%u], jettyNum[%u], sqSize[%u].",
     431              :         __func__, deviceLogicId, ipAddr.Describe().c_str(), ccuChannelPara.channelNum, ccuChannelPara.jettyNum,
     432              :         ccuChannelPara.sqSize);
     433              : 
     434            0 :     uint32_t devPhyId{0};
     435            0 :     CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<uint32_t>(deviceLogicId), devPhyId));
     436              : 
     437            0 :     DevEidInfo eidInfo{};
     438            0 :     CHK_RET(EidInfoMgr::GetInstance(devPhyId).GetEidInfoByAddr(ccuChannelPara.commAddr, eidInfo));
     439            0 :     const uint8_t dieId = static_cast<uint8_t>(eidInfo.dieId);
     440            0 :     const uint32_t feId = eidInfo.funcId;
     441            0 :     ChannelPara para{};
     442            0 :     para.feId = feId;
     443            0 :     para.jettyNum = ccuChannelPara.jettyNum;
     444            0 :     para.sqSize = ccuChannelPara.sqSize;
     445              : 
     446              :     HcclResult ret;
     447              :     EXCEPTION_HANDLE_BEGIN
     448            0 :     ret = CheckCcuOpenSourceEnable() ?
     449            0 :               CcuComponent::GetInstance(deviceLogicId).AllocChannels(dieId, para, ccuChannelInfos) :
     450            0 :               Hccl::CcuComponent::GetInstance(deviceLogicId).AllocChannels(dieId, para, ccuChannelInfos);
     451            0 :     EXCEPTION_HANDLE_END
     452            0 :     return ret;
     453            0 : }
     454              : 
     455            0 : HcclResult CcuReleaseChannel(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t ccuChannelId)
     456              : {
     457            0 :     HCCL_INFO(
     458              :         "[%s] new release request: deviceLogicId[%d], dieId[%u], "
     459              :         "ccuChannelId[%u].",
     460              :         __func__, deviceLogicId, dieId, ccuChannelId);
     461              : 
     462              :     HcclResult ret;
     463              :     EXCEPTION_HANDLE_BEGIN
     464            0 :     ret = CheckCcuOpenSourceEnable() ?
     465            0 :               CcuComponent::GetInstance(deviceLogicId).ReleaseChannel(dieId, ccuChannelId) :
     466            0 :               Hccl::CcuComponent::GetInstance(deviceLogicId).ReleaseChannel(dieId, ccuChannelId);
     467            0 :     EXCEPTION_HANDLE_END
     468            0 :     return ret;
     469              : }
     470              : 
     471              : // 以下为hcomm基础通信内部CCU流程使用的接口
     472            0 : HcclResult CcuDevMgrImp::GetCcuVersion(const int32_t deviceLogicId, CcuVersion& ccuVersion)
     473              : {
     474              :     EXCEPTION_HANDLE_BEGIN
     475            0 :     ccuVersion = CheckCcuOpenSourceEnable() ? CcuResSpecifications::GetInstance(deviceLogicId).GetCcuVersion() :
     476            0 :                                               Hccl::CcuResSpecifications::GetInstance(deviceLogicId).GetCcuVersion();
     477            0 :     EXCEPTION_HANDLE_END
     478            0 :     return HcclResult::HCCL_SUCCESS;
     479              : }
     480              : 
     481            0 : HcclResult CcuDevMgrImp::GetCcuResourceSpaceBufInfo(
     482              :     const int32_t deviceLogicId, const uint8_t dieId, uint64_t& addr, uint64_t& size)
     483              : {
     484              :     HcclResult ret;
     485              :     EXCEPTION_HANDLE_BEGIN
     486            0 :     ret = CheckCcuOpenSourceEnable() ?
     487            0 :               CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceBufInfo(dieId, addr, size) :
     488            0 :               Hccl::CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceBufInfo(dieId, addr, size);
     489            0 :     EXCEPTION_HANDLE_END
     490            0 :     return ret;
     491              : }
     492              : 
     493            0 : HcclResult CcuDevMgrImp::GetCcuResourceSpaceTokenInfo(
     494              :     const int32_t deviceLogicId, const uint8_t dieId, uint64_t& tokenId, uint64_t& tokenValue)
     495              : {
     496              :     HcclResult ret;
     497              :     EXCEPTION_HANDLE_BEGIN
     498            0 :     ret = CheckCcuOpenSourceEnable() ?
     499            0 :               CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceTokenInfo(dieId, tokenId, tokenValue) :
     500            0 :               Hccl::CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceTokenInfo(dieId, tokenId, tokenValue);
     501            0 :     EXCEPTION_HANDLE_END
     502            0 :     return ret;
     503              : }
     504              : 
     505            0 : HcclResult CcuDevMgrImp::ConfigChannel(const int32_t deviceLogicId, const uint8_t dieId, ChannelCfg& cfg)
     506              : {
     507              :     HcclResult ret;
     508              :     EXCEPTION_HANDLE_BEGIN
     509            0 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).ConfigChannel(dieId, cfg) :
     510            0 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).ConfigChannel(dieId, cfg);
     511            0 :     EXCEPTION_HANDLE_END
     512            0 :     return ret;
     513              : }
     514              : 
     515            0 : HcclResult CcuDevMgrImp::GetLoopChannelId(
     516              :     const int32_t deviceLogicId, const uint8_t srcDieId, const uint8_t dstDieId, uint32_t& channIdx)
     517              : {
     518              :     HcclResult ret;
     519              :     EXCEPTION_HANDLE_BEGIN
     520            0 :     ret = CheckCcuOpenSourceEnable() ?
     521            0 :               CcuComponent::GetInstance(deviceLogicId).GetLoopChannelId(srcDieId, dstDieId, channIdx) :
     522            0 :               Hccl::CcuComponent::GetInstance(deviceLogicId).GetLoopChannelId(srcDieId, dstDieId, channIdx);
     523            0 :     EXCEPTION_HANDLE_END
     524            0 :     return ret;
     525              : }
     526              : 
     527              : HcclResult
     528            0 : CcuDevMgrImp::GetResource(const int32_t deviceLogicId, const CcuResHandle handle, CcuResRepository& ccuResRepo)
     529              : {
     530              :     HcclResult ret;
     531              :     EXCEPTION_HANDLE_BEGIN
     532            0 :     ret = CheckCcuOpenSourceEnable() ?
     533            0 :               CcuResBatchAllocator::GetInstance(deviceLogicId).GetResource(handle, ccuResRepo) :
     534            0 :               Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId).GetResource(handle, ccuResRepo);
     535            0 :     EXCEPTION_HANDLE_END
     536            0 :     return ret;
     537              : }
     538              : 
     539            0 : HcclResult CcuDevMgrImp::AllocResHandle(const int32_t deviceLogicId, const CcuResReq resReq, CcuResHandle& handle)
     540              : {
     541              :     HcclResult ret;
     542              :     EXCEPTION_HANDLE_BEGIN
     543            0 :     ret = CheckCcuOpenSourceEnable() ?
     544            0 :               CcuResBatchAllocator::GetInstance(deviceLogicId).AllocResHandle(resReq, handle) :
     545            0 :               Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId).AllocResHandle(resReq, handle);
     546            0 :     EXCEPTION_HANDLE_END
     547            0 :     return ret;
     548              : }
     549              : 
     550            0 : HcclResult CcuDevMgrImp::ReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle handle)
     551              : {
     552              :     HcclResult ret;
     553              :     EXCEPTION_HANDLE_BEGIN
     554            0 :     ret = CheckCcuOpenSourceEnable() ? CcuResBatchAllocator::GetInstance(deviceLogicId).ReleaseResHandle(handle) :
     555            0 :                                        Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId).ReleaseResHandle(handle);
     556            0 :     EXCEPTION_HANDLE_END
     557            0 :     return ret;
     558              : }
     559              : 
     560            0 : HcclResult CcuDevMgrImp::QueryRemainRes(
     561              :     const int32_t deviceLogicId, const uint8_t dieId, const ResType& internalType, uint32_t& remainNum)
     562              : {
     563              :     HcclResult ret;
     564              :     EXCEPTION_HANDLE_BEGIN
     565            0 :     ret = CheckCcuOpenSourceEnable() ?
     566            0 :               CcuResBatchAllocator::GetInstance(deviceLogicId).QueryRemainRes(dieId, internalType, remainNum) :
     567            0 :               Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId).QueryRemainRes(dieId, internalType, remainNum);
     568            0 :     EXCEPTION_HANDLE_END
     569            0 :     return ret;
     570              : }
     571              : 
     572              : HcclResult
     573            0 : CcuDevMgrImp::AllocIns(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, ResInfo& insInfo)
     574              : {
     575              :     HcclResult ret;
     576              :     EXCEPTION_HANDLE_BEGIN
     577            0 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).AllocIns(dieId, num, insInfo) :
     578            0 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).AllocIns(dieId, num, insInfo);
     579            0 :     EXCEPTION_HANDLE_END
     580            0 :     return ret;
     581              : }
     582              : 
     583            0 : HcclResult CcuDevMgrImp::ReleaseIns(const int32_t deviceLogicId, const uint8_t dieId, const ResInfo& insInfo)
     584              : {
     585              :     HcclResult ret;
     586              :     EXCEPTION_HANDLE_BEGIN
     587            0 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).ReleaseIns(dieId, insInfo) :
     588            0 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).ReleaseIns(dieId, insInfo);
     589            0 :     EXCEPTION_HANDLE_END
     590            0 :     return ret;
     591              : }
     592              : 
     593            3 : uint32_t CcuDevMgrImp::GetInsConsecutiveRemainSize(const int32_t deviceLogicId, const uint8_t dieId)
     594              : {
     595            3 :     return CheckCcuOpenSourceEnable() ?
     596            0 :                CcuComponent::GetInstance(deviceLogicId).GetInsConsecutiveRemainSize(dieId) :
     597            3 :                Hccl::CcuComponent::GetInstance(deviceLogicId).GetInsConsecutiveRemainSize(dieId);
     598              : }
     599              : 
     600            0 : HcclResult CcuDevMgrImp::AllocCke(
     601              :     const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, std::vector<ResInfo>& ckeInfos)
     602              : {
     603              :     HcclResult ret;
     604              :     EXCEPTION_HANDLE_BEGIN
     605            0 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).AllocCke(dieId, num, ckeInfos) :
     606            0 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).AllocCke(dieId, num, ckeInfos);
     607            0 :     EXCEPTION_HANDLE_END
     608            0 :     return ret;
     609              : }
     610              : 
     611              : HcclResult
     612            0 : CcuDevMgrImp::ReleaseCke(const int32_t deviceLogicId, const uint8_t dieId, const std::vector<ResInfo>& ckeInfos)
     613              : {
     614              :     HcclResult ret;
     615              :     EXCEPTION_HANDLE_BEGIN
     616            0 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).ReleaseCke(dieId, ckeInfos) :
     617            0 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).ReleaseCke(dieId, ckeInfos);
     618            0 :     EXCEPTION_HANDLE_END
     619            0 :     return ret;
     620              : }
     621              : 
     622            0 : HcclResult CcuDevMgrImp::AllocXn(
     623              :     const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, std::vector<ResInfo>& xnInfos)
     624              : {
     625              :     HcclResult ret;
     626              :     EXCEPTION_HANDLE_BEGIN
     627            0 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).AllocXn(dieId, num, xnInfos) :
     628            0 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).AllocXn(dieId, num, xnInfos);
     629            0 :     EXCEPTION_HANDLE_END
     630            0 :     return ret;
     631              : }
     632              : 
     633              : HcclResult
     634            0 : CcuDevMgrImp::ReleaseXn(const int32_t deviceLogicId, const uint8_t dieId, const std::vector<ResInfo>& xnInfos)
     635              : {
     636              :     HcclResult ret;
     637              :     EXCEPTION_HANDLE_BEGIN
     638            0 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).ReleaseXn(dieId, xnInfos) :
     639            0 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).ReleaseXn(dieId, xnInfos);
     640            0 :     EXCEPTION_HANDLE_END
     641            0 :     return ret;
     642              : }
     643              : 
     644            0 : HcclResult CcuDevMgrImp::AllocWishCntXn(
     645              :     const int32_t deviceLogicId, const uint8_t dieId, const std::string& resGroupTag, uint32_t& wishCntXn)
     646              : {
     647            0 :     if (!CheckCcuOpenSourceEnable()) {
     648            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     649            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     650              :     }
     651              : 
     652            0 :     HCCL_INFO(
     653              :         "[%s] new alloc count xn request: deviceLogicId[%d], dieId[%u], resGroupTag[%s].", __func__, deviceLogicId,
     654              :         dieId, resGroupTag.c_str());
     655            0 :     return CcuComponent::GetInstance(deviceLogicId).AllocWishCntXn(dieId, resGroupTag, wishCntXn);
     656              : }
     657              : 
     658            0 : HcclResult CcuDevMgrImp::ReleaseWishCntXn(
     659              :     const int32_t deviceLogicId, const uint8_t dieId, const std::string& resGroupTag, uint32_t wishCntXn)
     660              : {
     661            0 :     if (!CheckCcuOpenSourceEnable()) {
     662            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     663            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     664              :     }
     665              : 
     666            0 :     HCCL_INFO(
     667              :         "[%s] new release count xn request: deviceLogicId[%d], dieId[%u], resGroupTag[%s], wishCntXn[%u].", __func__,
     668              :         deviceLogicId, dieId, resGroupTag.c_str(), wishCntXn);
     669            0 :     return CcuComponent::GetInstance(deviceLogicId).ReleaseWishCntXn(dieId, resGroupTag, wishCntXn);
     670              : }
     671              : 
     672            0 : HcclResult CcuDevMgrImp::GetCntXnBlock(
     673              :     const int32_t deviceLogicId, const uint8_t dieId, const std::string& resGroupTag,
     674              :     std::pair<uint32_t, uint32_t>& cntXnPair)
     675              : {
     676            0 :     if (!CheckCcuOpenSourceEnable()) {
     677            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     678            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     679              :     }
     680              : 
     681            0 :     HCCL_INFO(
     682              :         "[%s] get count xn request: deviceLogicId[%d], dieId[%u], resGroupTag[%s].", __func__, deviceLogicId, dieId,
     683              :         resGroupTag.c_str());
     684            0 :     return CcuComponent::GetInstance(deviceLogicId).GetCntXnBlock(dieId, resGroupTag, cntXnPair);
     685              : }
     686              : 
     687            0 : HcclResult CcuDevMgrImp::GetTotalCntXn(
     688              :     const int32_t deviceLogicId, const uint8_t dieId, const std::string& resGroupTag, uint32_t& totalCntXn)
     689              : {
     690            0 :     if (!CheckCcuOpenSourceEnable()) {
     691            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     692            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     693              :     }
     694              : 
     695            0 :     HCCL_INFO(
     696              :         "[%s] get count xn request: deviceLogicId[%d], dieId[%u], resGroupTag[%s].", __func__, deviceLogicId, dieId,
     697              :         resGroupTag.c_str());
     698            0 :     return CcuComponent::GetInstance(deviceLogicId).GetTotalCntXn(dieId, resGroupTag, totalCntXn);
     699              : }
     700              : 
     701            0 : HcclResult CcuDevMgrImp::GetMissionKey(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& missionKey)
     702              : {
     703              :     HcclResult ret;
     704              :     EXCEPTION_HANDLE_BEGIN
     705            0 :     ret = CheckCcuOpenSourceEnable() ?
     706            0 :               CcuResSpecifications::GetInstance(deviceLogicId).GetMissionKey(dieId, missionKey) :
     707            0 :               Hccl::CcuResSpecifications::GetInstance(deviceLogicId).GetMissionKey(dieId, missionKey);
     708            0 :     EXCEPTION_HANDLE_END
     709            0 :     return ret;
     710              : }
     711              : 
     712            0 : HcclResult CcuDevMgrImp::GetResSpecsInstructionNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& instrNum)
     713              : {
     714              :     HcclResult ret;
     715              :     EXCEPTION_HANDLE_BEGIN
     716            0 :     ret = CheckCcuOpenSourceEnable() ?
     717            0 :               CcuResSpecifications::GetInstance(deviceLogicId).GetInstructionNum(dieId, instrNum) :
     718            0 :               Hccl::CcuResSpecifications::GetInstance(deviceLogicId).GetInstructionNum(dieId, instrNum);
     719            0 :     EXCEPTION_HANDLE_END
     720            0 :     return ret;
     721              : }
     722              : 
     723              : HcclResult
     724            0 : CcuDevMgrImp::GetAllocatableMaxLoopEngineNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& loopNum)
     725              : {
     726              :     HcclResult ret;
     727              :     EXCEPTION_HANDLE_BEGIN
     728            0 :     ret = CheckCcuOpenSourceEnable() ? CcuResBatchAllocator::GetInstance(deviceLogicId)
     729            0 :                                            .GetAllocatableMaxBlockResNum(ResType::LOOP, dieId, loopNum) :
     730            0 :                                        Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId)
     731            0 :                                            .GetAllocatableMaxBlockResNum(ResType::LOOP, dieId, loopNum);
     732            0 :     EXCEPTION_HANDLE_END
     733            0 :     return ret;
     734              : }
     735              : 
     736            0 : HcclResult CcuDevMgrImp::GetAllocatableMaxMsNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& msNum)
     737              : {
     738              :     HcclResult ret;
     739              :     EXCEPTION_HANDLE_BEGIN
     740            0 :     ret = CheckCcuOpenSourceEnable() ?
     741            0 :               CcuResBatchAllocator::GetInstance(deviceLogicId).GetAllocatableMaxBlockResNum(ResType::MS, dieId, msNum) :
     742            0 :               Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId)
     743            0 :                   .GetAllocatableMaxBlockResNum(ResType::MS, dieId, msNum);
     744            0 :     EXCEPTION_HANDLE_END
     745            0 :     return ret;
     746              : }
     747              : 
     748            0 : HcclResult CcuDevMgrImp::GetAllocatableMaxCkeNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& ckeNum)
     749              : {
     750              :     HcclResult ret;
     751              :     EXCEPTION_HANDLE_BEGIN
     752            0 :     ret = CheckCcuOpenSourceEnable() ? CcuResBatchAllocator::GetInstance(deviceLogicId)
     753            0 :                                            .GetAllocatableMaxBlockResNum(ResType::CKE, dieId, ckeNum) :
     754            0 :                                        Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId)
     755            0 :                                            .GetAllocatableMaxBlockResNum(ResType::CKE, dieId, ckeNum);
     756            0 :     EXCEPTION_HANDLE_END
     757            0 :     return ret;
     758              : }
     759              : 
     760            0 : HcclResult CcuDevMgrImp::GetAllocatableMaxXnNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& xnNum)
     761              : {
     762              :     HcclResult ret;
     763              :     EXCEPTION_HANDLE_BEGIN
     764            0 :     ret = CheckCcuOpenSourceEnable() ?
     765            0 :               CcuResBatchAllocator::GetInstance(deviceLogicId).GetAllocatableMaxBlockResNum(ResType::XN, dieId, xnNum) :
     766            0 :               Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId)
     767            0 :                   .GetAllocatableMaxBlockResNum(ResType::XN, dieId, xnNum);
     768            0 :     EXCEPTION_HANDLE_END
     769            0 :     return ret;
     770              : }
     771              : 
     772            0 : HcclResult CcuDevMgrImp::GetAllocatableMaxGsaNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& gsaNum)
     773              : {
     774              :     HcclResult ret;
     775              :     EXCEPTION_HANDLE_BEGIN
     776            0 :     ret = CheckCcuOpenSourceEnable() ? CcuResBatchAllocator::GetInstance(deviceLogicId)
     777            0 :                                            .GetAllocatableMaxBlockResNum(ResType::GSA, dieId, gsaNum) :
     778            0 :                                        Hccl::CcuResBatchAllocator::GetInstance(deviceLogicId)
     779            0 :                                            .GetAllocatableMaxBlockResNum(ResType::GSA, dieId, gsaNum);
     780            0 :     EXCEPTION_HANDLE_END
     781            0 :     return ret;
     782              : }
     783              : 
     784            0 : HcclResult CcuDevMgrImp::GetResSpecsMissionNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& missionNum)
     785              : {
     786              :     HcclResult ret;
     787              :     EXCEPTION_HANDLE_BEGIN
     788            0 :     ret = CheckCcuOpenSourceEnable() ?
     789            0 :               CcuResSpecifications::GetInstance(deviceLogicId).GetMissionNum(dieId, missionNum) :
     790            0 :               Hccl::CcuResSpecifications::GetInstance(deviceLogicId).GetMissionNum(dieId, missionNum);
     791            0 :     EXCEPTION_HANDLE_END
     792            0 :     return ret;
     793              : }
     794              : 
     795            0 : HcclResult CcuDevMgrImp::GetXnBaseAddr(const int32_t devLogicId, const uint8_t dieId, uint64_t& xnBaseAddr)
     796              : {
     797              :     HcclResult ret;
     798              :     EXCEPTION_HANDLE_BEGIN
     799            0 :     ret = CheckCcuOpenSourceEnable() ?
     800            0 :               CcuResSpecifications::GetInstance(devLogicId).GetXnBaseAddr(dieId, xnBaseAddr) :
     801            0 :               Hccl::CcuResSpecifications::GetInstance(devLogicId).GetXnBaseAddr(dieId, xnBaseAddr);
     802            0 :     EXCEPTION_HANDLE_END
     803            0 :     return ret;
     804              : }
     805            0 : HcclResult CcuDevMgrImp::GetCkeBaseAddr(const int32_t devLogicId, const uint8_t dieId, uint64_t& ckeBaseAddr)
     806              : {
     807            0 :     if (!CheckCcuOpenSourceEnable()) {
     808            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     809            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     810              :     }
     811              : 
     812            0 :     return CcuResSpecifications::GetInstance(devLogicId).GetCkeBaseAddr(dieId, ckeBaseAddr);
     813              : }
     814              : 
     815              : HcclResult
     816            0 : CcuDevMgrImp::GetXnOffsetCcumAddrById(const int32_t devLogicId, const uint8_t dieId, uint16_t id, uint64_t& xnAddr)
     817              : {
     818            0 :     if (!CheckCcuOpenSourceEnable()) {
     819            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     820            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     821              :     }
     822              : 
     823            0 :     return CcuResSpecifications::GetInstance(devLogicId).GetXnOffsetCcumAddrById(dieId, id, xnAddr);
     824              : }
     825              : 
     826              : HcclResult
     827            0 : CcuDevMgrImp::GetCkeOffsetCcumAddrById(const int32_t devLogicId, const uint8_t dieId, uint16_t id, uint64_t& ckeAddr)
     828              : {
     829            0 :     if (!CheckCcuOpenSourceEnable()) {
     830            0 :         HCCL_WARNING("[CcuDevMgrImp][%s] is not supported for legacy interface.", __func__);
     831            0 :         return HcclResult::HCCL_E_NOT_SUPPORT;
     832              :     }
     833              : 
     834            0 :     return CcuResSpecifications::GetInstance(devLogicId).GetCkeOffsetCcumAddrById(dieId, id, ckeAddr);
     835              : }
     836              : 
     837         2786 : HcclResult CheckDieValid(
     838              :     const char* funcName, const int32_t devLogicId, const uint8_t dieId,
     839              :     const std::array<bool, CCU_MAX_IODIE_NUM>& dieEnableFlags)
     840              : {
     841         2786 :     CHK_PRT_RET(
     842              :         dieId >= CCU_MAX_IODIE_NUM,
     843              :         HCCL_ERROR(
     844              :             "[%s] failed, dieId[%u] is invalid, should be in [0-%u), devLogicId[%d].", funcName, dieId,
     845              :             CCU_MAX_IODIE_NUM, devLogicId),
     846              :         HcclResult::HCCL_E_PARA);
     847              : 
     848         2786 :     CHK_PRT_RET(
     849              :         !dieEnableFlags[dieId],
     850              :         HCCL_ERROR("[%s] failed, dieId[%u] is disable, devLogicId[%d].", funcName, dieId, devLogicId),
     851              :         HcclResult::HCCL_E_PARA);
     852              : 
     853         2786 :     return HcclResult::HCCL_SUCCESS;
     854              : }
     855              : 
     856            0 : bool CcuIsInited(const int32_t deviceLogicId)
     857              : {
     858            0 :     HCCL_INFO("[CcuIsInited] Input params: deviceLogicId[%d]", deviceLogicId);
     859            0 :     CHK_PRT_RET(
     860              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     861              :         HCCL_ERROR(
     862              :             "[CcuIsInited]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
     863              :         false);
     864              : 
     865            0 :     if (!CheckCcuOpenSourceEnable()) {
     866            0 :         return Hccl::CcuComponent::GetInstance(deviceLogicId).IsInited();
     867              :     }
     868              : 
     869            0 :     std::lock_guard<std::mutex> lock(ccuDrvHandleMutex);
     870              :     // ccu驱动已重复拉起失败时,直接返回,在锁保护内返回
     871            0 :     if (ccuDriverInitAgainFlag) {
     872            0 :         return false;
     873              :     }
     874              : 
     875            0 :     auto iter = ccuDrvHandleMap.find(deviceLogicId);
     876            0 :     if (iter == ccuDrvHandleMap.end()) {
     877            0 :         return false;
     878              :     }
     879              : 
     880            0 :     return true;
     881            0 : }
     882              : 
     883            4 : HcclResult CcuSetTaskKill(const int32_t deviceLogicId)
     884              : {
     885            4 :     HCCL_INFO("[CcuSetTaskKill] Input params: deviceLogicId[%d]", deviceLogicId);
     886              :     // 入参校验拦截
     887            4 :     CHK_PRT_RET(
     888              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     889              :         HCCL_ERROR(
     890              :             "[CcuSetTaskKill]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
     891              :         HcclResult::HCCL_E_PARA);
     892              :     HcclResult ret;
     893              :     EXCEPTION_HANDLE_BEGIN
     894            2 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).SetTaskKill() :
     895            2 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).SetTaskKill();
     896            0 :     EXCEPTION_HANDLE_END
     897            2 :     return ret;
     898              : }
     899              : 
     900            4 : HcclResult CcuSetTaskKillDone(const int32_t deviceLogicId)
     901              : {
     902            4 :     HCCL_INFO("[CcuSetTaskKillDone] Input params: deviceLogicId[%d]", deviceLogicId);
     903              :     // 入参校验拦截
     904            4 :     CHK_PRT_RET(
     905              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     906              :         HCCL_ERROR(
     907              :             "[CcuSetTaskKillDone]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     908              :             MAX_MODULE_DEVICE_NUM),
     909              :         HcclResult::HCCL_E_PARA);
     910              :     HcclResult ret;
     911              :     EXCEPTION_HANDLE_BEGIN
     912            2 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).SetTaskKillDone() :
     913            2 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).SetTaskKillDone();
     914            0 :     EXCEPTION_HANDLE_END
     915            2 :     return ret;
     916              : }
     917              : 
     918            4 : HcclResult CcuCleanTaskKillState(const int32_t deviceLogicId)
     919              : {
     920            4 :     HCCL_INFO("[CcuCleanTaskKillState] Input params: deviceLogicId[%d]", deviceLogicId);
     921              :     // 入参校验拦截
     922            4 :     CHK_PRT_RET(
     923              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     924              :         HCCL_ERROR(
     925              :             "[CcuCleanTaskKillState]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     926              :             MAX_MODULE_DEVICE_NUM),
     927              :         HcclResult::HCCL_E_PARA);
     928              :     HcclResult ret;
     929              :     EXCEPTION_HANDLE_BEGIN
     930            2 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).CleanTaskKillState() :
     931            2 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).CleanTaskKillState();
     932            0 :     EXCEPTION_HANDLE_END
     933            2 :     return ret;
     934              : }
     935              : 
     936            4 : HcclResult CcuCleanDieCkes(const int32_t deviceLogicId, const uint8_t dieId)
     937              : {
     938            4 :     HCCL_INFO("[CcuCleanDieCkes] Input params: deviceLogicId[%d], dieId[%u]", deviceLogicId, dieId);
     939              :     // 入参校验拦截
     940            4 :     CHK_PRT_RET(
     941              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     942              :         HCCL_ERROR(
     943              :             "[CcuCleanDieCkes]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     944              :             MAX_MODULE_DEVICE_NUM),
     945              :         HcclResult::HCCL_E_PARA);
     946              :     HcclResult ret;
     947              :     EXCEPTION_HANDLE_BEGIN
     948            2 :     ret = CheckCcuOpenSourceEnable() ? CcuComponent::GetInstance(deviceLogicId).CleanDieCkes(dieId) :
     949            2 :                                        Hccl::CcuComponent::GetInstance(deviceLogicId).CleanDieCkes(dieId);
     950            0 :     EXCEPTION_HANDLE_END
     951            2 :     return ret;
     952              : }
     953              : 
     954              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1