VXLIB User Guide
VXLIB_dilate.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_dilate_priv.h"
41 #include "VXLIB_types.h"
42 #include <cstdint>
43 
44 /**********************************************************************************************************************/
45 /* */
46 /* VXLIB_dilate_getHandleSize */
47 /* */
48 /**********************************************************************************************************************/
49 
50 // this method calculates and returns the size of the handle for the VXLIB_dilate kernel
52 {
53  int32_t privBufSize = sizeof(VXLIB_dilate_PrivArgs);
54  return privBufSize;
55 }
56 
57 /**********************************************************************************************************************/
58 /* */
59 /* VXLIB_dilate_init_checkParams */
60 /* */
61 /**********************************************************************************************************************/
62 
63 // this method checks the initialization parameters for the VXLIB_dilate kernel
66  const VXLIB_bufParams2D_t *bufParamsIn,
67  const VXLIB_bufParams2D_t *bufParamsOut,
68  const VXLIB_dilate_InitArgs *pKerInitArgs)
69 {
70  VXLIB_STATUS status = VXLIB_SUCCESS;
71 
72  // check for null handles
73  if (handle == NULL || bufParamsIn == NULL || bufParamsOut == NULL || pKerInitArgs == NULL) {
74  status = VXLIB_ERR_NULL_POINTER;
75  }
76  else {
77  // obtain input buffer parameters
78  uint32_t dTypeIn = bufParamsIn->data_type;
79  uint32_t widthIn = bufParamsIn->dim_x;
80  uint32_t heightIn = bufParamsIn->dim_y;
81  uint32_t strideIn = bufParamsIn->stride_y;
82 
83  // obtain output buffer parameters
84  uint32_t dTypeOut = bufParamsOut->data_type;
85  uint32_t widthOut = bufParamsOut->dim_x;
86  uint32_t heightOut = bufParamsOut->dim_y;
87  uint32_t strideOut = bufParamsOut->stride_y;
88 
89  size_t filterWidth = pKerInitArgs->filterWidth;
90  size_t filterHeight = pKerInitArgs->filterHeight;
91 
92  // check for valid datatype combinations
94  status = VXLIB_ERR_INVALID_TYPE;
95  }
96  // check valid dimensions; input height, width must be greater, equal to filter size for non padded implementation
97  else if ((widthIn < widthOut) || (heightIn - filterHeight + 1 != heightOut) ||
98  (strideIn / VXLIB_sizeof(dTypeIn) < widthIn) || (strideOut / VXLIB_sizeof(dTypeOut) < widthOut) ||
99  (widthIn < filterWidth) || (heightIn < filterHeight)) {
101  }
102 
103  else {
104  status = VXLIB_SUCCESS;
105  }
106  }
107 
108  return status;
109 }
110 
111 /**********************************************************************************************************************/
112 /* */
113 /* VXLIB_dilate_exec_checkParams */
114 /* */
115 /**********************************************************************************************************************/
116 
117 // this method checks the execution parameters for the VXLIB_dilate kernel
119 VXLIB_dilate_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
120 {
121  VXLIB_STATUS status;
122 
123 #if VXLIB_DEBUGPRINT
124  printf("Enter VXLIB_dilate_exec_checkParams\n");
125 #endif
126  if ((handle == NULL) || (pIn == NULL) || (pOut == NULL)) {
127  status = VXLIB_ERR_NULL_POINTER;
128  }
129  else {
130  status = VXLIB_SUCCESS;
131  }
132 
133  return status;
134 }
135 
136 /**********************************************************************************************************************/
137 /* */
138 /* VXLIB_dilate_init */
139 /* */
140 /**********************************************************************************************************************/
141 
142 // this method is the user-level initialization function for the VXLIB_dilate kernel
144  VXLIB_bufParams2D_t *bufParamsIn,
145  VXLIB_bufParams2D_t *bufParamsOut,
146  const VXLIB_dilate_InitArgs *pKerInitArgs)
147 {
148  VXLIB_STATUS status = VXLIB_SUCCESS;
149  VXLIB_dilate_PrivArgs *pKerPrivArgs = (VXLIB_dilate_PrivArgs *) handle;
150 
151  // copy pKerinitArgs into pKerPrivargs
152  pKerPrivArgs->pKerInitArgs = *pKerInitArgs;
153 
154  // set priv args
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  pKerPrivArgs->strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
161 
162 #if VXLIB_DEBUGPRINT
163  printf("VXLIB_DEBUGPRINT Enter VXLIB_dilate_init\n");
164 #endif
165 
166  // obtain buffer datatypes
167  uint32_t dTypeIn = bufParamsIn->data_type;
168  uint32_t dTypeOut = bufParamsOut->data_type;
169 
170  // determine natural C vs optimized function call
171  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
172 
173  // set function pointer for natural C function with appropriate template parameters based on datatypes
174 
175  if (VXLIB_DILATE_I8U_O8U) {
177  }
178 
179  else if (VXLIB_DILATE_I16U_O16U) {
181  }
182  else {
183  status = VXLIB_ERR_INVALID_TYPE;
184  }
185  }
186  else { // Optimized function
187 
188  // set function pointer for natural C function with appropriate template parameters based on datatypes
189 
190  if (VXLIB_DILATE_I8U_O8U) {
191  status = VXLIB_dilate_init_ci<VXLIB_DILATE_DTYPE_I8U_O8U>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
193  }
194 
195  else if (VXLIB_DILATE_I16U_O16U) {
196  status = VXLIB_dilate_init_ci<VXLIB_DILATE_DTYPE_I16U_O16U>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
198  }
199  else {
200  status = VXLIB_ERR_INVALID_TYPE;
201  }
202  }
203 
204  return status;
205 }
206 
207 /**********************************************************************************************************************/
208 /* */
209 /* VXLIB_dilate_exec */
210 /* */
211 /**********************************************************************************************************************/
212 
213 // this method is the user-level execution function for the VXLIB_dilate kernel
215 VXLIB_dilate_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
216 {
217  VXLIB_STATUS status;
218 
219 #if VXLIB_DEBUGPRINT
220  printf("VXLIB_DEBUGPRINT Enter VXLIB_dilate_exec\n");
221 #endif
222 
223  VXLIB_dilate_PrivArgs *pKerPrivArgs = (VXLIB_dilate_PrivArgs *) handle;
224 
225  status = pKerPrivArgs->execute(handle, pIn, pOut);
226 
227  return status;
228 }
template VXLIB_STATUS VXLIB_dilate_exec_ci< VXLIB_DILATE_TYPENAME_I16U_O16U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template VXLIB_STATUS VXLIB_dilate_init_ci< VXLIB_DILATE_DTYPE_I8U_O8U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_dilate_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_dilate_exec_ci< VXLIB_DILATE_TYPENAME_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template VXLIB_STATUS VXLIB_dilate_init_ci< VXLIB_DILATE_DTYPE_I16U_O16U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_dilate_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_dilate_exec_cn< VXLIB_DILATE_TYPENAME_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template VXLIB_STATUS VXLIB_dilate_exec_cn< VXLIB_DILATE_TYPENAME_I16U_O16U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_dilate.
#define VXLIB_DILATE_I16U_O16U
#define VXLIB_DILATE_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_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_dilate_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main kernel compute function.
VXLIB_STATUS VXLIB_dilate_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
This function checks the validity of the parameters passed to VXLIB_dilate_exec function....
VXLIB_STATUS VXLIB_dilate_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_dilate_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_dilate_exec function is called. This function takes c...
VXLIB_STATUS VXLIB_dilate_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_dilate_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_dilate_init function....
int32_t VXLIB_dilate_getHandleSize(VXLIB_dilate_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
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.
Definition: VXLIB_dilate.h:81
uint32_t filterWidth
Width and height of filter
Definition: VXLIB_dilate.h:86
int8_t funcStyle
Variant of the function, refer to VXLIB_FUNCTION_STYLE
Definition: VXLIB_dilate.h:83
Structure that is reserved for internal use by the kernel.
VXLIB_dilate_InitArgs pKerInitArgs
Initargs of the kernel.
size_t strideOutElements
Stride of output in elements.
size_t strideInElements
Stride of input in elements.
size_t height
Height of image
size_t width
Width of image
pFxnVXLIB_dilate_exec execute
Function pointer to point to the right execution variant between VXLIB_dilate_exec_cn and VXLIB_dilat...