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