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 "rank_pair_mgr.h"
12 :
13 : namespace hccl {
14 :
15 82 : HcclResult RankPairMgr::Get(RankIdPair rankIdPair, RankPair*& out)
16 : {
17 82 : auto iterPtr = rankPairMap_.find(rankIdPair);
18 82 : if (iterPtr != rankPairMap_.end()) {
19 69 : out = iterPtr->second.get();
20 69 : return HCCL_SUCCESS;
21 : }
22 :
23 13 : std::unique_ptr<RankPair> rankPair = nullptr;
24 13 : EXCEPTION_CATCH((rankPair = std::make_unique<RankPair>(rankIdPair, rankIpPortMap_)), return HCCL_E_PTR);
25 13 : CHK_SMART_PTR_NULL(rankPair);
26 13 : CHK_RET(rankPair->Init());
27 :
28 13 : out = rankPair.get();
29 13 : rankPairMap_.emplace(rankIdPair, std::move(rankPair));
30 :
31 13 : return HCCL_SUCCESS;
32 13 : }
33 :
34 0 : ChannelTable RankPairMgr::GetChannelTable()
35 : {
36 0 : ChannelTable channelTable;
37 0 : for (const auto& rankPair : rankPairMap_) {
38 0 : channelTable[rankPair.first] = rankPair.second->GetEpChannelMap();
39 : }
40 0 : return channelTable;
41 0 : }
42 :
43 : } // namespace hccl
|