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 HCCLV2_RMA_CONN_MANAGER_H
12 : #define HCCLV2_RMA_CONN_MANAGER_H
13 :
14 : #include <string>
15 : #include <vector>
16 : #include <map>
17 : #include <unordered_map>
18 : #include <memory>
19 : #include "types.h"
20 : #include "rma_connection.h"
21 : #include "virtual_topo.h"
22 : #include "socket.h"
23 :
24 : namespace Hccl {
25 :
26 : class CommunicatorImpl;
27 :
28 520 : MAKE_ENUM(UboeStatus, READY, INIT, SOCKET_OK, SOCKET_TIMEOUT);
29 :
30 : class RmaConnManager {
31 : public:
32 : explicit RmaConnManager(const CommunicatorImpl& comm);
33 : virtual ~RmaConnManager();
34 :
35 : RmaConnection*
36 1 : Create(const std::string& tag, const LinkData& linkData, const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL);
37 :
38 : void BatchCreate(vector<LinkData>& links);
39 :
40 : RmaConnection* Get(const std::string& tag, const LinkData& linkData);
41 :
42 : std::vector<RmaConnection*> GetOpTagConns(const std::string& tag) const;
43 :
44 : void Release(const std::string& tag, const LinkData& linkData);
45 :
46 : void Destroy();
47 :
48 : void Clear();
49 :
50 : private:
51 : void GetDeleteJettys(BatchDeleteJettyInfo& batchDeleteJettyInfo);
52 : void BatchDeleteJettys();
53 : unique_ptr<RmaConnection> CreateRdmaConn(Socket* socket, const std::string& tag, const LinkData& linkData) const;
54 : unique_ptr<RmaConnection> CreateUbConn(
55 : Socket* socket, const std::string& tag, const LinkData& linkData,
56 : const HrtUbJfcMode jfcMode = HrtUbJfcMode::STARS_POLL);
57 : bool isDestroyed{false};
58 : // tag -> LinkData -> RmaConnection
59 : std::unordered_map<std::string, std::unordered_map<LinkData, std::unique_ptr<RmaConnection>, hash<Hccl::LinkData>>>
60 : rmaConnectionMap;
61 :
62 : u32 localRank{0};
63 : const CommunicatorImpl* comm;
64 :
65 : IpAddress locAddr;
66 : IpAddress rmtAddr;
67 : UboeStatus uboeStatus{UboeStatus::INIT};
68 520 : MAKE_ENUM(UbStatus, INIT, SOCKET_OK, SEND_DATA, RECV_DATA, SEND_FIN, RECV_FIN, PROCESS_DATA, CONN_OK)
69 : UbStatus ubStatus{UbStatus::INIT};
70 : vector<char> sendData{};
71 : vector<char> recvData{};
72 : u32 exchangeDataSize{0}; // 交换的消息大小
73 :
74 : std::vector<RmaConnection*> GetAllConns() const;
75 : void RecreateAllConns();
76 : void BindRemoteRmaBuffers();
77 :
78 : bool IsSocketReady(Socket* socket, const LinkData& linkData);
79 : UboeStatus GetUboeSocketStatus(Socket* socket, const LinkData& linkData);
80 : void WaitUboeSocketReady(Socket* socket, const LinkData& linkData);
81 : void Ipv4Pack();
82 : void Ipv4UnPack(BinaryStream& binaryStream);
83 : void SendExchangeData(Socket* socket, const LinkData& linkData);
84 : void RecvExchangeData(Socket* socket, const LinkData& linkData);
85 : void RecvDataProcess(const LinkData& linkData);
86 : };
87 :
88 : } // namespace Hccl
89 :
90 : #endif // HCCLV2_RMA_CONN_MANAGER_H
|