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 14 : ~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 : u32 devPhyId_{0};
44 : RankTableInfo rankTable_{};
45 : IpAddress hostIp_{};
46 : u32 hostPort_{HCCL_INVALID_PORT};
47 : vector<RaSocketWhitelist> wlistInfo_{};
48 : std::string identifier_{};
49 : std::shared_ptr<RankInfoDetectClient> rankInfoDetectClient;
50 :
51 : void SetupRankInfoDetectService(shared_ptr<Socket> serverSocket, s32 devLogicId, u32 devPhyId,
52 : std::string identifier, vector<RaSocketWhitelist> wlistInfo);
53 : std::shared_ptr<Socket> ServerInit();
54 : std::shared_ptr<Socket> ClientInit(const HcclRootHandleV2 &rootHandle);
55 : void AddHostSocketWhitelist(SocketHandle &socketHandle, const std::vector<IpAddress> &hostSocketWlist);
56 : u32 GetHostListenPort();
57 : void GetRootHandle(HcclRootHandleV2 &rootHandle);
58 : SocketHandle GetHostSocketHandle();
59 :
60 : static UniversalConcurrentMap<u32, u32> g_detectServerStatus_;
61 : };
62 :
63 : } // namespace Hccl
64 :
65 : #endif // HCCL_VIRT_TOPO_DETECT_H
|