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