VXLIB User Guide
VXLIB_thresholdBinary.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 /* VXLIB_thresholdBinary_getHandleSize */
45 /* */
46 /**********************************************************************************************************************/
47 
48 // this method calculates and returns the size of the handle for the VXLIB_thresholdBinary kernel
50 {
51  int32_t privBufSize = sizeof(VXLIB_thresholdBinary_PrivArgs);
52  return privBufSize;
53 }
54 
55 /**********************************************************************************************************************/
56 /* */
57 /* VXLIB_thresholdBinary_init_checkParams */
58 /* */
59 /**********************************************************************************************************************/
60 
61 // this method checks the initialization parameters for the VXLIB_thresholdBinary kernel
64  const VXLIB_bufParams2D_t * bufParamsIn,
65  const VXLIB_bufParams2D_t * bufParamsOut,
66  const VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
67 {
68  VXLIB_STATUS status = VXLIB_SUCCESS;
69 
70  if ((handle == NULL) || (bufParamsIn == NULL) || (bufParamsOut == NULL) || (pKerInitArgs == NULL)) {
71  status = VXLIB_ERR_NULL_POINTER;
72  }
73 
74  if (status == VXLIB_SUCCESS) {
75  // check for dimensions and datatype combinations
76  // obtain input1 buffer parameters
77  uint32_t dTypeIn = bufParamsIn->data_type;
78  uint32_t widthIn = bufParamsIn->dim_x;
79  uint32_t heightIn = bufParamsIn->dim_y;
80  uint32_t strideIn = bufParamsIn->stride_y;
81 
82  // obtain output buffer parameters
83  uint32_t dTypeOut = bufParamsOut->data_type;
84  uint32_t widthOut = bufParamsOut->dim_x;
85  uint32_t heightOut = bufParamsOut->dim_y;
86  uint32_t strideOut = bufParamsOut->stride_y;
87 
88  uint32_t strideInElements = strideIn / VXLIB_sizeof(dTypeIn);
89  uint32_t strideOutElements = strideOut / VXLIB_sizeof(dTypeOut);
90 
91  if ((widthIn != widthOut) || (heightIn != heightOut)) {
93  }
94  else if ((strideInElements < widthIn) || (strideOutElements < widthOut)) {
96  }
99  status = VXLIB_ERR_INVALID_TYPE;
100  }
101  else {
102  status = VXLIB_SUCCESS;
103  }
104  }
105 
106  return status;
107 }
108 
109 /**********************************************************************************************************************/
110 /* */
111 /* VXLIB_thresholdBinary_exec_checkParams */
112 /* */
113 /**********************************************************************************************************************/
114 
115 // this method checks the execution parameters for the VXLIB_thresholdBinary kernel
117  const void *restrict pIn,
118  const void *restrict pOut,
119  const void *restrict pThresholdVal,
120  const void *restrict pTrueVal,
121  const void *restrict pFalseVal)
122 {
123  VXLIB_STATUS status;
124 
125 #if VXLIB_DEBUGPRINT
126  printf("Enter VXLIB_thresholdBinary_exec_checkParams\n");
127 #endif
128  if ((handle == NULL) || (pIn == NULL) || (pOut == NULL) || (pThresholdVal == NULL) || (pTrueVal == NULL) ||
129  (pFalseVal == NULL)) {
130  status = VXLIB_ERR_NULL_POINTER;
131  }
132  else {
133  status = VXLIB_SUCCESS;
134  }
135 
136  return status;
137 }
138 
139 /**********************************************************************************************************************/
140 /* */
141 /* VXLIB_thresholdBinary_init */
142 /* */
143 /**********************************************************************************************************************/
144 
145 // this method is the user-level initialization function for the VXLIB_thresholdBinary kernel
147  VXLIB_bufParams2D_t * bufParamsIn,
148  VXLIB_bufParams2D_t * bufParamsOut,
149  const VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
150 {
151  VXLIB_STATUS status = VXLIB_SUCCESS;
153 
154  // copy pKerinitArgs into pKerPrivargs
155  pKerPrivArgs->pKerInitArgs = *pKerInitArgs;
156 
157  // set width and height of image
158  pKerPrivArgs->width = bufParamsIn->dim_x;
159  pKerPrivArgs->height = bufParamsIn->dim_y;
160 
161  // compute stride in elements as SE/SA params are set to work with given element type
162  pKerPrivArgs->strideInElements = bufParamsIn->stride_y / VXLIB_sizeof(bufParamsIn->data_type);
163  pKerPrivArgs->strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
164 
165 #if VXLIB_DEBUGPRINT
166  printf("VXLIB_DEBUGPRINT Enter VXLIB_thresholdBinary_init\n");
167 #endif
168 
169  // obtain buffer datatypes
170  uint32_t dTypeIn = bufParamsIn->data_type;
171  uint32_t dTypeOut = bufParamsOut->data_type;
172 
173  // determine natural C vs optimized function call
174  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
175 
176  // set function pointer for natural C function with appropriate template parameters based on datatypes
179  }
182  }
185  }
188  }
189  else {
190  status = VXLIB_ERR_INVALID_TYPE;
191  }
192  }
193  else { // Optimized function
194 
195  // set function pointer for natural C function with appropriate template parameters based on datatypes
198  status = VXLIB_thresholdBinary_init_ci<VXLIB_THRESHOLDBINARY_DTYPE_I8U_O8U>(handle, bufParamsIn, bufParamsOut,
199  pKerInitArgs);
200  }
203  status = VXLIB_thresholdBinary_init_ci<VXLIB_THRESHOLDBINARY_DTYPE_I8S_O8S>(handle, bufParamsIn, bufParamsOut,
204  pKerInitArgs);
205  }
209  bufParamsOut, pKerInitArgs);
210  }
214  bufParamsOut, pKerInitArgs);
215  }
216  else {
217  status = VXLIB_ERR_INVALID_TYPE;
218  }
219  }
220 
221  return status;
222 }
223 
224 /**********************************************************************************************************************/
225 /* */
226 /* VXLIB_thresholdBinary_exec */
227 /* */
228 /**********************************************************************************************************************/
229 
230 // this method is the user-level execution function for the VXLIB_thresholdBinary kernel
232  void *restrict pIn,
233  void *restrict pOut,
234  void *restrict pThresholdVal,
235  void *restrict pTrueVal,
236  void *restrict pFalseVal)
237 {
238  VXLIB_STATUS status;
239 
240 #if VXLIB_DEBUGPRINT
241  printf("VXLIB_DEBUGPRINT Enter VXLIB_thresholdBinary_exec\n");
242 #endif
243 
245 
246  status = pKerPrivArgs->execute(handle, pIn, pOut, pThresholdVal, pTrueVal, pFalseVal);
247 
248  return status;
249 }
250 
251 /* ======================================================================== */
252 /* End of file: VXLIB_thresholdBinary.cpp */
253 /* ======================================================================== */
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)
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)
template VXLIB_STATUS VXLIB_thresholdBinary_exec_cn< VXLIB_THRESHOLDBINARY_TYPENAME_I8S_O8S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
template VXLIB_STATUS VXLIB_thresholdBinary_exec_cn< 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_cn< 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_exec_cn< VXLIB_THRESHOLDBINARY_TYPENAME_I8U_O8U >(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.
#define VXLIB_THRESHOLDBINARY_I16S_O16S
#define VXLIB_THRESHOLDBINARY_I16U_O16U
#define VXLIB_THRESHOLDBINARY_I8S_O8S
#define VXLIB_THRESHOLDBINARY_I8U_O8U
Macros that will be useful to check for datatype combinations.
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_DIMENSION
Definition: VXLIB_types.h:225
@ VXLIB_ERR_NOT_EQUAL_WIDTH_STRIDE
Definition: VXLIB_types.h:228
@ VXLIB_ERR_NULL_POINTER
Definition: VXLIB_types.h:226
@ VXLIB_SUCCESS
Definition: VXLIB_types.h:221
@ VXLIB_ERR_INVALID_TYPE
Definition: VXLIB_types.h:224
@ VXLIB_FUNCTION_NATC
Definition: VXLIB_types.h:251
static int32_t VXLIB_sizeof(uint32_t type)
Inline function returns number of bytes per element given a type of VXLIB_data_type_e.
VXLIB_STATUS VXLIB_thresholdBinary_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_thresholdBinary_init function....
VXLIB_STATUS VXLIB_thresholdBinary_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_thresholdBinary_exec function is called....
int32_t VXLIB_thresholdBinary_getHandleSize(VXLIB_thresholdBinary_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
VXLIB_STATUS VXLIB_thresholdBinary_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut, const void *restrict pThresholdVal, const void *restrict pTrueVal, const void *restrict pFalseVal)
This function checks the validity of the parameters passed to VXLIB_thresholdBinary_exec function....
VXLIB_STATUS VXLIB_thresholdBinary_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut, void *restrict pThresholdVal, void *restrict pTrueVal, void *restrict pFalseVal)
This function is the main kernel compute function.
A structure for a 2 dimensional buffer descriptor.
uint32_t dim_y
Height of buffer in Y dimension in elements.
uint32_t dim_x
Width of buffer in X dimension in elements.
uint32_t data_type
Values are of type VXLIB_data_type_e.
int32_t stride_y
Stride in Y dimension in bytes.
Structure containing the parameters to initialize the kernel.
int8_t funcStyle
Variant of the function, refer to VXLIB_FUNCTION_STYLE
Structure that is reserved for internal use by the kernel.
VXLIB_thresholdBinary_InitArgs pKerInitArgs
Initargs of the kernel.
size_t strideInElements
Stride of input in elements.
pFxnVXLIB_thresholdBinary_exec execute
Function pointer to point to the right execution variant between VXLIB_thresholdBinary_exec_cn and VX...
size_t strideOutElements
Stride of output in elements.