VXLIB User Guide
VXLIB_thresholdRange_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 
41 
42 /**********************************************************************************************************************/
43 /* */
44 /* DEFINES */
45 /* */
46 /**********************************************************************************************************************/
47 
48 #define SE_PARAM_BASE (0x0000)
49 #define SE0_PARAM_OFFSET (SE_PARAM_BASE)
50 #define SA0_PARAM_OFFSET (SE0_PARAM_OFFSET + VXLIB_SE_PARAM_SIZE)
51 
52 /**********************************************************************************************************************/
53 /* */
54 /* VXLIB_thresholdRange_init_ci */
55 /* */
56 /**********************************************************************************************************************/
57 
58 // this method initializes the kernel-specific parameters
59 // mainly, the streaming engine and streaming address generators
60 template <uint32_t dTypeIn, uint32_t dTypeOut>
62  const VXLIB_bufParams2D_t * bufParamsIn,
63  const VXLIB_bufParams2D_t * bufParamsOut,
64  const VXLIB_thresholdRange_InitArgs *pKerInitArgs)
65 {
66  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
67 
68  // typecast handle (void) to struct pointer type associated to kernel
70  // structs to hold SE and SA parameters
71  __SE_TEMPLATE_v1 se0Params = __gen_SE_TEMPLATE_v1();
72  __SA_TEMPLATE_v1 sa0Params = __gen_SA_TEMPLATE_v1();
73 
74  // address of SE and SA parameters
75  uint8_t *pBlock = pKerPrivArgs->bufPblock;
76 
77  // set SE0, and SA0 params
78  pKerPrivArgs->numBlocks = VXLIB_SE0SA0_init<dTypeIn, dTypeIn>(&se0Params, &sa0Params, bufParamsIn, bufParamsOut);
79 
80  /**************************/
81  /* Store SE and SA params */
82  /**************************/
83  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE0_PARAM_OFFSET) = se0Params;
84  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SA0_PARAM_OFFSET) = sa0Params;
85 
86  return status;
87 }
88 
89 /**********************************************************************************************************************/
90 /* */
91 /* Explicit instantiations for VXLIB_thresholdRange_init_ci */
92 /* */
93 /**********************************************************************************************************************/
94 
95 template VXLIB_STATUS
97  const VXLIB_bufParams2D_t * bufParamsIn,
98  const VXLIB_bufParams2D_t * bufParamsOut,
99  const VXLIB_thresholdRange_InitArgs *pKerInitArgs);
100 
101 template VXLIB_STATUS
103  const VXLIB_bufParams2D_t * bufParamsIn,
104  const VXLIB_bufParams2D_t * bufParamsOut,
105  const VXLIB_thresholdRange_InitArgs *pKerInitArgs);
106 
107 template VXLIB_STATUS
109  const VXLIB_bufParams2D_t * bufParamsIn,
110  const VXLIB_bufParams2D_t * bufParamsOut,
111  const VXLIB_thresholdRange_InitArgs *pKerInitArgs);
112 
113 template VXLIB_STATUS
115  const VXLIB_bufParams2D_t * bufParamsIn,
116  const VXLIB_bufParams2D_t * bufParamsOut,
117  const VXLIB_thresholdRange_InitArgs *pKerInitArgs);
118 
119 /**********************************************************************************************************************/
120 /* */
121 /* VXLIB_thresholdRange_exec_ci */
122 /* */
123 /**********************************************************************************************************************/
124 
125 // this method performs pixel-wise addition of two input images
126 template <typename dTypeIn, typename dTypeOut>
128  void *restrict pIn,
129  void *restrict pOut,
130  void *restrict pUpperVal,
131  void *restrict pLowerVal,
132  void *restrict pTrueVal,
133  void *restrict pFalseVal)
134 {
135 
136  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
137 
138  // typecast handle (void) to struct pointer type associated to kernel
140  size_t size = pKerPrivArgs->numBlocks;
141 
142 #if VXLIB_DEBUGPRINT
143  printf("Enter VXLIB_thresholdRange_exec_ci\n");
144 #endif
145 
146  // create local pointers
147  dTypeIn *restrict pInLocal = (dTypeIn *) pIn;
148  dTypeOut *restrict pOutLocal = (dTypeOut *) pOut;
149  // create local pointers
150  dTypeIn *restrict pUpperValLocal = (dTypeIn *) pUpperVal;
151  dTypeIn *restrict pLowerValLocal = (dTypeIn *) pLowerVal;
152  dTypeIn *restrict pTrueValLocal = (dTypeIn *) pTrueVal;
153  dTypeIn *restrict pFalseValLocal = (dTypeIn *) pFalseVal;
154 
155 #if VXLIB_DEBUGPRINT
156  printf("In VXLIB_thresholdRange_exec_ci, width: %d, height: %d\n", width, height);
157 #endif
158 
159  if (*pLowerValLocal > *pUpperValLocal) {
160  status = VXLIB_ERR_INVALID_VALUE;
161  }
162  else {
163 
164  // address of SE and SA parameters
165  uint8_t *pBlock = pKerPrivArgs->bufPblock;
166 
167  // retrieve SE and SA parameters
168  __SE_TEMPLATE_v1 se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE0_PARAM_OFFSET);
169  __SA_TEMPLATE_v1 sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SA0_PARAM_OFFSET);
170 
171  __SE0_OPEN(pInLocal, se0Params);
172  // open SA0 to write output samples
173  __SA0_OPEN(sa0Params);
174 
175  // derive c7x vector type from template typename
176  typedef typename c7x::make_full_vector<dTypeIn>::type vec;
177 
178  vec vUpper = (vec) *pUpperValLocal;
179  vec vLower = (vec) *pLowerValLocal;
180  vec vTrue = (vec) *pTrueValLocal;
181  vec vFalse = (vec) *pFalseValLocal;
182 
183  for (uint32_t counter = 0; counter < size; counter++) {
184 
185  vec a = c7x::strm_eng<0, vec>::get_adv(); // fetch input 0 via SE0
186 
187  __vpred vPred1 = __cmp_gt_pred(a, vUpper);
188  __vpred vPred2 = __cmp_gt_pred(vLower, a);
189 
190  __vpred vPred = __or(vPred1, vPred2);
191  vec vOut = __select(vPred, vFalse, vTrue);
192 
193  // store output via SA0
194  __vpred tmp = c7x::strm_agen<0, vec>::get_vpred(); // generate predicate
195  vec * addr = c7x::strm_agen<0, vec>::get_adv(pOutLocal); // generate address
196  __vstore_pred(tmp, addr, vOut); // store value
197  }
198  // close SE/SA
199  __SE0_CLOSE();
200  __SA0_CLOSE();
201  }
202 
203  return (status);
204 }
205 
206 /**********************************************************************************************************************/
207 /* */
208 /* Explicit instantiations for VXLIB_thresholdRange_exec_ci */
209 /* */
210 /**********************************************************************************************************************/
211 
213  void *restrict pIn,
214  void *restrict pOut,
215  void *restrict pUpperVal,
216  void *restrict pLowerVal,
217  void *restrict pTrueVal,
218  void *restrict pFalseVal);
220  void *restrict pIn,
221  void *restrict pOut,
222  void *restrict pUpperVal,
223  void *restrict pLowerVal,
224  void *restrict pTrueVal,
225  void *restrict pFalseVal);
226 
228  void *restrict pIn,
229  void *restrict pOut,
230  void *restrict pUpperVal,
231  void *restrict pLowerVal,
232  void *restrict pTrueVal,
233  void *restrict pFalseVal);
234 
236  void *restrict pIn,
237  void *restrict pOut,
238  void *restrict pUpperVal,
239  void *restrict pLowerVal,
240  void *restrict pTrueVal,
241  void *restrict pFalseVal);
242 
243 /**********************************************************************************************************************/
244 /* */
245 /* Performance estimation function */
246 /* */
247 /**********************************************************************************************************************/
248 
249 
250 void VXLIB_thresholdRange_perfEst(VXLIB_kernelHandle handle, size_t *archCycles, size_t *estCycles)
251 {
252 
253  // typecast handle (void) to struct pointer type associated to kernel
255 
256  // obtain loop count for compute loop
257  size_t numBlocks = pKerPrivArgs->numBlocks;
258  size_t overheadCnt = 53; // profiled code before entering compute loop
259  *archCycles = 3 + numBlocks * 1; // obtained from asm
260  *estCycles = overheadCnt + *archCycles;
261 }
262 
263 
264 /* ======================================================================== */
265 /* End of file: VXLIB_thresholdRange_ci.cpp */
266 /* ======================================================================== */
#define SE0_PARAM_OFFSET
template VXLIB_STATUS VXLIB_thresholdRange_init_ci< VXLIB_THRESHOLDRANGE_DTYPE_I16U_O16U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdRange_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_thresholdRange_init_ci< VXLIB_THRESHOLDRANGE_DTYPE_I16S_O16S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdRange_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_thresholdRange_exec_ci< VXLIB_THRESHOLDRANGE_TYPENAME_I16U_O16U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
template VXLIB_STATUS VXLIB_thresholdRange_exec_ci< VXLIB_THRESHOLDRANGE_TYPENAME_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
VXLIB_STATUS VXLIB_thresholdRange_init_ci(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdRange_InitArgs *pKerInitArgs)
This function is the initialization function for the C7x implementation of the kernel....
template VXLIB_STATUS VXLIB_thresholdRange_init_ci< VXLIB_THRESHOLDRANGE_DTYPE_I8U_O8U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdRange_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_thresholdRange_exec_ci< VXLIB_THRESHOLDRANGE_TYPENAME_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
template VXLIB_STATUS VXLIB_thresholdRange_exec_ci< VXLIB_THRESHOLDRANGE_TYPENAME_I8S_O8S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
VXLIB_STATUS VXLIB_thresholdRange_exec_ci(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pUpperVal, void *restrict pLowerVal, void *restrict pTrueVal, void *restrict pFalseVal)
This function is the main execution function for the C7x implementation of the kernel....
#define SA0_PARAM_OFFSET
template VXLIB_STATUS VXLIB_thresholdRange_init_ci< VXLIB_THRESHOLDRANGE_DTYPE_I8S_O8S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdRange_InitArgs *pKerInitArgs)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_thresholdRange.
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_ERR_INVALID_VALUE
Definition: VXLIB_types.h:223
@ VXLIB_SUCCESS
Definition: VXLIB_types.h:221
void VXLIB_thresholdRange_perfEst(VXLIB_kernelHandle handle, size_t *archCycles, size_t *estCycles)
This function estimates the archCycles and estCycles.
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.
uint8_t bufPblock[VXLIB_THRESHOLDRANGE_IXX_OXX_PBLOCK_SIZE]
Array to hold SE/SA params.
size_t numBlocks
Number of blocks to be processed after simidfication.