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_RANK_INFO_DETECT_CLIENT_H
12 : #define HCCLV2_RANK_INFO_DETECT_CLIENT_H
13 :
14 : #include <cstddef>
15 : #include <vector>
16 : #include "socket.h"
17 : #include "new_rank_info.h"
18 : #include "rank_table_info.h"
19 : #include "json_parser.h"
20 : #include "internal_exception.h"
21 : #include "timeout_exception.h"
22 : #include "socket_exception.h"
23 : #include "socket_agent.h"
24 : #include "root_handle_v2.h"
25 : #include "ip_address.h"
26 :
27 : namespace Hccl {
28 :
29 : #ifdef OPEN_HCCL_TEST
30 : const u32 WAIT_ERROR_BROADCAST_TIME = 1;
31 : #else
32 : const u32 WAIT_ERROR_BROADCAST_TIME = 20;
33 : #endif
34 :
35 : class RankInfoDetectClient {
36 : public:
37 47 : RankInfoDetectClient(u32 devPhyId, u32 rankSize, u32 rankId, const std::shared_ptr<Socket>& clientSocket)
38 47 : : devPhyId_(devPhyId),
39 47 : rankSize_(rankSize),
40 47 : rankId_(rankId),
41 47 : clientSocket_(clientSocket),
42 47 : socketAgent_(clientSocket.get())
43 47 : {}
44 : ~RankInfoDetectClient();
45 :
46 : void Setup(RankTableInfo& rankTable);
47 :
48 : private:
49 : u32 devPhyId_{0};
50 : u32 rankSize_{0};
51 : u32 rankId_{0};
52 : std::shared_ptr<Socket> clientSocket_{nullptr};
53 : u32 currentStep_{0};
54 : RankTableInfo rankTable_{};
55 : SocketAgent socketAgent_;
56 : std::mutex hostSocketLock_;
57 : std::shared_ptr<Socket> hostSocket_ = nullptr;
58 :
59 : void SetupHostListenPort(u32 devLogicId, u32 devPhyId, const IpAddress& hostIp, uint32_t& hostPort);
60 : void SocketTearDown(u32 devPhyId);
61 : void Connect();
62 : void CheckStatus();
63 : void SendAgentIdAndRankSize();
64 : void SendLocalRankTable(const RankTableInfo& localRankTable);
65 : void ConstructRankTable(RankTableInfo& localRankTable);
66 : void VerifyRankTable();
67 : void RecvRankTable();
68 : void RecvRankTableMsg(vector<char>& rankInfoMsg);
69 : void ParseRankTable(vector<char>& rankInfoMsg);
70 : void GetLocalRankTableJson(const nlohmann::json& parseJson, nlohmann::json& localRankTableJson);
71 : void GetLocalDevInfoJson(const nlohmann::json& parseJson, nlohmann::json& localDevInfoJson);
72 : void SelectLocalHostBackupAddr(nlohmann::json& localDevInfoJson);
73 : void SelectAvailableHostAddr(nlohmann::json& addrJson);
74 : void UpdateSelectedHostAddr(
75 : nlohmann::json& addrJson, const std::vector<IpAddress>& candidates, std::size_t selectedIndex) const;
76 : void ProbeHostRoceAddr(const IpAddress& hostAddr, bool& isAvailable) const;
77 : void ConstructSingleRank(RankTableInfo& localRankTable);
78 : HcclResult GetLocalTlsStatus(TlsStatus& tlsStatus) const;
79 : HcclResult VerifyTlsConsistency() const;
80 : void GenerateTlsStatusStr(std::string& tlsStatusStr, const std::vector<u32>& tlsStatusRanks) const;
81 : void ReportTlsConfigurationError(
82 : const std::string& tlsInconsistentTlsType, const std::string& tlsEnableRankStr,
83 : const std::string& tlsDisableRankStr, const std::string& tlsUnknownRankStr) const;
84 : void TearDown();
85 : void HostListenPortDetect(NewRankInfo& rankInfo);
86 : };
87 :
88 : } // namespace Hccl
89 : #endif // HCCLV2_RANK_INFO_DETECT_CLIENT_H
|