DSPLIB User Guide
DSPLIB_matMul_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_matMul_priv.h"
30 #include <cstdint>
31 
32 template <typename dataType>
34 DSPLIB_matMul_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
35 {
37 
38  DSPLIB_matMul_PrivArgs *pKerPrivArgs = (DSPLIB_matMul_PrivArgs *) handle;
39 
40  int32_t m = 0;
41  int32_t k = 0;
42  int32_t n = 0;
43 
44  dataType product, sum;
45 
46  int32_t M = pKerPrivArgs->M;
47  int32_t K = pKerPrivArgs->K;
48  int32_t N = pKerPrivArgs->N;
49  int32_t strideIn0 = pKerPrivArgs->strideIn0Elements;
50  int32_t strideIn1 = pKerPrivArgs->strideIn1Elements;
51  int32_t strideOut = pKerPrivArgs->strideOutElements;
52 
53 #if DSPLIB_DEBUGPRINT
54  printf("Enter DSPLIB_matMul_exec_cn\n");
55 #endif
56 
57 #if DSPLIB_DEBUGPRINT
58  printf("DSPLIB_matMul_exec_cn: M = %d, N = %d, K = %d, strideIn0 = %d, strideIn1 = %d, strideOut = %d\n", M, N, K,
59  strideIn0, strideIn1, strideOut);
60 #endif
61 
62  const dataType *restrict A = (const dataType *) pIn0;
63  const dataType *restrict B = (const dataType *) pIn1;
64  dataType *restrict C = (dataType *) pOut;
65 
66  for (m = 0; m < M; m++) {
67  for (n = 0; n < N; n++) {
68  sum = 0;
69  for (k = 0; k < K; k++) {
70  /* #if DSPLIB_DEBUGPRINT */
71  /* printf("%.2f * %.2f\n", A[k + m * strideIn0], B[n + k * strideIn1]); */
72  /* #endif */
73  product = A[k + m * strideIn0] * B[n + k * strideIn1];
74  sum = sum + product;
75  }
76  C[n + m * strideOut] = sum;
77  }
78  }
79 
80  return (status);
81 }
82 
83 // explicit insmatMultiation for the different data type versions
84 template DSPLIB_STATUS
85 DSPLIB_matMul_exec_cn<float>(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut);
86 
87 template DSPLIB_STATUS
88 DSPLIB_matMul_exec_cn<double>(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut);
template DSPLIB_STATUS DSPLIB_matMul_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matMul_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
This function is the main execution function for the natural C implementation of the kernel....
template DSPLIB_STATUS DSPLIB_matMul_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_matMul.
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.