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 HCCLV2_REMOTE_RMA_BUFFER_H
12 : #define HCCLV2_REMOTE_RMA_BUFFER_H
13 :
14 : #include "orion_adapter_hccp.h"
15 : #include "orion_adapter_rts.h"
16 : #include "rma_type.h"
17 : #include "serializable.h"
18 : #include <hcomm_res_defs.h>
19 : #include "hccl_mem_defs.h"
20 : namespace Hccl {
21 :
22 : class RemoteRmaBuffer {
23 : public:
24 94 : explicit RemoteRmaBuffer(const RmaType rmaType) : rmaType(rmaType)
25 : {
26 94 : }
27 :
28 94 : virtual ~RemoteRmaBuffer() = default;
29 :
30 4 : RmaType GetRmaType() const
31 : {
32 4 : return rmaType;
33 : }
34 :
35 74 : inline uintptr_t GetAddr() const
36 : {
37 74 : return addr;
38 : }
39 :
40 51 : inline u64 GetSize() const
41 : {
42 51 : return size;
43 : }
44 :
45 20 : inline HcclMemType GetMemType() const
46 : {
47 20 : return memType;
48 : }
49 :
50 21 : inline const std::string GetMemInfo() const
51 : {
52 21 : return memInfo;
53 : }
54 :
55 17 : u64 GetMemHandle() const
56 : {
57 17 : return memHandle;
58 : }
59 :
60 : virtual std::string Describe() const = 0;
61 :
62 : protected:
63 : uintptr_t addr{0};
64 : u64 size{0};
65 : RmaType rmaType;
66 : HcclMemType memType;
67 : std::string memInfo;
68 : u64 memHandle{0};
69 : };
70 :
71 : class RemoteIpcRmaBuffer : public RemoteRmaBuffer {
72 : public:
73 : RemoteIpcRmaBuffer();
74 :
75 : explicit RemoteIpcRmaBuffer(const Serializable &rmtDto);
76 :
77 : RemoteIpcRmaBuffer(const Serializable &rmtDto, const std::string tag);
78 :
79 : ~RemoteIpcRmaBuffer() override;
80 :
81 : RemoteIpcRmaBuffer(const RemoteIpcRmaBuffer &that) = delete;
82 :
83 : RemoteIpcRmaBuffer &operator=(const RemoteIpcRmaBuffer &that) = delete;
84 :
85 : std::string Describe() const override;
86 :
87 : private:
88 : void Close() const;
89 :
90 : char ipcName[RTS_IPC_MEM_NAME_LEN]{0};
91 : u64 ipcAddr{0};
92 : u64 ipcOffset{0};
93 : void *ipcPtr{};
94 : u32 remotePid{0};
95 : u32 myPid{0};
96 : bool isOpened;
97 : };
98 :
99 : class RemoteRdmaRmaBuffer : public RemoteRmaBuffer {
100 : public:
101 : explicit RemoteRdmaRmaBuffer(RdmaHandle rdmaHandle);
102 :
103 : RemoteRdmaRmaBuffer(RdmaHandle rdmaHandle, const Serializable &rmtDto);
104 :
105 : ~RemoteRdmaRmaBuffer() override;
106 :
107 : RemoteRdmaRmaBuffer(const RemoteRdmaRmaBuffer &that) = delete;
108 :
109 : RemoteRdmaRmaBuffer &operator=(const RemoteRdmaRmaBuffer &that) = delete;
110 :
111 : std::string Describe() const override;
112 :
113 : const u8 *GetKey() const
114 : {
115 : return key;
116 : }
117 :
118 17 : u32 GetRkey() const
119 : {
120 17 : return rkey;
121 : }
122 :
123 : private:
124 : RdmaHandle rdmaHandle{nullptr};
125 : u8 exchangedKey[RDMA_MEM_KEY_MAX_LEN]{0};
126 : u8 key[RDMA_MEM_KEY_MAX_LEN]{0};
127 : u32 keyValidLen{0};
128 : u32 rkey{0};
129 : };
130 :
131 : class RemoteUbRmaBuffer : public RemoteRmaBuffer {
132 : public:
133 : explicit RemoteUbRmaBuffer(RdmaHandle rdmaHandle);
134 :
135 : RemoteUbRmaBuffer(uintptr_t addr, u64 size, u32 tokenId, u32 tokenValue, HcclMemType memType,
136 : const std::string &memInfo);
137 :
138 : RemoteUbRmaBuffer(RdmaHandle rdmaHandle1, const Serializable &rmtDto);
139 :
140 : ~RemoteUbRmaBuffer() override;
141 :
142 : RemoteUbRmaBuffer(const RemoteUbRmaBuffer &that) = delete;
143 :
144 : RemoteUbRmaBuffer &operator=(const RemoteUbRmaBuffer &that) = delete;
145 :
146 : std::string Describe() const final;
147 :
148 7 : uint32_t GetTokenId() const
149 : {
150 7 : return tokenId;
151 : }
152 :
153 7 : uint32_t GetTokenValue() const
154 : {
155 7 : return tokenValue;
156 : }
157 :
158 0 : uint64_t GetSegVa() const
159 : {
160 0 : return segVa;
161 : }
162 :
163 5 : uint32_t GetNotifyId() const
164 : {
165 5 : return notifyId;
166 : }
167 :
168 : private:
169 : RdmaHandle rdmaHandle{nullptr};
170 : u8 key[HRT_UB_MEM_KEY_MAX_LEN]{0};
171 : u32 tokenId{0};
172 : u32 tokenValue{0};
173 : u32 keySize{0};
174 : u64 segVa{0};
175 : u32 notifyId{UINT32_MAX};
176 : };
177 :
178 : } // namespace Hccl
179 : #endif
|