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