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