LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/ccu_transport - ccu_transport_group.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 84.8 % 66 56
Test Date: 2026-07-28 12:11:00 Functions: 90.0 % 10 9

            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_transport_group.h"
      12              : #include "exception_util.h"
      13              : #include "ccu_device_manager.h"
      14              : 
      15              : namespace Hccl {
      16              : 
      17           28 : bool CcuTransportGroup::CheckTransports(const vector<CcuTransport*> &transports)
      18              : {
      19           28 :     if (transports.size() == 0) {
      20            6 :         HCCL_ERROR("[CcuTransportGroup::%s] Transports size is 0, please check.", __func__);
      21            2 :         return false;
      22              :     }
      23           78 :     HCCL_INFO("[CheckTransports] size[%llu].", transports.size());
      24              : 
      25              :     // 校验transports中所有的DieId是否相等,如果不相等,则构建失败,如果相等,则将transports传入transportsGrp中
      26          184 :     for (unsigned int i = 0; i < transports.size(); i++) {
      27          158 :         if (transports[0]->GetDieId() != transports[i]->GetDieId()) {
      28            0 :             HCCL_ERROR("[CcuTransportGroup::%s] Transports dieId is not equal, please check.", __func__);
      29            0 :             return false;
      30              :         }
      31              :     }
      32           26 :     return true;
      33              : }
      34              : 
      35           27 : HcclResult CcuTransportGroup::CheckTransportCntCke()
      36              : {
      37           27 :     HcclResult allocResHandleReturnValue = HcclResult::HCCL_SUCCESS;
      38              : 
      39           27 :     TRY_CATCH_RETURN(allocResHandleReturnValue = CcuDeviceManager::AllocCke(HrtGetDevice(), 
      40              :                     cntCkesGroupDieId, cntCkeNumTransportGroupUse, ckeInfoTransportGroupUse));
      41              : 
      42           27 :     if (allocResHandleReturnValue != HCCL_SUCCESS) {
      43           72 :         HCCL_ERROR("[CcuTransportGroup::%s] Failed to allocate cntCke resource, please check.", __func__);
      44           24 :         return HcclResult::HCCL_E_INTERNAL;
      45              :     }
      46              : 
      47            3 :     for (u32 i = 0; i < ckeInfoTransportGroupUse.size(); i++) {
      48            0 :         u32 ckeNum = ckeInfoTransportGroupUse[i].num;
      49            0 :         u32 ckesStartId = ckeInfoTransportGroupUse[i].startId;
      50            0 :         for (unsigned int j = 0; j < ckeNum; j++) {
      51            0 :             cntCkesGroup.push_back(ckesStartId + j);
      52              :         }
      53              :     }
      54              : 
      55            6 :     for (auto &transport : transportsGrp) {
      56            3 :         transport->SetCntCke(cntCkesGroup);
      57              :     }
      58            3 :     return HcclResult::HCCL_SUCCESS;
      59              : }
      60              : 
      61           45 : CcuTransportGroup::CcuTransportGroup(const vector<CcuTransport*> &transports, u32 cntCkeNum):isDestroyed(false)
      62              : {
      63          135 :     HCCL_INFO("[CcuTransportGroup] cntCkeNum[%u].", cntCkeNum);
      64           45 :     if (!CheckTransports(transports)) {
      65            1 :         grpStatus = TransportGrpStatus::FAIL;
      66            3 :         HCCL_ERROR("[CcuTransportGroup::%s] Func CheckTransports failed, please check.", __func__);
      67            1 :         return;
      68              :     }
      69              : 
      70           44 :     transportsGrp = transports;
      71           44 :     cntCkesGroupDieId = transports[0]->GetDieId();
      72           44 :     cntCkeNumTransportGroupUse = cntCkeNum;
      73              : 
      74           44 :     HcclResult ret = CheckTransportCntCke();
      75           44 :     if (ret != HcclResult::HCCL_SUCCESS) {
      76           24 :         grpStatus = TransportGrpStatus::FAIL;
      77           72 :         HCCL_ERROR("[CcuTransportGroup::%s] Func CheckTransportCntCke failed, ret=[%d], please check.", __func__, ret);
      78           24 :         return;
      79              :     }
      80              : 
      81           20 :     grpStatus = TransportGrpStatus::INIT;
      82            0 : }
      83              : 
      84            4 : TransportGrpStatus CcuTransportGroup::GetGrpStatus() const
      85              : {
      86           12 :     HCCL_INFO("[CcuTransportGroup] current group status [%s].", grpStatus.Describe().c_str());
      87            4 :     return grpStatus;
      88              : }
      89              : 
      90           52 : CcuTransportGroup::~CcuTransportGroup()
      91              : {
      92           45 :     if (!isDestroyed) {
      93           44 :         Destroy();
      94              :     }
      95              : 
      96              :     // 调用ReleaseResHandle接口,用来释放cntResHandleTransportGroupUse
      97           45 :     auto ret = CcuDeviceManager::ReleaseCke(HrtGetDevice(), cntCkesGroupDieId, ckeInfoTransportGroupUse);
      98           45 :     if (ret != HcclResult::HCCL_SUCCESS) {
      99           66 :         HCCL_ERROR("[CcuTransportGroup::%s] Release ckesRes failed, ret[%d], ckeInfo size is [%u]", __func__, ret, ckeInfoTransportGroupUse.size());
     100           22 :         for (auto& ckeInfo : ckeInfoTransportGroupUse) {
     101            0 :             HCCL_ERROR("[CcuTransportGroup::%s] Release ckesRes failed, ckeInfo.startId[%u], ckeInfo.num[%u]", __func__, ckeInfo.startId, ckeInfo.num);
     102              :         }
     103              :     } else {
     104           69 :         HCCL_INFO("[CcuTransportGroup::%s] CcuTransportGroup Destructor success.", __func__);
     105              :     }
     106           52 : }
     107              : 
     108           37 : void CcuTransportGroup::Destroy()
     109              : {
     110           37 :     isDestroyed = true;
     111           37 :     transportsGrp.clear();
     112           37 : }
     113              : 
     114           84 :  HcclResult CcuTransportGroup::GetCntCkeId(u32 index, u32 &cntCkeId) const
     115              : {
     116          252 :     HCCL_INFO("[GetCntCkeId] index[%u].", index);
     117           84 :     if (index >= cntCkesGroup.size()) {
     118            0 :         HCCL_ERROR("[GetCntCkeId] err[%s], index[%u] is bigger than cntCkesGroup size[%u], please check.",
     119              :                 __func__, index, cntCkesGroup.size());
     120            0 :         return HcclResult::HCCL_E_PARA;
     121              :     }
     122              : 
     123           84 :     cntCkeId = cntCkesGroup[index];
     124           84 :     return HcclResult::HCCL_SUCCESS;
     125              : }
     126              : 
     127           57 : const vector<CcuTransport*> &CcuTransportGroup::GetTransports() const
     128              : {
     129           57 :     return transportsGrp;
     130              : }
     131              : 
     132              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1