VXLIB User Guide
VXLIB_thresholdBinary_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_thresholdBinary_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_thresholdBinary_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 
71  // structs to hold SE and SA parameters
72  __SE_TEMPLATE_v1 se0Params = __gen_SE_TEMPLATE_v1();
73  __SA_TEMPLATE_v1 sa0Params = __gen_SA_TEMPLATE_v1();
74 
75  uint8_t *pBlock = pKerPrivArgs->bufPblock; // address to retrieve to store SE/SA params
76 
77  // set SE0, and SA0 params
78  pKerPrivArgs->numBlocks = VXLIB_SE0SA0_init<dTypeIn, dTypeIn>(&se0Params, &sa0Params, bufParamsIn, bufParamsOut);
79  /**************************/
80  /* Store SE and SA params */
81  /**************************/
82  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE0_PARAM_OFFSET) = se0Params;
83  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SA0_PARAM_OFFSET) = sa0Params;
84 
85  return status;
86 }
87 
88 /**********************************************************************************************************************/
89 /* */
90 /* Explicit instantiations for VXLIB_thresholdBinary_init_ci */
91 /* */
92 /**********************************************************************************************************************/
93 
94 template VXLIB_STATUS
96  const VXLIB_bufParams2D_t * bufParamsIn,
97  const VXLIB_bufParams2D_t * bufParamsOut,
98  const VXLIB_thresholdBinary_InitArgs *pKerInitArgs);
99 
100 template VXLIB_STATUS
102  const VXLIB_bufParams2D_t * bufParamsIn,
103  const VXLIB_bufParams2D_t * bufParamsOut,
104  const VXLIB_thresholdBinary_InitArgs *pKerInitArgs);
105 
107  VXLIB_kernelHandle handle,
108  const VXLIB_bufParams2D_t * bufParamsIn,
109  const VXLIB_bufParams2D_t * bufParamsOut,
110  const VXLIB_thresholdBinary_InitArgs *pKerInitArgs);
111 
113  VXLIB_kernelHandle handle,
114  const VXLIB_bufParams2D_t * bufParamsIn,
115  const VXLIB_bufParams2D_t * bufParamsOut,
116  const VXLIB_thresholdBinary_InitArgs *pKerInitArgs);
117 
118 /**********************************************************************************************************************/
119 /* */
120 /* VXLIB_thresholdBinary_exec_ci */
121 /* */
122 /**********************************************************************************************************************/
123 
124 // this method performs pixel-wise addition of two input images
125 template <typename dTypeIn, typename dTypeOut>
127  void *restrict pIn,
128  void *restrict pOut,
129  void *restrict pThresholdVal,
130  void *restrict pTrueVal,
131  void *restrict pFalseVal)
132 {
133 
134  // typecast handle (void) to struct pointer type associated to kernel
136  size_t size = pKerPrivArgs->numBlocks;
137 
138  // create local pointers
139  dTypeIn *restrict pInLocal = (dTypeIn *) pIn;
140  dTypeOut *restrict pOutLocal = (dTypeOut *) pOut;
141  // create local pointers
142  dTypeIn *restrict pThresholdValLocal = (dTypeIn *) pThresholdVal;
143  dTypeIn *restrict pTrueValLocal = (dTypeIn *) pTrueVal;
144  dTypeIn *restrict pFalseValLocal = (dTypeIn *) pFalseVal;
145 
146 #if VXLIB_DEBUGPRINT
147  printf("Enter VXLIB_Thresholdbinary_exec_ci\n");
148 #endif
149 
150  // address of SE and SA parameters
151  uint8_t *pBlock = pKerPrivArgs->bufPblock;
152 
153  // retrieve SE and SA parameters
154  __SE_TEMPLATE_v1 se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE0_PARAM_OFFSET);
155  __SA_TEMPLATE_v1 sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SA0_PARAM_OFFSET);
156 
157  __SE0_OPEN(pInLocal, se0Params);
158  // open SA0 to write output samples
159  __SA0_OPEN(sa0Params);
160 
161  // derive c7x vector type from template typename
162  typedef typename c7x::make_full_vector<dTypeIn>::type vec;
163 
164  vec vThreshold = (vec) *pThresholdValLocal;
165  vec vTrue = (vec) *pTrueValLocal;
166  vec vFalse = (vec) *pFalseValLocal;
167 
168  for (uint32_t counter = 0; counter < size; counter++) {
169 
170  vec a = c7x::strm_eng<0, vec>::get_adv(); // fetch input 0 via SE0
171 
172  __vpred vPred = __cmp_gt_pred(a, vThreshold);
173  vec vout = __select(vPred, vTrue, vFalse);
174 
175  // store output via SA0
176  __vpred tmp = c7x::strm_agen<0, vec>::get_vpred(); // generate predicate
177  vec * addr = c7x::strm_agen<0, vec>::get_adv(pOutLocal); // generate address
178  __vstore_pred(tmp, addr, vout); // store value
179  }
180  // close SE/SA
181  __SE0_CLOSE();
182  __SA0_CLOSE();
183 
184  return VXLIB_SUCCESS;
185 }
186 
187 /**********************************************************************************************************************/
188 /* */
189 /* Explicit instantiations for VXLIB_thresholdBinary_exec_ci */
190 /* */
191 /**********************************************************************************************************************/
192 
193 template VXLIB_STATUS
195  void *restrict pIn,
196  void *restrict pOut,
197  void *restrict pThresholdVal,
198  void *restrict pTrueVal,
199  void *restrict pFalseVal);
200 
201 template VXLIB_STATUS
203  void *restrict pIn,
204  void *restrict pOut,
205  void *restrict pThresholdVal,
206  void *restrict pTrueVal,
207  void *restrict pFalseVal);
208 
209 template VXLIB_STATUS
211  void *restrict pIn,
212  void *restrict pOut,
213  void *restrict pThresholdVal,
214  void *restrict pTrueVal,
215  void *restrict pFalseVal);
216 
217 template VXLIB_STATUS
219  void *restrict pIn,
220  void *restrict pOut,
221  void *restrict pThresholdVal,
222  void *restrict pTrueVal,
223  void *restrict pFalseVal);
224 
225 
226 
227 /**********************************************************************************************************************/
228 /* */
229 /* Performance estimation function */
230 /* */
231 /**********************************************************************************************************************/
232 
233 
234 void VXLIB_thresholdBinary_perfEst(VXLIB_kernelHandle handle, size_t *archCycles, size_t *estCycles)
235 {
236 
237  // typecast handle (void) to struct pointer type associated to kernel
239 
240  // obtain loop count for compute loop
241  size_t numBlocks = pKerPrivArgs->numBlocks;
242  size_t overheadCnt = 44; // profiled code before entering compute loop
243  *archCycles = 2 + numBlocks * 1; // obtained from asm
244  *estCycles = overheadCnt + *archCycles;
245 }
246 
247 /* ======================================================================== */
248 /* End of file: VXLIB_thresholdBinary_ci.cpp */
249 /* ======================================================================== */
VXLIB_STATUS VXLIB_thresholdBinary_init_ci(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
This function is the initialization function for the C7x implementation of the kernel....
#define SE0_PARAM_OFFSET
VXLIB_STATUS VXLIB_thresholdBinary_exec_ci(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
This function is the main execution function for the C7x implementation of the kernel....
template VXLIB_STATUS VXLIB_thresholdBinary_init_ci< VXLIB_THRESHOLDBINARY_DTYPE_I8U_O8U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_thresholdBinary_init_ci< VXLIB_THRESHOLDBINARY_DTYPE_I16S_O16S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_thresholdBinary_init_ci< VXLIB_THRESHOLDBINARY_DTYPE_I16U_O16U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_thresholdBinary_exec_ci< VXLIB_THRESHOLDBINARY_TYPENAME_I16U_O16U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
template VXLIB_STATUS VXLIB_thresholdBinary_exec_ci< VXLIB_THRESHOLDBINARY_TYPENAME_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
template VXLIB_STATUS VXLIB_thresholdBinary_init_ci< VXLIB_THRESHOLDBINARY_DTYPE_I8S_O8S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_thresholdBinary_exec_ci< VXLIB_THRESHOLDBINARY_TYPENAME_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
#define SA0_PARAM_OFFSET
template VXLIB_STATUS VXLIB_thresholdBinary_exec_ci< VXLIB_THRESHOLDBINARY_TYPENAME_I8S_O8S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_thresholdBinary.
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
void VXLIB_thresholdBinary_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.
size_t numBlocks
Number of blocks to be processed after simidfication.
uint8_t bufPblock[VXLIB_THRESHOLDBINARY_IXX_OXX_PBLOCK_SIZE]
Array to hold SE/SA params.