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