VXLIB User Guide
VXLIB_absDiff.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 #include "VXLIB_absDiff_priv.h"
35 
37 {
38  int32_t privBufSize = sizeof(VXLIB_absDiff_PrivArgs);
39  return privBufSize;
40 }
41 
44  const VXLIB_bufParams2D_t *bufParamsIn0,
45  const VXLIB_bufParams2D_t *bufParamsIn1,
46  const VXLIB_bufParams2D_t *bufParamsOut,
47  const VXLIB_absDiff_InitArgs *pKerInitArgs)
48 {
49  VXLIB_STATUS status = VXLIB_SUCCESS;
50 
51 #if VXLIB_DEBUGPRINT
52  printf("Enter VXLIB_absDiff_init_checkParams\n");
53 #endif
54  if (handle == NULL || bufParamsIn0 == NULL || bufParamsIn1 == NULL || bufParamsOut == NULL || pKerInitArgs == NULL) {
55  status = VXLIB_ERR_NULL_POINTER;
56  }
57 
58  if (status == VXLIB_SUCCESS) {
59  if (((bufParamsIn0->data_type != VXLIB_INT16) && (bufParamsIn1->data_type != VXLIB_INT16)) &&
60  ((bufParamsIn0->data_type != VXLIB_UINT8) && (bufParamsIn1->data_type != VXLIB_UINT8))) {
61  status = VXLIB_ERR_INVALID_TYPE;
62  }
63  else if (bufParamsIn0->data_type != bufParamsOut->data_type ||
64  bufParamsIn1->data_type != bufParamsOut->data_type) {
65  status = VXLIB_ERR_INVALID_TYPE;
66  }
67  else {
68  /* Nothing to do here */
69  }
70  }
71 
72  if (status == VXLIB_SUCCESS) {
73 
74  uint32_t strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
75  uint32_t strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
76  uint32_t strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
77 
78  if ((bufParamsIn0->dim_x != bufParamsIn1->dim_x) || (bufParamsIn0->dim_y != bufParamsIn1->dim_y) ||
79  (bufParamsIn0->dim_x != bufParamsOut->dim_x) || (bufParamsIn0->dim_y != bufParamsOut->dim_y) ||
80  (strideIn0Elements < bufParamsIn0->dim_x) || (strideIn1Elements < bufParamsIn1->dim_x) ||
81  (strideOutElements < bufParamsOut->dim_x)) {
83  }
84  }
85 
86  return status;
87 }
88 
90  const void *restrict pIn0,
91  const void *restrict pIn1,
92  const void *restrict pOut)
93 {
94  VXLIB_STATUS status;
95 
96 #if VXLIB_DEBUGPRINT
97  printf("Enter VXLIB_absDiff_exec_checkParams\n");
98 #endif
99  if ((handle == NULL) || (pIn0 == NULL) || (pIn1 == NULL) || (pOut == NULL)) {
100  status = VXLIB_ERR_NULL_POINTER;
101  }
102  else {
103  status = VXLIB_SUCCESS;
104  }
105 
106  return status;
107 }
108 
110  VXLIB_bufParams2D_t *bufParamsIn0,
111  VXLIB_bufParams2D_t *bufParamsIn1,
112  VXLIB_bufParams2D_t *bufParamsOut,
113  const VXLIB_absDiff_InitArgs *pKerInitArgs)
114 {
115  VXLIB_STATUS status = VXLIB_SUCCESS;
116  VXLIB_absDiff_PrivArgs *pKerPrivArgs = (VXLIB_absDiff_PrivArgs *) handle;
117 
118  uint32_t height = bufParamsOut->dim_y;
119  uint32_t width = bufParamsOut->dim_x;
120 
121  uint32_t strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
122  uint32_t strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
123  uint32_t strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
124 
125  pKerPrivArgs->height = height;
126  pKerPrivArgs->width = width;
127  pKerPrivArgs->strideIn0Elements = strideIn0Elements;
128  pKerPrivArgs->strideIn1Elements = strideIn1Elements;
129  pKerPrivArgs->strideOutElements = strideOutElements;
130 
131 #if VXLIB_DEBUGPRINT
132  printf("VXLIB_DEBUGPRINT Enter VXLIB_absDiff_init\n");
133 #endif
134 
135  // determine natural C vs optimized function call
136  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
137 
138  // set function pointer for natural C function with appropriate template parameters based on datatypes
139  if (bufParamsIn0->data_type == VXLIB_UINT8) {
140  pKerPrivArgs->execute = VXLIB_absDiff_exec_cn<uint8_t>;
141  }
142  else if (bufParamsIn0->data_type == VXLIB_INT16) {
143  pKerPrivArgs->execute = VXLIB_absDiff_exec_cn<int16_t>;
144  }
145  else {
146  status = VXLIB_ERR_INVALID_TYPE;
147  }
148  }
149  else {
150 
151  // optimized function
152  // set function pointer for optimized function with appropriate template parameters based on datatypes
153  if (bufParamsIn0->data_type == VXLIB_UINT8) {
154  pKerPrivArgs->execute = VXLIB_absDiff_exec_ci<uint8_t>;
155  status = VXLIB_absDiff_init_ci<VXLIB_UINT8>(handle, bufParamsIn0, bufParamsIn1, bufParamsOut, pKerInitArgs);
156  }
157  else if (bufParamsIn0->data_type == VXLIB_INT16) {
158  pKerPrivArgs->execute = VXLIB_absDiff_exec_ci<int16_t>;
159  status = VXLIB_absDiff_init_ci<VXLIB_INT16>(handle, bufParamsIn0, bufParamsIn1, bufParamsOut, pKerInitArgs);
160  }
161  else {
162  status = VXLIB_ERR_INVALID_TYPE;
163  }
164  }
165 
166  return status;
167 }
168 
170 VXLIB_absDiff_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
171 {
172  VXLIB_STATUS status;
173 
174 #if VXLIB_DEBUGPRINT
175  printf("VXLIB_DEBUGPRINT Enter VXLIB_absDiff_exec\n");
176 #endif
177 
178  VXLIB_absDiff_PrivArgs *pKerPrivArgs = (VXLIB_absDiff_PrivArgs *) handle;
179 
180  status = pKerPrivArgs->execute(handle, pIn0, pIn1, pOut);
181 
182  return status;
183 }
template VXLIB_STATUS VXLIB_absDiff_init_ci< VXLIB_INT16 >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_absDiff_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_absDiff_exec_ci< uint8_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_absDiff_exec_ci< int16_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_absDiff_init_ci< VXLIB_UINT8 >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_absDiff_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_absDiff_exec_cn< int16_t >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_absDiff_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_absDiff.
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_INT16
@ VXLIB_UINT8
VXLIB_STATUS VXLIB_absDiff_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
This function is the main kernel compute function.
VXLIB_STATUS VXLIB_absDiff_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn0, VXLIB_bufParams2D_t *bufParamsIn1, VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_absDiff_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_absDiff_exec function is called. This function takes ...
VXLIB_STATUS VXLIB_absDiff_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_absDiff_exec function....
int32_t VXLIB_absDiff_getHandleSize(VXLIB_absDiff_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
VXLIB_STATUS VXLIB_absDiff_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_absDiff_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_absDiff_init function....
Structure containing the parameters to initialize the kernel.
Definition: VXLIB_absDiff.h:78
int8_t funcStyle
Variant of the function refer to VXLIB_FUNCTION_STYLE
Definition: VXLIB_absDiff.h:80
Structure that is reserved for internal use by the kernel.
uint32_t height
Height of image
uint32_t strideIn1Elements
Stride of input1 in elements.
pFxnVXLIB_absDiff_exec execute
Function pointer to point to the right execution variant between VXLIB_absDiff_exec_cn and VXLIB_absD...
uint32_t strideIn0Elements
Stride of input0 in elements.
uint32_t width
Width of image
uint32_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.