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_SQE_BUILD_A5_H
12 : #define HCCLV2_SQE_BUILD_A5_H
13 : #include "types.h"
14 : #include "ub_jetty_lite.h"
15 : #include "sqe_v82.h"
16 : #include "log.h"
17 :
18 : namespace Hccl {
19 :
20 : constexpr u32 LOW_BITS = 16;
21 :
22 : u32 GetKernelExecTimeoutFromEnvConfig();
23 :
24 44 : inline void SetSqeHeaderTaskFields(void* sqe, u32 taskId)
25 : {
26 44 : auto header = reinterpret_cast<Rt91095StarsSqeHeader*>(sqe);
27 44 : header->rtStreamId = static_cast<uint16_t>(taskId);
28 44 : header->taskId = static_cast<uint16_t>(taskId >> LOW_BITS);
29 44 : }
30 :
31 : inline void BuildA5SqeNotifyWait(u32 streamId, u32 taskId, u32 notifyId, uint8_t* const sqeIn)
32 : {
33 : (void)streamId;
34 : Rt91095StarsNotifySqe* sqe = (Rt91095StarsNotifySqe*)sqeIn;
35 : SetSqeHeaderTaskFields(sqe, taskId);
36 :
37 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT);
38 : sqe->header.wrCqe = 0U;
39 :
40 : sqe->cntFlag = false;
41 : sqe->clrFlag = true;
42 : sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_SINGLE_NOTIFY_WAIT);
43 : sqe->kernelCredit
44 : = RT_STARS_NEVER_TIMEOUT_KERNEL_CREDIT; // wait任务需要设置为0xff,否则会触发rtsq的超时机制,即使record了也wait不到
45 : sqe->notifyId = notifyId;
46 : sqe->timeout = GetKernelExecTimeoutFromEnvConfig();
47 : }
48 :
49 11 : inline void BuildA5SqeNotifyWait(u32 streamId, u32 taskId, u32 notifyId, u32 timeout, uint8_t* const sqeIn)
50 : {
51 : (void)streamId;
52 11 : Rt91095StarsNotifySqe* sqe = (Rt91095StarsNotifySqe*)sqeIn;
53 11 : SetSqeHeaderTaskFields(sqe, taskId);
54 :
55 11 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT);
56 11 : sqe->header.wrCqe = 0U;
57 :
58 11 : sqe->kernelCredit = RT_STARS_NEVER_TIMEOUT_KERNEL_CREDIT;
59 11 : sqe->cntFlag = false;
60 11 : sqe->clrFlag = true;
61 11 : sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_SINGLE_NOTIFY_WAIT);
62 11 : sqe->notifyId = notifyId;
63 11 : sqe->timeout = timeout;
64 11 : }
65 :
66 1 : inline void BuildA5SqeNotifyRecord(u32 streamId, u32 taskId, u32 notifyId, uint8_t* const sqeIn)
67 : {
68 : (void)streamId;
69 1 : Rt91095StarsNotifySqe* sqe = (Rt91095StarsNotifySqe*)sqeIn;
70 1 : SetSqeHeaderTaskFields(sqe, taskId);
71 :
72 1 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_RECORD);
73 1 : sqe->header.wrCqe = 0U;
74 :
75 1 : sqe->kernelCredit = RT_STARS_DEFAULT_KERNEL_CREDIT;
76 1 : sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_SINGLE_NOTIFY_RECORD);
77 1 : sqe->notifyId = notifyId;
78 1 : }
79 :
80 1 : inline void BuildA5SqeCnt1toNNotifyRecord(u32 streamId, u32 taskId, u32 notifyId, u32 cntValue, uint8_t* const sqeIn)
81 : {
82 : (void)streamId;
83 1 : Rt91095StarsNotifySqe* sqe = (Rt91095StarsNotifySqe*)sqeIn;
84 1 : SetSqeHeaderTaskFields(sqe, taskId);
85 :
86 1 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_RECORD);
87 1 : sqe->header.wrCqe = 0U;
88 :
89 1 : sqe->kernelCredit = RT_STARS_DEFAULT_KERNEL_CREDIT;
90 1 : sqe->clrFlag = false;
91 1 : sqe->cntFlag = true;
92 1 : sqe->recordModeBit = 0x0U;
93 1 : sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_COUNT_NOTIFY_RECORD);
94 1 : sqe->notifyId = notifyId;
95 1 : sqe->cntValue = cntValue;
96 1 : }
97 :
98 1 : inline void BuildA5SqeCnt1toNNotifyWait(u32 streamId, u32 taskId, u32 notifyId, u32 cntValue, uint8_t* const sqeIn)
99 : {
100 : (void)streamId;
101 1 : Rt91095StarsNotifySqe* sqe = (Rt91095StarsNotifySqe*)sqeIn;
102 1 : SetSqeHeaderTaskFields(sqe, taskId);
103 :
104 1 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT);
105 1 : sqe->header.wrCqe = 0U;
106 :
107 1 : sqe->kernelCredit = RT_STARS_NEVER_TIMEOUT_KERNEL_CREDIT;
108 1 : sqe->cntFlag = true;
109 1 : sqe->clrFlag = true;
110 1 : sqe->bitmap = 1U;
111 1 : sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_COUNT_NOTIFY_WAIT);
112 1 : sqe->notifyId = notifyId;
113 1 : sqe->cntValue = cntValue;
114 1 : }
115 :
116 1 : inline void BuildA5SqeCntNto1NotifyRecord(u32 streamId, u32 taskId, u32 notifyId, u32 cntValue, uint8_t* const sqeIn)
117 : {
118 : (void)streamId;
119 1 : Rt91095StarsNotifySqe* sqe = (Rt91095StarsNotifySqe*)sqeIn;
120 1 : SetSqeHeaderTaskFields(sqe, taskId);
121 :
122 1 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_RECORD);
123 1 : sqe->header.wrCqe = 0U;
124 1 : sqe->kernelCredit = RT_STARS_DEFAULT_KERNEL_CREDIT;
125 :
126 1 : sqe->clrFlag = false;
127 1 : sqe->cntFlag = true;
128 1 : sqe->recordModeBit = 0x2U;
129 1 : sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_COUNT_NOTIFY_RECORD);
130 1 : sqe->notifyId = notifyId;
131 1 : sqe->cntValue = cntValue;
132 1 : }
133 :
134 1 : inline void BuildA5SqeCntNto1NotifyWait(u32 streamId, u32 taskId, u32 notifyId, u32 cntValue, uint8_t* const sqeIn)
135 : {
136 : (void)streamId;
137 1 : Rt91095StarsNotifySqe* sqe = (Rt91095StarsNotifySqe*)sqeIn;
138 1 : SetSqeHeaderTaskFields(sqe, taskId);
139 :
140 1 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT);
141 1 : sqe->header.wrCqe = 0U;
142 :
143 1 : sqe->kernelCredit = RT_STARS_NEVER_TIMEOUT_KERNEL_CREDIT;
144 1 : sqe->cntFlag = true;
145 1 : sqe->clrFlag = true;
146 1 : sqe->waitModeBit = 0x1U;
147 1 : sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_COUNT_NOTIFY_WAIT);
148 1 : sqe->notifyId = notifyId;
149 1 : sqe->cntValue = cntValue;
150 1 : }
151 :
152 4 : inline void BuildA5SqeSdmaCopy(
153 : u32 streamId, u32 taskId, u64 dstAddr, u64 srcAddr, u32 size, u32 partId, u32 opcode, uint8_t* const sqeIn)
154 : {
155 : (void)streamId;
156 4 : Rt91095StarsMemcpySqe* sqe = (Rt91095StarsMemcpySqe*)sqeIn;
157 4 : SetSqeHeaderTaskFields(sqe, taskId);
158 :
159 4 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_SDMA);
160 4 : sqe->header.wrCqe = 0U;
161 :
162 4 : sqe->opcode = opcode;
163 4 : sqe->kernelCredit = RT_STARS_DEFAULT_KERNEL_CREDIT;
164 4 : sqe->sssv = 1U;
165 4 : sqe->dssv = 1U;
166 4 : sqe->sns = 1U;
167 4 : sqe->dns = 1U;
168 4 : sqe->mapamPartId = partId;
169 :
170 4 : sqe->u.strideMode0.lengthMove = size;
171 4 : sqe->u.strideMode0.srcAddrLow = static_cast<uint32_t>(srcAddr & 0x00000000ffffffffU);
172 4 : sqe->u.strideMode0.srcAddrHigh = static_cast<uint32_t>((srcAddr & 0xffffffff00000000U) >> 32);
173 4 : sqe->u.strideMode0.dstAddrLow = static_cast<uint32_t>(dstAddr & 0x00000000ffffffffU);
174 4 : sqe->u.strideMode0.dstAddrHigh = static_cast<uint32_t>((dstAddr & 0xffffffff00000000U) >> 32);
175 4 : }
176 :
177 : inline void
178 2 : BuildA5SqeUbDbSend(u32 streamId, u32 taskId, const UbJettyLiteId& jettyLiteId, u16 piValue, uint8_t* const sqeIn)
179 : {
180 : (void)streamId;
181 2 : Rt91095StarsUbdmaDBmodeSqe* sqe = (Rt91095StarsUbdmaDBmodeSqe*)sqeIn;
182 2 : SetSqeHeaderTaskFields(sqe, taskId);
183 :
184 2 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_UBDMA);
185 :
186 2 : sqe->mode = Rt91095UbDmaSqeMode::RT_91095_SQE_DOORBELL_MODE;
187 2 : sqe->kernelCredit = RT_STARS_DEFAULT_KERNEL_CREDIT;
188 2 : sqe->doorbellNum = 1U;
189 2 : sqe->jettyId1 = jettyLiteId.GetJettyId();
190 2 : sqe->funcId1 = jettyLiteId.GetFuncId();
191 2 : sqe->piValue1 = piValue;
192 2 : sqe->dieId1 = jettyLiteId.GetDieId();
193 2 : }
194 :
195 0 : inline void BuildA5SqeP2pWriteValue(u32 streamId, u32 taskId, u64 remoteAddr, u32 writeValue, uint8_t* const sqeIn)
196 : {
197 : (void)streamId;
198 0 : Rt91095StarsWriteValueSqe* sqe = reinterpret_cast<Rt91095StarsWriteValueSqe*>(sqeIn);
199 0 : SetSqeHeaderTaskFields(sqe, taskId);
200 :
201 0 : sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_WRITE_VALUE);
202 :
203 0 : sqe->kernelCredit = RT_STARS_DEFAULT_KERNEL_CREDIT;
204 0 : sqe->writeAddrLow = remoteAddr & MASK_32_BIT;
205 0 : sqe->writeAddrHigh = (remoteAddr >> UINT32_BIT_NUM) & MASK_17_BIT;
206 0 : sqe->awsize = RtStarsWriteValueSizeType::RT_STARS_WRITE_VALUE_SIZE_TYPE_32BIT;
207 0 : sqe->writeValuePart[0] = writeValue;
208 0 : sqe->va = 1;
209 0 : }
210 :
211 : u32 GetKernelExecTimeoutFromEnvConfig();
212 :
213 : void BuildA5SqeCCoreNotifyWait(u32 streamId, u32 taskId, u64 waitAddr, u64 actAddr, bool last, uint8_t* const sqeIn);
214 :
215 : void BuildA5SqeCCoreNotifyRecord(u32 streamId, u32 taskId, u64 writeAddr, u64 valueAddr, uint8_t* const sqeIn);
216 :
217 : void BuildA5SqeRdmaDbSend(u32 streamId, u32 taskId, u64 dbAddr, u64 dbValue, uint8_t* const sqeIn);
218 :
219 : } // namespace Hccl
220 :
221 : #endif
|