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 : #ifndef RANK_PAIR_H
11 : #define RANK_PAIR_H
12 :
13 : #include <cstdint>
14 : #include <functional>
15 : #include <memory>
16 : #include <utility>
17 : #include <vector>
18 : #include "hccl/hccl_types.h"
19 : #include "socket_manager.h"
20 : #include "hcomm_res_defs.h"
21 : #include "endpoint_pair_mgr.h"
22 :
23 : using RankId = uint32_t;
24 : using RankIdPair = std::pair<RankId, RankId>;
25 :
26 : namespace std {
27 :
28 : template <>
29 : struct hash<RankIdPair> {
30 44 : size_t operator()(const RankIdPair& p) const noexcept {
31 44 : uint64_t key = (uint64_t(p.first) << 32) | uint64_t(p.second);
32 44 : return std::hash<uint64_t>{}(key);
33 : }
34 : };
35 :
36 : } // namespace std
37 :
38 : namespace hccl {
39 :
40 : /**
41 : * @note 职责:管理一个rank对(MyRank+DstRank)中的多个源EndPoint下的EndPointPair。
42 : * 当前先只考虑一个源EndPoint下只有一个EndPointPair的场景。
43 : */
44 : class RankPair {
45 : public:
46 8 : RankPair(RankIdPair rankIdPair,
47 : const Hccl::RankIpPortMapPtr& rankIpPortMap)
48 8 : : localRankId_(rankIdPair.first),
49 8 : remoteRankId_(rankIdPair.second),
50 8 : rankIpPortMap_(rankIpPortMap)
51 : {
52 8 : }
53 8 : ~RankPair() = default;
54 :
55 : HcclResult Init();
56 : HcclResult GetEndpointPair(const EndpointDescPair &epDescPair, hcomm::EndpointPair*& out);
57 : hcomm::EpChannelMap GetEpChannelMap();
58 :
59 : private:
60 : RankId localRankId_{};
61 : RankId remoteRankId_{};
62 : std::unique_ptr<hcomm::EndpointPairMgr> endpointPairMgr_{};
63 : Hccl::RankIpPortMapPtr rankIpPortMap_;
64 : };
65 : }
66 :
67 : #endif // RANK_PAIR_H
|