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