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.4 % 41 35
Test Date: 2026-07-28 12:11:00 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.h"
      12              : #include "ccu_res_specs.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("[CcuJettyCtxMgr][%s] sqSize[%u] is too small, reset to [%u].",
      36              :             __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("[CcuJettyCtxMgr][%s] sqSize[%u] is not power of 2, reset to [%u].",
      44              :             __func__, sqSize, wqeBBReqNum);
      45              :     }
      46              : 
      47           25 :     if (sqSize > CCU_MAX_SQ_DEPTH) {
      48            0 :         HCCL_WARNING("[CcuJettyCtxMgr][%s] sqSize[%u] is too large, reset to [%u].",
      49              :             __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)
      57           24 :     : devLogicId(devLogicId), dieId(dieId)
      58              : {
      59           24 :     uint32_t wqeBBNum = 0; // 获取失败或为0场景,分配将按资源不足操作
      60           24 :     (void)CcuResSpecifications::GetInstance(devLogicId).GetWqeBBNum(dieId, wqeBBNum);
      61           24 :     idAllocator = std::make_unique<CcuResIdAllocator>(wqeBBNum);
      62           24 : }
      63              : 
      64           34 : HcclResult CcuWqeBBMgr::Alloc(const uint32_t sqSize, ResInfo &wqeBBInfo)
      65              : {
      66           34 :     uint32_t wqeBBReqSize = GetWqeBBReqSizeBySqSize(sqSize);
      67           34 :     vector<ResInfo> resInfo;
      68           68 :     auto ret = idAllocator->Alloc(wqeBBReqSize, true, resInfo, "ResType::WqeBB"); // wqebb资源要求连续
      69           34 :     if (ret != HcclResult::HCCL_SUCCESS) {
      70            0 :         HCCL_WARNING("[CcuWqeBBMgr][%s] failed, sqSize[%u], wqeBBSize[%u]",
      71              :             __func__, sqSize, wqeBBReqSize);
      72            0 :         return ret;
      73              :     }
      74              : 
      75           34 :     wqeBBInfo = resInfo[0]; // 分配连续资源包含1个元素
      76           34 :     return ret;
      77           34 : }
      78              : 
      79            4 : HcclResult CcuWqeBBMgr::Release(const ResInfo &wqeBBInfo)
      80              : {
      81            4 :     auto ret = idAllocator->Release(wqeBBInfo.startId, wqeBBInfo.num);
      82            4 :     CHK_PRT_RET(ret != HcclResult::HCCL_SUCCESS,
      83              :         HCCL_ERROR("[CcuWqeBBMgr][%s] failed, wqe basic block resource info[%s]",
      84              :             __func__, wqeBBInfo.Describe().c_str()),
      85              :         ret);
      86              : 
      87            4 :     return HcclResult::HCCL_SUCCESS;
      88              : }
      89              : 
      90              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1