LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_instance - ccu_res_pack.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 77.1 % 35 27
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 5 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_res_pack.h"
      12              : 
      13              : #include "ccu_log.h"
      14              : #include "hcom_common.h"
      15              : 
      16              : namespace hcomm {
      17              : 
      18          135 : CcuResPack::~CcuResPack()
      19              : {
      20           68 :     if (resHandle_ == 0) {
      21            1 :         return;
      22              :     }
      23              : 
      24           67 :     auto ret = CcuReleaseResHandle(devLogicId_, resHandle_);
      25           67 :     if (ret != HcclResult::HCCL_SUCCESS) {
      26            0 :         HCCL_ERROR("[CcuResPack][%s] failed, resHandle[%p] devLogicId[%d].", __func__, resHandle_, devLogicId_);
      27              :     }
      28           67 :     resHandle_ = 0;
      29           68 : }
      30              : 
      31          122 : CcuResult CcuResPack::Reset()
      32              : {
      33          122 :     if (!resHandle_) {
      34            0 :         return CcuResult::CCU_SUCCESS;
      35              :     }
      36              : 
      37          122 :     CCU_CHK_RET(CcuCheckResource(devLogicId_, resHandle_, resRepo_));
      38          122 :     return CcuResult::CCU_SUCCESS;
      39              : }
      40              : 
      41            6 : CcuResult CcuResPack::InitByInsType(const CcuInstanceType insType)
      42              : {
      43            6 :     devLogicId_ = HcclGetThreadDeviceId();
      44            6 :     if (insType == CcuInstanceType::CCU_UNUSED) {
      45            0 :         HCCL_ERROR("[CcuResPack][%s] failed, error ccu instance type[%d].", __func__, static_cast<int32_t>(insType));
      46            0 :         return CcuResult::CCU_E_PARA;
      47              :     }
      48              : 
      49              :     // 根据通信域算子展开模式申请资源
      50              :     // 如果资源不足,返回HCCL_E_UNAVAIL,表示需要回退
      51            6 :     auto ret = CcuAllocResHandleByInsType(devLogicId_, insType, resHandle_);
      52            6 :     if (ret == CcuResult::CCU_E_UNAVAIL) {
      53            0 :         HCCL_RUN_WARNING(
      54              :             "[%s] failed but passed, resource is not enough, "
      55              :             "devLogicId[%d], ccuInsType[%d].",
      56              :             __func__, devLogicId_, insType);
      57            0 :         return ret;
      58              :     }
      59            6 :     CCU_CHK_RET(ret);
      60            6 :     CCU_CHK_RET(Reset());
      61            6 :     return CcuResult::CCU_SUCCESS;
      62              : }
      63              : 
      64           61 : CcuResult CcuResPack::InitByResDescs(const CcuResDesc* descs[], uint32_t descNum)
      65              : {
      66           61 :     devLogicId_ = HcclGetThreadDeviceId();
      67              : 
      68              :     // 基于 resDesc 驱动的资源数量申请资源
      69              :     // 如果资源不足,返回CCU_E_UNAVAIL,表示需要回退
      70           61 :     auto ret = CcuAllocResHandleByResDescs(devLogicId_, descs, descNum, resHandle_);
      71           61 :     if (ret == CcuResult::CCU_E_UNAVAIL) {
      72            0 :         HCCL_RUN_WARNING(
      73              :             "[%s] failed but passed, resource is not enough, "
      74              :             "devLogicId[%d], descNum[%u].",
      75              :             __func__, devLogicId_, descNum);
      76            0 :         return ret;
      77              :     }
      78           61 :     CCU_CHK_RET(ret);
      79           61 :     CCU_CHK_RET(Reset());
      80           61 :     return CcuResult::CCU_SUCCESS;
      81              : }
      82              : 
      83          171 : CcuResRepository& CcuResPack::GetCcuResRepo() { return resRepo_; }
      84              : 
      85              : } // namespace hcomm
        

Generated by: LCOV version 2.0-1