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 : /*!
12 : * \file kernel_check_vec_select_util.h
13 : * \brief
14 : */
15 :
16 : #ifndef ASCENDC_CHECK_VEC_SELECT_UTIL_H
17 : #define ASCENDC_CHECK_VEC_SELECT_UTIL_H
18 : #if ASCENDC_CPU_DEBUG
19 : #include <string>
20 : #include "kernel_utils.h"
21 : namespace AscendC {
22 : namespace check {
23 :
24 : struct VecSelectApiParams {
25 : VecSelectApiParams() {}
26 : VecSelectApiParams(
27 : uint64_t dstAddrIn, uint64_t selMaskAddrIn, uint64_t src0AddrIn, uint64_t src1AddrIn, uint8_t repeatIn,
28 : uint16_t dstBlockStrideIn, uint16_t src0BlockStrideIn, uint16_t src1BlockStrideIn, uint16_t dstRepeatStrideIn,
29 : uint16_t src0RepeatStrideIn, uint16_t src1RepeatStrideIn, uint32_t dstDtypeBytesIn,
30 : uint32_t selMaskDtypeBytesIn, uint32_t src0DtypeBytesIn, uint32_t src1DtypeBytesIn, uint64_t dstSizeIn,
31 : uint64_t selMaskSizeIn, uint64_t src0SizeIn, uint64_t src1SizeIn, uint8_t dstPosIn, uint8_t selMaskIn,
32 : uint8_t src0PosIn, uint8_t src1PosIn)
33 : {
34 : dstAddr = dstAddrIn;
35 : selMaskAddr = selMaskAddrIn;
36 : src0Addr = src0AddrIn;
37 : src1Addr = src1AddrIn;
38 : repeatTimes = repeatIn;
39 : dstBlockStride = dstBlockStrideIn;
40 : src0BlockStride = src0BlockStrideIn;
41 : src1BlockStride = src1BlockStrideIn;
42 : dstRepeatStride = dstRepeatStrideIn;
43 : src0RepeatStride = src0RepeatStrideIn;
44 : src1RepeatStride = src1RepeatStrideIn;
45 : dstDtypeBytes = dstDtypeBytesIn;
46 : selMaskDtypeBytes = selMaskDtypeBytesIn;
47 : src0DtypeBytes = src0DtypeBytesIn;
48 : src1DtypeBytes = src1DtypeBytesIn;
49 : dstSize = dstSizeIn;
50 : selMaskSize = selMaskSizeIn;
51 : src0Size = src0SizeIn;
52 : src1Size = src1SizeIn;
53 : dstLogicPos = dstPosIn;
54 : selMaskLogicPos = selMaskIn;
55 : src0LogicPos = src0PosIn;
56 : src1LogicPos = src1PosIn;
57 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
58 : selMaskPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(selMaskIn)));
59 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
60 : src1Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src1PosIn)));
61 : }
62 :
63 : VecSelectApiParams(
64 : uint64_t dstAddrIn, uint64_t selMaskAddrIn, uint64_t src0AddrIn, uint64_t src1AddrIn, uint32_t dstDtypeBytesIn,
65 : uint32_t selMaskDtypeBytesIn, uint32_t src0DtypeBytesIn, uint32_t src1DtypeBytesIn, uint64_t dstSizeIn,
66 : uint64_t selMaskSizeIn, uint64_t src0SizeIn, uint64_t src1SizeIn, uint8_t dstPosIn, uint8_t selMaskIn,
67 : uint8_t src0PosIn, uint8_t src1PosIn, uint32_t count)
68 : {
69 : dstAddr = dstAddrIn;
70 : selMaskAddr = selMaskAddrIn;
71 : src0Addr = src0AddrIn;
72 : src1Addr = src1AddrIn;
73 : dstDtypeBytes = dstDtypeBytesIn;
74 : selMaskDtypeBytes = selMaskDtypeBytesIn;
75 : src0DtypeBytes = src0DtypeBytesIn;
76 : src1DtypeBytes = src1DtypeBytesIn;
77 : dstSize = dstSizeIn;
78 : selMaskSize = selMaskSizeIn;
79 : src0Size = src0SizeIn;
80 : src1Size = src1SizeIn;
81 : dstLogicPos = dstPosIn;
82 : selMaskLogicPos = selMaskIn;
83 : src0LogicPos = src0PosIn;
84 : src1LogicPos = src1PosIn;
85 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
86 : selMaskPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(selMaskIn)));
87 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
88 : src1Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src1PosIn)));
89 : calCount = count;
90 : }
91 :
92 : uint64_t dstAddr = 0;
93 : uint64_t selMaskAddr = 0;
94 : uint64_t src0Addr = 0;
95 : uint64_t src1Addr = 0;
96 : uint8_t repeatTimes = 0;
97 : uint16_t dstBlockStride = 0;
98 : uint16_t src0BlockStride = 0;
99 : uint16_t src1BlockStride = 0;
100 : uint16_t dstRepeatStride = 0;
101 : uint16_t src0RepeatStride = 0;
102 : uint16_t src1RepeatStride = 0;
103 : uint32_t dstDtypeBytes = 0;
104 : uint32_t selMaskDtypeBytes = 0;
105 : uint32_t src0DtypeBytes = 0;
106 : uint32_t src1DtypeBytes = 0;
107 : uint64_t dstSize = 0;
108 : uint64_t selMaskSize = 0;
109 : uint64_t src0Size = 0;
110 : uint64_t src1Size = 0;
111 : uint8_t dstLogicPos = 0;
112 : uint8_t selMaskLogicPos = 0;
113 : uint8_t src0LogicPos = 0;
114 : uint8_t src1LogicPos = 0;
115 : uint8_t dstPos = 0;
116 : uint8_t selMaskPos = 0;
117 : uint8_t src0Pos = 0;
118 : uint8_t src1Pos = 0;
119 : uint32_t calCount = 0;
120 : };
121 :
122 : struct VecGatherApiParams {
123 : VecGatherApiParams() {}
124 20 : VecGatherApiParams(
125 : uint64_t dstAddrIn, uint64_t srcAddrIn, uint64_t offsetAddrIn, uint8_t repeatIn, uint16_t dstBlockStrideIn,
126 : uint16_t dstRepeatStrideIn, uint32_t dstDtypeBytesIn, uint32_t srcDtypeBytesIn, uint32_t offsetDtypeBytesIn,
127 : uint64_t dstSizeIn, uint64_t srcSizeIn, uint64_t offsetSizeIn, uint8_t dstPosIn, uint8_t srcPosIn,
128 : uint8_t offsetPosIn)
129 20 : {
130 20 : dstAddr = dstAddrIn;
131 20 : srcAddr = srcAddrIn;
132 20 : offsetAddr = offsetAddrIn;
133 20 : repeatTimes = repeatIn;
134 20 : dstBlockStride = dstBlockStrideIn;
135 20 : dstRepeatStride = dstRepeatStrideIn;
136 20 : dstDtypeBytes = dstDtypeBytesIn;
137 20 : srcDtypeBytes = srcDtypeBytesIn;
138 20 : offsetDtypeBytes = offsetDtypeBytesIn;
139 20 : dstSize = dstSizeIn;
140 20 : srcSize = srcSizeIn;
141 20 : offsetSize = offsetSizeIn;
142 20 : dstLogicPos = dstPosIn;
143 20 : srcLogicPos = srcPosIn;
144 20 : offsetLogicPos = offsetPosIn;
145 20 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
146 20 : srcPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(srcPosIn)));
147 20 : offsetPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(offsetPosIn)));
148 20 : }
149 :
150 : VecGatherApiParams(
151 : uint64_t dstAddrIn, uint64_t srcAddrIn, uint64_t offsetAddrIn, uint32_t srcBaseOffsetIn, uint8_t repeatIn,
152 : uint16_t dstBlockStrideIn, uint16_t dstRepeatStrideIn, uint32_t dstDtypeBytesIn, uint32_t srcDtypeBytesIn,
153 : uint32_t offsetDtypeBytesIn, uint64_t dstSizeIn, uint64_t srcSizeIn, uint64_t offsetSizeIn, uint8_t dstPosIn,
154 : uint8_t srcPosIn, uint8_t offsetPosIn)
155 : {
156 : dstAddr = dstAddrIn;
157 : srcAddr = srcAddrIn;
158 : offsetAddr = offsetAddrIn;
159 : srcBaseOffset = srcBaseOffsetIn;
160 : repeatTimes = repeatIn;
161 : dstBlockStride = dstBlockStrideIn;
162 : dstRepeatStride = dstRepeatStrideIn;
163 : dstDtypeBytes = dstDtypeBytesIn;
164 : srcDtypeBytes = srcDtypeBytesIn;
165 : offsetDtypeBytes = offsetDtypeBytesIn;
166 : dstSize = dstSizeIn;
167 : srcSize = srcSizeIn;
168 : offsetSize = offsetSizeIn;
169 : dstLogicPos = dstPosIn;
170 : srcLogicPos = srcPosIn;
171 : offsetLogicPos = offsetPosIn;
172 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
173 : srcPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(srcPosIn)));
174 : offsetPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(offsetPosIn)));
175 : }
176 :
177 : VecGatherApiParams(
178 : uint64_t dstAddrIn, uint64_t srcAddrIn, uint64_t offsetAddrIn, uint32_t srcBaseOffsetIn,
179 : uint32_t dstDtypeBytesIn, uint32_t srcDtypeBytesIn, uint32_t offsetDtypeBytesIn, uint64_t dstSizeIn,
180 : uint64_t srcSizeIn, uint64_t offsetSizeIn, uint8_t dstPosIn, uint8_t srcPosIn, uint8_t offsetPosIn,
181 : uint32_t calCountIn)
182 : {
183 : dstAddr = dstAddrIn;
184 : srcAddr = srcAddrIn;
185 : offsetAddr = offsetAddrIn;
186 : srcBaseOffset = srcBaseOffsetIn;
187 : dstDtypeBytes = dstDtypeBytesIn;
188 : srcDtypeBytes = srcDtypeBytesIn;
189 : offsetDtypeBytes = offsetDtypeBytesIn;
190 : dstSize = dstSizeIn;
191 : srcSize = srcSizeIn;
192 : offsetSize = offsetSizeIn;
193 : dstLogicPos = dstPosIn;
194 : srcLogicPos = srcPosIn;
195 : offsetLogicPos = offsetPosIn;
196 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
197 : srcPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(srcPosIn)));
198 : offsetPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(offsetPosIn)));
199 : calCount = calCountIn;
200 : }
201 :
202 : uint64_t dstAddr = 0;
203 : uint64_t srcAddr = 0;
204 : uint64_t offsetAddr = 0;
205 : uint32_t srcBaseOffset = 0;
206 : uint8_t repeatTimes = 0;
207 : uint16_t dstBlockStride = 0;
208 : uint16_t dstRepeatStride = 0;
209 : uint32_t dstDtypeBytes = 0;
210 : uint32_t srcDtypeBytes = 0;
211 : uint32_t offsetDtypeBytes = 0;
212 : uint64_t dstSize = 0;
213 : uint64_t srcSize = 0;
214 : uint64_t offsetSize = 0;
215 : uint8_t dstLogicPos = 0;
216 : uint8_t srcLogicPos = 0;
217 : uint8_t offsetLogicPos = 0;
218 : uint8_t dstPos = 0;
219 : uint8_t srcPos = 0;
220 : uint8_t offsetPos = 0;
221 : uint32_t calCount = 0;
222 : };
223 :
224 : const uint8_t BLKSTR = 1;
225 : const uint8_t REPSTR = 8;
226 : const uint16_t REPSIZE = 256;
227 : struct VecGatherMaskApiParams {
228 : VecGatherMaskApiParams() {}
229 : VecGatherMaskApiParams(
230 : uint64_t dstAddrIn, uint64_t src0AddrIn, uint64_t src1AddrIn, bool reduceModeIn, uint8_t src0BlockStrideIn,
231 : uint16_t repeatTimesIn, uint16_t src0RepeatStrideIn, uint16_t src1RepeatStrideIn, uint64_t rsvdCntIn,
232 : uint32_t dstDtypeBytesIn, uint32_t src0DtypeBytesIn, uint32_t src1DtypeBytesIn, uint64_t dstSizeIn,
233 : uint64_t src0SizeIn, uint64_t src1SizeIn, uint8_t dstPosIn, uint8_t src0PosIn, uint8_t src1PosIn)
234 : {
235 : dstAddr = dstAddrIn;
236 : src0Addr = src0AddrIn;
237 : src1Addr = src1AddrIn;
238 : src1Pattern = 0;
239 : reduceMode = reduceModeIn;
240 : dstBlockStride = BLKSTR;
241 : src0BlockStride = src0BlockStrideIn;
242 : src1BlockStride = BLKSTR;
243 : repeatTimes = repeatTimesIn;
244 : dstRepeatStride = REPSTR;
245 : src0RepeatStride = src0RepeatStrideIn;
246 : src1RepeatStride = src1RepeatStrideIn;
247 : rsvdCnt = rsvdCntIn;
248 : dstDtypeBytes = dstDtypeBytesIn;
249 : src0DtypeBytes = src0DtypeBytesIn;
250 : src1DtypeBytes = src1DtypeBytesIn;
251 : dstSize = dstSizeIn;
252 : src0Size = src0SizeIn;
253 : src1Size = src1SizeIn;
254 : dstLogicPos = dstPosIn;
255 : src0LogicPos = src0PosIn;
256 : src1LogicPos = src1PosIn;
257 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
258 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
259 : src1Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src1PosIn)));
260 : }
261 :
262 : VecGatherMaskApiParams(
263 : uint64_t dstAddrIn, uint64_t src0AddrIn, uint8_t src1PatternIn, bool reduceModeIn, uint8_t src0BlockStrideIn,
264 : uint16_t repeatTimesIn, uint16_t src0RepeatStrideIn, uint16_t src1RepeatStrideIn, uint64_t rsvdCntIn,
265 : uint32_t dstDtypeBytesIn, uint32_t src0DtypeBytesIn, uint64_t dstSizeIn, uint64_t src0SizeIn, uint8_t dstPosIn,
266 : uint8_t src0PosIn)
267 : {
268 : dstAddr = dstAddrIn;
269 : src0Addr = src0AddrIn;
270 : src1Addr = src0AddrIn + REPSIZE * src0DtypeBytesIn;
271 : src1Pattern = src1PatternIn;
272 : reduceMode = reduceModeIn;
273 : dstBlockStride = BLKSTR;
274 : src0BlockStride = src0BlockStrideIn;
275 : src1BlockStride = BLKSTR;
276 : repeatTimes = repeatTimesIn;
277 : dstRepeatStride = REPSTR;
278 : src0RepeatStride = src0RepeatStrideIn;
279 : src1RepeatStride = src1RepeatStrideIn;
280 : rsvdCnt = rsvdCntIn;
281 : dstDtypeBytes = dstDtypeBytesIn;
282 : src0DtypeBytes = src0DtypeBytesIn;
283 : src1DtypeBytes = src0DtypeBytesIn;
284 : dstSize = dstSizeIn;
285 : src0Size = src0SizeIn;
286 : src1Size = 0;
287 : dstLogicPos = dstPosIn;
288 : src0LogicPos = src0PosIn;
289 : src1LogicPos = src0PosIn;
290 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
291 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
292 : src1Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
293 : }
294 :
295 : uint64_t dstAddr = 0;
296 : uint64_t src0Addr = 0;
297 : uint64_t src1Addr = 0;
298 : bool reduceMode = 0;
299 : uint8_t dstBlockStride = 0;
300 : uint8_t src0BlockStride = 0;
301 : uint8_t src1BlockStride = 0;
302 : uint16_t repeatTimes = 0;
303 : uint16_t dstRepeatStride = 0;
304 : uint16_t src0RepeatStride = 0;
305 : uint16_t src1RepeatStride = 0;
306 : uint64_t rsvdCnt = 0;
307 : uint32_t dstDtypeBytes = 0;
308 : uint32_t src0DtypeBytes = 0;
309 : uint32_t src1DtypeBytes = 0;
310 : uint64_t dstSize = 0;
311 : uint64_t src0Size = 0;
312 : uint64_t src1Size = 0;
313 : uint8_t src1Pattern = 0;
314 : uint8_t dstLogicPos = 0;
315 : uint8_t src0LogicPos = 0;
316 : uint8_t src1LogicPos = 0;
317 : uint8_t dstPos = 0;
318 : uint8_t src0Pos = 0;
319 : uint8_t src1Pos = 0;
320 : };
321 :
322 : bool CheckFuncVecSelectImplForMaskArray(VecSelectApiParams& chkParams, const uint64_t mask[], const char* intriName);
323 : bool CheckFuncVecSelectImpl(VecSelectApiParams& chkParams, const uint64_t mask, const char* intriName);
324 : bool CheckFuncVecSelectImpl(VecSelectApiParams& chkParams, const char* intriName);
325 :
326 : bool CheckFuncGatherbImpl(VecGatherApiParams& chkParams, uint32_t dtypeSize, const char* intriName);
327 :
328 : bool CheckFuncGatherImpl(VecGatherApiParams& chkParams, const uint64_t mask, const char* intriName);
329 : bool CheckFuncGatherImpl(VecGatherApiParams& chkParams, const uint64_t mask[], const char* intriName);
330 : bool CheckFuncGatherImpl(VecGatherApiParams& chkParams, const char* intriName);
331 :
332 : bool CheckFuncVecGatherMaskImpl(VecGatherMaskApiParams& chkParams, const uint32_t mask, const char* intriName);
333 : } // namespace check
334 : } // namespace AscendC
335 : #endif
336 : #endif
|