VXLIB User Guide
VXLIB_accumulateImage.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_add/VXLIB_add_priv.h"
42 #include <cstdint>
43 
44 /**********************************************************************************************************************/
45 /* */
46 /* VXLIB_accumulateImage_getHandleSize */
47 /* */
48 /**********************************************************************************************************************/
49 
50 // this method calculates and returns the size of the handle for the VXLIB_accumulateImage kernel
51 // in this case, the function returns the size of the handle for the VXLIB_add kernel becuase accumulateSqureImage
52 // has no internal implementation and it calls add implementation instead.
54 {
55  int32_t privBufSize = sizeof(VXLIB_add_PrivArgs);
56  return privBufSize;
57 }
58 
59 /**********************************************************************************************************************/
60 /* */
61 /* VXLIB_accumulateImage_init_checkParams */
62 /* */
63 /**********************************************************************************************************************/
64 
65 // this method checks the initialization parameters for the VXLIB_accumulateImage kernel
68  const VXLIB_bufParams2D_t *bufParamsIn,
69  const VXLIB_bufParams2D_t *bufParamsOut,
70  const VXLIB_accumulateImage_InitArgs *pKerInitArgs)
71 {
72  VXLIB_STATUS status = VXLIB_SUCCESS;
73 
74  // obtain input buffer parameters
75  uint32_t dTypeIn = bufParamsIn->data_type;
76  uint32_t widthIn = bufParamsIn->dim_x;
77  uint32_t heightIn = bufParamsIn->dim_y;
78  uint32_t strideIn = bufParamsIn->stride_y;
79 
80  // obtain output buffer parameters
81  uint32_t dTypeOut = bufParamsOut->data_type;
82  uint32_t widthOut = bufParamsOut->dim_x;
83  uint32_t heightOut = bufParamsOut->dim_y;
84  uint32_t strideOut = bufParamsOut->stride_y;
85 
86  uint32_t strideInElements = strideIn / VXLIB_sizeof(bufParamsIn->data_type);
87  uint32_t strideOutElements = strideOut / VXLIB_sizeof(bufParamsOut->data_type);
88 
89  // check for dimensions and datatype combinations
90  if (handle == NULL) {
91  status = VXLIB_ERR_NULL_POINTER;
92  }
93  else if ((widthIn != widthOut) || (heightIn != heightOut)) {
95  }
96  else if (strideInElements < widthIn || strideOutElements < widthOut) {
98  }
101  status = VXLIB_ERR_INVALID_TYPE;
102  }
103  else {
104  status = VXLIB_SUCCESS;
105  }
106 
107  return status;
108 }
109 
110 /**********************************************************************************************************************/
111 /* */
112 /* VXLIB_accumulateImage_exec_checkParams */
113 /* */
114 /**********************************************************************************************************************/
115 
116 // this method checks the execution parameters for the VXLIB_accumulateImage kernel
118 VXLIB_accumulateImage_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
119 {
120  VXLIB_STATUS status;
121 
122 #if VXLIB_DEBUGPRINT
123  printf("Enter VXLIB_accumulateImage_exec_checkParams\n");
124 #endif
125  if ((handle == NULL) || (pIn == NULL) || (pOut == 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_accumulateImage_init */
138 /* */
139 /**********************************************************************************************************************/
140 
141 // this method is the user-level initialization function for the VXLIB_accumulateImage kernel
143  VXLIB_bufParams2D_t *bufParamsIn,
144  VXLIB_bufParams2D_t *bufParamsOut,
145  const VXLIB_accumulateImage_InitArgs *pKerInitArgs)
146 {
147  VXLIB_STATUS status = VXLIB_SUCCESS;
148  VXLIB_add_PrivArgs *pKerPrivArgs = (VXLIB_add_PrivArgs *) handle;
149 
150  // copy pKerinitArgs into pKerPrivargs
151  // cast the VXLIB_accumulateImage_InitArgs to VXLIB_add_InitArgs
152  VXLIB_add_InitArgs *kerInitArgsAdd = (VXLIB_add_InitArgs *) pKerInitArgs;
153 
154  pKerPrivArgs->pKerInitArgs = *kerInitArgsAdd;
155 
156  // set width and height of image
157  pKerPrivArgs->width = bufParamsIn->dim_x;
158  pKerPrivArgs->height = bufParamsIn->dim_y;
159 
160  // compute stride in elements as SE/SA params are set to work with given element type
161  pKerPrivArgs->strideIn0Elements = bufParamsIn->stride_y / VXLIB_sizeof(bufParamsIn->data_type);
162  pKerPrivArgs->strideIn1Elements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
163  pKerPrivArgs->strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
164 
165 #if VXLIB_DEBUGPRINT
166  printf("VXLIB_DEBUGPRINT Enter VXLIB_accumulateImage_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  }
186  else {
187  status = VXLIB_ERR_INVALID_TYPE;
188  }
189  }
190  else { // Optimized function
191 
192  // set function pointer for natural C function with appropriate template parameters based on datatypes
195  status = VXLIB_add_init_ci<VXLIB_ADD_DTYPE_I8U_I8U_O8U>(handle, bufParamsIn, bufParamsOut, bufParamsOut,
196  kerInitArgsAdd);
197  }
200  status = VXLIB_add_init_ci<VXLIB_ADD_DTYPE_I8U_I16S_O16S>(handle, bufParamsIn, bufParamsOut, bufParamsOut,
201  kerInitArgsAdd);
202  }
205  status = VXLIB_add_init_ci<VXLIB_ADD_DTYPE_I16S_I16S_O16S>(handle, bufParamsIn, bufParamsOut, bufParamsOut,
206  kerInitArgsAdd);
207  }
208  else {
209  status = VXLIB_ERR_INVALID_TYPE;
210  }
211  }
212 
213  return status;
214 }
215 
216 /**********************************************************************************************************************/
217 /* */
218 /* VXLIB_accumulateImage_exec */
219 /* */
220 /**********************************************************************************************************************/
221 
222 // this method is the user-level execution function for the VXLIB_accumulateImage kernel
223 VXLIB_STATUS VXLIB_accumulateImage_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
224 {
225  VXLIB_STATUS status;
226 
227 #if VXLIB_DEBUGPRINT
228  printf("VXLIB_DEBUGPRINT Enter VXLIB_accumulateImage_exec\n");
229 #endif
230 
231  VXLIB_add_PrivArgs *pKerPrivArgs = (VXLIB_add_PrivArgs *) handle;
232 
233  status = pKerPrivArgs->execute(handle, pIn, pOut, pOut);
234 
235  return status;
236 }
237 
238 void VXLIB_accumulateImage_perfEst(VXLIB_kernelHandle handle, size_t *archCycles, size_t *estCycles)
239 {
240 
241  // typecast handle (void) to struct pointer type associated to kernel
242  VXLIB_add_PrivArgs *pKerPrivArgs = (VXLIB_add_PrivArgs *) handle;
243 
244  // obtain loop count for compute loop
245  size_t numBlocks = pKerPrivArgs->numBlocks;
246  size_t overheadCnt = 17; // profiled code before entering compute loop
247  *archCycles = 7 + numBlocks * 2; // obtained from asm
248  *estCycles = overheadCnt + *archCycles;
249 }
Header file for kernel's internal use. For the kernel's interface. Note: The VXLIB_accumulateImage do...
#define VXLIB_ACCUMULATEIMAGE_I8U_O8U
Macros that will be useful to check for datatype combinations.
#define VXLIB_ACCUMULATEIMAGE_I16S_O16S
#define VXLIB_ACCUMULATEIMAGE_I8U_O16S
template VXLIB_STATUS VXLIB_add_init_ci< VXLIB_ADD_DTYPE_I16S_I16S_O16S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_add_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_add_init_ci< VXLIB_ADD_DTYPE_I8U_I8U_O8U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_add_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_add_exec_ci< VXLIB_ADD_TYPENAME_I8U_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_add_exec_ci< VXLIB_ADD_TYPENAME_I8U_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_add_init_ci< VXLIB_ADD_DTYPE_I8U_I16S_O16S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_add_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_add_exec_ci< VXLIB_ADD_TYPENAME_I16S_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_add_exec_cn< VXLIB_ADD_TYPENAME_I8U_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_add_exec_cn< VXLIB_ADD_TYPENAME_I8U_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_add_exec_cn< VXLIB_ADD_TYPENAME_I16S_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
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_accumulateImage_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
This function checks the validity of the parameters passed to VXLIB_accumulateImage_exec function....
void VXLIB_accumulateImage_perfEst(VXLIB_kernelHandle handle, size_t *archCycles, size_t *estCycles)
VXLIB_STATUS VXLIB_accumulateImage_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_accumulateImage_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_accumulateImage_exec function is called....
int32_t VXLIB_accumulateImage_getHandleSize(VXLIB_accumulateImage_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
VXLIB_STATUS VXLIB_accumulateImage_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main kernel compute function.
VXLIB_STATUS VXLIB_accumulateImage_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_accumulateImage_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_accumulateImage_init function....
Structure containing the parameters to initialize the kernel.
int8_t funcStyle
Variant of the function, refer to VXLIB_FUNCTION_STYLE
Structure containing the parameters to initialize the kernel.
Definition: VXLIB_add.h:82
Structure that is reserved for internal use by the kernel.
VXLIB_add_InitArgs pKerInitArgs
Initargs of the kernel.
size_t strideIn0Elements
Stride of input0 in elements.
size_t strideIn1Elements
Stride of input1 in elements.
pFxnVXLIB_add_exec execute
Function pointer to point to the right execution variant between VXLIB_add_exec_cn and VXLIB_add_exec...
size_t width
Width of image
size_t numBlocks
Number of blocks to be processed after simidfication.
size_t height
Height of image
size_t strideOutElements
Stride of output in elements.
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.