VXLIB User Guide
VXLIB_meanStdDev.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_meanStdDev_priv.h"
41 #include "VXLIB_types.h"
42 
43 /**********************************************************************************************************************/
44 /* */
45 /* VXLIB_meanStdDev_getHandleSize */
46 /* */
47 /**********************************************************************************************************************/
48 
49 // this method calculates and returns the size of the handle for the VXLIB_meanStdDev kernel
51 {
52  int32_t privBufSize = sizeof(VXLIB_meanStdDev_PrivArgs);
53  return privBufSize;
54 }
55 
56 /**********************************************************************************************************************/
57 /* */
58 /* VXLIB_meanStdDev_init_checkParams */
59 /* */
60 /**********************************************************************************************************************/
61 
62 // this method checks the initialization parameters for the VXLIB_meanStdDev kernel
65  const VXLIB_bufParams2D_t *bufParamsIn,
66  const VXLIB_meanStdDev_InitArgs *pKerInitArgs)
67 {
68  VXLIB_STATUS status = VXLIB_SUCCESS;
69 
70  // obtain input0 buffer parameters
71  uint32_t dTypeIn = bufParamsIn->data_type;
72  uint32_t widthIn = bufParamsIn->dim_x;
73  uint32_t strideIn = bufParamsIn->stride_y;
74 
75  // obtain output buffer parameters
76  uint32_t dTypeOut = VXLIB_FLOAT32;
77 
78  // check for dimensions and datatype combinations
79  if (handle == NULL) {
80  status = VXLIB_ERR_NULL_POINTER;
81  }
83  status = VXLIB_ERR_INVALID_TYPE;
84  }
85  else if (strideIn < widthIn) {
87  }
88  else {
89  status = VXLIB_SUCCESS;
90  }
91 
92  return status;
93 }
94 
95 /**********************************************************************************************************************/
96 /* */
97 /* VXLIB_meanStdDev_exec_checkParams */
98 /* */
99 /**********************************************************************************************************************/
100 
101 // this method checks the execution parameters for the VXLIB_meanStdDev kernel
103  const void *restrict pIn,
104  const void *restrict pOut0,
105  const void *restrict pOut1,
106  const void *restrict pPixelsProcessed,
107  const void *restrict pCurrentSum,
108  const void *restrict pCurrentSqSum)
109 {
110  VXLIB_STATUS status;
111 
112 #if VXLIB_DEBUGPRINT
113  printf("Enter VXLIB_meanStdDev_exec_checkParams\n");
114 #endif
115  if ((handle == NULL) || (pIn == NULL) || (pOut0 == NULL) || (pOut1 == NULL) || (pPixelsProcessed == NULL) ||
116  (pCurrentSum == NULL) || (pCurrentSqSum == NULL)) {
117  status = VXLIB_ERR_NULL_POINTER;
118  }
119  else {
120  status = VXLIB_SUCCESS;
121  }
122 
123  return status;
124 }
125 
126 /**********************************************************************************************************************/
127 /* */
128 /* VXLIB_meanStdDev_init */
129 /* */
130 /**********************************************************************************************************************/
131 
132 // this method is the user-level initialization function for the VXLIB_meanStdDev kernel
134  VXLIB_bufParams2D_t *bufParamsIn,
135  const VXLIB_meanStdDev_InitArgs *pKerInitArgs)
136 {
137  VXLIB_STATUS status = VXLIB_SUCCESS;
138  VXLIB_meanStdDev_PrivArgs *pKerPrivArgs = (VXLIB_meanStdDev_PrivArgs *) handle;
139 
140  // copy pKerinitArgs into pKerPrivargs
141  pKerPrivArgs->pKerInitArgs = *pKerInitArgs;
142 
143  // set width and height of image
144  pKerPrivArgs->width = bufParamsIn->dim_x;
145  pKerPrivArgs->height = bufParamsIn->dim_y;
146 
147  // compute stride in elements as SE/SA params are set to work with given element type
148  pKerPrivArgs->strideInElements = bufParamsIn->stride_y / VXLIB_sizeof(bufParamsIn->data_type);
149 
150 #if VXLIB_DEBUGPRINT
151  printf("VXLIB_DEBUGPRINT Enter VXLIB_meanStdDev_init\n");
152 #endif
153 
154  // obtain buffer datatypes
155  uint32_t dTypeIn = bufParamsIn->data_type;
156  uint32_t dTypeOut = VXLIB_FLOAT32;
157 
158  // determine natural C vs optimized function call
159  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
160 
161  // set function pointer for natural C function with appropriate template parameters based on datatypes
164  }
165  else if (VXLIB_MEANSTDDEV_I16U_O32F) {
167  }
168  else {
169  status = VXLIB_ERR_INVALID_TYPE;
170  }
171  }
172  else { // Optimized function
173 
174  // set function pointer for natural C function with appropriate template parameters based on datatypes
177  status = VXLIB_meanStdDev_init_ci<VXLIB_MEANSTDDEV_DTYPE_I8U_O32F>(handle, bufParamsIn, pKerInitArgs);
178  }
179  else if (VXLIB_MEANSTDDEV_I16U_O32F) {
181  status = VXLIB_meanStdDev_init_ci<VXLIB_MEANSTDDEV_DTYPE_I16U_O32F>(handle, bufParamsIn, pKerInitArgs);
182  }
183  else {
184  status = VXLIB_ERR_INVALID_TYPE;
185  }
186  }
187 
188  return status;
189 }
190 
191 /**********************************************************************************************************************/
192 /* */
193 /* VXLIB_meanStdDev_exec */
194 /* */
195 /**********************************************************************************************************************/
196 
197 // this method is the user-level execution function for the VXLIB_meanStdDev kernel
200  void *restrict pIn,
201  void *restrict pOut0,
202  void *restrict pOut1,
203  void *restrict pPixelsProcessed,
204  void *restrict pCurrentSum,
205  void *restrict pCurrentSqSum)
206 {
207  VXLIB_STATUS status;
208 
209 #if VXLIB_DEBUGPRINT
210  printf("VXLIB_DEBUGPRINT Enter VXLIB_meanStdDev_exec\n");
211 #endif
212 
213  VXLIB_meanStdDev_PrivArgs *pKerPrivArgs = (VXLIB_meanStdDev_PrivArgs *) handle;
214 
215  status = pKerPrivArgs->execute(handle, pIn, pOut0, pOut1, pPixelsProcessed, pCurrentSum, pCurrentSqSum);
216 
217  return status;
218 }
template VXLIB_STATUS VXLIB_meanStdDev_init_ci< VXLIB_MEANSTDDEV_DTYPE_I8U_O32F >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_meanStdDev_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_meanStdDev_exec_ci< VXLIB_MEANSTDDEV_TYPENAME_I8U_O32F >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut0, void *restrict pOut1, void *restrict pPixelsProcessed, void *restrict pCurrentSum, void *restrict pCurrentSqSum)
template VXLIB_STATUS VXLIB_meanStdDev_exec_ci< VXLIB_MEANSTDDEV_TYPENAME_I16U_O32F >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut0, void *restrict pOut1, void *restrict pPixelsProcessed, void *restrict pCurrentSum, void *restrict pCurrentSqSum)
template VXLIB_STATUS VXLIB_meanStdDev_init_ci< VXLIB_MEANSTDDEV_DTYPE_I16U_O32F >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_meanStdDev_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_meanStdDev_exec_cn< VXLIB_MEANSTDDEV_TYPENAME_I16U_O32F >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut0, void *restrict pOut1, void *restrict pPixelsProcessed, void *restrict pCurrentSum, void *restrict pCurrentSqSum)
template VXLIB_STATUS VXLIB_meanStdDev_exec_cn< VXLIB_MEANSTDDEV_TYPENAME_I8U_O32F >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut0, void *restrict pOut1, void *restrict pPixelsProcessed, void *restrict pCurrentSum, void *restrict pCurrentSqSum)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_meanStdDev.
#define VXLIB_MEANSTDDEV_I16U_O32F
#define VXLIB_MEANSTDDEV_I8U_O32F
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_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_FLOAT32
VXLIB_STATUS VXLIB_meanStdDev_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_meanStdDev_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_meanStdDev_init function....
VXLIB_STATUS VXLIB_meanStdDev_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut0, void *restrict pOut1, void *restrict pPixelsProcessed, void *restrict pCurrentSum, void *restrict pCurrentSqSum)
This function is the main kernel compute function.
int32_t VXLIB_meanStdDev_getHandleSize(VXLIB_meanStdDev_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
VXLIB_STATUS VXLIB_meanStdDev_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut0, const void *restrict pOut1, const void *restrict pPixelsProcessed, const void *restrict pCurrentSum, const void *restrict pCurrentSqSum)
This function checks the validity of the parameters passed to VXLIB_meanStdDev_exec function....
VXLIB_STATUS VXLIB_meanStdDev_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_meanStdDev_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_meanStdDev_exec function is called....
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.
size_t height
Height of image
VXLIB_meanStdDev_InitArgs pKerInitArgs
Initargs of the kernel.
pFxnVXLIB_meanStdDev_exec execute
Function pointer to point to the right execution variant between VXLIB_meanStdDev_exec_cn and VXLIB_m...
size_t strideInElements
Stride of input in elements.