VXLIB User Guide
VXLIB_minMaxLoc.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_minMaxLoc_priv.h"
41 
42 /**********************************************************************************************************************/
43 /* */
44 /* VXLIB_minMaxLoc_getHandleSize */
45 /* */
46 /**********************************************************************************************************************/
47 
48 // this method calculates and returns the size of the handle for the VXLIB_minMaxLoc kernel
50 {
51  int32_t privBufSize = sizeof(VXLIB_minMaxLoc_PrivArgs);
52  return privBufSize;
53 }
54 
55 /**********************************************************************************************************************/
56 /* */
57 /* VXLIB_minMaxLoc_init_checkParams */
58 /* */
59 /**********************************************************************************************************************/
60 
61 // this method checks the initialization parameters for the VXLIB_minMaxLoc kernel
64  const VXLIB_bufParams2D_t *bufParamsIn,
65  const VXLIB_bufParams1D_t *bufParamsMinLoc,
66  const VXLIB_bufParams1D_t *bufParamsMaxLoc,
67  const VXLIB_minMaxLoc_InitArgs *pKerInitArgs)
68 {
69  VXLIB_STATUS status = VXLIB_SUCCESS;
70 
71 
72  if ((handle == NULL) || (bufParamsIn == NULL) || (bufParamsMinLoc == NULL) || (bufParamsMaxLoc == NULL) ||
73  (pKerInitArgs == NULL)) {
74  status = VXLIB_ERR_NULL_POINTER;
75  }
76 
77  if (status == VXLIB_SUCCESS) {
78 
79  // obtain input0 buffer parameters
80  uint32_t dType = bufParamsIn->data_type;
81  uint32_t widthIn = bufParamsIn->dim_x;
82  uint32_t strideIn = bufParamsIn->stride_y;
83  uint32_t strideInElements = strideIn / VXLIB_sizeof(dType);
84 
85  // check for dimensions and datatype combinations
86  if (strideInElements < widthIn) {
88  }
90  status = VXLIB_ERR_INVALID_TYPE;
91  }
92  else {
93  status = VXLIB_SUCCESS;
94  }
95  }
96 
97  return status;
98 }
99 
100 /**********************************************************************************************************************/
101 /* */
102 /* VXLIB_minMaxLoc_exec_checkParams */
103 /* */
104 /**********************************************************************************************************************/
105 
106 // this method checks the execution parameters for the VXLIB_minMaxLoc kernel
108  const void *restrict pIn,
109  const void *restrict pMinVal,
110  const void *restrict pMaxVal,
111  const void *restrict pMinCount,
112  const void *restrict pMaxCount,
113  const void *restrict pMinLocCapacity,
114  const void *restrict pMaxLocCapacity,
115  const void *restrict pMinLoc,
116  const void *restrict pMaxLoc,
117  const void *restrict pStartX,
118  const void *restrict pStartY)
119 {
120  VXLIB_STATUS status;
121 
122 #if VXLIB_DEBUGPRINT
123  printf("Enter VXLIB_minMaxLoc_exec_checkParams\n");
124 #endif
125  if ((handle == NULL) || (pIn == NULL) || (pMinVal == NULL) || (pMaxVal == NULL)) {
126  status = VXLIB_ERR_NULL_POINTER;
127  }
128  else {
129  status = VXLIB_SUCCESS;
130  }
131 
132  return status;
133 }
134 
135 /**********************************************************************************************************************/
136 /* */
137 /* VXLIB_minMaxLoc_init */
138 /* */
139 /**********************************************************************************************************************/
140 
141 // this method is the user-level initialization function for the VXLIB_minMaxLoc kernel
143  VXLIB_bufParams2D_t *bufParamsIn,
144  VXLIB_bufParams1D_t *bufParamsMinLoc,
145  VXLIB_bufParams1D_t *bufParamsMaxLoc,
146  const VXLIB_minMaxLoc_InitArgs *pKerInitArgs)
147 {
148  VXLIB_STATUS status = VXLIB_SUCCESS;
149  VXLIB_minMaxLoc_PrivArgs *pKerPrivArgs = (VXLIB_minMaxLoc_PrivArgs *) handle;
150 
151  // copy pKerinitArgs into pKerPrivargs
152  pKerPrivArgs->pKerInitArgs = *pKerInitArgs;
153 
154  // set width and height of image
155  pKerPrivArgs->width = bufParamsIn->dim_x;
156  pKerPrivArgs->height = bufParamsIn->dim_y;
157 
158  // compute stride in elements as SE/SA params are set to work with given element type
159  pKerPrivArgs->strideInElements = bufParamsIn->stride_y / VXLIB_sizeof(bufParamsIn->data_type);
160 
161 #if VXLIB_DEBUGPRINT
162  printf("VXLIB_DEBUGPRINT Enter VXLIB_minMaxLoc_init\n");
163 #endif
164 
165  // obtain buffer datatypes
166  uint32_t dType = bufParamsIn->data_type;
167 
168  // determine natural C vs optimized function call
169  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
170 
171  // set function pointer for natural C function with appropriate template parameters based on datatypes
172  if (VXLIB_MINMAXLOC_8U) {
174  }
175  else if (VXLIB_MINMAXLOC_8S) {
177  }
178  else if (VXLIB_MINMAXLOC_16U) {
180  }
181  else if (VXLIB_MINMAXLOC_16S) {
183  }
184  else {
185  status = VXLIB_ERR_INVALID_TYPE;
186  }
187  }
188  else { // Optimized function
189 
190  // set function pointer for natural C function with appropriate template parameters based on datatypes
191  if (VXLIB_MINMAXLOC_8U) {
193  status = VXLIB_minMaxLoc_init_ci<VXLIB_MINMAXLOC_DTYPE_8U>(handle, bufParamsIn, bufParamsMinLoc,
194  bufParamsMaxLoc, pKerInitArgs);
195  }
196  else if (VXLIB_MINMAXLOC_8S) {
198  status = VXLIB_minMaxLoc_init_ci<VXLIB_MINMAXLOC_DTYPE_8S>(handle, bufParamsIn, bufParamsMinLoc,
199  bufParamsMaxLoc, pKerInitArgs);
200  }
201  else if (VXLIB_MINMAXLOC_16U) {
203  status = VXLIB_minMaxLoc_init_ci<VXLIB_MINMAXLOC_DTYPE_16U>(handle, bufParamsIn, bufParamsMinLoc,
204  bufParamsMaxLoc, pKerInitArgs);
205  }
206  else if (VXLIB_MINMAXLOC_16S) {
208  status = VXLIB_minMaxLoc_init_ci<VXLIB_MINMAXLOC_DTYPE_16S>(handle, bufParamsIn, bufParamsMinLoc,
209  bufParamsMaxLoc, pKerInitArgs);
210  }
211  else {
212  status = VXLIB_ERR_INVALID_TYPE;
213  }
214  }
215 
216  return status;
217 }
218 
219 /**********************************************************************************************************************/
220 /* */
221 /* VXLIB_minMaxLoc_exec */
222 /* */
223 /**********************************************************************************************************************/
224 
225 // this method is the user-level execution function for the VXLIB_minMaxLoc kernel
228  void *restrict pIn,
229  void *restrict pMinVal,
230  void *restrict pMaxVal,
231  void *restrict pMinCount,
232  void *restrict pMaxCount,
233  void *restrict pMinLocCapacity,
234  void *restrict pMaxLocCapacity,
235  void *restrict pMinLoc,
236  void *restrict pMaxLoc,
237  void *restrict pStartX,
238  void *restrict pStartY)
239 {
240  VXLIB_STATUS status;
241 
242 #if VXLIB_DEBUGPRINT
243  printf("VXLIB_DEBUGPRINT Enter VXLIB_minMaxLoc_exec\n");
244 #endif
245 
246  VXLIB_minMaxLoc_PrivArgs *pKerPrivArgs = (VXLIB_minMaxLoc_PrivArgs *) handle;
247 
248  status = pKerPrivArgs->execute(handle, pIn, pMinVal, pMaxVal, pMinCount, pMaxCount, pMinLocCapacity, pMaxLocCapacity,
249  pMinLoc, pMaxLoc, pStartX, pStartY);
250 
251  return status;
252 }
253 /* ======================================================================== */
254 /* End of file: VXLIB_minMaxLoc.cpp */
255 /* ======================================================================== */
template VXLIB_STATUS VXLIB_minMaxLoc_exec_ci< VXLIB_MINMAXLOC_TYPENAME_8S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_ci< VXLIB_MINMAXLOC_TYPENAME_16S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_init_ci< VXLIB_MINMAXLOC_DTYPE_16U >(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams1D_t *bufParamsMinLoc, VXLIB_bufParams1D_t *bufParamsMaxLoc, const VXLIB_minMaxLoc_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_minMaxLoc_init_ci< VXLIB_MINMAXLOC_DTYPE_16S >(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams1D_t *bufParamsMinLoc, VXLIB_bufParams1D_t *bufParamsMaxLoc, const VXLIB_minMaxLoc_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_minMaxLoc_init_ci< VXLIB_MINMAXLOC_DTYPE_8U >(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams1D_t *bufParamsMinLoc, VXLIB_bufParams1D_t *bufParamsMaxLoc, const VXLIB_minMaxLoc_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_ci< VXLIB_MINMAXLOC_TYPENAME_16U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_init_ci< VXLIB_MINMAXLOC_DTYPE_8S >(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams1D_t *bufParamsMinLoc, VXLIB_bufParams1D_t *bufParamsMaxLoc, const VXLIB_minMaxLoc_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_ci< VXLIB_MINMAXLOC_TYPENAME_8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_cn< VXLIB_MINMAXLOC_TYPENAME_8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_cn< VXLIB_MINMAXLOC_TYPENAME_16U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_cn< VXLIB_MINMAXLOC_TYPENAME_16S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
template VXLIB_STATUS VXLIB_minMaxLoc_exec_cn< VXLIB_MINMAXLOC_TYPENAME_8S >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_minMaxLoc.
#define VXLIB_MINMAXLOC_8S
#define VXLIB_MINMAXLOC_16S
#define VXLIB_MINMAXLOC_8U
Macros that will be useful to check for datatype combinations.
#define VXLIB_MINMAXLOC_16U
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_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_minMaxLoc_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams1D_t *bufParamsMinLoc, VXLIB_bufParams1D_t *bufParamsMaxLoc, const VXLIB_minMaxLoc_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_minMaxLoc_exec function is called....
VXLIB_STATUS VXLIB_minMaxLoc_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams1D_t *bufParamsMinLoc, const VXLIB_bufParams1D_t *bufParamsMaxLoc, const VXLIB_minMaxLoc_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_minMaxLoc_init function....
VXLIB_STATUS VXLIB_minMaxLoc_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pMinVal, const void *restrict pMaxVal, const void *restrict pMinCount, const void *restrict pMaxCount, const void *restrict pMinLocCapacity, const void *restrict pMaxLocCapacity, const void *restrict pMinLoc, const void *restrict pMaxLoc, const void *restrict pStartX, const void *restrict pStartY)
This function checks the validity of the parameters passed to VXLIB_minMaxLoc_exec function....
VXLIB_STATUS VXLIB_minMaxLoc_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pMinVal, void *restrict pMaxVal, void *restrict pMinCount, void *restrict pMaxCount, void *restrict pMinLocCapacity, void *restrict pMaxLocCapacity, void *restrict pMinLoc, void *restrict pMaxLoc, void *restrict pStartX, void *restrict pStartY)
This function is the main kernel compute function.
int32_t VXLIB_minMaxLoc_getHandleSize(VXLIB_minMaxLoc_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
A structure for a 1 dimensional buffer descriptor.
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.
pFxnVXLIB_minMaxLoc_exec execute
Function pointer to point to the right execution variant between VXLIB_minMaxLoc_exec_cn and VXLIB_mi...
VXLIB_minMaxLoc_InitArgs pKerInitArgs
Initargs of the kernel.
uint32_t strideInElements
Stride of input0 in elements.
uint32_t height
Height of image
uint32_t width
Width of image