DSPLIB User Guide
DSPLIB_add_ci.cpp
Go to the documentation of this file.
1 /******************************************************************************/
5 /* Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution.
18  *
19  * Neither the name of Texas Instruments Incorporated nor the names of
20  * its contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  ******************************************************************************/
36 
37 /******************************************************************************
38  * Version 1.0 Date 10/2/22 Author: Asheesh Bhardwaj
39  *****************************************************************************/
40 
41 /*******************************************************************************
42  *
43  * INCLUDES
44  *
45  ******************************************************************************/
46 
47 #include "../common/c71/DSPLIB_inlines.h"
48 #include "DSPLIB_add_priv.h"
49 #include <float.h>
50 
51 /*******************************************************************************
52  *
53  * DEFINES
54  *
55  ******************************************************************************/
56 
57 #define SE_PARAM_BASE (0x0000)
58 #define SE_SE0_PARAM_OFFSET (SE_PARAM_BASE)
59 #define SE_SA0_PARAM_OFFSET (SE_SE0_PARAM_OFFSET + SE_PARAM_SIZE)
60 
61 template <typename dataType>
63  const DSPLIB_bufParams1D_t *bufParamsIn,
64  const DSPLIB_bufParams1D_t *bufParamsOut,
65  const DSPLIB_add_InitArgs *pKerInitArgs)
66 {
68  __SE_TEMPLATE_v1 se0Params;
69  __SA_TEMPLATE_v1 sa0Params;
70 
71  __SE_ELETYPE SE_ELETYPE;
72  __SE_VECLEN SE_VECLEN;
73  __SA_VECLEN SA_VECLEN;
74 
75  DSPLIB_add_PrivArgs *pKerPrivArgs = (DSPLIB_add_PrivArgs *) handle;
76 
77  uint8_t *pBlock = pKerPrivArgs->bufPblock;
78  uint32_t blockSize = pKerPrivArgs->blockSize;
79 
80  typedef typename c7x::make_full_vector<dataType>::type vec;
81  SE_VECLEN = c7x::se_veclen<vec>::value;
82  SA_VECLEN = c7x::sa_veclen<vec>::value;
83  SE_ELETYPE = c7x::se_eletype<vec>::value;
84 
85 #if DSPLIB_DEBUGPRINT
86  int32_t eleCount = c7x::element_count_of<vec>::value;
87  printf("Enter eleCount %d\n", eleCount);
88 #endif
89 
90  /**********************************************************************/
91  /* Prepare streaming engine 1 to fetch the input */
92  /**********************************************************************/
93  se0Params = __gen_SE_TEMPLATE_v1();
94 
95  se0Params.ICNT0 = blockSize;
96  se0Params.ELETYPE = SE_ELETYPE;
97  se0Params.VECLEN = SE_VECLEN;
98  se0Params.DIMFMT = __SE_DIMFMT_1D;
99 
100  /**********************************************************************/
101  /* Prepare SA template to store output */
102  /**********************************************************************/
103  sa0Params = __gen_SA_TEMPLATE_v1();
104 
105  sa0Params.ICNT0 = blockSize;
106  sa0Params.DIM1 = blockSize;
107  sa0Params.VECLEN = SA_VECLEN;
108  sa0Params.DIMFMT = __SA_DIMFMT_1D;
109 
110  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET) = se0Params;
111  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET) = sa0Params;
112 
113  return status;
114 }
115 
117  const DSPLIB_bufParams1D_t *bufParamsIn,
118  const DSPLIB_bufParams1D_t *bufParamsOut,
119  const DSPLIB_add_InitArgs *pKerInitArgs);
120 
122  const DSPLIB_bufParams1D_t *bufParamsIn,
123  const DSPLIB_bufParams1D_t *bufParamsOut,
124  const DSPLIB_add_InitArgs *pKerInitArgs);
125 
127  const DSPLIB_bufParams1D_t *bufParamsIn,
128  const DSPLIB_bufParams1D_t *bufParamsOut,
129  const DSPLIB_add_InitArgs *pKerInitArgs);
130 
132  const DSPLIB_bufParams1D_t *bufParamsIn,
133  const DSPLIB_bufParams1D_t *bufParamsOut,
134  const DSPLIB_add_InitArgs *pKerInitArgs);
135 
137  const DSPLIB_bufParams1D_t *bufParamsIn,
138  const DSPLIB_bufParams1D_t *bufParamsOut,
139  const DSPLIB_add_InitArgs *pKerInitArgs);
140 
142  const DSPLIB_bufParams1D_t *bufParamsIn,
143  const DSPLIB_bufParams1D_t *bufParamsOut,
144  const DSPLIB_add_InitArgs *pKerInitArgs);
145 
147  const DSPLIB_bufParams1D_t *bufParamsIn,
148  const DSPLIB_bufParams1D_t *bufParamsOut,
149  const DSPLIB_add_InitArgs *pKerInitArgs);
150 
152  const DSPLIB_bufParams1D_t *bufParamsIn,
153  const DSPLIB_bufParams1D_t *bufParamsOut,
154  const DSPLIB_add_InitArgs *pKerInitArgs);
155 
156 template <typename dataType>
158 DSPLIB_add_exec_ci(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
159 {
160  DSPLIB_add_PrivArgs *pKerPrivArgs = (DSPLIB_add_PrivArgs *) handle;
161  uint32_t blockSize = pKerPrivArgs->blockSize;
162 
163  __SE_TEMPLATE_v1 se0Params;
164  __SA_TEMPLATE_v1 sa0Params;
165 
166  dataType *restrict pInLocal1 = (dataType *) pIn1;
167  dataType *restrict pInLocal2 = (dataType *) pIn2;
168  dataType *restrict pOutLocal = (dataType *) pOut;
169 
170 #if DSPLIB_DEBUGPRINT
171  printf("Enter DSPLIB_add_exec_ci\n");
172 #endif
173 
174  typedef typename c7x::make_full_vector<dataType>::type vec;
175  int32_t eleCount = c7x::element_count_of<vec>::value;
176 
177 #if DSPLIB_DEBUGPRINT
178  printf("Enter eleCount %d\n", eleCount);
179 #endif
180  uint8_t *pBlock = pKerPrivArgs->bufPblock;
181 
182  se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SE0_PARAM_OFFSET);
183 
184  sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE_SA0_PARAM_OFFSET);
185  __SA0_OPEN(sa0Params);
186 
187  // Input samples
188  __SE0_OPEN(pInLocal1, se0Params);
189  __SE1_OPEN(pInLocal2, se0Params);
190 
191  // Output samples
192  __SA0_OPEN(sa0Params);
193 
194 #if DSPLIB_DEBUGPRINT
195  printf("DSPLIB_DEBUGPRINT blockSize %d\n", blockSize);
196 #endif
197 
198  vec out;
199  for (int32_t counter = 0; counter < blockSize; counter += eleCount) {
200  vec a = c7x::strm_eng<0, vec>::get_adv();
201  vec b = c7x::strm_eng<1, vec>::get_adv();
202 
203  out = a + b;
204 
205  __vpred tmp = c7x::strm_agen<0, vec>::get_vpred();
206  vec *VB1 = c7x::strm_agen<0, vec>::get_adv(pOutLocal);
207 
208  __vstore_pred(tmp, VB1, out);
209  }
210  __SE0_CLOSE();
211  __SE1_CLOSE();
212  __SA0_CLOSE();
213 
214  return DSPLIB_SUCCESS;
215 }
216 
218 DSPLIB_add_exec_ci<float>(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut);
219 
221 DSPLIB_add_exec_ci<double>(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut);
222 
224 DSPLIB_add_exec_ci<int8_t>(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut);
225 
227 DSPLIB_add_exec_ci<uint8_t>(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut);
228 
230 DSPLIB_add_exec_ci<int16_t>(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut);
231 
233 DSPLIB_add_exec_ci<uint16_t>(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut);
234 
236 DSPLIB_add_exec_ci<int32_t>(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut);
237 
239 DSPLIB_add_exec_ci<uint32_t>(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut);
template DSPLIB_STATUS DSPLIB_add_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_add_InitArgs *pKerInitArgs)
#define SE_SE0_PARAM_OFFSET
template DSPLIB_STATUS DSPLIB_add_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_add_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_add_exec_ci< double >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_add_exec_ci< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_add_init_ci< uint32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_add_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_add_exec_ci< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
DSPLIB_STATUS DSPLIB_add_init_ci(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_add_InitArgs *pKerInitArgs)
This function is the initialization function for the C7x implementation of the kernel....
template DSPLIB_STATUS DSPLIB_add_exec_ci< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_add_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_add_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_add_init_ci< uint8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_add_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_add_init_ci< uint16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_add_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_add_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_add_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_add_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_add_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_add_exec_ci(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
This function is the main execution function for the C7x implementation of the kernel....
template DSPLIB_STATUS DSPLIB_add_exec_ci< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_add_exec_ci< float >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_add_exec_ci< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_add_exec_ci< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pOut)
#define SE_SA0_PARAM_OFFSET
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_add.
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 containing the parameters to initialize the kernel.
Definition: DSPLIB_add.h:108
Structure that is reserved for internal use by the kernel.
int32_t blockSize
Size of input buffer for different batches DSPLIB_add_init that will be retrieved and used by DSPLIB_...
uint8_t bufPblock[DSPLIB_ADD_IXX_IXX_OXX_PBLOCK_SIZE]
A structure for a 1 dimensional buffer descriptor.