Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 HCCL_RANK_INFO_DETECT_H
12 : #define HCCL_RANK_INFO_DETECT_H
13 :
14 : #include "types.h"
15 : #include "socket.h"
16 : #include "ip_address.h"
17 : #include "rank_table_info.h"
18 : #include "root_handle_v2.h"
19 : #include "orion_adapter_hccp.h"
20 : #include "rank_info_detect_service.h"
21 : #include "rank_info_detect_client.h"
22 : #include "socket_handle_manager.h"
23 : #include "universal_concurrent_map.h"
24 :
25 : namespace Hccl {
26 :
27 : const u32 RANKINFO_DETECT_SERVER_STATUS_IDLE = 0;
28 : const u32 RANKINFO_DETECT_SERVER_STATUS_RUNING = 1;
29 : const u32 RANKINFO_DETECT_SERVER_STATUS_ERROR = 2;
30 :
31 : class RankInfoDetect {
32 : public:
33 : RankInfoDetect();
34 21 : ~RankInfoDetect() = default;
35 :
36 : void SetupServer(HcclRootHandleV2& rootHandle);
37 : void SetupAgent(u32 rankSize, u32 rankId, const HcclRootHandleV2& rootHandle);
38 : void GetRankTable(RankTableInfo& ranktable) const;
39 : void WaitComplete(u32 listenPort, u32 listenStatus) const;
40 :
41 : private:
42 : s32 devLogicId_{0};
43 : s32 userDevId_{0};
44 : u32 devPhyId_{0};
45 : RankTableInfo rankTable_{};
46 : IpAddress hostIp_{};
47 : u32 hostPort_{HCCL_INVALID_PORT};
48 : vector<IpAddress> hostSocketWlist_{};
49 : vector<RaSocketWhitelist> wlistInfo_{};
50 : std::string identifier_{};
51 : std::shared_ptr<RankInfoDetectClient> rankInfoDetectClient;
52 : void SetupRankInfoDetectService(
53 : shared_ptr<Socket> serverSocket, s32 devLogicId, u32 devPhyId, std::string identifier,
54 : vector<RaSocketWhitelist> wlistInfo);
55 : std::shared_ptr<Socket> ServerInit();
56 : std::shared_ptr<Socket> ClientInit(const HcclRootHandleV2& rootHandle);
57 : HcclResult GetHandleAndAddHostSocketWhitelist();
58 : HcclResult AddHostSocketWhitelist(SocketHandle& socketHandle, const vector<IpAddress>& hostSocketWlist);
59 : u32 GetHostListenPort();
60 : void GetRootHandle(HcclRootHandleV2& rootHandle);
61 : SocketHandle GetHostSocketHandle();
62 :
63 : static UniversalConcurrentMap<u32, u32> g_detectServerStatus_;
64 : };
65 :
66 : } // namespace Hccl
67 :
68 : #endif // HCCL_VIRT_TOPO_DETECT_H
|