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 "endpoint_pair_mgr.h"
12 :
13 : namespace hcomm {
14 :
15 82 : HcclResult EndpointPairMgr::Get(
16 : const EndpointDescPair& endpointDescPair, EndpointPair*& out, const Hccl::RankIpPortMapPtr& rankIpPortMap)
17 : {
18 82 : if (endpointPairMap_.find(endpointDescPair) != endpointPairMap_.end()) {
19 68 : out = endpointPairMap_[endpointDescPair].get();
20 68 : return HCCL_SUCCESS;
21 : }
22 :
23 14 : std::unique_ptr<EndpointPair> endpointPair = nullptr;
24 14 : EXCEPTION_CATCH(
25 : (endpointPair = std::make_unique<EndpointPair>(endpointDescPair.first, endpointDescPair.second, rankIpPortMap)),
26 : return HCCL_E_PTR);
27 14 : CHK_SMART_PTR_NULL(endpointPair);
28 14 : CHK_RET(endpointPair->Init());
29 :
30 14 : out = endpointPair.get();
31 14 : endpointPairMap_.emplace(endpointDescPair, std::move(endpointPair));
32 :
33 14 : return HCCL_SUCCESS;
34 14 : }
35 :
36 2 : EpChannelMap EndpointPairMgr::GetEpChannelMap()
37 : {
38 2 : EpChannelMap epChannelMap;
39 3 : for (const auto& endpointPair : endpointPairMap_) {
40 1 : auto channelList = endpointPair.second->GetChannelHandles();
41 1 : epChannelMap[endpointPair.first] = channelList;
42 1 : }
43 2 : return epChannelMap;
44 0 : }
45 :
46 : } // namespace hcomm
|