VXLIB User Guide
VXLIB_halfScaleGaussian.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_halfScaleGaussian_getHandleSize */
45 /* */
46 /**********************************************************************************************************************/
47 
48 // this method calculates and returns the size of the handle for the VXLIB_halfScaleGaussian kernel
50 {
51  int32_t privBufSize = sizeof(VXLIB_halfScaleGaussian_PrivArgs);
52  return privBufSize;
53 }
54 
55 /**********************************************************************************************************************/
56 /* */
57 /* VXLIB_halfScaleGaussian_init_checkParams */
58 /* */
59 /**********************************************************************************************************************/
60 
61 // this method checks the initialization parameters for the VXLIB_halfScaleGaussian kernel
64  const VXLIB_bufParams2D_t *bufParamsIn,
65  const VXLIB_bufParams2D_t *bufParamsOut,
66  const VXLIB_halfScaleGaussian_InitArgs *pKerInitArgs)
67 {
68  VXLIB_STATUS status = VXLIB_SUCCESS;
69 
70  // check for null handles
71  if (handle == NULL || bufParamsIn == NULL || bufParamsOut == NULL || pKerInitArgs == NULL) {
72  status = VXLIB_ERR_NULL_POINTER;
73  }
74  else {
75  // obtain input buffer parameters
76  uint32_t dTypeIn = bufParamsIn->data_type;
77  uint32_t widthIn = bufParamsIn->dim_x;
78  uint32_t heightIn = bufParamsIn->dim_y;
79  uint32_t strideIn = bufParamsIn->stride_y;
80 
81  // obtain output buffer parameters
82  uint32_t dTypeOut = bufParamsOut->data_type;
83  uint32_t widthOut = bufParamsOut->dim_x;
84  uint32_t heightOut = bufParamsOut->dim_y;
85  uint32_t strideOut = bufParamsOut->stride_y;
86 
87  // get init arg
88  size_t padLeft = pKerInitArgs->padLeft;
89  size_t padRight = pKerInitArgs->padRight;
90  size_t padTop = pKerInitArgs->padTop;
91  size_t padBottom = pKerInitArgs->padBottom;
92  size_t filterDim = pKerInitArgs->filterSize;
93 
94  bool isNotPadded = (padLeft == 0) && (padRight == 0) && (padTop == 0) && (padBottom == 0);
95 
96  uint32_t strideInElements = strideIn / VXLIB_sizeof(bufParamsIn->data_type);
97  uint32_t strideOutElements = strideOut / VXLIB_sizeof(bufParamsOut->data_type);
98 
99  // check for valid datatype combinations
100  if ((dTypeIn != VXLIB_UINT8) || (dTypeOut != VXLIB_UINT8)) {
101  status = VXLIB_ERR_INVALID_TYPE;
102  }
103 
104  // disqualify padded implementation
105  else if (!isNotPadded) {
106  status = VXLIB_ERR_NOT_IMPLEMENTED;
107  }
108 
109  // check valid dimensions; input height, width must be greater, equal to filter size for non padded implementation
110  else if ((widthIn < ((widthOut + 2) * 2)) || (heightIn != ((heightOut + 2) * 2)) ||
111  (strideInElements < widthIn) || (strideOutElements < widthOut) || (widthIn < filterDim) ||
112  (heightIn < filterDim)) {
114  }
115 
116  else {
117  status = VXLIB_SUCCESS;
118  }
119  }
120  return status;
121 }
122 
123 /**********************************************************************************************************************/
124 /* */
125 /* VXLIB_halfScaleGaussian_exec_checkParams */
126 /* */
127 /**********************************************************************************************************************/
128 
129 // this method checks the execution parameters for the VXLIB_halfScaleGaussian kernel
131 VXLIB_halfScaleGaussian_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
132 {
133  VXLIB_STATUS status;
134 
135 #if VXLIB_DEBUGPRINT
136  printf("Enter VXLIB_halfScaleGaussian_exec_checkParams\n");
137 #endif
138  if ((handle == NULL) || (pIn == NULL) || (pOut == NULL)) {
139  status = VXLIB_ERR_NULL_POINTER;
140  }
141  else {
142  status = VXLIB_SUCCESS;
143  }
144 
145  return status;
146 }
147 
148 /**********************************************************************************************************************/
149 /* */
150 /* VXLIB_halfScaleGaussian_init */
151 /* */
152 /**********************************************************************************************************************/
153 
154 // this method is the user-level initialization function for the VXLIB_halfScaleGaussian kernel
156  VXLIB_bufParams2D_t *bufParamsIn,
157  VXLIB_bufParams2D_t *bufParamsOut,
158  const VXLIB_halfScaleGaussian_InitArgs *pKerInitArgs)
159 {
160  VXLIB_STATUS status = VXLIB_SUCCESS;
162 
163  // copy pKerinitArgs into pKerPrivargs
164  pKerPrivArgs->pKerInitArgs = *pKerInitArgs;
165 
166  // set priv args
167  pKerPrivArgs->widthIn = bufParamsIn->dim_x;
168  pKerPrivArgs->heightIn = bufParamsIn->dim_y;
169  pKerPrivArgs->widthOut = bufParamsOut->dim_x;
170  pKerPrivArgs->heightOut = bufParamsOut->dim_y;
171 
172  // compute stride in elements as SE/SA params are set to work with given element type
173  pKerPrivArgs->strideInElements = bufParamsIn->stride_y / VXLIB_sizeof(bufParamsIn->data_type);
174  pKerPrivArgs->strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
175 
176 #if VXLIB_DEBUGPRINT
177  printf("VXLIB_DEBUGPRINT Enter VXLIB_halfScaleGaussian_init\n");
178 #endif
179 
180  // obtain buffer datatypes
181  uint32_t dTypeIn = bufParamsIn->data_type;
182  uint32_t dTypeOut = bufParamsOut->data_type;
183 
184  // determine natural C vs optimized function call
185  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
186 
187  // set function pointer for natural C function with appropriate template parameters based on datatypes
188 
191  }
192  else {
193  status = VXLIB_ERR_INVALID_TYPE;
194  }
195  }
196  else { // Optimized function
197 
198  // set function pointer for natural C function with appropriate template parameters based on datatypes
199 
202  bufParamsOut, pKerInitArgs);
204  }
205  else {
206  status = VXLIB_ERR_INVALID_TYPE;
207  }
208  }
209 
210  return status;
211 }
212 
213 /**********************************************************************************************************************/
214 /* */
215 /* VXLIB_halfScaleGaussian_exec */
216 /* */
217 /**********************************************************************************************************************/
218 
219 // this method is the user-level execution function for the VXLIB_halfScaleGaussian kernel
221 VXLIB_halfScaleGaussian_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
222 {
223  VXLIB_STATUS status;
224 
225 #if VXLIB_DEBUGPRINT
226  printf("VXLIB_DEBUGPRINT Enter VXLIB_halfScaleGaussian_exec\n");
227 #endif
228 
230 
231  status = pKerPrivArgs->execute(handle, pIn, pOut);
232 
233  return status;
234 }
template VXLIB_STATUS VXLIB_halfScaleGaussian_exec_ci< VXLIB_HALF_SCALE_GAUSSIAN_TYPENAME_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template VXLIB_STATUS VXLIB_halfScaleGaussian_init_ci< VXLIB_HALF_SCALE_GAUSSIAN_DTYPE_I8U_O8U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_halfScaleGaussian_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_halfScaleGaussian_exec_cn< VXLIB_HALF_SCALE_GAUSSIAN_TYPENAME_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_halfScaleGaussian...
#define VXLIB_HALF_SCALE_GAUSSIAN_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_NOT_IMPLEMENTED
Definition: VXLIB_types.h:227
@ 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_UINT8
int32_t VXLIB_halfScaleGaussian_getHandleSize(VXLIB_halfScaleGaussian_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
VXLIB_STATUS VXLIB_halfScaleGaussian_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_halfScaleGaussian_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_halfScaleGaussian_exec function is called....
VXLIB_STATUS VXLIB_halfScaleGaussian_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main kernel compute function.
VXLIB_STATUS VXLIB_halfScaleGaussian_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_halfScaleGaussian_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_halfScaleGaussian_init function....
VXLIB_STATUS VXLIB_halfScaleGaussian_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
This function checks the validity of the parameters passed to VXLIB_halfScaleGaussian_exec 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
int8_t filterSize
Width and height of filter
Structure that is reserved for internal use by the kernel.
VXLIB_halfScaleGaussian_InitArgs pKerInitArgs
Initargs of the kernel.
size_t strideInElements
Stride of input in elements.
pFxnVXLIB_halfScaleGaussian_exec execute
Function pointer to point to the right execution variant between VXLIB_halfScaleGaussian_exec_cn and ...
size_t strideOutElements
Stride of output in elements.