DSPLIB User Guide
DSPLIB_dotprod_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_dotprod_priv.h"
30 
31 /**********************************************************************/
32 /* Execute for datatypes float and double */
33 /**********************************************************************/
34 
35 // This is the generic implementation of exec_ci. It is used for float and double.
36 // Other datatypes have their own explicet implementation.
37 template <typename dataType>
39 DSPLIB_dotprod_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
40 {
42 
43  DSPLIB_dotprod_PrivArgs *pKerPrivArgs = (DSPLIB_dotprod_PrivArgs *) handle;
44  int32_t blockSize = pKerPrivArgs->blockSize;
45 
46 #if DSPLIB_DEBUGPRINT
47  printf("Enter DSPLIB_dotprod_exec_cn\n");
48 #endif
49 
50  dataType *pInLocal1 = (dataType *) pIn1;
51  dataType *pInLocal2 = (dataType *) pIn2;
52  dataType *pOutLocal = (dataType *) pOut;
53 
54 #if DSPLIB_DEBUGPRINT
55  printf("Enter pInLocal1 %p pInLocal2 %p pOut %p\n", pInLocal1, pInLocal2, pOut);
56 #endif
57 
58  dataType a, b;
59  dataType out;
60  out = 0;
61  for (int32_t counter = 0; counter < blockSize; counter++) {
62  a = *pInLocal1++;
63  b = *pInLocal2++;
64 #if DSPLIB_DEBUGPRINT
65  if (counter <= 8)
66  printf("counter %d a %d b %d\n", counter, a, b);
67 #endif
68 
69  out += a * b;
70 #if DSPLIB_DEBUGPRINT
71  if (counter <= 8)
72  printf("counter %d out %d\n", counter, out);
73 #endif
74  }
75  *pOutLocal = out;
76 
77  return (status);
78 }
79 
80 /**********************************************************************/
81 /* Execute for datatype int8_t */
82 /**********************************************************************/
83 
84 template <>
86  void *restrict pIn1,
87  void *restrict pIn2,
88  void *restrict pOut)
89 {
91 
92  DSPLIB_dotprod_PrivArgs *pKerPrivArgs = (DSPLIB_dotprod_PrivArgs *) handle;
93  int32_t blockSize = pKerPrivArgs->blockSize;
94 
95 #if DSPLIB_DEBUGPRINT
96  printf("Enter DSPLIB_dotprod_exec_cn\n");
97 #endif
98 
99  int8_t *pInLocal1 = (int8_t *) pIn1;
100  int8_t *pInLocal2 = (int8_t *) pIn2;
101  int32_t *pOutLocal = (int32_t *) pOut;
102 
103 #if DSPLIB_DEBUGPRINT
104  printf("Enter pInLocal1 %p pInLocal2 %p pOut %p\n", pInLocal1, pInLocal2, pOut);
105 #endif
106 
107  int8_t a, b;
108  int32_t out;
109  out = 0;
110  for (int32_t counter = 0; counter < blockSize; counter++) {
111  a = *pInLocal1++;
112  b = *pInLocal2++;
113 #if DSPLIB_DEBUGPRINT
114  if (counter <= 8)
115  printf("counter %d a %d b %d\n", counter, a, b);
116 #endif
117 
118  out += (int32_t) a * (int32_t) b;
119 #if DSPLIB_DEBUGPRINT
120  if (counter <= 8)
121  printf("counter %d out %d\n", counter, out);
122 #endif
123  }
124  *pOutLocal = out;
125 
126  return (status);
127 }
128 
129 /**********************************************************************/
130 /* Execute for datatype uint8_t */
131 /**********************************************************************/
132 
133 template <>
135  void *restrict pIn1,
136  void *restrict pIn2,
137  void *restrict pOut)
138 {
139  DSPLIB_STATUS status = DSPLIB_SUCCESS;
140 
141  DSPLIB_dotprod_PrivArgs *pKerPrivArgs = (DSPLIB_dotprod_PrivArgs *) handle;
142  int32_t blockSize = pKerPrivArgs->blockSize;
143 
144 #if DSPLIB_DEBUGPRINT
145  printf("Enter DSPLIB_dotprod_exec_cn\n");
146 #endif
147 
148  uint8_t *pInLocal1 = (uint8_t *) pIn1;
149  uint8_t *pInLocal2 = (uint8_t *) pIn2;
150  uint32_t *pOutLocal = (uint32_t *) pOut;
151 
152 #if DSPLIB_DEBUGPRINT
153  printf("Enter pInLocal1 %p pInLocal2 %p pOut %p\n", pInLocal1, pInLocal2, pOut);
154 #endif
155 
156  uint8_t a, b;
157  uint32_t out;
158  out = 0;
159  for (int32_t counter = 0; counter < blockSize; counter++) {
160  a = *pInLocal1++;
161  b = *pInLocal2++;
162 #if DSPLIB_DEBUGPRINT
163  if (counter <= 8)
164  printf("counter %d a %d b %d\n", counter, a, b);
165 #endif
166 
167  out += (uint32_t) a * (uint32_t) b;
168 #if DSPLIB_DEBUGPRINT
169  if (counter <= 8)
170  printf("counter %d out %d\n", counter, out);
171 #endif
172  }
173  *pOutLocal = out;
174 
175  return (status);
176 }
177 
178 /**********************************************************************/
179 /* Execute for datatype int16_t */
180 /**********************************************************************/
181 
182 template <>
184  void *restrict pIn1,
185  void *restrict pIn2,
186  void *restrict pOut)
187 {
188  DSPLIB_STATUS status = DSPLIB_SUCCESS;
189 
190  DSPLIB_dotprod_PrivArgs *pKerPrivArgs = (DSPLIB_dotprod_PrivArgs *) handle;
191  int32_t blockSize = pKerPrivArgs->blockSize;
192 
193 #if DSPLIB_DEBUGPRINT
194  printf("Enter DSPLIB_dotprod_exec_cn\n");
195 #endif
196 
197  int16_t *pInLocal1 = (int16_t *) pIn1;
198  int16_t *pInLocal2 = (int16_t *) pIn2;
199  int64_t *pOutLocal = (int64_t *) pOut;
200 
201 #if DSPLIB_DEBUGPRINT
202  printf("Enter pInLocal1 %p pInLocal2 %p pOut %p\n", pInLocal1, pInLocal2, pOut);
203 #endif
204 
205  int16_t a, b;
206  int64_t out;
207  out = 0;
208  for (int32_t counter = 0; counter < blockSize; counter++) {
209  a = *pInLocal1++;
210  b = *pInLocal2++;
211 #if DSPLIB_DEBUGPRINT
212  if (counter <= 8)
213  printf("counter %d a %d b %d\n", counter, a, b);
214 #endif
215 
216  out += (int64_t) a * (int64_t) b;
217 #if DSPLIB_DEBUGPRINT
218  if (counter <= 8)
219  printf("counter %d out %d\n", counter, out);
220 #endif
221  }
222  *pOutLocal = out;
223 
224  return (status);
225 }
226 
227 /**********************************************************************/
228 /* Execute for datatype uint16_t */
229 /**********************************************************************/
230 
231 template <>
233  void *restrict pIn1,
234  void *restrict pIn2,
235  void *restrict pOut)
236 {
237  DSPLIB_STATUS status = DSPLIB_SUCCESS;
238 
239  DSPLIB_dotprod_PrivArgs *pKerPrivArgs = (DSPLIB_dotprod_PrivArgs *) handle;
240  int32_t blockSize = pKerPrivArgs->blockSize;
241 
242 #if DSPLIB_DEBUGPRINT
243  printf("Enter DSPLIB_dotprod_exec_cn\n");
244 #endif
245 
246  uint16_t *pInLocal1 = (uint16_t *) pIn1;
247  uint16_t *pInLocal2 = (uint16_t *) pIn2;
248  uint64_t *pOutLocal = (uint64_t *) pOut;
249 
250 #if DSPLIB_DEBUGPRINT
251  printf("Enter pInLocal1 %p pInLocal2 %p pOut %p\n", pInLocal1, pInLocal2, pOut);
252 #endif
253 
254  uint16_t a, b;
255  uint64_t out;
256  out = 0;
257  for (int32_t counter = 0; counter < blockSize; counter++) {
258  a = *pInLocal1++;
259  b = *pInLocal2++;
260 #if DSPLIB_DEBUGPRINT
261  if (counter <= 8)
262  printf("counter %d a %d b %d\n", counter, a, b);
263 #endif
264 
265  out += (uint64_t) a * (uint64_t) b;
266 #if DSPLIB_DEBUGPRINT
267  if (counter <= 8)
268  printf("counter %d out %d\n", counter, out);
269 #endif
270  }
271  *pOutLocal = out;
272  return (status);
273 }
274 
275 /**********************************************************************/
276 /* Execute for datatype int32_t */
277 /**********************************************************************/
278 
279 template <>
281  void *restrict pIn1,
282  void *restrict pIn2,
283  void *restrict pOut)
284 {
285  DSPLIB_STATUS status = DSPLIB_SUCCESS;
286 
287  DSPLIB_dotprod_PrivArgs *pKerPrivArgs = (DSPLIB_dotprod_PrivArgs *) handle;
288  int32_t blockSize = pKerPrivArgs->blockSize;
289 
290 #if DSPLIB_DEBUGPRINT
291  printf("Enter DSPLIB_dotprod_exec_cn\n");
292 #endif
293 
294  int32_t *pInLocal1 = (int32_t *) pIn1;
295  int32_t *pInLocal2 = (int32_t *) pIn2;
296  int64_t *pOutLocal = (int64_t *) pOut;
297 
298 #if DSPLIB_DEBUGPRINT
299  printf("Enter pInLocal1 %p pInLocal2 %p pOut %p\n", pInLocal1, pInLocal2, pOut);
300 #endif
301 
302  int32_t a, b;
303  int64_t out;
304  out = 0;
305  for (int32_t counter = 0; counter < blockSize; counter++) {
306  a = *pInLocal1++;
307  b = *pInLocal2++;
308 #if DSPLIB_DEBUGPRINT
309  if (counter <= 8)
310  printf("counter %d a %d b %d\n", counter, a, b);
311 #endif
312 
313  out += (int64_t) a * (int64_t) b;
314 #if DSPLIB_DEBUGPRINT
315  if (counter <= 8)
316  printf("counter %d out %d\n", counter, out);
317 #endif
318  }
319  *pOutLocal = out;
320 
321  return (status);
322 }
323 
324 /**********************************************************************/
325 /* Execute for datatype uint32_t */
326 /**********************************************************************/
327 
328 template <>
330  void *restrict pIn1,
331  void *restrict pIn2,
332  void *restrict pOut)
333 {
334  DSPLIB_STATUS status = DSPLIB_SUCCESS;
335 
336  DSPLIB_dotprod_PrivArgs *pKerPrivArgs = (DSPLIB_dotprod_PrivArgs *) handle;
337  int32_t blockSize = pKerPrivArgs->blockSize;
338 
339 #if DSPLIB_DEBUGPRINT
340  printf("Enter DSPLIB_dotprod_exec_cn\n");
341 #endif
342 
343  uint32_t *pInLocal1 = (uint32_t *) pIn1;
344  uint32_t *pInLocal2 = (uint32_t *) pIn2;
345  uint64_t *pOutLocal = (uint64_t *) pOut;
346 
347 #if DSPLIB_DEBUGPRINT
348  printf("Enter pInLocal1 %p pInLocal2 %p pOut %p\n", pInLocal1, pInLocal2, pOut);
349 #endif
350 
351  uint32_t a, b;
352  uint64_t out;
353  out = 0;
354  for (int32_t counter = 0; counter < blockSize; counter++) {
355  a = *pInLocal1++;
356  b = *pInLocal2++;
357 #if DSPLIB_DEBUGPRINT
358  if (counter <= 8)
359  printf("counter %d a %d b %d\n", counter, a, b);
360 #endif
361 
362  out += a * b;
363 #if DSPLIB_DEBUGPRINT
364  if (counter <= 8)
365  printf("counter %d out %d\n", counter, out);
366 #endif
367  }
368  *pOutLocal = out;
369 
370  return (status);
371 }
372 
373 // explicit insaddtiation for the different data type versions
375  void *restrict pIn1,
376  void *restrict pIn2,
377  void *restrict pOut);
379  void *restrict pIn1,
380  void *restrict pIn2,
381  void *restrict pOut);
383  void *restrict pIn1,
384  void *restrict pIn2,
385  void *restrict pOut);
387  void *restrict pIn1,
388  void *restrict pIn2,
389  void *restrict pOut);
391  void *restrict pIn1,
392  void *restrict pIn2,
393  void *restrict pOut);
395  void *restrict pIn1,
396  void *restrict pIn2,
397  void *restrict pOut);
399  void *restrict pIn1,
400  void *restrict pIn2,
401  void *restrict pOut);
403  void *restrict pIn1,
404  void *restrict pIn2,
405  void *restrict pOut);
DSPLIB_STATUS DSPLIB_dotprod_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
This function is the main execution function for the natural C implementation of the kernel....
DSPLIB_STATUS DSPLIB_dotprod_exec_cn< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
DSPLIB_STATUS DSPLIB_dotprod_exec_cn< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
DSPLIB_STATUS DSPLIB_dotprod_exec_cn< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_dotprod_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
DSPLIB_STATUS DSPLIB_dotprod_exec_cn< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_dotprod_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
DSPLIB_STATUS DSPLIB_dotprod_exec_cn< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
DSPLIB_STATUS DSPLIB_dotprod_exec_cn< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_dotprod.
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.
int32_t blockSize
Size of input buffer for different batches DSPLIB_dotprod_init that will be retrieved and used by DSP...