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: 74.1 % 27 20
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 4 4

            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           54 : CcuResPack::~CcuResPack()
      19              : {
      20           27 :     if (resHandle_ == 0) {
      21            0 :         return;
      22              :     }
      23              : 
      24           27 :     auto ret = CcuReleaseResHandle(devLogicId_, resHandle_);
      25           27 :     if (ret != HcclResult::HCCL_SUCCESS) {
      26            0 :         HCCL_ERROR("[CcuResPack][%s] failed, resHandle[0x%llx] devLogicId[%d].",
      27              :             __func__, resHandle_, devLogicId_);
      28              :     }
      29           27 :     resHandle_ = 0;
      30           27 : }
      31              : 
      32           27 : CcuResult CcuResPack::Init()
      33              : {
      34           27 :     devLogicId_ = HcclGetThreadDeviceId();
      35           27 :     if (insType_ == CcuInstanceType::CCU_UNUSED) {
      36            0 :         HCCL_ERROR("[CcuResPack][%s] failed, error ccu instance type[%d].",
      37              :             __func__, static_cast<int32_t>(insType_));
      38            0 :         return CcuResult::CCU_E_PARA;
      39              :     }
      40              : 
      41              :     // 根据通信域算子展开模式申请资源
      42              :     // 如果资源不足,返回HCCL_E_UNAVAIL,表示需要回退
      43           27 :     auto ret = CcuAllocResHandleByInsType(devLogicId_, insType_, resHandle_);
      44           27 :     if (ret == CcuResult::CCU_E_UNAVAIL) {
      45            0 :         HCCL_RUN_WARNING("[%s] failed but passed, resource is not enough, "
      46              :             "devLogicId[%d], ccuInsType[%d].", __func__, devLogicId_, insType_);
      47            0 :         return ret;
      48              :     }
      49           27 :     CCU_CHK_RET(ret);
      50           27 :     CCU_CHK_RET(Reset());
      51           27 :     return CcuResult::CCU_SUCCESS;
      52              : }
      53              : 
      54           53 : CcuResult CcuResPack::Reset()
      55              : {
      56           53 :     if (!resHandle_) {
      57            0 :         return CcuResult::CCU_SUCCESS;
      58              :     }
      59              : 
      60           53 :     CCU_CHK_RET(CcuCheckResource(devLogicId_, resHandle_, resRepo_));
      61           53 :     return CcuResult::CCU_SUCCESS;
      62              : }
      63              : 
      64           38 : CcuResRepository &CcuResPack::GetCcuResRepo()
      65              : {
      66           38 :     return resRepo_;
      67              : }
      68              : 
      69              : } // namespace hcomm
        

Generated by: LCOV version 2.0-1