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: 21.9 % 73 16
Test Date: 2026-08-18 17:47:01 Functions: 9.6 % 52 5

            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, MAX_MODULE_DEVICE_NUM),
      97              :         HcclResult::HCCL_E_PARA);
      98            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).SetTaskKill(););
      99              : }
     100              : 
     101            0 : HcclResult CcuSetTaskKillDone(const int32_t deviceLogicId)
     102              : {
     103            0 :     HCCL_INFO("[CcuSetTaskKillDone] Input params: deviceLogicId[%d]", deviceLogicId);
     104              :     // 入参校验拦截
     105            0 :     CHK_PRT_RET(
     106              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     107              :         HCCL_ERROR(
     108              :             "[CcuSetTaskKillDone]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     109              :             MAX_MODULE_DEVICE_NUM),
     110              :         HcclResult::HCCL_E_PARA);
     111            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).SetTaskKillDone(););
     112              : }
     113              : 
     114            0 : HcclResult CcuCleanTaskKillState(const int32_t deviceLogicId)
     115              : {
     116            0 :     HCCL_INFO("[CcuCleanTaskKillState] Input params: deviceLogicId[%d]", deviceLogicId);
     117              :     // 入参校验拦截
     118            0 :     CHK_PRT_RET(
     119              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     120              :         HCCL_ERROR(
     121              :             "[CcuCleanTaskKillState]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     122              :             MAX_MODULE_DEVICE_NUM),
     123              :         HcclResult::HCCL_E_PARA);
     124            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).CleanTaskKillState(););
     125              : }
     126              : 
     127            0 : HcclResult CcuCleanDieCkes(const int32_t deviceLogicId, const uint8_t dieId)
     128              : {
     129            0 :     HCCL_INFO("[CcuCleanDieCkes] Input params: deviceLogicId[%d], dieId[%u]", deviceLogicId, dieId);
     130              :     // 入参校验拦截
     131            0 :     CHK_PRT_RET(
     132              :         (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
     133              :         HCCL_ERROR(
     134              :             "[CcuCleanDieCkes]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
     135              :             MAX_MODULE_DEVICE_NUM),
     136              :         HcclResult::HCCL_E_PARA);
     137            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).CleanDieCkes(dieId););
     138              : }
     139              : 
     140            0 : HcclResult CcuDeviceManager::GetCcuVersion(const int32_t deviceLogicId, CcuVersion& ccuVersion)
     141              : {
     142            0 :     TRY_CATCH_RETURN(ccuVersion = CcuResSpecifications::GetInstance(deviceLogicId).GetCcuVersion(););
     143              : 
     144            0 :     return HcclResult::HCCL_SUCCESS;
     145              : }
     146              : 
     147            0 : HcclResult CcuDeviceManager::GetCcuResourceSpaceBufInfo(
     148              :     const int32_t deviceLogicId, const uint8_t dieId, uint64_t& addr, uint64_t& size)
     149              : {
     150            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceBufInfo(dieId, addr, size););
     151              : }
     152              : 
     153            0 : HcclResult CcuDeviceManager::GetCcuResourceSpaceTokenInfo(
     154              :     const int32_t deviceLogicId, const uint8_t dieId, uint64_t& tokenId, uint64_t& tokenValue)
     155              : {
     156            0 :     TRY_CATCH_RETURN(
     157              :         return CcuComponent::GetInstance(deviceLogicId).GetCcuResourceSpaceTokenInfo(dieId, tokenId, tokenValue););
     158              : }
     159              : 
     160            0 : HcclResult CcuDeviceManager::GetCcuResourceSpaceTokenInfoForLocal(
     161              :     const int32_t deviceLogicId, const uint8_t dieId, uint64_t& tokenId, uint64_t& tokenValue)
     162              : {
     163            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId)
     164              :                          .GetCcuResourceSpaceTokenInfoForLocal(dieId, tokenId, tokenValue););
     165              : }
     166              : 
     167            0 : HcclResult CcuDeviceManager::ConfigChannel(const int32_t deviceLogicId, const uint8_t dieId, ChannelCfg& cfg)
     168              : {
     169            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).ConfigChannel(dieId, cfg););
     170              : }
     171              : 
     172            0 : HcclResult CcuDeviceManager::GetLoopChannelId(
     173              :     const int32_t deviceLogicId, const uint8_t srcDieId, const uint8_t dstDieId, uint32_t& channIdx)
     174              : {
     175            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).GetLoopChannelId(srcDieId, dstDieId, channIdx););
     176              : }
     177              : 
     178              : HcclResult
     179            0 : CcuDeviceManager::GetResource(const int32_t deviceLogicId, const CcuResHandle handle, CcuResRepository& ccuResRepo)
     180              : {
     181            0 :     TRY_CATCH_RETURN(return CcuResBatchAllocator::GetInstance(deviceLogicId).GetResource(handle, ccuResRepo););
     182              : }
     183              : 
     184            0 : HcclResult CcuDeviceManager::AllocResHandle(const int32_t deviceLogicId, const CcuResReq resReq, CcuResHandle& handle)
     185              : {
     186            0 :     TRY_CATCH_RETURN(return CcuResBatchAllocator::GetInstance(deviceLogicId).AllocResHandle(resReq, handle););
     187              : }
     188              : 
     189            0 : HcclResult CcuDeviceManager::ReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle handle)
     190              : {
     191            0 :     TRY_CATCH_RETURN(return CcuResBatchAllocator::GetInstance(deviceLogicId).ReleaseResHandle(handle););
     192              : }
     193              : 
     194              : HcclResult
     195            0 : CcuDeviceManager::AllocIns(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, ResInfo& insInfo)
     196              : {
     197            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).AllocIns(dieId, num, insInfo););
     198              : }
     199              : 
     200            0 : HcclResult CcuDeviceManager::ReleaseIns(const int32_t deviceLogicId, const uint8_t dieId, ResInfo& insInfo)
     201              : {
     202            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).ReleaseIns(dieId, insInfo););
     203              : }
     204              : 
     205          176 : HcclResult CcuDeviceManager::AllocCke(
     206              :     const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, std::vector<ResInfo>& ckeInfos)
     207              : {
     208          176 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).AllocCke(dieId, num, ckeInfos););
     209              : }
     210              : 
     211              : HcclResult
     212           22 : CcuDeviceManager::ReleaseCke(const int32_t deviceLogicId, const uint8_t dieId, std::vector<ResInfo>& ckeInfos)
     213              : {
     214           22 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).ReleaseCke(dieId, ckeInfos););
     215              : }
     216              : 
     217            0 : HcclResult CcuDeviceManager::AllocXn(
     218              :     const int32_t deviceLogicId, const uint8_t dieId, const uint32_t num, vector<ResInfo>& xnInfos)
     219              : {
     220            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).AllocXn(dieId, num, xnInfos););
     221              : }
     222              : 
     223            0 : HcclResult CcuDeviceManager::ReleaseXn(const int32_t deviceLogicId, const uint8_t dieId, vector<ResInfo>& xnInfos)
     224              : {
     225            0 :     TRY_CATCH_RETURN(return CcuComponent::GetInstance(deviceLogicId).ReleaseXn(dieId, xnInfos););
     226              : }
     227              : 
     228            0 : HcclResult CcuDeviceManager::GetMissionKey(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& missionKey)
     229              : {
     230            0 :     TRY_CATCH_RETURN(return CcuResSpecifications::GetInstance(deviceLogicId).GetMissionKey(dieId, missionKey););
     231              : }
     232              : 
     233            0 : HcclResult CcuDeviceManager::GetInstructionNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& instrNum)
     234              : {
     235            0 :     TRY_CATCH_RETURN(return CcuResSpecifications::GetInstance(deviceLogicId).GetInstructionNum(dieId, instrNum););
     236              : }
     237              : 
     238            0 : HcclResult CcuDeviceManager::GetXnBaseAddr(const uint32_t devLogicId, const uint8_t dieId, uint64_t& xnBaseAddr)
     239              : {
     240            0 :     TRY_CATCH_RETURN(return CcuResSpecifications::GetInstance(devLogicId).GetXnBaseAddr(dieId, xnBaseAddr););
     241              : }
     242              : 
     243          764 : HcclResult CheckDieValid(
     244              :     const char* funcName, const int32_t devLogicId, const uint8_t dieId,
     245              :     const std::array<bool, MAX_CCU_IODIE_NUM>& dieEnableFlags)
     246              : {
     247          785 :     CHK_PRT_RET(
     248              :         dieId >= MAX_CCU_IODIE_NUM,
     249              :         HCCL_ERROR(
     250              :             "[%s] failed, dieId[%u] is invalid, shoudle be in [0-%u), devLogicId[%d].", funcName, dieId,
     251              :             MAX_CCU_IODIE_NUM, devLogicId),
     252              :         HcclResult::HCCL_E_PARA);
     253              : 
     254         1357 :     CHK_PRT_RET(
     255              :         !dieEnableFlags[dieId],
     256              :         HCCL_WARNING("[%s] failed, dieId[%u] is disable, devLogicId[%d].", funcName, dieId, devLogicId),
     257              :         HcclResult::HCCL_E_PARA);
     258              : 
     259          557 :     return HcclResult::HCCL_SUCCESS;
     260              : }
     261              : 
     262              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1