DSPLIB User Guide
DSPLIB_lud_sol_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_lud_sol_priv.h"
30 #include <cstdint>
31 
32 /**********************************************************************/
33 /* INITIALIZATION */
34 /**********************************************************************/
35 
37  const DSPLIB_bufParams2D_t * bufParamsP,
38  const DSPLIB_bufParams2D_t * bufParamsL,
39  const DSPLIB_bufParams2D_t * bufParamsU,
40  const DSPLIB_bufParams1D_t * bufParamsB,
41  const DSPLIB_bufParams1D_t * bufParamsX,
42  const DSPLIB_bufParams2D_t * bufParamsVecScratch,
43  const DSPLIB_bufParams2D_t * bufParamsScratchTrans,
44  const DSPLIB_lud_solInitArgs *pKerInitArgs)
45 {
46  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
47 
48  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", DSPLIB_SUCCESS);
49  return DSPLIB_SUCCESS;
50 }
51 
52 /**********************************************************************/
53 /* NATURAL C IMPLEMENTATION */
54 /**********************************************************************/
55 
56 template <typename dataType>
57 int DSPLIB_lud_sol_cn(int32_t order,
58  unsigned short *P,
59  dataType * L,
60  dataType * U,
61  dataType * B,
62  dataType * B_Mod,
63  dataType * Y,
64  dataType * X,
65  const int32_t strideOrder,
66  const int32_t strideP)
67 {
68  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering nat C c7x implementation");
69  int row, col;
70  dataType sum;
71 
72  int32_t dataSize = sizeof(dataType);
73  int32_t dataSizeP = sizeof(unsigned short);
74 
75  int32_t orderStride = strideOrder / dataSize;
76  int32_t orderPStride = strideP / dataSizeP;
77 
78  /* modify b based on permutation matrix P */
79  for (row = 0; row < order; row++) {
80  sum = 0;
81  for (col = 0; col < order; col++) {
82  sum += P[col + row * orderPStride] * B[col];
83  }
84  B_Mod[row] = sum;
85  }
86 
87  /* solve L*y=b for y using forward substitution */
88  for (row = 0; row < order; row++) {
89  if (row == 0) {
90  Y[row] = B_Mod[row] / L[0];
91  }
92  else {
93  sum = 0.0;
94  for (col = 0; col <= row - 1; col++){
95  sum += L[row * orderStride + col] * Y[col];
96  }
97  Y[row] = (B_Mod[row] - sum) / L[row * orderStride + row];
98  }
99  }
100 
101  /* solve U*x=y for x using backward substitution */
102  for (row = order - 1; row >= 0; row--) {
103  if (row == order - 1) {
104  X[row] = Y[row] / U[row * orderStride + row];
105  }
106  else {
107  sum = 0.0;
108  for (col = order - 1; col >= row + 1; col--){
109  sum += U[row * orderStride + col] * X[col];
110  }
111  X[row] = (Y[row] - sum) / U[row * orderStride + row];
112  }
113  }
114 
115  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Exiting nat C c7x implementation");
116  return 0;
117 }
118 
119 template int DSPLIB_lud_sol_cn<float>(int32_t order,
120  unsigned short *P,
121  float * L,
122  float * U,
123  float * B,
124  float * B_Mod,
125  float * Y,
126  float * X,
127  const int32_t strideOrder,
128  const int32_t strideP);
129 template int DSPLIB_lud_sol_cn<double>(int32_t order,
130  unsigned short *P,
131  double * L,
132  double * U,
133  double * B,
134  double * B_Mod,
135  double * Y,
136  double * X,
137  const int32_t strideOrder,
138  const int32_t strideP);
139 
140 template <typename dataType>
142  void *restrict pP,
143  void *restrict pL,
144  void *restrict pU,
145  void *restrict pB,
146  void *restrict pX,
147  void *restrict pVecScratch,
148  void *restrict pScratchTrans)
149 {
150  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering exec_cn function");
151 
152  DSPLIB_STATUS status = DSPLIB_SUCCESS;
153 
154  DSPLIB_lud_sol_PrivArgs *pKerPrivArgs = (DSPLIB_lud_sol_PrivArgs *) handle;
155 
156  int32_t order = pKerPrivArgs->order;
157  int32_t strideOrder = pKerPrivArgs->strideOrder;
158  int32_t strideP = pKerPrivArgs->strideP;
159  int32_t strideVec = pKerPrivArgs->strideVec;
160 
161  /* Typecast void pointers to respective data type */
162  unsigned short *pPLocal = (unsigned short *) pP;
163  dataType * pLLocal = (dataType *) pL;
164  dataType * pULocal = (dataType *) pU;
165  dataType * pBLocal = (dataType *) pB;
166  dataType * pB_ModLocal = (dataType *) pVecScratch;
167  dataType * pYLocal = (dataType *) (pVecScratch) + (strideVec / sizeof(dataType));
168  dataType * pXLocal = (dataType *) pX;
169 
171  "pPLocal: %p pLLocal: %p pULocal: %p pBLocal: %p pB_ModLocal: %p pYLocal: %p pXLocal: %p\n",
172  pPLocal, pLLocal, pULocal, pBLocal, pB_ModLocal, pYLocal, pXLocal);
173 
174  DSPLIB_lud_sol_cn<dataType>(order, pPLocal, pLLocal, pULocal, pBLocal, pB_ModLocal, pYLocal, pXLocal, strideOrder,
175  strideP);
176 
177  DSPLIB_DEBUGPRINTFN(0, "Exiting exec_cn function with return status: %d\n", status);
178 
179  return (status);
180 }
181 
183  void *restrict pP,
184  void *restrict pL,
185  void *restrict pU,
186  void *restrict pB,
187  void *restrict pX,
188  void *restrict pVecScratch,
189  void *restrict pScratchTrans);
190 
192  void *restrict pP,
193  void *restrict pL,
194  void *restrict pU,
195  void *restrict pB,
196  void *restrict pX,
197  void *restrict pVecScratch,
198  void *restrict pScratchTrans);
199 
200 /* ======================================================================== */
201 /* End of file: DSPLIB_lud_sol_cn.cpp */
202 /* ======================================================================== */
template int DSPLIB_lud_sol_cn< float >(int32_t order, unsigned short *P, float *L, float *U, float *B, float *B_Mod, float *Y, float *X, const int32_t strideOrder, const int32_t strideP)
template DSPLIB_STATUS DSPLIB_lud_sol_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pP, void *restrict pL, void *restrict pU, void *restrict pB, void *restrict pX, void *restrict pVecScratch, void *restrict pScratchTrans)
DSPLIB_STATUS DSPLIB_lud_sol_init_cn(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsP, const DSPLIB_bufParams2D_t *bufParamsL, const DSPLIB_bufParams2D_t *bufParamsU, const DSPLIB_bufParams1D_t *bufParamsB, const DSPLIB_bufParams1D_t *bufParamsX, const DSPLIB_bufParams2D_t *bufParamsVecScratch, const DSPLIB_bufParams2D_t *bufParamsScratchTrans, const DSPLIB_lud_solInitArgs *pKerInitArgs)
This function is the initialization function for the natural C implementation of the kernel....
int DSPLIB_lud_sol_cn(int32_t order, unsigned short *P, dataType *L, dataType *U, dataType *B, dataType *B_Mod, dataType *Y, dataType *X, const int32_t strideOrder, const int32_t strideP)
template int DSPLIB_lud_sol_cn< double >(int32_t order, unsigned short *P, double *L, double *U, double *B, double *B_Mod, double *Y, double *X, const int32_t strideOrder, const int32_t strideP)
template DSPLIB_STATUS DSPLIB_lud_sol_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pP, void *restrict pL, void *restrict pU, void *restrict pB, void *restrict pX, void *restrict pVecScratch, void *restrict pScratchTrans)
DSPLIB_STATUS DSPLIB_lud_sol_exec_cn(DSPLIB_kernelHandle handle, void *restrict pP, void *restrict pL, void *restrict pU, void *restrict pB, void *restrict pX, void *restrict pVecScratch, void *restrict pScratchTrans)
This function is the main execution function for the natural C implementation of the kernel....
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_lud_sol.
#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
A structure for a 1 dimensional buffer descriptor.
A structure for a 2 dimensional buffer descriptor.
Structure containing the parameters to initialize the kernel.
Structure that is reserved for internal use by the kernel.
int32_t strideOrder
Stride between rows of input and output data matrix
int32_t order
Size of input buffer for different batches DSPLIB_lud_sol_init that will be retrieved and used by DSP...
int32_t strideP
Stride between rows of input data matrix P
int32_t strideVec
Stride between rows of scratch data matrix