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 TRANSPORT_HETEROG_DEF_H
12 : #define TRANSPORT_HETEROG_DEF_H
13 :
14 : #include <hccl/hccl_types.h>
15 : #include "hccl/base.h"
16 : #include "sal_pub.h"
17 : #include "mr_manager.h"
18 : #include "memory_alloc_ring.h"
19 : #include "heterog_mem_blocks_manager_pub.h"
20 : #include <memory>
21 :
22 : namespace hccl {
23 : constexpr s64 DEFAULT_GLOBAL_STEP_VALUE = -1;
24 : constexpr u32 DEFAULT_TABLE_ID_VALUE = 0;
25 :
26 : constexpr u32 HCCL_TEST_INCOMPLETED = 0;
27 : constexpr u32 HCCL_TEST_COMPLETED = 1;
28 : constexpr u32 HCCL_IMPROBE_INCOMPLETED = 0;
29 : constexpr u32 HCCL_IMPROBE_COMPLETED = 1;
30 :
31 : using CommHandle = void*;
32 : using TransportHandle = void*;
33 :
34 : enum class HcclHeterogCommType : s32 { INVALID = 0, PCIE = 1, RDMA = 2 };
35 :
36 : using MemType = enum TagMemType {
37 : USER_INPUT_MEM,
38 : USER_OUTPUT_MEM,
39 : DATA_NOTIFY_MEM,
40 : ACK_NOTIFY_MEM,
41 : DATA_ACK_NOTIFY_MEM,
42 : MULTI_QP_DATA_NOTIFY_MEM,
43 : NOTIFY_SRC_MEM,
44 : ENVELOPE_SHM_MEM,
45 : SEND_NOTIFY_MEM,
46 : RECV_NOTIFY_MEM,
47 : NOTIFY_VALUE_MEM,
48 : RESPONCE_MEM,
49 : RESPONCE_VALUE_MEM,
50 : RESPONCE_CANCEL_VALUE_MEM,
51 : MUILT_NOTIFY_MEM,
52 : AICPU_SYNC_MEM,
53 : MEM_TYPE_RESERVED
54 : };
55 :
56 : enum class HcclRequestType { HCCL_REQUEST_SEND, HCCL_REQUEST_RECV, HCCL_REQUEST_INVAIL };
57 :
58 : using TransData = struct TransDataDef {
59 : u64 srcBuf;
60 : u64 dstBuf;
61 : u64 count;
62 : u32 dataType;
63 : bool errorFlag;
64 : u32 tableId;
65 : s64 globalStep;
66 :
67 0 : TransDataDef()
68 0 : : srcBuf(0),
69 0 : dstBuf(0),
70 0 : count(0),
71 0 : dataType(HCCL_DATA_TYPE_RESERVED),
72 0 : errorFlag(false),
73 0 : tableId(DEFAULT_TABLE_ID_VALUE),
74 0 : globalStep(DEFAULT_GLOBAL_STEP_VALUE)
75 0 : {}
76 0 : TransDataDef(
77 : u64 srcBuf, u64 dstBuf, u64 count, HcclDataType dataType, bool errorFlag = false,
78 : u32 tableId = DEFAULT_TABLE_ID_VALUE, s64 globalStep = DEFAULT_GLOBAL_STEP_VALUE)
79 0 : : srcBuf(srcBuf),
80 0 : dstBuf(dstBuf),
81 0 : count(count),
82 0 : dataType(dataType),
83 0 : errorFlag(errorFlag),
84 0 : tableId(tableId),
85 0 : globalStep(globalStep)
86 0 : {}
87 : };
88 :
89 : using TransportEndPointInfo = struct TransportEndPointInfoDef {
90 : u32 commId; // 该rank所在通信域的通信域ID
91 : u32 rank; // 该rank所在通信域内的user rank
92 : s32 tag; // 通信使用的user tag
93 :
94 0 : TransportEndPointInfoDef() : commId(0), rank(INVALID_VALUE_RANKID), tag(-1) {}
95 0 : TransportEndPointInfoDef(u32 commId, u32 rank, s32 tag) : commId(commId), rank(rank), tag(tag) {}
96 0 : bool operator==(const TransportEndPointInfoDef& that) const
97 : {
98 0 : return ((this->commId == that.commId) && (this->rank == that.rank) && (this->tag == that.tag));
99 : }
100 : };
101 :
102 : using TransportEndPointParam = struct TransportEndPointParamDef {
103 : TransportEndPointInfo src;
104 : TransportEndPointInfo dst;
105 :
106 0 : TransportEndPointParamDef() : src(), dst() {}
107 0 : TransportEndPointParamDef(TransportEndPointInfo& src, TransportEndPointInfo& dst) : src(src), dst(dst) {}
108 : };
109 :
110 : using TransportRequestInfo = struct TransportRequestInfoDef {
111 : TransData transData;
112 : TransportEndPointParam epParam;
113 : HcclRequestType requestType;
114 : u8 protocol; // rendezvous:0; eager:1
115 : u64 msn;
116 : s32 status;
117 : u64 envoffset;
118 : u64 tranoffset;
119 :
120 0 : TransportRequestInfoDef()
121 0 : : requestType(HcclRequestType::HCCL_REQUEST_INVAIL),
122 0 : protocol(0),
123 0 : msn(0),
124 0 : status(-1),
125 0 : envoffset(0),
126 0 : tranoffset(0)
127 0 : {}
128 : };
129 :
130 : struct HcclRequestInfo {
131 : s32 tag;
132 : CommHandle commHandle;
133 : TransportHandle transportHandle;
134 : TransportRequestInfo transportRequest;
135 : HcclRequestInfo* next;
136 0 : HcclRequestInfo() : tag(INVALID_INT), commHandle(nullptr), transportHandle(nullptr) {}
137 : };
138 :
139 : using HcclUserRequire = struct HcclUserRequireDef {
140 : u32 tableId;
141 : s64 globalStep;
142 : HcclUserRequireDef() : tableId(DEFAULT_TABLE_ID_VALUE), globalStep(DEFAULT_GLOBAL_STEP_VALUE) {}
143 : HcclUserRequireDef(u32 tableId, s64 globalStep = DEFAULT_GLOBAL_STEP_VALUE)
144 : : tableId(tableId),
145 : globalStep(globalStep)
146 : {}
147 : };
148 :
149 : using HcclEnvelope = struct HcclEnvelopeDef {
150 : u8 protocol; // rendezvous:0; eager:1
151 : TransData transData;
152 : TransportEndPointParam epParam;
153 : u32 key; // RDMA Read用的Key
154 : u64 msn; // 消息序列号
155 : u64 rsv[4]; // 临时驱动问题,保证128字节对齐,待驱动问题上线后,删除此代码。
156 0 : HcclEnvelopeDef() : protocol(0), key(0), msn(0) {}
157 0 : HcclEnvelopeDef(u8 protocol, TransData& transData, TransportEndPointParam& epParam, u32 key, u64 msn)
158 0 : : protocol(protocol),
159 0 : transData(transData),
160 0 : epParam(epParam),
161 0 : key(key),
162 0 : msn(msn)
163 0 : {}
164 : };
165 :
166 : struct HcclEsRdmaInfoForLookup {
167 : s32 errorStatus{};
168 : HcclHeterogCommType commType{};
169 : HcclEnvelope envelope{};
170 : };
171 :
172 : struct HcclEsRdmaInfoForUpdate : public HcclEsRdmaInfoForLookup {
173 : HcclEnvelope envelopeValue{};
174 : };
175 :
176 : using HcclEsRdmaInfo = HcclEsRdmaInfoForUpdate;
177 :
178 : using HcclEnvelopePcie = struct HcclEnvelopePcieDef {
179 : MemType memType;
180 : u64 offset;
181 : u64 count;
182 : u32 dataType;
183 : bool updateEndFlag; // embedding service update flag
184 : u32 tableId;
185 : s64 globalStep;
186 :
187 0 : HcclEnvelopePcieDef()
188 0 : : memType(USER_INPUT_MEM),
189 0 : offset(0),
190 0 : count(0),
191 0 : dataType(HCCL_DATA_TYPE_RESERVED),
192 0 : updateEndFlag(true),
193 0 : tableId(DEFAULT_TABLE_ID_VALUE),
194 0 : globalStep(DEFAULT_GLOBAL_STEP_VALUE)
195 0 : {}
196 : HcclEnvelopePcieDef(
197 : MemType memType, u64 offset, u64 count, u32 dataType, bool updateEndFlag = false,
198 : u32 tableId = DEFAULT_TABLE_ID_VALUE, s64 globalStep = DEFAULT_GLOBAL_STEP_VALUE)
199 : : memType(memType),
200 : offset(offset),
201 : count(count),
202 : dataType(dataType),
203 : updateEndFlag(updateEndFlag),
204 : tableId(tableId),
205 : globalStep(globalStep)
206 : {}
207 : };
208 :
209 : using HcclEnvelopeSummary = struct HcclEnvelopeSummaryDef {
210 : HcclEnvelope envelope;
211 : HcclEnvelopePcie pcieEnvelope;
212 : s32 status;
213 0 : HcclEnvelopeSummaryDef() : envelope(), status(0) {}
214 0 : HcclEnvelopeSummaryDef(HcclEnvelope& envelope, s32 status) : envelope(envelope), status(status) {}
215 : };
216 :
217 : using HcclMessageInfo = struct HcclMessageInfoDef {
218 : CommHandle commHandle;
219 : TransportHandle transportHandle;
220 : HcclEnvelopeSummary envelope;
221 0 : HcclMessageInfoDef() : commHandle(nullptr), transportHandle(nullptr) {}
222 : };
223 :
224 : struct RecvWrInfo {
225 : TransportHandle transportHandle = nullptr;
226 : void* buf = nullptr;
227 : };
228 : } // namespace hccl
229 : #endif
|