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_binary_util.h
13 : * \brief
14 : */
15 :
16 : #ifndef ASCENDC_CHECK_VEC_BINARY_UTIL_H
17 : #define ASCENDC_CHECK_VEC_BINARY_UTIL_H
18 : #if ASCENDC_CPU_DEBUG
19 : #include <string>
20 : #include "kernel_utils.h"
21 : namespace AscendC {
22 : namespace check {
23 :
24 : struct VecBinaryApiParams {
25 : VecBinaryApiParams() {}
26 20 : VecBinaryApiParams(
27 : uint64_t dstAddrIn, uint64_t src0AddrIn, uint64_t src1AddrIn, uint8_t repeatIn, uint16_t dstBlockStrideIn,
28 : uint16_t src0BlockStrideIn, uint16_t src1BlockStrideIn, uint16_t dstRepeatStrideIn, uint16_t src0RepeatStrideIn,
29 : uint16_t src1RepeatStrideIn, uint32_t dstDtypeBytesIn, uint32_t src0DtypeBytesIn, uint32_t src1DtypeBytesIn,
30 : uint64_t dstSizeIn, uint64_t src0SizeIn, uint64_t src1SizeIn, uint8_t dstPosIn, uint8_t src0PosIn,
31 : uint8_t src1PosIn)
32 20 : {
33 20 : dstAddr = dstAddrIn;
34 20 : src0Addr = src0AddrIn;
35 20 : src1Addr = src1AddrIn;
36 20 : repeatTimes = repeatIn;
37 20 : dstBlockStride = dstBlockStrideIn;
38 20 : src0BlockStride = src0BlockStrideIn;
39 20 : src1BlockStride = src1BlockStrideIn;
40 20 : dstRepeatStride = dstRepeatStrideIn;
41 20 : src0RepeatStride = src0RepeatStrideIn;
42 20 : src1RepeatStride = src1RepeatStrideIn;
43 20 : dstDtypeBytes = dstDtypeBytesIn;
44 20 : src0DtypeBytes = src0DtypeBytesIn;
45 20 : src1DtypeBytes = src1DtypeBytesIn;
46 20 : dstSize = dstSizeIn;
47 20 : src0Size = src0SizeIn;
48 20 : src1Size = src1SizeIn;
49 20 : dstLogicPos = dstPosIn;
50 20 : src0LogicPos = src0PosIn;
51 20 : src1LogicPos = src1PosIn;
52 20 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
53 20 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
54 20 : src1Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src1PosIn)));
55 20 : }
56 :
57 : // 外部参数修改,传入logic_pos,但是新增内部新增log_pos,原有的pos保留,在内部转换
58 20 : VecBinaryApiParams(
59 : uint64_t dstAddrIn, uint64_t src0AddrIn, uint64_t src1AddrIn, uint32_t dstDtypeBytesIn,
60 : uint32_t src0DtypeBytesIn, uint32_t src1DtypeBytesIn, uint64_t dstSizeIn, uint64_t src0SizeIn,
61 : uint64_t src1SizeIn, uint8_t dstPosIn, uint8_t src0PosIn, uint8_t src1PosIn, uint32_t count)
62 20 : {
63 20 : dstAddr = dstAddrIn;
64 20 : src0Addr = src0AddrIn;
65 20 : src1Addr = src1AddrIn;
66 20 : dstDtypeBytes = dstDtypeBytesIn;
67 20 : src0DtypeBytes = src0DtypeBytesIn;
68 20 : src1DtypeBytes = src1DtypeBytesIn;
69 20 : dstSize = dstSizeIn;
70 20 : src0Size = src0SizeIn;
71 20 : src1Size = src1SizeIn;
72 20 : dstLogicPos = dstPosIn;
73 20 : src0LogicPos = src0PosIn;
74 20 : src1LogicPos = src1PosIn;
75 20 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
76 20 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
77 20 : src1Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src1PosIn)));
78 20 : calCount = count;
79 20 : }
80 :
81 : uint64_t dstAddr = 0;
82 : uint64_t src0Addr = 0;
83 : uint64_t src1Addr = 0;
84 : uint8_t repeatTimes = 0;
85 : uint16_t dstBlockStride = 0;
86 : uint16_t src0BlockStride = 0;
87 : uint16_t src1BlockStride = 0;
88 : uint16_t dstRepeatStride = 0;
89 : uint16_t src0RepeatStride = 0;
90 : uint16_t src1RepeatStride = 0;
91 : uint32_t dstDtypeBytes = 0;
92 : uint32_t src0DtypeBytes = 0;
93 : uint32_t src1DtypeBytes = 0;
94 : uint64_t dstSize = 0;
95 : uint64_t src0Size = 0;
96 : uint64_t src1Size = 0;
97 : uint8_t dstLogicPos = 0;
98 : uint8_t src0LogicPos = 0;
99 : uint8_t src1LogicPos = 0;
100 : uint8_t dstPos = 0;
101 : uint8_t src0Pos = 0;
102 : uint8_t src1Pos = 0;
103 : uint32_t calCount = 0;
104 : };
105 :
106 : struct VecBinaryScalarApiParams {
107 : VecBinaryScalarApiParams() {}
108 16 : VecBinaryScalarApiParams(
109 : uint64_t dstAddrIn, uint64_t src0AddrIn, uint8_t repeatIn, uint16_t dstBlockStrideIn,
110 : uint16_t src0BlockStrideIn, uint16_t dstRepeatStrideIn, uint16_t src0RepeatStrideIn, uint32_t dstDtypeBytesIn,
111 : uint32_t src0DtypeBytesIn, uint64_t dstSizeIn, uint64_t src0SizeIn, uint8_t dstPosIn, uint8_t src0PosIn)
112 16 : {
113 16 : dstAddr = dstAddrIn;
114 16 : src0Addr = src0AddrIn;
115 16 : repeatTimes = repeatIn;
116 16 : dstBlockStride = dstBlockStrideIn;
117 16 : src0BlockStride = src0BlockStrideIn;
118 16 : dstRepeatStride = dstRepeatStrideIn;
119 16 : src0RepeatStride = src0RepeatStrideIn;
120 16 : dstDtypeBytes = dstDtypeBytesIn;
121 16 : src0DtypeBytes = src0DtypeBytesIn;
122 16 : dstSize = dstSizeIn;
123 16 : src0Size = src0SizeIn;
124 16 : dstLogicPos = dstPosIn;
125 16 : src0LogicPos = src0PosIn;
126 16 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
127 16 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
128 16 : }
129 :
130 16 : VecBinaryScalarApiParams(
131 : uint64_t dstAddrIn, uint64_t src0AddrIn, uint32_t dstDtypeBytesIn, uint32_t src0DtypeBytesIn,
132 : uint64_t dstSizeIn, uint64_t src0SizeIn, uint8_t dstPosIn, uint8_t src0PosIn, uint32_t count)
133 16 : {
134 16 : dstAddr = dstAddrIn;
135 16 : src0Addr = src0AddrIn;
136 16 : dstDtypeBytes = dstDtypeBytesIn;
137 16 : src0DtypeBytes = src0DtypeBytesIn;
138 16 : dstSize = dstSizeIn;
139 16 : src0Size = src0SizeIn;
140 16 : dstLogicPos = dstPosIn;
141 16 : src0LogicPos = src0PosIn;
142 16 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
143 16 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
144 16 : calCount = count;
145 16 : }
146 :
147 : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
148 : VecBinaryScalarApiParams(
149 : uint64_t dstAddrIn, uint64_t src0AddrIn, uint8_t repeatIn, uint16_t dstBlockStrideIn,
150 : uint16_t src0BlockStrideIn, uint16_t dstRepeatStrideIn, uint16_t src0RepeatStrideIn, uint32_t dstDtypeBytesIn,
151 : uint32_t src0DtypeBytesIn, uint64_t dstSizeIn, uint64_t src0SizeIn, uint8_t dstPosIn, uint8_t src0PosIn,
152 : uint8_t scalarPosIn)
153 : {
154 : dstAddr = dstAddrIn;
155 : src0Addr = src0AddrIn;
156 : repeatTimes = repeatIn;
157 : dstBlockStride = dstBlockStrideIn;
158 : src0BlockStride = src0BlockStrideIn;
159 : dstRepeatStride = dstRepeatStrideIn;
160 : src0RepeatStride = src0RepeatStrideIn;
161 : dstDtypeBytes = dstDtypeBytesIn;
162 : src0DtypeBytes = src0DtypeBytesIn;
163 : dstSize = dstSizeIn;
164 : src0Size = src0SizeIn;
165 : dstLogicPos = dstPosIn;
166 : src0LogicPos = src0PosIn;
167 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
168 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
169 : scalarPos = scalarPosIn;
170 : enableFlexibleScalar = 1;
171 : }
172 :
173 : VecBinaryScalarApiParams(
174 : uint64_t dstAddrIn, uint64_t src0AddrIn, uint32_t dstDtypeBytesIn, uint32_t src0DtypeBytesIn,
175 : uint64_t dstSizeIn, uint64_t src0SizeIn, uint8_t dstPosIn, uint8_t src0PosIn, uint32_t count,
176 : uint8_t scalarPosIn)
177 : {
178 : dstAddr = dstAddrIn;
179 : src0Addr = src0AddrIn;
180 : dstDtypeBytes = dstDtypeBytesIn;
181 : src0DtypeBytes = src0DtypeBytesIn;
182 : dstSize = dstSizeIn;
183 : src0Size = src0SizeIn;
184 : dstLogicPos = dstPosIn;
185 : src0LogicPos = src0PosIn;
186 : dstPos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(dstPosIn)));
187 : src0Pos = static_cast<uint8_t>(GetPhyType(static_cast<TPosition>(src0PosIn)));
188 : calCount = count;
189 : scalarPos = scalarPosIn;
190 : enableFlexibleScalar = 1;
191 : }
192 : #endif
193 :
194 : uint64_t dstAddr = 0;
195 : uint64_t src0Addr = 0;
196 : uint8_t repeatTimes = 0;
197 : uint16_t dstBlockStride = 0;
198 : uint16_t src0BlockStride = 0;
199 : uint16_t dstRepeatStride = 0;
200 : uint16_t src0RepeatStride = 0;
201 : uint32_t dstDtypeBytes = 0;
202 : uint32_t src0DtypeBytes = 0;
203 : uint64_t dstSize = 0;
204 : uint64_t src0Size = 0;
205 : uint8_t dstPos = 0;
206 : uint8_t src0Pos = 0;
207 : uint8_t dstLogicPos = 0;
208 : uint8_t src0LogicPos = 0;
209 : uint32_t calCount = 0;
210 :
211 : #if defined(__NPU_ARCH__) && ((__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102))
212 : uint8_t scalarPos = 1;
213 : uint8_t enableFlexibleScalar = 0;
214 : #endif
215 : };
216 :
217 : bool CheckFuncVecBinaryImplForMaskArray(VecBinaryApiParams& chkParams, const uint64_t mask[], const char* intriName);
218 : bool CheckFuncVecBinaryImpl(VecBinaryApiParams& chkParams, const uint64_t mask, const char* intriName);
219 : bool CheckFuncVecBinaryImpl(VecBinaryApiParams& chkParams, const char* intriName);
220 :
221 : bool CheckFuncVecBinaryCmpImplForMaskArray(VecBinaryApiParams& chkParams, const uint64_t mask[], const char* intriName);
222 : bool CheckFuncVecBinaryCmpImpl(VecBinaryApiParams& chkParams, const uint64_t mask, const char* intriName);
223 : bool CheckFuncVecBinaryCmpImpl(VecBinaryApiParams& chkParams, const char* intriName);
224 :
225 : bool CheckFuncVecBinaryScalarCmpImpl(VecBinaryScalarApiParams& chkParams, const char* intriName);
226 : bool CheckFuncVecBinaryScalarCmpImpl(VecBinaryScalarApiParams& chkParams, const uint64_t mask, const char* intriName);
227 :
228 : bool CheckFunVecBinaryScalarImplForMaskArray(
229 : VecBinaryScalarApiParams& chkParams, const uint64_t mask[], const char* intriName);
230 : bool CheckFunVecBinaryScalarImpl(VecBinaryScalarApiParams& chkParams, const uint64_t mask, const char* intriName);
231 : bool CheckFunVecBinaryScalarImpl(VecBinaryScalarApiParams& chkParams, const char* intriName);
232 : } // namespace check
233 : } // namespace AscendC
234 : #endif
235 : #endif
|