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_mgr.h"
12 :
13 : #include <unordered_set>
14 :
15 : #include "hccl_common.h"
16 : #include "eid_info_mgr.h"
17 : #include "ccu_res_specs.h"
18 :
19 : namespace hcomm {
20 :
21 606 : CcuPfeCfgMgr& CcuPfeCfgMgr::GetInstance(const int32_t deviceLogicId)
22 : {
23 672 : static CcuPfeCfgMgr ccuPfeCfgMgr[MAX_MODULE_DEVICE_NUM + 1];
24 :
25 606 : int32_t devLogicId = deviceLogicId;
26 606 : if (devLogicId < 0 || static_cast<uint32_t>(devLogicId) >= MAX_MODULE_DEVICE_NUM) {
27 0 : HCCL_WARNING(
28 : "[CcuPfeCfgMgr][%s] use the backup device, devLogicId[%d] should be "
29 : "less than %u.",
30 : __func__, devLogicId, MAX_MODULE_DEVICE_NUM);
31 0 : devLogicId = MAX_MODULE_DEVICE_NUM; // 使用备份设备
32 : }
33 :
34 606 : ccuPfeCfgMgr[devLogicId].devLogicId_ = deviceLogicId;
35 :
36 606 : return ccuPfeCfgMgr[devLogicId];
37 : }
38 :
39 188 : HcclResult CcuPfeCfgMgr::Init()
40 : {
41 188 : if (initFlag_) {
42 84 : return HcclResult::HCCL_SUCCESS;
43 : }
44 :
45 104 : CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<uint32_t>(devLogicId_), devPhyId_));
46 :
47 104 : std::vector<DevEidInfo> eidInfos;
48 104 : CHK_RET(EidInfoMgr::GetInstance(devPhyId_).GetEidInfos(eidInfos));
49 :
50 104 : bool dieEnableFlags[CCU_MAX_IODIE_NUM] = {false, false};
51 312 : for (uint8_t i = 0; i < CCU_MAX_IODIE_NUM; i++) {
52 208 : const auto& ccuResSpecs = CcuResSpecifications::GetInstance(devLogicId_);
53 208 : (void)ccuResSpecs.GetDieEnableFlag(i, dieEnableFlags[i]);
54 : }
55 :
56 : // 不同die的feId独立分配,可能一致,需要die粒度去重
57 104 : std::array<std::unordered_set<uint32_t>, CCU_MAX_IODIE_NUM> dieFuncIdSet;
58 416 : for (auto& param : eidInfos) {
59 312 : const uint32_t dieId = param.dieId;
60 312 : if (dieId >= CCU_MAX_IODIE_NUM) {
61 106 : continue; // 跳过HCCL不使用的dieId
62 : }
63 :
64 312 : if (!dieEnableFlags[dieId]) {
65 3 : continue; // die如果未使能认为无需分配
66 : }
67 :
68 309 : const uint32_t feId = param.funcId;
69 309 : if (dieFuncIdSet[dieId].find(feId) != dieFuncIdSet[dieId].end()) {
70 103 : continue; // 跳过已配置的feId
71 : }
72 :
73 206 : constexpr uint32_t startJettyCtxId = 0;
74 206 : constexpr uint32_t startTaJettyId = CCU_START_TA_JETTY_ID;
75 206 : constexpr uint8_t pfeJettyNum = CCU_PER_DIE_JETTY_RESERVED_NUM;
76 :
77 206 : PfeJettyCtxCfg cfg{feId, startJettyCtxId, startTaJettyId, pfeJettyNum};
78 206 : pfeJettyCtxCfgs_[dieId].emplace_back(std::move(cfg));
79 206 : dieFuncIdSet[dieId].insert(feId);
80 :
81 206 : HCCL_RUN_INFO(
82 : "[CcuPfeCfgMgr] new pfe cfg set: dieId[%u] feId[%u] startJettyCtxId[%u] "
83 : "startTaJettyId[%u] pfeJettyNum[%u].",
84 : dieId, feId, startJettyCtxId, startTaJettyId, pfeJettyNum);
85 : }
86 :
87 104 : initFlag_ = true;
88 104 : return HcclResult::HCCL_SUCCESS;
89 104 : }
90 :
91 180 : HcclResult CcuPfeCfgMgr::Deinit()
92 : {
93 540 : for (auto& cfg : pfeJettyCtxCfgs_) {
94 360 : cfg.clear();
95 : }
96 180 : initFlag_ = false;
97 180 : return HcclResult::HCCL_SUCCESS;
98 : }
99 :
100 238 : std::vector<PfeJettyCtxCfg> CcuPfeCfgMgr::GetPfeJettyCtxCfg(const uint8_t dieId)
101 : {
102 238 : if (dieId >= CCU_MAX_IODIE_NUM) {
103 1 : HCCL_WARNING("[CcuPfeCfgMgr][PfeJettyCtxCfg] invalid dieId[%u]", dieId);
104 1 : return std::vector<PfeJettyCtxCfg>();
105 : }
106 :
107 237 : if (pfeJettyCtxCfgs_[dieId].empty()) {
108 23 : HCCL_WARNING("[CcuPfeCfgMgr][PfeJettyCtxCfg] pfeJettyCtxCfgMap is empty, dieId[%u]", dieId);
109 23 : return std::vector<PfeJettyCtxCfg>();
110 : }
111 :
112 214 : return pfeJettyCtxCfgs_[dieId];
113 : }
114 :
115 : } // namespace hcomm
|