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 HCCL_NETWORK_H
12 : #define HCCL_NETWORK_H
13 :
14 : #include "hccl_network_pub.h"
15 : #include "hccl_common.h"
16 : #include "hccl_ip_address.h"
17 : #include "hccl_net_dev.h"
18 : #include "rma_buffer_mgr.h"
19 : #include "local_ipc_rma_buffer.h"
20 : #include "local_rdma_rma_buffer.h"
21 :
22 : namespace hccl {
23 : class NetDevContext {
24 : public:
25 : using LocalIpcRmaBufferMgr = hcomm::RmaBufferMgr<BufferKey<uintptr_t, u64>, std::shared_ptr<LocalIpcRmaBuffer>>;
26 : using LocalRdmaRmaBufferMgr = hcomm::RmaBufferMgr<BufferKey<uintptr_t, u64>, std::shared_ptr<LocalRdmaRmaBuffer>>;
27 :
28 387 : NetDevContext() {}
29 379 : ~NetDevContext() {}
30 : HcclResult Init(
31 : NicType nicType, s32 devicePhyId, s32 deviceLogicId, HcclIpAddress localIp,
32 : HcclIpAddress backupIp = HcclIpAddress(0));
33 : HcclResult Deinit();
34 : HcclResult InitV2(const HcclNetDevInfos* info);
35 : HcclResult GetinfoConfig(const HcclNetDevInfos* info);
36 : HcclResult ConvertIP(const HcclAddress address);
37 : HcclResult DeinitV2();
38 : void SetTlsStatus(TlsStatus tlsStatus);
39 : void SetIsNotNeedGetTlsStatus(bool isNotNeedGetTlsStatus);
40 : std::mutex mu_;
41 :
42 347 : NicType GetNicType() const { return nicType_; }
43 :
44 558 : HcclIpAddress GetLocalIp() const { return localIp_; }
45 :
46 260 : HcclIpAddress GetBackupIp() const { return backupIp_; }
47 :
48 301 : s32 GetPhyId() const { return devicePhyId_; }
49 :
50 277 : s32 GetLogicId() const { return deviceLogicId_; }
51 0 : HcclNetDevDeployment GetNetDevDeployment() const { return netDevDeployment_; }
52 :
53 0 : bool GetIsBackup() const { return isBackup_; }
54 13 : NICDeployment GetNicDeployment() const { return nicDeployment_; }
55 38 : bool IsNotNeedGetTlsStatus() { return isNotNeedGetTlsStatus_; }
56 38 : TlsStatus GettlsStatus() { return tlsStatus_; }
57 20 : HcclProtoType GetProtoType() const { return protoType_; }
58 0 : void SetProtoType(u32 proto) { protoType_ = (HcclProtoType)proto; }
59 :
60 50 : std::shared_ptr<LocalIpcRmaBufferMgr> GetlocalIpcRmaBufferMgr()
61 : {
62 50 : if (!localIpcRmaBufferMgr_) {
63 10 : EXCEPTION_CATCH((localIpcRmaBufferMgr_ = std::make_shared<LocalIpcRmaBufferMgr>()), return nullptr);
64 : }
65 50 : return localIpcRmaBufferMgr_;
66 : }
67 :
68 0 : std::shared_ptr<LocalRdmaRmaBufferMgr> GetlocalRdmaRmaBufferMgr()
69 : {
70 0 : if (!localRdmaRmaBufferMgr_) {
71 0 : EXCEPTION_CATCH((localRdmaRmaBufferMgr_ = std::make_shared<LocalRdmaRmaBufferMgr>()), return nullptr);
72 : }
73 0 : return localRdmaRmaBufferMgr_;
74 : }
75 :
76 : private:
77 : NICDeployment nicDeployment_;
78 : s32 devicePhyId_;
79 : s32 deviceLogicId_;
80 : HcclIpAddress localIp_;
81 : HcclIpAddress backupIp_;
82 : NicType nicType_;
83 : bool isHostUseDevNic_{false};
84 : SocketHandle hostSocketHandle_{nullptr};
85 : HcclProtoType protoType_{HCCL_PROTO_TYPE_RESERVED};
86 : HcclNetDevDeployment netDevDeployment_;
87 : void* handle_{nullptr};
88 : bool isBackup_;
89 : TlsStatus tlsStatus_ = TlsStatus::UNKNOWN;
90 : bool isNotNeedGetTlsStatus_ = false;
91 : std::shared_ptr<LocalIpcRmaBufferMgr> localIpcRmaBufferMgr_{nullptr};
92 : std::shared_ptr<LocalRdmaRmaBufferMgr> localRdmaRmaBufferMgr_{nullptr};
93 : };
94 : } // namespace hccl
95 :
96 : #endif
|