LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_device/ccu_component/ccu_pfe - ccu_pfe_cfg_generator.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 76.6 % 47 36
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 3 3

            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_pfe_cfg_generator.h"
      12              : 
      13              : #include "hccl_common_v2.h"
      14              : 
      15              : #include "ccu_eid_info.h"
      16              : #include "ccu_res_specs_legacy.h"
      17              : #include <unordered_set>
      18              : 
      19              : namespace Hccl {
      20              : 
      21           26 : CcuPfeCfgGenerator& CcuPfeCfgGenerator::GetInstance(const int32_t deviceLogicId)
      22              : {
      23           92 :     static CcuPfeCfgGenerator ccuPfeCfgGenerator[MAX_MODULE_DEVICE_NUM + 1];
      24              : 
      25           26 :     if (deviceLogicId < 0 || static_cast<uint32_t>(deviceLogicId) > MAX_MODULE_DEVICE_NUM) {
      26            0 :         THROW<InvalidParamsException>(
      27              :             "[CcuPfeCfgGenerator][%s] failed to get instance, devLogicId[%d] "
      28              :             "should be less than %u.",
      29              :             __func__, deviceLogicId, MAX_MODULE_DEVICE_NUM);
      30              :     }
      31              : 
      32           26 :     ccuPfeCfgGenerator[deviceLogicId].Init(deviceLogicId);
      33              : 
      34           26 :     return ccuPfeCfgGenerator[deviceLogicId];
      35              : }
      36              : 
      37           26 : void CcuPfeCfgGenerator::Init(const int32_t deviceLogicId)
      38              : {
      39           26 :     if (initFlag) {
      40           23 :         return;
      41              :     }
      42              : 
      43            3 :     devLogicId = deviceLogicId;
      44              : 
      45            3 :     std::vector<HrtDevEidInfo> eidInfoList;
      46            3 :     (void)CcuEidInfo::GetInstance(devLogicId).GetEidInfo(devLogicId, eidInfoList);
      47            3 :     if (eidInfoList.empty()) {
      48            0 :         HCCL_RUN_INFO("[CcuPfeCfgGenerator][%s] eid infos are empty, devLogicId[%d]", __func__, devLogicId);
      49            0 :         initFlag = true;
      50            0 :         return;
      51              :     }
      52              : 
      53            3 :     bool dieEnableFlags[MAX_CCU_IODIE_NUM] = {false, false};
      54            9 :     for (uint8_t i = 0; i < MAX_CCU_IODIE_NUM; i++) {
      55            6 :         const auto& ccuResSpecs = CcuResSpecifications::GetInstance(devLogicId);
      56            6 :         (void)ccuResSpecs.GetDieEnableFlag(i, dieEnableFlags[i]);
      57              :     }
      58              : 
      59              :     // 不同die的feId独立分配,可能一致,需要die粒度去重
      60            3 :     std::array<std::unordered_set<uint32_t>, MAX_CCU_IODIE_NUM> dieFuncIdSet;
      61            8 :     for (auto& param : eidInfoList) {
      62            5 :         const uint32_t dieId = param.dieId;
      63            5 :         if (dieId >= MAX_CCU_IODIE_NUM) {
      64            0 :             continue; // 跳过HCCL不使用的dieId
      65              :         }
      66              : 
      67            5 :         if (!dieEnableFlags[dieId]) {
      68            0 :             continue; // die如果未使能认为无需分配
      69              :         }
      70              : 
      71            5 :         const uint32_t feId = param.funcId;
      72            5 :         if (dieFuncIdSet[dieId].find(feId) != dieFuncIdSet[dieId].end()) {
      73            0 :             continue; // 跳过已配置的feId
      74              :         }
      75              : 
      76            5 :         uint32_t startJettyCtxId = 0;
      77            5 :         uint32_t startTaJettyId = CCU_START_TA_JETTY_ID;
      78            5 :         uint8_t pfeJettyNum = CCU_PER_DIE_JETTY_RESERVED_NUM;
      79              : 
      80            5 :         PfeJettyCtxCfg cfg{feId, startJettyCtxId, startTaJettyId, pfeJettyNum};
      81            5 :         pfeJettyCtxCfgs[dieId].emplace_back(std::move(cfg));
      82            5 :         dieFuncIdSet[dieId].insert(feId);
      83              : 
      84           15 :         HCCL_RUN_INFO(
      85              :             "[CcuPfeCfgGenerator] new pfe cfg set: dieId[%u] feId[%u] startJettyCtxId[%u] "
      86              :             "startTaJettyId[%u] pfeJettyNum[%u].",
      87              :             dieId, feId, startJettyCtxId, startTaJettyId, pfeJettyNum);
      88              :     }
      89              : 
      90            3 :     initFlag = true;
      91            3 : }
      92              : 
      93           25 : std::vector<PfeJettyCtxCfg> CcuPfeCfgGenerator::GetPfeJettyCtxCfg(const uint8_t dieId)
      94              : {
      95           25 :     if (dieId >= MAX_CCU_IODIE_NUM) {
      96            0 :         HCCL_WARNING("[CcuPfeCfgGenerator][PfeJettyCtxCfg] invaild dieId[%u]", dieId);
      97            0 :         return std::vector<PfeJettyCtxCfg>();
      98              :     }
      99              : 
     100           25 :     if (pfeJettyCtxCfgs[dieId].empty()) {
     101            0 :         HCCL_WARNING("[CcuPfeCfgGenerator][PfeJettyCtxCfg] pfeJettyCtxCfgMap is empty, dieId[%u]", dieId);
     102            0 :         return std::vector<PfeJettyCtxCfg>();
     103              :     }
     104              : 
     105           25 :     return pfeJettyCtxCfgs[dieId];
     106              : }
     107              : 
     108              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1