DSPLIB User Guide
DSPLIB_matMul_fixed_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 
30 #include <cstdint>
31 
32 template <typename dataType>
34 DSPLIB_matMul_fixed_exec_cn(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
35 {
37 
39 
40  int32_t m = 0;
41  int32_t k = 0;
42  int32_t n = 0;
43  int32_t qs = 0;
44  int64_t product = 0;
45  int64_t sum = 0;
46 
47  int32_t M = pKerPrivArgs->M;
48  int32_t K = pKerPrivArgs->K;
49  int32_t N = pKerPrivArgs->N;
50  qs = pKerPrivArgs->qs;
51  int32_t strideIn0 = pKerPrivArgs->strideIn0Elements;
52  int32_t strideIn1 = pKerPrivArgs->strideIn1Elements;
53  int32_t strideOut = pKerPrivArgs->strideOutElements;
54 
55 #if DSPLIB_DEBUGPRINT
56  printf("Enter DSPLIB_matMul_fixed_exec_cn\n");
57 #endif
58 
59 #if DSPLIB_DEBUGPRINT
60  printf("DSPLIB_matMul_fixed_exec_cn: M = %d, N = %d, K = %d, strideIn0 = %d, strideIn1 = %d, strideOut = %d\n", M, N, K,
61  strideIn0, strideIn1, strideOut);
62 #endif
63 
64  dataType *restrict A = (dataType *) pIn0;
65  dataType *restrict B = (dataType *) pIn1;
66 
67  dataType *restrict C = (dataType *) pOut;
68 
69  for (m = 0; m < M; m++) {
70  for (n = 0; n < N; n++) {
71  sum = 0;
72  for (k = 0; k < K; k++) {
73  product = A[k + m * strideIn0] * B[n + k * strideIn1];
74  sum = sum + product;
75  }
76  C[n + m * strideOut] = (int64_t)((uint64_t)sum >> (uint64_t)qs);
77  }
78  }
79  return (status);
80 }
81 
82 // explicit instantiation for the different data type versions
83 template DSPLIB_STATUS
84 DSPLIB_matMul_fixed_exec_cn<int8_t>(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut);
85 
86 template DSPLIB_STATUS
87 DSPLIB_matMul_fixed_exec_cn<int16_t>(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut);
template DSPLIB_STATUS DSPLIB_matMul_fixed_exec_cn< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matMul_fixed_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_fixed_exec_cn< int16_t >(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_fixed.
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.