DSPLIB User Guide
DSPLIB_qrd_common.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 withInvA |**
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 /*******************************************************************************
30  *
31  * INCLUDES
32  *
33  ******************************************************************************/
34 #include "DSPLIB_qrd_common.h"
35 
36 /*******************************************************************************
37  *
38  * DEFINES
39  *
40  ******************************************************************************/
41 
42 /*******************************************************************************
43  *
44  * INITIALIZATION
45  *
46  ******************************************************************************/
47 template <typename dataType>
48 void DSPLIB_qrd_identity_matrix_generate_init_ci(int32_t nRows, int32_t stride, uint8_t *pBlock)
49 {
50  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
51 
52  int32_t colStride = stride / sizeof(dataType);
53  typedef typename c7x::make_full_vector<dataType>::type vec;
54  __SA_VECLEN SA_VECLEN = c7x::sa_veclen<vec>::value;
55  __SA_TEMPLATE_v1 sa0Params = __gen_SA_TEMPLATE_v1();
56 
57  sa0Params.ICNT0 = nRows;
58  sa0Params.DIM1 = colStride;
59  sa0Params.ICNT1 = nRows;
60  sa0Params.DIMFMT = __SA_DIMFMT_2D;
61  sa0Params.VECLEN = SA_VECLEN;
62  sa0Params.DECDIM1 = __SA_DECDIM_DIM1;
63  sa0Params.DECDIM1_WIDTH = nRows * colStride;
64 
65  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock) = sa0Params;
66  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", DSPLIB_SUCCESS);
67 }
68 template void DSPLIB_qrd_identity_matrix_generate_init_ci<float>(int32_t nRows, int32_t stride, uint8_t *pBlock);
69 template void DSPLIB_qrd_identity_matrix_generate_init_ci<double>(int32_t nRows, int32_t strideQ, uint8_t *pBloc);
70 
71 template <typename dataType>
72 void DSPLIB_qrd_blk_move_init_ci(int32_t nRows, int32_t nCols, int32_t strideR, uint8_t *pBlock)
73 {
74  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
75 
76  typedef typename c7x::make_full_vector<dataType>::type vec;
77 
78  int32_t colStrideOrder = strideR / sizeof(dataType);
79 
80  __SE_ELETYPE SE_ELETYPE = c7x::se_eletype<vec>::value;
81  __SE_VECLEN SE_VECLEN = c7x::se_veclen<vec>::value;
82  __SA_VECLEN SA_VECLEN = c7x::sa_veclen<vec>::value;
83 
84  __SE_TEMPLATE_v1 seMatrixParams = __gen_SE_TEMPLATE_v1();
85  __SA_TEMPLATE_v1 saMatrixParams = __gen_SA_TEMPLATE_v1();
86 
87  seMatrixParams.ICNT0 = nCols;
88  seMatrixParams.ICNT1 = nRows;
89  seMatrixParams.DIM1 = colStrideOrder;
90  seMatrixParams.DIMFMT = __SE_DIMFMT_2D;
91  seMatrixParams.ELETYPE = SE_ELETYPE;
92  seMatrixParams.VECLEN = SE_VECLEN;
93 
94  saMatrixParams.ICNT0 = nCols;
95  saMatrixParams.ICNT1 = nRows;
96  saMatrixParams.DIM1 = colStrideOrder;
97  saMatrixParams.DIMFMT = __SA_DIMFMT_2D;
98  saMatrixParams.VECLEN = SA_VECLEN;
99 
100  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock) = seMatrixParams;
101  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + (SE_PARAM_SIZE)) = saMatrixParams;
102 
103  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", DSPLIB_SUCCESS);
104 }
105 template void DSPLIB_qrd_blk_move_init_ci<float>(int32_t nRows, int32_t nCols, int32_t strideR, uint8_t *pBlock);
106 template void DSPLIB_qrd_blk_move_init_ci<double>(int32_t nRows, int32_t nCols, int32_t strideR, uint8_t *pBlock);
107 
108 /*******************************************************************************
109  *
110  * IMPLEMENTATION
111  *
112  ******************************************************************************/
113 template <typename dataType>
114 void DSPLIB_qrd_identity_matrix_generate_exec_ci(dataType *pMat, int32_t nRows, int32_t colStride, uint8_t *pBlock)
115 {
116 
117  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
118  typedef typename c7x::make_full_vector<dataType>::type vec;
119 
120  uint32_t eleCount = c7x::element_count_of<vec>::value;
121 
122  __SA_TEMPLATE_v1 sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock);
123  __SA_TEMPLATE_v1 sa1Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock);
124 
125  int32_t iter1 = DSPLIB_ceilingDiv(nRows, eleCount);
126  vec zeroVec = (vec) 0;
127 
128  __SA0_OPEN(sa0Params);
129 
130  for (int32_t horizontal = 0; horizontal < iter1 * nRows; horizontal++) {
131  __vpred pred = c7x::strm_agen<0, vec>::get_vpred();
132  vec *pStoreVec = c7x::strm_agen<0, vec>::get_adv(pMat);
133  __vstore_pred(pred, pStoreVec, zeroVec);
134  }
135 
136  __SA0_CLOSE();
137 
138  sa1Params.ICNT0 = 1;
139  sa1Params.ICNT1 = nRows / 2;
140  sa1Params.DIM1 = 2 * (colStride + 1);
141 
142  sa0Params.ICNT0 = 1;
143  sa0Params.ICNT1 = nRows - sa1Params.ICNT1;
144  sa0Params.DIM1 = 2 * (colStride + 1);
145 
146  __SA0_OPEN(sa0Params);
147  if (sa1Params.ICNT1 != 0) {
148  __SA1_OPEN(sa1Params);
149  }
150 
151  for (int32_t diag = 0; diag < nRows; diag += 2) {
152  dataType *pDiag = c7x::strm_agen<0, dataType>::get_adv(pMat);
153  *pDiag = 1.0;
154  dataType *pDiag1 = c7x::strm_agen<1, dataType>::get_adv(pMat + (colStride + 1));
155  *pDiag1 = 1.0;
156  }
157  __SA0_CLOSE();
158  __SA1_CLOSE();
159 
160  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", DSPLIB_SUCCESS);
161 }
162 template void
163 DSPLIB_qrd_identity_matrix_generate_exec_ci<float>(float *pMat, int32_t nRows, int32_t colStride, uint8_t *pBlock);
164 template void
165 DSPLIB_qrd_identity_matrix_generate_exec_ci<double>(double *pMat, int32_t nRows, int32_t colStride, uint8_t *pBlock);
166 
167 template <typename dataType>
168 void DSPLIB_qrd_blk_move_exec_ci(dataType *pOut,
169  dataType *pIn,
170  int32_t Nrows,
171  int32_t Ncols,
172  int32_t colOutStride,
173  int32_t colInStride,
174  uint8_t *pBlock)
175 {
176  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
177 
178  __SE_TEMPLATE_v1 se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock);
179  __SA_TEMPLATE_v1 sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + (SE_PARAM_SIZE));
180 
181  typedef typename c7x::make_full_vector<dataType>::type vec;
182 
183  int32_t eleCount = c7x::element_count_of<vec>::value;
184  int32_t nVec = DSPLIB_ceilingDiv(Ncols, eleCount);
185  int32_t loopCount = nVec * Nrows;
186 
187  __SE0_OPEN(pIn, se0Params);
188  __SA0_OPEN(sa0Params);
189  for (int32_t i = 0; i < loopCount; i++) {
190  vec v1 = c7x::strm_eng<0, vec>::get_adv();
191 
192  __vpred pred = c7x::strm_agen<0, vec>::get_vpred();
193  vec *pStore = c7x::strm_agen<0, vec>::get_adv(pOut);
194  __vstore_pred(pred, pStore, v1);
195  }
196 
197  __SE0_CLOSE();
198  __SA0_CLOSE();
199  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Exiting function");
200 }
201 template void DSPLIB_qrd_blk_move_exec_ci<float>(float *pOut,
202  float *pIn,
203  int32_t Nrows,
204  int32_t Ncols,
205  int32_t colOutStride,
206  int32_t colInStride,
207  uint8_t *pBlock);
208 template void DSPLIB_qrd_blk_move_exec_ci<double>(double *pOut,
209  double *pIn,
210  int32_t Nrows,
211  int32_t Ncols,
212  int32_t colOutStride,
213  int32_t colInStride,
214  uint8_t *pBlock);
215 
216 /* ======================================================================== */
217 /* End of file: DSPLIB_qrd_common.cpp */
218 /* ======================================================================== */
template void DSPLIB_qrd_blk_move_init_ci< double >(int32_t nRows, int32_t nCols, int32_t strideR, uint8_t *pBlock)
void DSPLIB_qrd_blk_move_exec_ci(dataType *pOut, dataType *pIn, int32_t Nrows, int32_t Ncols, int32_t colOutStride, int32_t colInStride, uint8_t *pBlock)
void DSPLIB_qrd_identity_matrix_generate_init_ci(int32_t nRows, int32_t stride, uint8_t *pBlock)
void DSPLIB_qrd_identity_matrix_generate_exec_ci(dataType *pMat, int32_t nRows, int32_t colStride, uint8_t *pBlock)
template void DSPLIB_qrd_identity_matrix_generate_exec_ci< double >(double *pMat, int32_t nRows, int32_t colStride, uint8_t *pBlock)
template void DSPLIB_qrd_identity_matrix_generate_exec_ci< float >(float *pMat, int32_t nRows, int32_t colStride, uint8_t *pBlock)
void DSPLIB_qrd_blk_move_init_ci(int32_t nRows, int32_t nCols, int32_t strideR, uint8_t *pBlock)
template void DSPLIB_qrd_identity_matrix_generate_init_ci< float >(int32_t nRows, int32_t stride, uint8_t *pBlock)
template void DSPLIB_qrd_identity_matrix_generate_init_ci< double >(int32_t nRows, int32_t strideQ, uint8_t *pBloc)
template void DSPLIB_qrd_blk_move_exec_ci< float >(float *pOut, float *pIn, int32_t Nrows, int32_t Ncols, int32_t colOutStride, int32_t colInStride, uint8_t *pBlock)
template void DSPLIB_qrd_blk_move_exec_ci< double >(double *pOut, double *pIn, int32_t Nrows, int32_t Ncols, int32_t colOutStride, int32_t colInStride, uint8_t *pBlock)
template void DSPLIB_qrd_blk_move_init_ci< float >(int32_t nRows, int32_t nCols, int32_t strideR, uint8_t *pBlock)
#define DSPLIB_DEBUGPRINTFN(N, fmt,...)
Definition: DSPLIB_types.h:83
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152