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_AICPU_WQEMGR_WQE_H
12 : #define HCCLV2_AICPU_WQEMGR_WQE_H
13 :
14 : #include <string>
15 : #include "string_util.h"
16 : #include "hccl/base.h"
17 : #include "enum_factory_legacy.h"
18 : #include "task_param.h"
19 : #include "ip_address.h"
20 :
21 : namespace Hccl {
22 :
23 : #define UDMA_SQE_RMT_EID_SIZE 4
24 :
25 312 : MAKE_ENUM(
26 : UdmaSqOpcode, UDMA_OPC_SEND, UDMA_OPC_SEND_WITH_IMM, UDMA_OPC_SEND_WITH_INVALID, UDMA_OPC_WRITE,
27 : UDMA_OPC_WRITE_WITH_IMM, UDMA_OPC_READ = 0x6, UDMA_OPC_CAS, UDMA_OPC_FAA = 0xb, UDMA_OPC_NOP = 0x11,
28 : UDMA_OPC_INVALID = 0x12)
29 :
30 : MAKE_ENUM(
31 : UdmaDataOp, REDUCE_OP_MAX = 0x8, REDUCE_OP_MIN = 0x9, REDUCE_OP_ADD = 0xA, REDUCE_OP_EQUAL = 0xB,
32 : REDUCE_OP_RESEVERD = 0xC)
33 :
34 : MAKE_ENUM(
35 : UdmaDataType, REDUCE_TYPE_INT8 = 0x0, REDUCE_TYPE_INT16 = 0X1, REDUCE_TYPE_INT32 = 0x2, REDUCE_TYPE_UINT32 = 0X5,
36 : REDUCE_TYPE_FP16_NORMAL = 0X6, REDUCE_TYPE_FP32 = 0X7, REDUCE_TYPE_FP16 = 0X8, REDUCE_TYPE_FP16_SAT = 0X9,
37 : REDUCE_TYPE_RESEVERD = 0XA)
38 :
39 : struct UdmaNormalSge {
40 : uint32_t length;
41 : uint32_t tokenId;
42 : uint32_t dataAddrLow;
43 : uint32_t dataAddrHigh;
44 :
45 : std::string Desc() const
46 : {
47 : constexpr uint64_t UINT32_BIT_WIDTH = 32;
48 : const uint64_t dataAddr
49 : = (static_cast<uint64_t>(dataAddrHigh) << UINT32_BIT_WIDTH) | static_cast<uint64_t>(dataAddrLow);
50 : return StringFormat(
51 : "length = %u dataAddrLow = %u dataAddrHigh = %u dataAddr = 0x%016llx", length, dataAddrLow, dataAddrHigh,
52 : static_cast<unsigned long long>(dataAddr));
53 : }
54 : };
55 :
56 : struct UdmaInlineData {
57 : u8 data[16];
58 : };
59 :
60 : struct UdfExtDate { // UDF扩展数据
61 : uint32_t udfType : 8;
62 : uint32_t reduceType : 4;
63 : uint32_t reduceOp : 4;
64 : uint32_t rsv : 16;
65 : };
66 :
67 : struct UdmaSqe {
68 : uint32_t sqeBbIdx : 16;
69 : uint32_t placeOdr : 2;
70 : uint32_t compOrder : 1;
71 : uint32_t fence : 1;
72 : uint32_t se : 1;
73 : uint32_t cqe : 1;
74 : uint32_t inlineEn : 1;
75 : uint32_t rsv : 5;
76 : uint32_t tokenEn : 1;
77 : uint32_t rmtJettyType : 2;
78 : uint32_t owner : 1;
79 : uint32_t targetHint : 8;
80 : uint32_t opcode : 8;
81 : uint32_t rsv1 : 6;
82 : uint32_t inlineMsgLen : 10;
83 : uint32_t tpn : 24;
84 : uint32_t sgeNum : 8;
85 : uint32_t rmtObjId : 20;
86 : uint32_t rsv2 : 12;
87 : uint32_t rmtEid[UDMA_SQE_RMT_EID_SIZE];
88 : uint32_t rmtTokenValue;
89 : union {
90 : uint32_t rsv3;
91 : UdfExtDate udfData;
92 : } inlinedata;
93 :
94 : uint32_t rmtAddrLow;
95 : uint32_t rmtAddrHigh;
96 : union {
97 : UdmaNormalSge sge;
98 : UdmaInlineData inlineData;
99 : } u;
100 : };
101 :
102 : union LocalValueU {
103 : UdmaNormalSge sge;
104 : UdmaInlineData inlineData;
105 : };
106 :
107 : struct UdmaSqeNotify {
108 : uint32_t notifyTokenId : 20;
109 : uint32_t rsv : 12;
110 : uint32_t notifyTokenValue;
111 : uint32_t notifyAddrLow;
112 : uint32_t notifyAddrHigh;
113 : uint32_t notifyDataLow;
114 : uint32_t notifyDataHigh;
115 : std::string Desc() const
116 : {
117 : return StringFormat(
118 : "notifyAddrLow = %u notifyAddrHigh %u notifyDataLow = %u "
119 : "notifyDataHigh %u",
120 : notifyAddrLow, notifyAddrHigh, notifyDataLow, notifyDataHigh);
121 : }
122 : };
123 :
124 : struct UdmaSqeCommon {
125 : uint32_t sqeBbIdx : 16;
126 : uint32_t placeOdr : 2;
127 : uint32_t compOrder : 1;
128 : uint32_t fence : 1;
129 : uint32_t se : 1;
130 : uint32_t cqe : 1;
131 : uint32_t inlineEn : 1;
132 : uint32_t udfFlag : 1;
133 : uint32_t rsv : 4;
134 : uint32_t tokenEn : 1;
135 : uint32_t rmtJettyType : 2;
136 : uint32_t owner : 1;
137 : uint32_t targetHint : 8;
138 : uint32_t opcode : 8;
139 : uint32_t rsv1 : 6;
140 : uint32_t inlineMsgLen : 10;
141 : uint32_t tpn : 24;
142 : uint32_t sgeNum : 8;
143 : uint32_t rmtObjId : 20;
144 : uint32_t rsv2 : 12;
145 : uint32_t rmtEid[UDMA_SQE_RMT_EID_SIZE];
146 : uint32_t rmtTokenValue;
147 : union {
148 : uint32_t rsv3;
149 : UdfExtDate udfData;
150 : } inlinedata;
151 :
152 : uint32_t rmtAddrLow;
153 : uint32_t rmtAddrHigh;
154 : };
155 :
156 : struct UdmaSqeWriteWithNotify {
157 : struct UdmaSqeCommon comm;
158 : struct UdmaSqeNotify notify;
159 : uint32_t rsv1;
160 : uint32_t rsv2;
161 : union LocalValueU localU;
162 : };
163 :
164 : struct UdmaSqeWrite {
165 : struct UdmaSqeCommon comm;
166 : union LocalValueU u;
167 : };
168 :
169 : struct UdmaSqeRead {
170 : struct UdmaSqeCommon comm;
171 : union LocalValueU u;
172 : };
173 :
174 : // 定义WqeTask用于aicpu task cache
175 : // 注意: 不需要额外维护wqeType指定struct, 因为所有struct开头都是UdmaSqeCommon, 可以利用opCode判断wqe类型
176 : union WqeTask {
177 : struct UdmaSqeRead wqeRead; // 64B (48 + 16); ub_conn_lite.cc中暂不使用UdmaSqeRead
178 : struct UdmaSqeWrite wqeWrite; // 64B (48 + 16)
179 : struct UdmaSqeWriteWithNotify wqeWriteWithNotify; // 96B (48 + 32 + 16)
180 :
181 18 : WqeTask() {}
182 48 : ~WqeTask() {}
183 :
184 : explicit WqeTask(const struct UdmaSqeRead& tmpWqeRead) : wqeRead(tmpWqeRead) {}
185 0 : explicit WqeTask(const struct UdmaSqeWrite& tmpWqeWrite) : wqeWrite(tmpWqeWrite) {}
186 0 : explicit WqeTask(const struct UdmaSqeWriteWithNotify& tmpWqeWriteWithNotify)
187 0 : : wqeWriteWithNotify(tmpWqeWriteWithNotify)
188 0 : {}
189 : };
190 :
191 : // 记录DbSqe TaskParam中, 与WQE相关的profiling信息, 用于aicpu task cache适配profiling
192 : struct DbSqeProfInfo {
193 : bool isValid = false;
194 : TaskParamType taskParamType;
195 : uint64_t srcAddr; // TASK_UB, TASK_UB_REDUCE_INLINE, TASK_WRITE_WITH_NOTIFY, TASK_WRITE_REDUCE_WITH_NOTIFY
196 : uint64_t dstAddr; // TASK_UB_INLINE_WRITE, TASK_UB, TASK_UB_REDUCE_INLINE, TASK_WRITE_WITH_NOTIFY,
197 : // TASK_WRITE_REDUCE_WITH_NOTIFY
198 : uint64_t size; // TASK_UB_INLINE_WRITE, TASK_UB, TASK_UB_REDUCE_INLINE, TASK_WRITE_WITH_NOTIFY,
199 : // TASK_WRITE_REDUCE_WITH_NOTIFY
200 : Eid locEid; // TASK_UB_INLINE_WRITE, TASK_UB, TASK_UB_REDUCE_INLINE, TASK_WRITE_WITH_NOTIFY,
201 : // TASK_WRITE_REDUCE_WITH_NOTIFY
202 : Eid rmtEid; // TASK_UB_INLINE_WRITE, TASK_UB, TASK_UB_REDUCE_INLINE, TASK_WRITE_WITH_NOTIFY,
203 : // TASK_WRITE_REDUCE_WITH_NOTIFY
204 : DmaOp dmaOp; // TASK_UB
205 : HcclReduceOp reduceOp; // TASK_UB_REDUCE_INLINE, TASK_WRITE_REDUCE_WITH_NOTIFY
206 : HcclDataType dataType; // TASK_UB_REDUCE_INLINE, TASK_WRITE_REDUCE_WITH_NOTIFY
207 : u64 notifyId; // TASK_UB_INLINE_WRITE, TASK_WRITE_WITH_NOTIFY, TASK_WRITE_REDUCE_WITH_NOTIFY
208 : uint64_t jettyHandle{0}; // TASK_UB_INLINE_WRITE
209 : uint32_t jettyId{0}; // TASK_UB_INLINE_WRITE, TASK_UB, TASK_UB_REDUCE_INLINE, TASK_WRITE_WITH_NOTIFY,
210 : // TASK_WRITE_REDUCE_WITH_NOTIFY
211 : };
212 :
213 : } // namespace Hccl
214 : #endif // HCCL_AICPU_RESOURCE_AI_CPU_RESOUCES_H_
|