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 "ub_ci_updater_manager.h"
12 : #include "dev_ub_connection.h"
13 :
14 : namespace Hccl {
15 :
16 196 : UbCiUpdaterManager::UbCiUpdaterManager(const RmaConnManager* rmaConnMgr) : rmaConnMgrPtr(rmaConnMgr) {}
17 :
18 196 : UbCiUpdaterManager::~UbCiUpdaterManager() { ubCiUpdaters.clear(); }
19 :
20 2 : void UbCiUpdaterManager::SaveConnsCi(const std::string& opTag)
21 : {
22 2 : auto ubCiUpdatersPair = ubCiUpdaters.emplace(opTag, BatchCreate(opTag));
23 4 : for (auto& ubCiUpdater : ubCiUpdatersPair.first->second) {
24 2 : if (ubCiUpdater == nullptr) {
25 0 : continue;
26 : }
27 2 : ubCiUpdater->SaveCi();
28 : }
29 2 : }
30 :
31 1 : void UbCiUpdaterManager::UpdateConnsCi(const std::string& opTag)
32 : {
33 1 : if (ubCiUpdaters.find(opTag) == ubCiUpdaters.end()) {
34 0 : return;
35 : }
36 1 : std::vector<DevUbConnection::UbCiUpdater*> tmpUbCiUpdaters = Get(opTag);
37 2 : for (auto& ubCiUpdater : tmpUbCiUpdaters) {
38 1 : if (ubCiUpdater == nullptr) {
39 0 : continue;
40 : }
41 1 : ubCiUpdater->UpdateCi();
42 : }
43 1 : }
44 :
45 : std::vector<std::unique_ptr<DevUbConnection::UbCiUpdater>>
46 2 : UbCiUpdaterManager::BatchCreate(const std::string& opTag) const
47 : {
48 2 : std::vector<std::unique_ptr<DevUbConnection::UbCiUpdater>> tmpUbCiUpdaters;
49 4 : for (auto& rmaConn : rmaConnMgrPtr->GetOpTagConns(opTag)) {
50 2 : if (rmaConn->GetRmaConnType() == RmaConnType::UB) {
51 2 : if (dynamic_cast<DevUbConnection*>(rmaConn)->GetUbJfcMode() == HrtUbJfcMode::STARS_POLL) {
52 2 : tmpUbCiUpdaters.emplace_back(
53 4 : std::make_unique<DevUbConnection::UbCiUpdater>(dynamic_cast<DevUbConnection*>(rmaConn)));
54 : }
55 : }
56 2 : }
57 2 : return tmpUbCiUpdaters;
58 0 : }
59 :
60 2 : std::vector<DevUbConnection::UbCiUpdater*> UbCiUpdaterManager::Get(const std::string& opTag)
61 : {
62 2 : std::vector<DevUbConnection::UbCiUpdater*> tmpUbCiUpdaters;
63 2 : auto tagIter = ubCiUpdaters.find(opTag);
64 4 : for (auto& ubCiUpdater : tagIter->second) {
65 2 : tmpUbCiUpdaters.emplace_back(ubCiUpdater.get());
66 : }
67 2 : return tmpUbCiUpdaters;
68 0 : }
69 :
70 : } // namespace Hccl
|