LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_device/ccu_component/ccu_channel - ccu_wqebb_mgr.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.0 % 40 34
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_wqebb_mgr_legacy.h"
      12              : #include "ccu_res_specs_legacy.h"
      13              : 
      14              : namespace Hccl {
      15              : 
      16              : // 计算 num 的以 2 为底的对数后移位,相当于向上最接近的 2 的整数次幂
      17           25 : static uint32_t RoundUpToNextPowerOfTwo(uint32_t num)
      18              : {
      19           25 :     if (num == 0) {
      20            0 :         return 1;
      21              :     }
      22              : 
      23           25 :     num--;
      24           25 :     num |= num >> 1;
      25           25 :     num |= num >> SHIFT_2BITS;
      26           25 :     num |= num >> SHIFT_4BITS;
      27           25 :     num |= num >> SHIFT_8BITS;
      28           25 :     num |= num >> SHIFT_16BITS;
      29           25 :     return num + 1;
      30              : }
      31              : 
      32           34 : static uint32_t GetWqeBBReqSizeBySqSize(uint32_t sqSize)
      33              : {
      34           34 :     if (sqSize < CCU_MIN_SQ_DEPTH) {
      35           27 :         HCCL_WARNING(
      36              :             "[CcuJettyCtxMgr][%s] sqSize[%u] is too small, reset to [%u].", __func__, sqSize, CCU_MIN_SQ_DEPTH);
      37            9 :         return CCU_MIN_SQ_DEPTH;
      38              :     }
      39              : 
      40              :     // WQE basic block 的 size 必须是 2 的整数次幂,向上取整
      41           25 :     uint32_t wqeBBReqNum = RoundUpToNextPowerOfTwo(sqSize);
      42           25 :     if (wqeBBReqNum != sqSize) {
      43            0 :         HCCL_WARNING(
      44              :             "[CcuJettyCtxMgr][%s] sqSize[%u] is not power of 2, reset to [%u].", __func__, sqSize, wqeBBReqNum);
      45              :     }
      46              : 
      47           25 :     if (sqSize > CCU_MAX_SQ_DEPTH) {
      48            0 :         HCCL_WARNING(
      49              :             "[CcuJettyCtxMgr][%s] sqSize[%u] is too large, reset to [%u].", __func__, sqSize, CCU_MAX_SQ_DEPTH);
      50            0 :         return CCU_MAX_SQ_DEPTH;
      51              :     }
      52              : 
      53           25 :     return wqeBBReqNum;
      54              : }
      55              : 
      56           24 : CcuWqeBBMgr::CcuWqeBBMgr(const int32_t devLogicId, const uint8_t dieId) : devLogicId(devLogicId), dieId(dieId)
      57              : {
      58           24 :     uint32_t wqeBBNum = 0; // 获取失败或为0场景,分配将按资源不足操作
      59           24 :     (void)CcuResSpecifications::GetInstance(devLogicId).GetWqeBBNum(dieId, wqeBBNum);
      60           24 :     idAllocator = std::make_unique<CcuResIdAllocator>(wqeBBNum);
      61           24 : }
      62              : 
      63           34 : HcclResult CcuWqeBBMgr::Alloc(const uint32_t sqSize, ResInfo& wqeBBInfo)
      64              : {
      65           34 :     uint32_t wqeBBReqSize = GetWqeBBReqSizeBySqSize(sqSize);
      66           34 :     vector<ResInfo> resInfo;
      67           68 :     auto ret = idAllocator->Alloc(wqeBBReqSize, true, resInfo, "ResType::WqeBB"); // wqebb资源要求连续
      68           34 :     if (ret != HcclResult::HCCL_SUCCESS) {
      69            0 :         HCCL_WARNING("[CcuWqeBBMgr][%s] failed, sqSize[%u], wqeBBSize[%u]", __func__, sqSize, wqeBBReqSize);
      70            0 :         return ret;
      71              :     }
      72              : 
      73           34 :     wqeBBInfo = resInfo[0]; // 分配连续资源包含1个元素
      74           34 :     return ret;
      75           34 : }
      76              : 
      77            4 : HcclResult CcuWqeBBMgr::Release(const ResInfo& wqeBBInfo)
      78              : {
      79            4 :     auto ret = idAllocator->Release(wqeBBInfo.startId, wqeBBInfo.num);
      80            4 :     CHK_PRT_RET(
      81              :         ret != HcclResult::HCCL_SUCCESS,
      82              :         HCCL_ERROR(
      83              :             "[CcuWqeBBMgr][%s] failed, wqe basic block resource info[%s]", __func__, wqeBBInfo.Describe().c_str()),
      84              :         ret);
      85              : 
      86            4 :     return HcclResult::HCCL_SUCCESS;
      87              : }
      88              : 
      89              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1