VXLIB User Guide
VXLIB_and.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_and_priv.h"
41 #include <cstdint>
42 
43 /**********************************************************************************************************************/
44 /* */
45 /* VXLIB_and_getHandleSize */
46 /* */
47 /**********************************************************************************************************************/
48 
49 // this method calculates and returns the size of the handle for the VXLIB_and kernel
51 {
52  int32_t privBufSize = sizeof(VXLIB_and_PrivArgs);
53  return privBufSize;
54 }
55 
56 /**********************************************************************************************************************/
57 /* */
58 /* VXLIB_and_init_checkParams */
59 /* */
60 /**********************************************************************************************************************/
61 
62 // this method checks the initialization parameters for the VXLIB_and kernel
65  const VXLIB_bufParams2D_t *bufParamsIn0,
66  const VXLIB_bufParams2D_t *bufParamsIn1,
67  const VXLIB_bufParams2D_t *bufParamsOut,
68  const VXLIB_and_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  status = VXLIB_ERR_INVALID_TYPE;
80  }
81  }
82 
83  if (status == VXLIB_SUCCESS) {
84  if ((bufParamsIn0->dim_x != bufParamsIn1->dim_x) || (bufParamsIn0->dim_y != bufParamsIn1->dim_y) ||
85  (bufParamsIn0->dim_x != bufParamsOut->dim_x) || (bufParamsIn0->dim_y != bufParamsOut->dim_y)) {
87  }
88  }
89 
90  if (status == VXLIB_SUCCESS) {
91  uint32_t strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
92  uint32_t strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
93  uint32_t strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
94  if ((strideIn0Elements < bufParamsIn0->dim_x) || (strideIn1Elements < bufParamsIn1->dim_x) ||
95  (strideOutElements < bufParamsOut->dim_x)) {
97  }
98  }
99 
100  return status;
101 }
102 
103 /**********************************************************************************************************************/
104 /* */
105 /* VXLIB_and_exec_checkParams */
106 /* */
107 /**********************************************************************************************************************/
108 
109 // this method checks the execution parameters for the VXLIB_and kernel
111  const void *restrict pIn0,
112  const void *restrict pIn1,
113  const void *restrict pOut)
114 {
115  VXLIB_STATUS status;
116 
117 #if VXLIB_DEBUGPRINT
118  printf("Enter VXLIB_and_exec_checkParams\n");
119 #endif
120  if ((handle == NULL) || (pIn0 == NULL) || (pIn1 == NULL) || (pOut == NULL)) {
121  status = VXLIB_ERR_NULL_POINTER;
122  }
123  else {
124  status = VXLIB_SUCCESS;
125  }
126 
127  return status;
128 }
129 
130 /**********************************************************************************************************************/
131 /* */
132 /* VXLIB_and_init */
133 /* */
134 /**********************************************************************************************************************/
135 
136 // this method is the user-level initialization function for the VXLIB_and kernel
138  VXLIB_bufParams2D_t *bufParamsIn0,
139  VXLIB_bufParams2D_t *bufParamsIn1,
140  VXLIB_bufParams2D_t *bufParamsOut,
141  const VXLIB_and_InitArgs *pKerInitArgs)
142 {
143  VXLIB_STATUS status = VXLIB_SUCCESS;
144  VXLIB_and_PrivArgs *pKerPrivArgs = (VXLIB_and_PrivArgs *) handle;
145 
146  // set width and height of image
147  pKerPrivArgs->width = bufParamsIn0->dim_x;
148  pKerPrivArgs->height = bufParamsIn0->dim_y;
149 
150  // compute stride in elements as SE/SA params are set to work with given element type
151  pKerPrivArgs->strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
152  pKerPrivArgs->strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
153  pKerPrivArgs->strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
154 
155 #if VXLIB_DEBUGPRINT
156  printf("VXLIB_DEBUGPRINT Enter VXLIB_and_init\n");
157 #endif
158 
159  // obtain buffer datatypes
160  uint32_t dTypeIn0 = bufParamsIn0->data_type;
161 
162  // determine natural C vs optimized function call
163  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
164 
165  // set function pointer for natural C function with appropriate template parameters based on datatypes
166 
167  if ((dTypeIn0 == VXLIB_UINT8)) {
168  pKerPrivArgs->execute = VXLIB_and_exec_cn<uint8_t>;
169  }
170  else {
171  status = VXLIB_ERR_INVALID_TYPE;
172  }
173  }
174  else { // Optimized function
175 
176  // set function pointer for optimized function with appropriate template parameters based on datatypes
177 
178  if (dTypeIn0 == VXLIB_UINT8) {
179  pKerPrivArgs->execute = VXLIB_and_exec_ci<uint8_t>;
180  status = VXLIB_and_init_ci<VXLIB_UINT8>(handle, bufParamsIn0, bufParamsIn1, bufParamsOut, pKerInitArgs);
181  }
182  else {
183  status = VXLIB_ERR_INVALID_TYPE;
184  }
185  }
186 
187  return status;
188 }
189 
190 /**********************************************************************************************************************/
191 /* */
192 /* VXLIB_and_exec */
193 /* */
194 /**********************************************************************************************************************/
195 
196 // this method is the user-level execution function for the VXLIB_and kernel
197 VXLIB_STATUS VXLIB_and_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
198 {
199  VXLIB_STATUS status;
200 
201 #if VXLIB_DEBUGPRINT
202  printf("VXLIB_DEBUGPRINT Enter VXLIB_and_exec\n");
203 #endif
204 
205  VXLIB_and_PrivArgs *pKerPrivArgs = (VXLIB_and_PrivArgs *) handle;
206 
207  status = pKerPrivArgs->execute(handle, pIn0, pIn1, pOut);
208 
209  return status;
210 }
template VXLIB_STATUS VXLIB_and_init_ci< VXLIB_UINT8 >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_and_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_and_exec_ci< uint8_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_and_exec_cn< uint8_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_and.
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_UINT8
int32_t VXLIB_and_getHandleSize(VXLIB_and_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
Definition: VXLIB_and.cpp:50
VXLIB_STATUS VXLIB_and_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_and_exec function....
Definition: VXLIB_and.cpp:110
VXLIB_STATUS VXLIB_and_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn0, VXLIB_bufParams2D_t *bufParamsIn1, VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_and_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_and_exec function is called. This function takes care...
Definition: VXLIB_and.cpp:137
VXLIB_STATUS VXLIB_and_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_and_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_and_init function....
Definition: VXLIB_and.cpp:64
VXLIB_STATUS VXLIB_and_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
This function is the main kernel compute function.
Definition: VXLIB_and.cpp:197
Structure containing the parameters to initialize the kernel.
Definition: VXLIB_and.h:77
int8_t funcStyle
Variant of the function, refer to VXLIB_FUNCTION_STYLE
Definition: VXLIB_and.h:79
Structure that is reserved for internal use by the kernel.
size_t strideIn1Elements
Stride of input1 in elements.
size_t width
Width of image
pFxnVXLIB_and_exec execute
Function pointer to point to the right execution variant between VXLIB_and_exec_cn and VXLIB_and_exec...
size_t strideOutElements
Stride of output in elements.
size_t strideIn0Elements
Stride of input0 in elements.
size_t height
Height of image
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.