VXLIB User Guide
VXLIB_normL1.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_normL1_priv.h"
41 #include <cstdint>
42 
43 /**********************************************************************************************************************/
44 /* */
45 /* VXLIB_normL1_getHandleSize */
46 /* */
47 /**********************************************************************************************************************/
48 
49 // this method calculates and returns the size of the handle for the VXLIB_normL1 kernel
51 {
52  int32_t privBufSize = sizeof(VXLIB_normL1_PrivArgs);
53  return privBufSize;
54 }
55 
56 /**********************************************************************************************************************/
57 /* */
58 /* VXLIB_normL1_init_checkParams */
59 /* */
60 /**********************************************************************************************************************/
61 
62 // this method checks the initialization parameters for the VXLIB_normL1 kernel
65  const VXLIB_bufParams2D_t * bufParamsIn0,
66  const VXLIB_bufParams2D_t * bufParamsIn1,
67  const VXLIB_bufParams2D_t * bufParamsOut,
68  const VXLIB_normL1_InitArgs *pKerInitArgs)
69 {
70  VXLIB_STATUS status = VXLIB_SUCCESS;
71 
72  if (handle == NULL || bufParamsIn0 == NULL || bufParamsIn1 == NULL || bufParamsOut == NULL || pKerInitArgs == NULL) {
73  status = VXLIB_ERR_NULL_POINTER;
74  }
75 
76  if (status == VXLIB_SUCCESS) {
77  if (((bufParamsIn0->data_type != VXLIB_INT8) || (bufParamsIn1->data_type != VXLIB_INT8) ||
78  (bufParamsOut->data_type != VXLIB_UINT8)) &&
79  ((bufParamsIn0->data_type != VXLIB_INT16) || (bufParamsIn1->data_type != VXLIB_INT16) ||
80  (bufParamsOut->data_type != VXLIB_UINT16))) {
81  status = VXLIB_ERR_INVALID_TYPE;
82  }
83  }
84 
85  if (status == VXLIB_SUCCESS) {
86  if ((bufParamsIn0->dim_x != bufParamsIn1->dim_x) || (bufParamsIn0->dim_y != bufParamsIn1->dim_y) ||
87  (bufParamsIn0->dim_x != bufParamsOut->dim_x) || (bufParamsIn0->dim_y != bufParamsOut->dim_y)) {
89  }
90  }
91 
92  if (status == VXLIB_SUCCESS) {
93  uint32_t strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
94  uint32_t strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
95  uint32_t strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
96  if ((strideIn0Elements < bufParamsIn0->dim_x) || (strideIn1Elements < bufParamsIn1->dim_x) ||
97  (strideOutElements < bufParamsOut->dim_x)) {
99  }
100  }
101 
102  return status;
103 }
104 
105 /**********************************************************************************************************************/
106 /* */
107 /* VXLIB_normL1_exec_checkParams */
108 /* */
109 /**********************************************************************************************************************/
110 
111 // this method checks the execution parameters for the VXLIB_normL1 kernel
113  const void *restrict pIn0,
114  const void *restrict pIn1,
115  const void *restrict pOut)
116 {
117  VXLIB_STATUS status;
118 
119 #if VXLIB_DEBUGPRINT
120  printf("Enter VXLIB_normL1_exec_checkParams\n");
121 #endif
122  if ((handle == NULL) || (pIn0 == NULL) || (pIn1 == NULL) || (pOut == NULL)) {
123  status = VXLIB_ERR_NULL_POINTER;
124  }
125  else {
126  status = VXLIB_SUCCESS;
127  }
128 
129  return status;
130 }
131 
132 /**********************************************************************************************************************/
133 /* */
134 /* VXLIB_normL1_init */
135 /* */
136 /**********************************************************************************************************************/
137 
138 // this method is the user-level initialization function for the VXLIB_normL1 kernel
140  VXLIB_bufParams2D_t * bufParamsIn0,
141  VXLIB_bufParams2D_t * bufParamsIn1,
142  VXLIB_bufParams2D_t * bufParamsOut,
143  const VXLIB_normL1_InitArgs *pKerInitArgs)
144 {
145  VXLIB_STATUS status = VXLIB_SUCCESS;
146  VXLIB_normL1_PrivArgs *pKerPrivArgs = (VXLIB_normL1_PrivArgs *) handle;
147 
148  // set width and height of image
149  pKerPrivArgs->width = bufParamsIn0->dim_x;
150  pKerPrivArgs->height = bufParamsIn0->dim_y;
151 
152  // compute stride in elements as SE/SA params are set to work with given element type
153  pKerPrivArgs->strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
154  pKerPrivArgs->strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
155  pKerPrivArgs->strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
156 
157 #if VXLIB_DEBUGPRINT
158  printf("VXLIB_DEBUGPRINT Enter VXLIB_normL1_init\n");
159 #endif
160 
161  // obtain buffer datatypes
162  uint32_t dTypeIn = bufParamsIn0->data_type;
163  uint32_t dTypeOut = bufParamsOut->data_type;
164 
165  // determine natural C vs optimized function call
166  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
167 
168  if (VXLIB_NOMRL1_I8S_O8U) {
170  }
171  else if (VXLIB_NORML1_I16S_O16U) {
173  }
174  else {
175  status = VXLIB_ERR_INVALID_TYPE;
176  }
177  }
178  else {
179  // Optimized function
180  // set function pointer for optimized function with appropriate template parameters based on datatypes
181  if (VXLIB_NOMRL1_I8S_O8U) {
183  status = VXLIB_normL1_init_ci<VXLIB_NORML1_DTYPE_I8S_O8U>(handle, bufParamsIn0, bufParamsIn1, bufParamsOut,
184  pKerInitArgs);
185  }
186  else if (VXLIB_NORML1_I16S_O16U) {
188  status = VXLIB_normL1_init_ci<VXLIB_NORML1_DTYPE_I16S_O16U>(handle, bufParamsIn0, bufParamsIn1, bufParamsOut,
189  pKerInitArgs);
190  }
191  else {
192  status = VXLIB_ERR_INVALID_TYPE;
193  }
194  }
195 
196  return status;
197 }
198 
199 /**********************************************************************************************************************/
200 /* */
201 /* VXLIB_normL1_exec */
202 /* */
203 /**********************************************************************************************************************/
204 
205 // this method is the user-level execution function for the VXLIB_normL1 kernel
206 VXLIB_STATUS VXLIB_normL1_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
207 {
208  VXLIB_STATUS status;
209 
210 #if VXLIB_DEBUGPRINT
211  printf("VXLIB_DEBUGPRINT Enter VXLIB_normL1_exec\n");
212 #endif
213 
214  VXLIB_normL1_PrivArgs *pKerPrivArgs = (VXLIB_normL1_PrivArgs *) handle;
215 
216  status = pKerPrivArgs->execute(handle, pIn0, pIn1, pOut);
217 
218  return status;
219 }
220 
221 /* ======================================================================== */
222 /* End of file: VXLIB_normL1.cpp */
223 /* ======================================================================== */
template VXLIB_STATUS VXLIB_normL1_exec_ci< VXLIB_NORML1_TYPENAME_I16S_O16U >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_normL1_init_ci< VXLIB_NORML1_DTYPE_I8S_O8U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_normL1_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_normL1_init_ci< VXLIB_NORML1_DTYPE_I16S_O16U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_normL1_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_normL1_exec_ci< VXLIB_NORML1_TYPENAME_I8S_O8U >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_normL1_exec_cn< VXLIB_NORML1_TYPENAME_I16S_O16U >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_normL1_exec_cn< VXLIB_NORML1_TYPENAME_I8S_O8U >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_normL1.
#define VXLIB_NOMRL1_I8S_O8U
Macros that will be useful to check for datatype combinations.
#define VXLIB_NORML1_I16S_O16U
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_UINT16
@ VXLIB_INT16
@ VXLIB_INT8
@ VXLIB_UINT8
VXLIB_STATUS VXLIB_normL1_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_normL1_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_normL1_init function....
VXLIB_STATUS VXLIB_normL1_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
This function is the main kernel compute function.
VXLIB_STATUS VXLIB_normL1_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn0, const void *restrict pIn1, const void *restrict pOut)
This function checks the validity of the parameters passed to VXLIB_normL1_exec function....
int32_t VXLIB_normL1_getHandleSize(VXLIB_normL1_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
VXLIB_STATUS VXLIB_normL1_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn0, VXLIB_bufParams2D_t *bufParamsIn1, VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_normL1_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_normL1_exec function is called. This function takes c...
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_normL1.h:79
int8_t funcStyle
Variant of the function, refer to VXLIB_FUNCTION_STYLE
Definition: VXLIB_normL1.h:81
Structure that is reserved for internal use by the kernel.
pFxnVXLIB_normL1_exec execute
Function pointer to point to the right execution variant between VXLIB_normL1_exec_cn and VXLIB_normL...
size_t strideOutElements
Stride of output in elements.
size_t strideIn1Elements
Stride of input1 in elements.
size_t height
Height of image
size_t width
Width of image
size_t strideIn0Elements
Stride of input0 in elements.