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 90 : size_t operator()(const RankIdPair& p) const noexcept
31 : {
32 90 : uint64_t key = (uint64_t(p.first) << 32) | uint64_t(p.second);
33 90 : return std::hash<uint64_t>{}(key);
34 : }
35 : };
36 :
37 : } // namespace std
38 :
39 : namespace hccl {
40 :
41 : /**
42 : * @note 职责:管理一个rank对(MyRank+DstRank)中的多个源EndPoint下的EndPointPair。
43 : * 当前先只考虑一个源EndPoint下只有一个EndPointPair的场景。
44 : */
45 : class RankPair {
46 : public:
47 13 : RankPair(RankIdPair rankIdPair, const Hccl::RankIpPortMapPtr& rankIpPortMap)
48 13 : : localRankId_(rankIdPair.first),
49 13 : remoteRankId_(rankIdPair.second),
50 13 : rankIpPortMap_(rankIpPortMap)
51 13 : {}
52 13 : ~RankPair() = default;
53 :
54 : HcclResult Init();
55 : HcclResult GetEndpointPair(const EndpointDescPair& epDescPair, hcomm::EndpointPair*& out);
56 : hcomm::EpChannelMap GetEpChannelMap();
57 :
58 : private:
59 : RankId localRankId_{};
60 : RankId remoteRankId_{};
61 : std::unique_ptr<hcomm::EndpointPairMgr> endpointPairMgr_{};
62 : Hccl::RankIpPortMapPtr rankIpPortMap_;
63 : };
64 : } // namespace hccl
65 :
66 : #endif // RANK_PAIR_H
|