VXLIB User Guide
VXLIB_tableLookup_generic_ci.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2023 Texas Instruments Incorporated - https://www.ti.com/
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  ******************************************************************************/
33 
34 /**********************************************************************************************************************/
35 /* */
36 /* INCLUDES */
37 /* */
38 /**********************************************************************************************************************/
39 
40 #include "VXLIB_tableLookup_priv.h"
41 /**********************************************************************************************************************/
42 /* */
43 /* DEFINES */
44 /* */
45 /**********************************************************************************************************************/
46 
47 /**********************************************************************************************************************/
48 /* */
49 /* VXLIB_tableLookup_generic_init_ci */
50 /* */
51 /**********************************************************************************************************************/
52 
53 // this method initializes the kernel-specific parameters
54 // mainly, the streaming engine and streaming address generators
55 template <uint32_t dTypeIn, uint32_t dTypeOut>
57  const VXLIB_bufParams2D_t *bufParamsIn,
58  const VXLIB_bufParams2D_t *bufParamsOut,
59  const VXLIB_bufParams1D_t *bufParamsLut,
60  const VXLIB_tableLookup_InitArgs *pKerInitArgs)
61 {
62 #if VXLIB_DEBUGPRINT
63  printf("Enter VXLIB_tableLookup_generic_init_ci\n");
64 #endif
65  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
66  VXLIB_tableLookup_PrivArgs *pKerPrivArgs = (VXLIB_tableLookup_PrivArgs *) handle;
67 
68  // structs to hold SE and SA parameters
69  __SE_TEMPLATE_v1 se0Params = __gen_SE_TEMPLATE_v1();
70  __SA_TEMPLATE_v1 sa0Params = __gen_SA_TEMPLATE_v1();
71  size_t width = pKerPrivArgs->width;
72  size_t height = pKerPrivArgs->height;
73  // typecast handle (void) to struct pointer type associated to kernel
74 
75  uint8_t *pBlock = pKerPrivArgs->bufPblock; // address to retrieve to store SE/SA params
76 
77  // set SE0, and SA0 params
78  VXLIB_SE0SA0_init<dTypeIn, dTypeIn>(&se0Params, &sa0Params, bufParamsIn, bufParamsOut);
79  sa0Params.VECLEN = __SA_VECLEN_1ELEM;
80  se0Params.VECLEN = __SE_VECLEN_1ELEM;
81 
82  pKerPrivArgs->numBlocksLut = (height * width) / 8;
83  /**************************/
84  /* Store SE and SA params */
85  /**************************/
86  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE1_PARAM_OFFSET) = se0Params;
87  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SA0_PARAM_OFFSET) = sa0Params;
88 #if VXLIB_DEBUGPRINT
89  printf("Exit VXLIB_tableLookup_generic_init_ci\n");
90 #endif
91  return status;
92 }
93 template VXLIB_STATUS
95  const VXLIB_bufParams2D_t * bufParamsIn,
96  const VXLIB_bufParams2D_t * bufParamsOut,
97  const VXLIB_bufParams1D_t * bufParamsLut,
98  const VXLIB_tableLookup_InitArgs *pKerInitArgs);
99 template VXLIB_STATUS
101  const VXLIB_bufParams2D_t * bufParamsIn,
102  const VXLIB_bufParams2D_t * bufParamsOut,
103  const VXLIB_bufParams1D_t * bufParamsLut,
104  const VXLIB_tableLookup_InitArgs *pKerInitArgs);
105 template VXLIB_STATUS
107  const VXLIB_bufParams2D_t * bufParamsIn,
108  const VXLIB_bufParams2D_t * bufParamsOut,
109  const VXLIB_bufParams1D_t * bufParamsLut,
110  const VXLIB_tableLookup_InitArgs *pKerInitArgs);
111 
112 template VXLIB_STATUS
114  const VXLIB_bufParams2D_t * bufParamsIn,
115  const VXLIB_bufParams2D_t * bufParamsOut,
116  const VXLIB_bufParams1D_t * bufParamsLut,
117  const VXLIB_tableLookup_InitArgs *pKerInitArgs);
118 
119 /**********************************************************************************************************************/
120 /* */
121 /* Explicit instantiations for VXLIB_tableLookup_generic_init_ci */
122 /* */
123 /**********************************************************************************************************************/
124 
125 /**********************************************************************************************************************/
126 /* */
127 /* VXLIB_tableLookup_generic_exec_ci */
128 /* */
129 /**********************************************************************************************************************/
130 template <typename dataType>
132 {
133 #if VXLIB_DEBUGPRINT
134  printf("Enter VXLIB_tableLookup_generic_set_ci\n");
135 #endif
136  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
137 
138 #if VXLIB_DEBUGPRINT
139  printf("Exit VXLIB_tableLookup_generic_set_ci\n");
140 #endif
141  return (status);
142 }
147 
148 /**********************************************************************************************************************/
149 /* */
150 /* Explicit instantiations for VXLIB_tableLookup_generic_exec_ci */
151 /* */
152 /**********************************************************************************************************************/
153 template <typename vecType, typename dataType> static inline dataType getVal(vecType inpVec, dataType idx)
154 {
155  return inpVec.s[0];
156 }
157 
158 template <typename dataType>
160  void *restrict pIn,
161  void *restrict pOut,
162  void *restrict pLut)
163 {
164  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
165 
166 #if VXLIB_DEBUGPRINT
167  printf("Enter VXLIB_tableLookup_generic_exec_ci\n");
168 #endif
169 
170  // typecast handle (void) to struct pointer type associated to kernel
171  VXLIB_tableLookup_PrivArgs *pKerPrivArgs = (VXLIB_tableLookup_PrivArgs *) handle;
172 
173  // obtain image parameters
174  size_t width = pKerPrivArgs->width;
175  size_t height = pKerPrivArgs->height;
176  dataType offset = pKerPrivArgs->pKerInitArgs.offset;
177 
178  typedef typename c7x::make_full_vector<dataType>::type vec;
179 
180  /******************************* INDEX FINDING ******************************/
181  uint8_t *pBlock = pKerPrivArgs->bufPblock;
182  int32_t numBlocksLut = pKerPrivArgs->numBlocksLut;
183  __SE_TEMPLATE_v1 se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE1_PARAM_OFFSET);
184  __SA_TEMPLATE_v1 sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SA0_PARAM_OFFSET);
185 
186  dataType *restrict pInLocal = (dataType *) pIn;
187  dataType *restrict pOutLocal = (dataType *) pOut;
188  dataType *restrict lutLocal = (dataType *) pLut;
189 #if VXLIB_DEBUGPRINT
190  printf("In VXLIB_tableLookup_generic_exec_ci, width: %d, height: %d\n", width, height);
191 #endif
192 
193  __SE0_OPEN(pInLocal, se0Params);
194  __SA0_OPEN(sa0Params);
195 
196  int32_t remElem = (height * width) - (numBlocksLut * 8);
197  for (int32_t j = 0; j < numBlocksLut; j++) {
198  vec srcVec = c7x::strm_eng<0, vec>::get_adv();
199  uint64_t srcIndex = getVal(srcVec, 0) + offset;
200  dataType lutValue = lutLocal[srcIndex];
201  dataType *addr = c7x::strm_agen<0, dataType>::get_adv(pOutLocal); // generate address
202  *addr = lutValue;
203 
204  srcVec = c7x::strm_eng<0, vec>::get_adv();
205  srcIndex = getVal(srcVec, 0) + offset;
206  lutValue = lutLocal[srcIndex];
207  addr = c7x::strm_agen<0, dataType>::get_adv(pOutLocal); // generate address
208  *addr = lutValue;
209 
210  srcVec = c7x::strm_eng<0, vec>::get_adv();
211  srcIndex = getVal(srcVec, 0) + offset;
212  lutValue = lutLocal[srcIndex];
213  addr = c7x::strm_agen<0, dataType>::get_adv(pOutLocal); // generate address
214  *addr = lutValue;
215 
216  srcVec = c7x::strm_eng<0, vec>::get_adv();
217  srcIndex = getVal(srcVec, 0) + offset;
218  lutValue = lutLocal[srcIndex];
219  addr = c7x::strm_agen<0, dataType>::get_adv(pOutLocal); // generate address
220  *addr = lutValue;
221 
222  srcVec = c7x::strm_eng<0, vec>::get_adv();
223  srcIndex = getVal(srcVec, 0) + offset;
224  lutValue = lutLocal[srcIndex];
225  addr = c7x::strm_agen<0, dataType>::get_adv(pOutLocal); // generate address
226  *addr = lutValue;
227 
228  srcVec = c7x::strm_eng<0, vec>::get_adv();
229  srcIndex = getVal(srcVec, 0) + offset;
230  lutValue = lutLocal[srcIndex];
231  addr = c7x::strm_agen<0, dataType>::get_adv(pOutLocal); // generate address
232  *addr = lutValue;
233 
234  srcVec = c7x::strm_eng<0, vec>::get_adv();
235  srcIndex = getVal(srcVec, 0) + offset;
236  lutValue = lutLocal[srcIndex];
237  addr = c7x::strm_agen<0, dataType>::get_adv(pOutLocal); // generate address
238  *addr = lutValue;
239 
240  srcVec = c7x::strm_eng<0, vec>::get_adv();
241  srcIndex = getVal(srcVec, 0) + offset;
242  lutValue = lutLocal[srcIndex];
243  addr = c7x::strm_agen<0, dataType>::get_adv(pOutLocal); // generate address
244  *addr = lutValue;
245  }
246  for (int32_t j = 0; j < remElem; j++) {
247 
248  vec srcVec = c7x::strm_eng<0, vec>::get_adv();
249  uint64_t srcIndex = getVal(srcVec, 0) + offset;
250  dataType lutValue = lutLocal[srcIndex];
251  dataType *addr = c7x::strm_agen<0, dataType>::get_adv(pOutLocal); // generate address
252  *addr = lutValue;
253  }
254 
255  __SE0_CLOSE();
256  __SA0_CLOSE();
257 #if VXLIB_DEBUGPRINT
258  printf("Exit VXLIB_tableLookup_generic_exec_ci \n");
259 #endif
260  return (status);
261 }
263  void *restrict pIn,
264  void *restrict pOut,
265  void *restrict pLut);
267  void *restrict pIn,
268  void *restrict pOut,
269  void *restrict pLut);
271  void *restrict pIn,
272  void *restrict pOut,
273  void *restrict pLut);
275  void *restrict pIn,
276  void *restrict pOut,
277  void *restrict pLut);
278 
279 /* ======================================================================== */
280 /* End of file: VXLIB_tableLookup_generic_ci.cpp */
281 /* ======================================================================== */
#define SA0_PARAM_OFFSET
#define SE1_PARAM_OFFSET
template VXLIB_STATUS VXLIB_tableLookup_generic_set_ci< uint8_t >(VXLIB_kernelHandle handle, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_generic_exec_ci< uint16_t >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_generic_init_ci< VXLIB_TABLELOOKUP_DTYPE_I8U_O8U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_bufParams1D_t *bufParamsLut, const VXLIB_tableLookup_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_tableLookup_generic_exec_ci< int16_t >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
static dataType getVal(vecType inpVec, dataType idx)
VXLIB_STATUS VXLIB_tableLookup_generic_set_ci(VXLIB_kernelHandle handle, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_generic_init_ci< VXLIB_TABLELOOKUP_DTYPE_I16S_O16S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_bufParams1D_t *bufParamsLut, const VXLIB_tableLookup_InitArgs *pKerInitArgs)
VXLIB_STATUS VXLIB_tableLookup_generic_exec_ci(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
VXLIB_STATUS VXLIB_tableLookup_generic_init_ci(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_bufParams1D_t *bufParamsLut, const VXLIB_tableLookup_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_tableLookup_generic_init_ci< VXLIB_TABLELOOKUP_DTYPE_I8S_O8S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_bufParams1D_t *bufParamsLut, const VXLIB_tableLookup_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_tableLookup_generic_init_ci< VXLIB_TABLELOOKUP_DTYPE_I16U_O16U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_bufParams1D_t *bufParamsLut, const VXLIB_tableLookup_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_tableLookup_generic_exec_ci< uint8_t >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_generic_set_ci< int8_t >(VXLIB_kernelHandle handle, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_generic_exec_ci< int8_t >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_generic_set_ci< uint16_t >(VXLIB_kernelHandle handle, void *restrict pLut)
template VXLIB_STATUS VXLIB_tableLookup_generic_set_ci< int16_t >(VXLIB_kernelHandle handle, void *restrict pLut)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_tableLookup.
void * VXLIB_kernelHandle
Handle type for VXLIB operations.
Definition: VXLIB_types.h:247
VXLIB_STATUS_NAME
The enumeration of all status codes.
Definition: VXLIB_types.h:220
@ VXLIB_SUCCESS
Definition: VXLIB_types.h:221
A structure for a 1 dimensional buffer descriptor.
A structure for a 2 dimensional buffer descriptor.
Structure containing the parameters to initialize the kernel.
uint16_t offset
Parameter indicating index of input value = 0 in the lookup table
Structure that is reserved for internal use by the kernel.
size_t numBlocksLut
Number of blocks to be processed for lut logic after simidfication.
VXLIB_tableLookup_InitArgs pKerInitArgs
Initargs of the kernel.
uint8_t bufPblock[VXLIB_TABLELOOKUP_IXX_IXX_OXX_PBLOCK_SIZE]
Array to hold SE/SA params.