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