LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_device - ccu_device_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 27.4 % 73 20
Test Date: 2026-08-29 17:38:31 Functions: 11.5 % 52 6

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "ccu_device_manager.h"
      12              : 
      13              : #include "hccl_common_v2.h"
      14              : #include "rdma_handle_manager.h"
      15              : 
      16              : #include "ccu_component.h"
      17              : #include "ccu_res_specs_legacy.h"
      18              : #include "ccu_res_batch_allocator_legacy.h"
      19              : 
      20              : namespace Hccl {
      21              : 
      22            1 : HcclResult CcuAllocChannels(
      23              :     const int32_t deviceLogicId, const CcuChannelPara& ccuChannelPara, std::vector<CcuChannelInfo>& ccuChannelInfos)
      24              : {
      25            3 :     HCCL_INFO(
      26              :         "[%s] new allocation request: deviceLogicId[%d], ipAddr[%s], "
      27              :         "channelnum[%u], jettyNum[%u], sqSize[%u].",
      28              :         __func__, deviceLogicId, ccuChannelPara.ipAddr.Describe().c_str(), ccuChannelPara.channelNum,
      29              :         ccuChannelPara.jettyNum, ccuChannelPara.sqSize);
      30              :     // 入参校验拦截
      31            1 :     CHK_PRT_RET(
      32              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
      33              :         HCCL_ERROR(
      34              :             "[CcuAllocChannels]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
      35              :             MAX_MODULE_DEVICE_NUM),
      36              :         HcclResult::HCCL_E_PARA);
      37            1 :     TRY_CATCH_RETURN(
      38              :         const uint32_t devPhyId = HrtGetDevicePhyIdByIndex(deviceLogicId);
      39              :         auto& rdmaHandleMgr = RdmaHandleManager::GetInstance();
      40              :         const RdmaHandle rdmaHandle = rdmaHandleMgr.GetByIp(devPhyId, ccuChannelPara.ipAddr);
      41              :         const auto& dieIdAndFuncId = rdmaHandleMgr.GetDieAndFuncId(rdmaHandle);
      42              :         const uint8_t dieId = dieIdAndFuncId.first; ChannelPara para{}; // TRY_CATCH_RETURN 宏内不能直接在{}传参
      43              :         para.feId = dieIdAndFuncId.second; para.jettyNum = ccuChannelPara.jettyNum; para.sqSize = ccuChannelPara.sqSize;
      44              :         return CcuComponent::GetInstance(deviceLogicId).AllocChannels(dieId, para, ccuChannelInfos););
      45              : }
      46              : 
      47            0 : HcclResult CcuReleaseChannel(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t ccuChannelId)
      48              : {
      49            0 :     HCCL_INFO(
      50              :         "[%s] new release request: deviceLogicId[%d], dieId[%u], "
      51              :         "ccuChannelId[%u].",
      52              :         __func__, deviceLogicId, dieId, ccuChannelId);
      53              :     // 入参校验拦截
      54            0 :     CHK_PRT_RET(
      55              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
      56              :         HCCL_ERROR(
      57              :             "[CcuReleaseChannel]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
      58              :             MAX_MODULE_DEVICE_NUM),
      59              :         HcclResult::HCCL_E_PARA);
      60            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).ReleaseChannel(dieId, ccuChannelId););
      61              : }
      62              : 
      63            0 : HcclResult CcuGetChannelSpecNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& channelNum)
      64              : {
      65            0 :     HCCL_INFO(
      66              :         "[CcuGetChannelSpecNum] Input params: deviceLogicId[%d], dieId[%u], channelNum[%u]", deviceLogicId, dieId,
      67              :         channelNum);
      68              :     // 入参校验拦截
      69            0 :     CHK_PRT_RET(
      70              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
      71              :         HCCL_ERROR(
      72              :             "[CcuGetChannelSpecNum]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
      73              :             MAX_MODULE_DEVICE_NUM),
      74              :         HcclResult::HCCL_E_PARA);
      75            0 :     TRY_CATCH_RETURN(return CcuResSpecifications::GetInstance(deviceLogicId).GetChannelNum(dieId, channelNum););
      76              : }
      77              : 
      78            6 : bool CcuIsInited(const int32_t deviceLogicId)
      79              : {
      80           18 :     HCCL_INFO("[CcuIsInited] Input params: deviceLogicId[%d]", deviceLogicId);
      81            6 :     CHK_PRT_RET(
      82              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
      83              :         HCCL_ERROR(
      84              :             "[CcuIsInited] deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId, MAX_MODULE_DEVICE_NUM),
      85              :         false);
      86            6 :     return CcuComponent::GetInstance(deviceLogicId).IsInited();
      87              : }
      88              : 
      89            0 : HcclResult CcuSetTaskKill(const int32_t deviceLogicId)
      90              : {
      91            0 :     HCCL_INFO("[CcuSetTaskKill] Input params: deviceLogicId[%d]", deviceLogicId);
      92              :     // 入参校验拦截
      93            0 :     CHK_PRT_RET(
      94              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
      95              :         HCCL_ERROR(
      96              :             "[CcuSetTaskKill] deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
      97              :             MAX_MODULE_DEVICE_NUM),
      98              :         HcclResult::HCCL_E_PARA);
      99            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).SetTaskKill(););
     100              : }
     101              : 
     102            0 : HcclResult CcuSetTaskKillDone(const int32_t deviceLogicId)
     103              : {
     104            0 :     HCCL_INFO("[CcuSetTaskKillDone] Input params: deviceLogicId[%d]", deviceLogicId);
     105              :     // 入参校验拦截
     106            0 :     CHK_PRT_RET(
     107              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     108              :         HCCL_ERROR(
     109              :             "[CcuSetTaskKillDone] deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     110              :             MAX_MODULE_DEVICE_NUM),
     111              :         HcclResult::HCCL_E_PARA);
     112            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).SetTaskKillDone(););
     113              : }
     114              : 
     115            2 : HcclResult CcuCleanTaskKillState(const int32_t deviceLogicId)
     116              : {
     117            6 :     HCCL_INFO("[CcuCleanTaskKillState] Input params: deviceLogicId[%d]", deviceLogicId);
     118              :     // 入参校验拦截
     119            2 :     CHK_PRT_RET(
     120              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     121              :         HCCL_ERROR(
     122              :             "[CcuCleanTaskKillState] deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     123              :             MAX_MODULE_DEVICE_NUM),
     124              :         HcclResult::HCCL_E_PARA);
     125            2 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).CleanTaskKillState(););
     126              : }
     127              : 
     128            0 : HcclResult CcuCleanDieCkes(const int32_t deviceLogicId, const uint8_t dieId)
     129              : {
     130            0 :     HCCL_INFO("[CcuCleanDieCkes] Input params: deviceLogicId[%d], dieId[%u]", deviceLogicId, dieId);
     131              :     // 入参校验拦截
     132            0 :     CHK_PRT_RET(
     133              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     134              :         HCCL_ERROR(
     135              :             "[CcuCleanDieCkes] deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     136              :             MAX_MODULE_DEVICE_NUM),
     137              :         HcclResult::HCCL_E_PARA);
     138            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).CleanDieCkes(dieId););
     139              : }
     140              : 
     141            0 : HcclResult CcuDeviceManager::GetCcuVersion(const int32_t deviceLogicId, CcuVersion& ccuVersion)
     142              : {
     143            0 :     TRY_CATCH_RETURN(ccuVersion = CcuResSpecifications::GetInstance(deviceLogicId).GetCcuVersion(););
     144              : 
     145            0 :     return HcclResult::HCCL_SUCCESS;
     146              : }
     147              : 
     148            0 : HcclResult CcuDeviceManager::GetCcuResourceSpaceBufInfo(
     149              :     const int32_t deviceLogicId, const uint8_t dieId, uint64_t& addr, uint64_t& size)
     150              : {
     151            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceBufInfo(dieId, addr, size););
     152              : }
     153              : 
     154            0 : HcclResult CcuDeviceManager::GetCcuResourceSpaceTokenInfo(
     155              :     const int32_t deviceLogicId, const uint8_t dieId, uint64_t& tokenId, uint64_t& tokenValue)
     156              : {
     157            0 :     TRY_CATCH_RETURN(
     158              :         return CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceTokenInfo(dieId, tokenId, tokenValue););
     159              : }
     160              : 
     161            0 : HcclResult CcuDeviceManager::GetCcuResourceSpaceTokenInfoForLocal(
     162              :     const int32_t deviceLogicId, const uint8_t dieId, uint64_t& tokenId, uint64_t& tokenValue)
     163              : {
     164            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId)
     165              :                          .GetCcuResourceSpaceTokenInfoForLocal(dieId, tokenId, tokenValue););
     166              : }
     167              : 
     168            0 : HcclResult CcuDeviceManager::ConfigChannel(const int32_t deviceLogicId, const uint8_t dieId, ChannelCfg& cfg)
     169              : {
     170            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).ConfigChannel(dieId, cfg););
     171              : }
     172              : 
     173            0 : HcclResult CcuDeviceManager::GetLoopChannelId(
     174              :     const int32_t deviceLogicId, const uint8_t srcDieId, const uint8_t dstDieId, uint32_t& channIdx)
     175              : {
     176            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).GetLoopChannelId(srcDieId, dstDieId, channIdx););
     177              : }
     178              : 
     179              : HcclResult
     180            0 : CcuDeviceManager::GetResource(const int32_t deviceLogicId, const CcuResHandle handle, CcuResRepository& ccuResRepo)
     181              : {
     182            0 :     TRY_CATCH_RETURN(return CcuResBatchAllocator::GetInstance(deviceLogicId).GetResource(handle, ccuResRepo););
     183              : }
     184              : 
     185            0 : HcclResult CcuDeviceManager::AllocResHandle(const int32_t deviceLogicId, const CcuResReq resReq, CcuResHandle& handle)
     186              : {
     187            0 :     TRY_CATCH_RETURN(return CcuResBatchAllocator::GetInstance(deviceLogicId).AllocResHandle(resReq, handle););
     188              : }
     189              : 
     190            0 : HcclResult CcuDeviceManager::ReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle handle)
     191              : {
     192            0 :     TRY_CATCH_RETURN(return CcuResBatchAllocator::GetInstance(deviceLogicId).ReleaseResHandle(handle););
     193              : }
     194              : 
     195              : HcclResult
     196            0 : CcuDeviceManager::AllocIns(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, ResInfo& insInfo)
     197              : {
     198            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).AllocIns(dieId, num, insInfo););
     199              : }
     200              : 
     201            0 : HcclResult CcuDeviceManager::ReleaseIns(const int32_t deviceLogicId, const uint8_t dieId, ResInfo& insInfo)
     202              : {
     203            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).ReleaseIns(dieId, insInfo););
     204              : }
     205              : 
     206          176 : HcclResult CcuDeviceManager::AllocCke(
     207              :     const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, std::vector<ResInfo>& ckeInfos)
     208              : {
     209          176 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).AllocCke(dieId, num, ckeInfos););
     210              : }
     211              : 
     212              : HcclResult
     213           22 : CcuDeviceManager::ReleaseCke(const int32_t deviceLogicId, const uint8_t dieId, std::vector<ResInfo>& ckeInfos)
     214              : {
     215           22 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).ReleaseCke(dieId, ckeInfos););
     216              : }
     217              : 
     218            0 : HcclResult CcuDeviceManager::AllocXn(
     219              :     const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, vector<ResInfo>& xnInfos)
     220              : {
     221            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).AllocXn(dieId, num, xnInfos););
     222              : }
     223              : 
     224            0 : HcclResult CcuDeviceManager::ReleaseXn(const int32_t deviceLogicId, const uint8_t dieId, vector<ResInfo>& xnInfos)
     225              : {
     226            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).ReleaseXn(dieId, xnInfos););
     227              : }
     228              : 
     229            0 : HcclResult CcuDeviceManager::GetMissionKey(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& missionKey)
     230              : {
     231            0 :     TRY_CATCH_RETURN(return CcuResSpecifications::GetInstance(deviceLogicId).GetMissionKey(dieId, missionKey););
     232              : }
     233              : 
     234            0 : HcclResult CcuDeviceManager::GetInstructionNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& instrNum)
     235              : {
     236            0 :     TRY_CATCH_RETURN(return CcuResSpecifications::GetInstance(deviceLogicId).GetInstructionNum(dieId, instrNum););
     237              : }
     238              : 
     239            0 : HcclResult CcuDeviceManager::GetXnBaseAddr(const uint32_t devLogicId, const uint8_t dieId, uint64_t& xnBaseAddr)
     240              : {
     241            0 :     TRY_CATCH_RETURN(return CcuResSpecifications::GetInstance(devLogicId).GetXnBaseAddr(dieId, xnBaseAddr););
     242              : }
     243              : 
     244          764 : HcclResult CheckDieValid(
     245              :     const char* funcName, const int32_t devLogicId, const uint8_t dieId,
     246              :     const std::array<bool, MAX_CCU_IODIE_NUM>& dieEnableFlags)
     247              : {
     248          785 :     CHK_PRT_RET(
     249              :         dieId >= MAX_CCU_IODIE_NUM,
     250              :         HCCL_ERROR(
     251              :             "[%s] failed, dieId[%u] is invalid, should be in [0-%u), devLogicId[%d].", funcName, dieId,
     252              :             MAX_CCU_IODIE_NUM, devLogicId),
     253              :         HcclResult::HCCL_E_PARA);
     254              : 
     255         1357 :     CHK_PRT_RET(
     256              :         !dieEnableFlags[dieId],
     257              :         HCCL_WARNING("[%s] failed, dieId[%u] is disable, devLogicId[%d].", funcName, dieId, devLogicId),
     258              :         HcclResult::HCCL_E_PARA);
     259              : 
     260          557 :     return HcclResult::HCCL_SUCCESS;
     261              : }
     262              : 
     263              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1