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 : #ifndef DEV_RDMA_CONNECTION_V2_H
11 : #define DEV_RDMA_CONNECTION_V2_H
12 :
13 : #include "hccp_common.h"
14 : #include "enum_factory.h"
15 : #include "hccl_common.h"
16 : #include "mem_device_pub.h"
17 : #include "../host/exchange_rdma_conn_dto.h"
18 : #include "orion_adapter_hccp.h"
19 : #include "hcomm/hcomm_res_entity_defs.h"
20 :
21 : // Orion
22 : #include "../../../../../legacy/ascend950/unified_platform/resource/socket/socket.h"
23 : #include "hccp_nda.h"
24 :
25 : namespace hcomm {
26 : class DevRdmaConnectionV2 {
27 : public:
28 : struct QpAttrDto {
29 : uint32_t qpn{UINT32_MAX};
30 : uint32_t psn{UINT32_MAX};
31 : uint32_t gid_idx{0};
32 : unsigned char gid[HCCP_GID_RAW_LEN];
33 :
34 5 : bool IsValid()
35 : {
36 5 : if (qpn == UINT32_MAX || psn == UINT32_MAX) {
37 3 : return false;
38 : }
39 2 : return true;
40 : }
41 : };
42 315 : MAKE_ENUM(RdmaConnStatus, CLOSED, INIT, QP_CREATED, QP_MODIFIED, SOCKET_TIMEOUT)
43 : DevRdmaConnectionV2(Hccl::Socket* socket, RdmaHandle rdmaHandle, uint32_t cqAttrFlags);
44 : ~DevRdmaConnectionV2();
45 :
46 : HcclResult Init();
47 : HcclResult CreateQp();
48 : HcclResult GetExchangeDto(std::unique_ptr<Hccl::Serializable>& serial);
49 : HcclResult ParseRmtExchangeDto(const Hccl::Serializable& rmtDto);
50 : HcclResult ModifyQp();
51 :
52 : std::string Describe() const;
53 35 : Hccl::QpInfo& GetQpInfo() { return qpInfo_; }
54 :
55 : HcclResult BuildSqContext(SqContext* context);
56 : HcclResult BuildCqContext(CqContext* context);
57 :
58 : std::vector<char> GetUniqueId() const;
59 :
60 : private:
61 : void GetNdaOps();
62 : HcclResult GetDirectFlag();
63 : HcclResult GetDmaMode();
64 : HcclResult DestroyQp();
65 :
66 : std::vector<char> GetSqUniqueId() const;
67 : std::vector<char> GetCqUniqueId() const;
68 :
69 : Hccl::Socket* socket_{nullptr};
70 : Hccl::RdmaHandle rdmaHandle_{nullptr};
71 : int32_t directFlag_{0};
72 : uint32_t dmaMode_{0};
73 : uint32_t cqAttrFlags_{0};
74 : NdaOps ndaOps_{};
75 :
76 : Hccl::QpHandle qpHandle_;
77 : NdaQpInfo ndaQpInfo_;
78 : Hccl::CqHandle cqHandle_;
79 : NdaCqInfo ndaCqInfo_;
80 :
81 : RdmaConnStatus rdmaConnStatus_{RdmaConnStatus::CLOSED};
82 : QpAttrDto rmtQpAttr_{};
83 : QpAttrDto locQpAttr_{};
84 : Hccl::QpInfo qpInfo_{};
85 :
86 : hccl::DeviceMem SqPiMem_;
87 : hccl::DeviceMem SqCiMem_;
88 : hccl::DeviceMem CqPiMem_;
89 : hccl::DeviceMem CqCiMem_;
90 : };
91 :
92 : } // namespace hcomm
93 :
94 : #endif // DEV_RDMA_CONNECTION_V2_H
|