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