DSPLIB User Guide
DSPLIB_minerror_cn.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 **+--------------------------------------------------------------------------+**
3 **| **** |**
4 **| **** |**
5 **| ******o*** |**
6 **| ********_///_**** |**
7 **| ***** /_//_/ **** |**
8 **| ** ** (__/ **** |**
9 **| ********* |**
10 **| **** |**
11 **| *** |**
12 **| |**
13 **| Copyright (c) 2016 Texas Instruments Incorporated |**
14 **| ALL RIGHTS RESERVED |**
15 **| |**
16 **| Permission to use, copy, modify, or distribute this software, |**
17 **| whether in part or in whole, for any purpose is forbidden without |**
18 **| a signed licensing agreement and NDA from Texas Instruments |**
19 **| Incorporated (TI). |**
20 **| |**
21 **| TI makes no representation or warranties with respect to the |**
22 **| performance of this computer program, and specifically disclaims |**
23 **| any responsibility for any damages, special or consequential, |**
24 **| connected with the use of this program. |**
25 **| |**
26 **+--------------------------------------------------------------------------+**
27 *******************************************************************************/
28 
29 #include "DSPLIB_minerror_priv.h"
30 
31 // Promote the datatype to handle overflow
32 template <typename Integer8or16or32BitDataType, typename Integer8or16or32BitPromotedDataType>
33 inline void minerror_exec_cn_integer8or16or32_inputs(void *restrict pIn,
34  void *restrict pErrCoefs,
35  const int *restrict pMaxIndex,
36  const void *restrict pMaxVal,
37  uint32_t vecInSize,
38  uint32_t errCoefsSize,
39  int32_t strideIn)
40 {
41  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
42  int32_t dataSize = sizeof(Integer8or16or32BitDataType);
43  Integer8or16or32BitDataType *pInLocal = (Integer8or16or32BitDataType *) pIn;
44  Integer8or16or32BitDataType *pErrCoefsLocal = (Integer8or16or32BitDataType *) pErrCoefs;
45  int *pMaxIndexLocal = (int *) pMaxIndex;
46  Integer8or16or32BitPromotedDataType *pMaxValLocal = (Integer8or16or32BitPromotedDataType *) pMaxVal;
47 
48  Integer8or16or32BitPromotedDataType val;
49  *pMaxValLocal = std::numeric_limits<Integer8or16or32BitPromotedDataType>::min();
50 
51  for (int32_t counter = 0; counter < (int32_t) vecInSize; counter++) {
52  val = 0;
53  Integer8or16or32BitPromotedDataType product1 =
54  ((((Integer8or16or32BitPromotedDataType) pInLocal[counter * (strideIn / dataSize) + 0]) *
55  (Integer8or16or32BitPromotedDataType) pErrCoefsLocal[0]));
56  Integer8or16or32BitPromotedDataType product2 =
57  ((((Integer8or16or32BitPromotedDataType) pInLocal[counter * (strideIn / dataSize) + 1]) *
58  (Integer8or16or32BitPromotedDataType) pErrCoefsLocal[1]));
59  Integer8or16or32BitPromotedDataType product3 =
60  ((((Integer8or16or32BitPromotedDataType) pInLocal[counter * (strideIn / dataSize) + 2]) *
61  (Integer8or16or32BitPromotedDataType) pErrCoefsLocal[2]));
62  Integer8or16or32BitPromotedDataType product4 =
63  ((((Integer8or16or32BitPromotedDataType) pInLocal[counter * (strideIn / dataSize) + 3]) *
64  (Integer8or16or32BitPromotedDataType) pErrCoefsLocal[3]));
65  Integer8or16or32BitPromotedDataType product5 =
66  ((((Integer8or16or32BitPromotedDataType) pInLocal[counter * (strideIn / dataSize) + 4]) *
67  (Integer8or16or32BitPromotedDataType) pErrCoefsLocal[4]));
68  Integer8or16or32BitPromotedDataType product6 =
69  ((((Integer8or16or32BitPromotedDataType) pInLocal[counter * (strideIn / dataSize) + 5]) *
70  (Integer8or16or32BitPromotedDataType) pErrCoefsLocal[5]));
71  Integer8or16or32BitPromotedDataType product7 =
72  ((((Integer8or16or32BitPromotedDataType) pInLocal[counter * (strideIn / dataSize) + 6]) *
73  (Integer8or16or32BitPromotedDataType) pErrCoefsLocal[6]));
74  Integer8or16or32BitPromotedDataType product8 =
75  ((((Integer8or16or32BitPromotedDataType) pInLocal[counter * (strideIn / dataSize) + 7]) *
76  (Integer8or16or32BitPromotedDataType) pErrCoefsLocal[7]));
77  Integer8or16or32BitPromotedDataType product9 =
78  ((((Integer8or16or32BitPromotedDataType) pInLocal[counter * (strideIn / dataSize) + 8]) *
79  (Integer8or16or32BitPromotedDataType) pErrCoefsLocal[8]));
80 
81  Integer8or16or32BitPromotedDataType acc1 = (product1 >> 1) + (product2 >> 1);
82  Integer8or16or32BitPromotedDataType acc2 = (product3 >> 1) + (product4 >> 1);
83  Integer8or16or32BitPromotedDataType acc3 = (product5 >> 1) + (product6 >> 1);
84  Integer8or16or32BitPromotedDataType acc4 = (product7 >> 1) + (product8 >> 1);
85  Integer8or16or32BitPromotedDataType acc5 = (acc1 >> 1) + (acc2 >> 1);
86  Integer8or16or32BitPromotedDataType acc6 = (acc3 >> 1) + (acc4 >> 1);
87  Integer8or16or32BitPromotedDataType acc7 = (acc5 >> 1) + (acc6 >> 1);
88  val = (acc7 >> 1) + (product9 >> 1);
89 
90  // Store the max value and the corresponding index
91  if (val > (*pMaxValLocal)) {
92  *pMaxValLocal = val;
93  *pMaxIndexLocal = counter;
94  }
95  }
96  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Exit Function");
97 
98 }
99 
100 // Convert integer 64 bits to double to handle overflow
101 
102 template <typename Integer64BitDataType, typename Integer64BitConvertedDataType>
103 inline void minerror_exec_cn_integer64_inputs(void *restrict pIn,
104  void *restrict pErrCoefs,
105  const int *restrict pMaxIndex,
106  const void *restrict pMaxVal,
107  uint32_t vecInSize,
108  uint32_t errCoefsSize,
109  int32_t strideIn)
110 {
111 
112  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
113  int32_t dataSize = sizeof(Integer64BitDataType);
114  Integer64BitDataType *pInLocal = (Integer64BitDataType *) pIn;
115  Integer64BitDataType *pErrCoefsLocal = (Integer64BitDataType *) pErrCoefs;
116  int *pMaxIndexLocal = (int *) pMaxIndex;
117  Integer64BitConvertedDataType *pMaxValLocal = (Integer64BitConvertedDataType *) pMaxVal;
118 
119  Integer64BitConvertedDataType val, pMaxValScaler;
120  pMaxValScaler = std::numeric_limits<Integer64BitConvertedDataType>::min();
121  *pMaxValLocal = pMaxValScaler;
122 
123  for (int32_t counter = 0; counter < (int32_t) vecInSize; counter++) {
124  val = 0;
125  // Dot product
126  for (int32_t j = 0; j < (int32_t) errCoefsSize; j++) {
127  val += ((Integer64BitConvertedDataType) pInLocal[counter * (strideIn / dataSize) + j]) *
128  (Integer64BitDataType) pErrCoefsLocal[j];
129  }
130 
131  // Store the max value and the corresponding index
132  if (val > (pMaxValScaler)) {
133  pMaxValScaler = val;
134  *pMaxIndexLocal = counter;
135  }
136  }
137  *pMaxValLocal = (Integer64BitDataType) pMaxValScaler;
138  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Exit Function");
139 
140 }
141 
142 template <typename FloatingPointDataType, typename FloatingPointPromotedDataType>
143 inline void minerror_exec_cn_float_inputs(void *restrict pIn,
144  void *restrict pErrCoefs,
145  const int *restrict pMaxIndex,
146  const void *restrict pMaxVal,
147  uint32_t vecInSize,
148  uint32_t errCoefsSize,
149  int32_t strideIn)
150 {
151  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
152  int32_t dataSize = sizeof(FloatingPointDataType);
153  FloatingPointDataType *pInLocal = (FloatingPointDataType *) pIn;
154  FloatingPointPromotedDataType *pErrCoefsLocal = (FloatingPointPromotedDataType *) pErrCoefs;
155  int *pMaxIndexLocal = (int *) pMaxIndex;
156  FloatingPointPromotedDataType *pMaxValLocal = (FloatingPointPromotedDataType *) pMaxVal;
157 
158  FloatingPointPromotedDataType val;
159  *pMaxValLocal = std::numeric_limits<FloatingPointPromotedDataType>::min();
160 
161  for (int32_t counter = 0; counter < (int32_t) vecInSize; counter++) {
162  val = 0;
163  // Dot product
164  for (int32_t j = 0; j < (int32_t) errCoefsSize; j++) {
165  val += ((FloatingPointPromotedDataType) pInLocal[counter * (strideIn / dataSize) + j]) * pErrCoefsLocal[j];
166  }
167 
168  // Store the max value and the corresponding index
169  if (val > (*pMaxValLocal)) {
170  *pMaxValLocal = val;
171  *pMaxIndexLocal = counter;
172  }
173  }
174  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Exit Function");
175 
176 }
177 
178 template <>
180  void *restrict pIn,
181  void *restrict pErrCoefs,
182  const int *restrict pMaxIndex,
183  const void *restrict pMaxVal)
184 {
185  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
186  DSPLIB_STATUS status = DSPLIB_SUCCESS;
187 
188  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
189 
190 
191  minerror_exec_cn_integer8or16or32_inputs<int8_t, int16_t>(
192  pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize, pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
193 
194  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
195  return (status);
196 }
197 
198 template <>
200  void *restrict pIn,
201  void *restrict pErrCoefs,
202  const int *restrict pMaxIndex,
203  const void *restrict pMaxVal)
204 {
205  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
206  DSPLIB_STATUS status = DSPLIB_SUCCESS;
207 
208  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
209 
210 
211  minerror_exec_cn_integer8or16or32_inputs<uint8_t, uint16_t>(
212  pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize, pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
213 
214  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
215  return (status);
216 }
217 
218 template <>
220  void *restrict pIn,
221  void *restrict pErrCoefs,
222  const int *restrict pMaxIndex,
223  const void *restrict pMaxVal)
224 {
225  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
226  DSPLIB_STATUS status = DSPLIB_SUCCESS;
227 
228  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
229 
230 
231  minerror_exec_cn_integer8or16or32_inputs<int16_t, int32_t>(
232  pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize, pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
233 
234  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
235  return (status);
236 }
237 
238 template <>
240  void *restrict pIn,
241  void *restrict pErrCoefs,
242  const int *restrict pMaxIndex,
243  const void *restrict pMaxVal)
244 {
245  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
246  DSPLIB_STATUS status = DSPLIB_SUCCESS;
247 
248  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
249 
250  minerror_exec_cn_integer8or16or32_inputs<uint16_t, uint32_t>(
251  pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize, pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
252 
253  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
254  return (status);
255 }
256 
257 template <>
259  void *restrict pIn,
260  void *restrict pErrCoefs,
261  const int *restrict pMaxIndex,
262  const void *restrict pMaxVal)
263 {
264  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
265  DSPLIB_STATUS status = DSPLIB_SUCCESS;
266 
267  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
268 
269  minerror_exec_cn_integer8or16or32_inputs<int32_t, int64_t>(
270  pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize, pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
271 
272  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
273  return (status);
274 }
275 
276 template <>
278  void *restrict pIn,
279  void *restrict pErrCoefs,
280  const int *restrict pMaxIndex,
281  const void *restrict pMaxVal)
282 {
283  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
284  DSPLIB_STATUS status = DSPLIB_SUCCESS;
285 
286  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
287 
288  minerror_exec_cn_integer8or16or32_inputs<uint32_t, uint64_t>(
289  pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize, pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
290 
291  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
292  return (status);
293 }
294 
295 template <>
297  void *restrict pIn,
298  void *restrict pErrCoefs,
299  const int *restrict pMaxIndex,
300  const void *restrict pMaxVal)
301 {
302  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
303  DSPLIB_STATUS status = DSPLIB_SUCCESS;
304 
305  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
306 
307  minerror_exec_cn_integer64_inputs<int64_t, double>(pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize,
308  pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
309 
310  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
311  return (status);
312 }
313 
314 template <>
316  void *restrict pIn,
317  void *restrict pErrCoefs,
318  const int *restrict pMaxIndex,
319  const void *restrict pMaxVal)
320 {
321  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
322  DSPLIB_STATUS status = DSPLIB_SUCCESS;
323 
324  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
325 
326  minerror_exec_cn_integer64_inputs<uint64_t, double>(pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize,
327  pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
328 
329  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
330  return (status);
331 }
332 
333 template <>
335  void *restrict pIn,
336  void *restrict pErrCoefs,
337  const int *restrict pMaxIndex,
338  const void *restrict pMaxVal)
339 {
340  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
341  DSPLIB_STATUS status = DSPLIB_SUCCESS;
342 
343  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
344 
345  minerror_exec_cn_float_inputs<float, float>(pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize,
346  pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
347 
348 
349  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
350  return (status);
351 }
352 
353 template <>
355  void *restrict pIn,
356  void *restrict pErrCoefs,
357  const int *restrict pMaxIndex,
358  const void *restrict pMaxVal)
359 {
360  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
361  DSPLIB_STATUS status = DSPLIB_SUCCESS;
362 
363  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
364 
365  minerror_exec_cn_float_inputs<double, double>(pIn, pErrCoefs, pMaxIndex, pMaxVal, pKerPrivArgs->vecInSize,
366  pKerPrivArgs->errCoefsSize, pKerPrivArgs->strideIn);
367 
368  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
369  return (status);
370 }
DSPLIB_STATUS DSPLIB_minerror_exec_cn< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
void minerror_exec_cn_integer64_inputs(void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal, uint32_t vecInSize, uint32_t errCoefsSize, int32_t strideIn)
void minerror_exec_cn_integer8or16or32_inputs(void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal, uint32_t vecInSize, uint32_t errCoefsSize, int32_t strideIn)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< uint64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< int64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
void minerror_exec_cn_float_inputs(void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal, uint32_t vecInSize, uint32_t errCoefsSize, int32_t strideIn)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_minerror.
#define DSPLIB_DEBUGPRINTFN(N, fmt,...)
Definition: DSPLIB_types.h:83
DSPLIB_STATUS_NAME
The enumeration of all status codes.
Definition: DSPLIB_types.h:151
void * DSPLIB_kernelHandle
Handle type for DSPLIB operations.
Definition: DSPLIB_types.h:172
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152
Structure that is reserved for internal use by the kernel.
uint32_t errCoefsSize
Size of error coefficients vector
uint32_t vecInSize
Size of input data DSPLIB_minerror_init that will be retrieved and used by DSPLIB_minerror_exec