VXLIB User Guide
VXLIB_xor.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_xor_priv.h"
41 #include <cstdint>
42 
43 /**********************************************************************************************************************/
44 /* */
45 /* VXLIB_xor_getHandleSize */
46 /* */
47 /**********************************************************************************************************************/
48 
49 // this method calculates and returns the size of the handle for the VXLIB_xor kernel
51 {
52  int32_t privBufSize = sizeof(VXLIB_xor_PrivArgs);
53  return privBufSize;
54 }
55 
56 /**********************************************************************************************************************/
57 /* */
58 /* VXLIB_xor_init_checkParams */
59 /* */
60 /**********************************************************************************************************************/
61 
62 // this method checks the initialization parameters for the VXLIB_xor kernel
65  const VXLIB_bufParams2D_t *bufParamsIn0,
66  const VXLIB_bufParams2D_t *bufParamsIn1,
67  const VXLIB_bufParams2D_t *bufParamsOut,
68  const VXLIB_xor_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_UINT8) || (bufParamsIn1->data_type != VXLIB_UINT8) ||
78  (bufParamsOut->data_type != VXLIB_UINT8)) &&
79  ((bufParamsIn0->data_type != VXLIB_UINT16) || (bufParamsIn1->data_type != VXLIB_UINT16) ||
80  (bufParamsOut->data_type != VXLIB_UINT16)) &&
81  ((bufParamsIn0->data_type != VXLIB_INT8) || (bufParamsIn1->data_type != VXLIB_INT8) ||
82  (bufParamsOut->data_type != VXLIB_INT8)) &&
83  ((bufParamsIn0->data_type != VXLIB_INT16) || (bufParamsIn1->data_type != VXLIB_INT16) ||
84  (bufParamsOut->data_type != VXLIB_INT16))) {
85  status = VXLIB_ERR_INVALID_TYPE;
86  }
87  }
88 
89  if (status == VXLIB_SUCCESS) {
90  if ((bufParamsIn0->dim_x != bufParamsIn1->dim_x) || (bufParamsIn0->dim_y != bufParamsIn1->dim_y) ||
91  (bufParamsIn0->dim_x != bufParamsOut->dim_x) || (bufParamsIn0->dim_y != bufParamsOut->dim_y)) {
93  }
94  }
95 
96  if (status == VXLIB_SUCCESS) {
97  uint32_t strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
98  uint32_t strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
99  uint32_t strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
100  if ((strideIn0Elements < bufParamsIn0->dim_x) || (strideIn1Elements < bufParamsIn1->dim_x) ||
101  (strideOutElements < bufParamsOut->dim_x)) {
103  }
104  }
105 
106  return status;
107 }
108 
109 /**********************************************************************************************************************/
110 /* */
111 /* VXLIB_xor_exec_checkParams */
112 /* */
113 /**********************************************************************************************************************/
114 
115 // this method checks the execution parameters for the VXLIB_xor kernel
117  const void *restrict pIn0,
118  const void *restrict pIn1,
119  const void *restrict pOut)
120 {
121  VXLIB_STATUS status;
122 
123 #if VXLIB_DEBUGPRINT
124  printf("Enter VXLIB_xor_exec_checkParams\n");
125 #endif
126  if ((handle == NULL) || (pIn0 == NULL) || (pIn1 == 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_xor_init */
139 /* */
140 /**********************************************************************************************************************/
141 
142 // this method is the user-level initialization function for the VXLIB_xor kernel
144  VXLIB_bufParams2D_t * bufParamsIn0,
145  VXLIB_bufParams2D_t * bufParamsIn1,
146  VXLIB_bufParams2D_t * bufParamsOut,
147  const VXLIB_xor_InitArgs *pKerInitArgs)
148 {
149  VXLIB_STATUS status = VXLIB_SUCCESS;
150  VXLIB_xor_PrivArgs *pKerPrivArgs = (VXLIB_xor_PrivArgs *) handle;
151 
152  // set width and height of image
153  pKerPrivArgs->width = bufParamsIn0->dim_x;
154  pKerPrivArgs->height = bufParamsIn0->dim_y;
155 
156  // compute stride in elements as SE/SA params are set to work with given element type
157  pKerPrivArgs->strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
158  pKerPrivArgs->strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
159  pKerPrivArgs->strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
160 
161 #if VXLIB_DEBUGPRINT
162  printf("VXLIB_DEBUGPRINT Enter VXLIB_xor_init\n");
163 #endif
164 
165  // obtain buffer datatypes
166  uint32_t dTypeIn0 = bufParamsIn0->data_type;
167 
168  // determine natural C vs optimized function call
169  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
170 
171  // set function pointer for natural C function with appropriate template parameters based on datatypes
172 
173  if ((dTypeIn0 == VXLIB_UINT8)) {
174  pKerPrivArgs->execute = VXLIB_xor_exec_cn<uint8_t>;
175  }
176  else if (dTypeIn0 == VXLIB_UINT16) {
177  pKerPrivArgs->execute = VXLIB_xor_exec_cn<uint16_t>;
178  }
179  else if ((dTypeIn0 == VXLIB_INT8)) {
180  pKerPrivArgs->execute = VXLIB_xor_exec_cn<int8_t>;
181  }
182  else if (dTypeIn0 == VXLIB_INT16) {
183  pKerPrivArgs->execute = VXLIB_xor_exec_cn<int16_t>;
184  }
185  else {
186  status = VXLIB_ERR_INVALID_TYPE;
187  }
188  }
189  else { // Optimized function
190 
191  // set function pointer for optimized function with appropriate template parameters based on datatypes
192 
193  if (dTypeIn0 == VXLIB_UINT8) {
194  pKerPrivArgs->execute = VXLIB_xor_exec_ci<uint8_t>;
195  status = VXLIB_xor_init_ci<VXLIB_UINT8>(handle, bufParamsIn0, bufParamsIn1, bufParamsOut, pKerInitArgs);
196  }
197  else if (dTypeIn0 == VXLIB_UINT16) {
198  pKerPrivArgs->execute = VXLIB_xor_exec_ci<uint16_t>;
199  status = VXLIB_xor_init_ci<VXLIB_UINT16>(handle, bufParamsIn0, bufParamsIn1, bufParamsOut, pKerInitArgs);
200  }
201  else if (dTypeIn0 == VXLIB_INT8) {
202  pKerPrivArgs->execute = VXLIB_xor_exec_ci<int8_t>;
203  status = VXLIB_xor_init_ci<VXLIB_INT8>(handle, bufParamsIn0, bufParamsIn1, bufParamsOut, pKerInitArgs);
204  }
205  else if (dTypeIn0 == VXLIB_INT16) {
206  pKerPrivArgs->execute = VXLIB_xor_exec_ci<int16_t>;
207  status = VXLIB_xor_init_ci<VXLIB_INT16>(handle, bufParamsIn0, bufParamsIn1, bufParamsOut, pKerInitArgs);
208  }
209  else {
210  status = VXLIB_ERR_INVALID_TYPE;
211  }
212  }
213 
214  return status;
215 }
216 
217 /**********************************************************************************************************************/
218 /* */
219 /* VXLIB_xor_exec */
220 /* */
221 /**********************************************************************************************************************/
222 
223 // this method is the user-level execution function for the VXLIB_xor kernel
224 VXLIB_STATUS VXLIB_xor_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
225 {
226  VXLIB_STATUS status;
227 
228 #if VXLIB_DEBUGPRINT
229  printf("VXLIB_DEBUGPRINT Enter VXLIB_xor_exec\n");
230 #endif
231 
232  VXLIB_xor_PrivArgs *pKerPrivArgs = (VXLIB_xor_PrivArgs *) handle;
233 
234  status = pKerPrivArgs->execute(handle, pIn0, pIn1, pOut);
235 
236  return status;
237 }
238 
239 /* ======================================================================== */
240 /* End of file: VXLIB_xor.cpp */
241 /* ======================================================================== */
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
template VXLIB_STATUS VXLIB_xor_init_ci< VXLIB_INT8 >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_xor_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_xor_init_ci< VXLIB_INT16 >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_xor_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_xor_init_ci< VXLIB_UINT16 >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_xor_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_xor_exec_ci< int16_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_xor_exec_ci< uint16_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_xor_exec_ci< int8_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_xor_exec_ci< uint8_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_xor_init_ci< VXLIB_UINT8 >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_xor_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_xor_exec_cn< uint16_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_xor_exec_cn< uint8_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_xor_exec_cn< int16_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_xor_exec_cn< int8_t >(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_xor.
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_xor_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
This function is the main kernel compute function.
Definition: VXLIB_xor.cpp:224
VXLIB_STATUS VXLIB_xor_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_xor_exec function....
Definition: VXLIB_xor.cpp:116
VXLIB_STATUS VXLIB_xor_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn0, VXLIB_bufParams2D_t *bufParamsIn1, VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_xor_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_xor_exec function is called. This function takes care...
Definition: VXLIB_xor.cpp:143
VXLIB_STATUS VXLIB_xor_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_xor_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_xor_init function....
Definition: VXLIB_xor.cpp:64
int32_t VXLIB_xor_getHandleSize(VXLIB_xor_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
Definition: VXLIB_xor.cpp:50
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_xor.h:81
int8_t funcStyle
Variant of the function, refer to VXLIB_FUNCTION_STYLE
Definition: VXLIB_xor.h:83
Structure that is reserved for internal use by the kernel.
size_t height
Height of image
size_t width
Width of image
pFxnVXLIB_xor_exec execute
Function pointer to point to the right execution variant between VXLIB_xor_exec_cn and VXLIB_xor_exec...
size_t strideIn1Elements
Stride of input1 in elements.
size_t strideOutElements
Stride of output in elements.
size_t strideIn0Elements
Stride of input0 in elements.