VXLIB User Guide
VXLIB_histogram.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_histogram_priv.h"
41 
42 /**********************************************************************************************************************/
43 /* */
44 /* VXLIB_histogram_getHandleSize */
45 /* */
46 /**********************************************************************************************************************/
47 
48 // this method calculates and returns the size of the handle for the VXLIB_histogram kernel
50 {
51  int32_t privBufSize = sizeof(VXLIB_histogram_PrivArgs);
52  return privBufSize;
53 }
54 
55 /**********************************************************************************************************************/
56 /* */
57 /* VXLIB_histogram_init_checkParams */
58 /* */
59 /**********************************************************************************************************************/
60 
61 // this method checks the initialization parameters for the VXLIB_histogram kernel
64  const VXLIB_bufParams2D_t *bufParamsIn,
65  const VXLIB_bufParams1D_t *bufParamsOut,
66  const VXLIB_histogram_InitArgs *pKerInitArgs)
67 {
68  VXLIB_STATUS status = VXLIB_SUCCESS;
69 
70  // obtain input0 buffer parameters
71  uint32_t dTypeIn = bufParamsIn->data_type;
72  uint32_t widthIn = bufParamsIn->dim_x;
73  uint32_t strideIn = bufParamsIn->stride_y;
74 
75  // obtain output buffer parameters
76  uint32_t dTypeOut = bufParamsOut->data_type;
77 
78  uint8_t offset = pKerInitArgs->offset;
79  uint16_t range = pKerInitArgs->range;
80  uint16_t numBins = pKerInitArgs->numBins;
81  uint8_t lastBlock = pKerInitArgs->lastBlock;
82 
83  // check for dimensions and datatype combinations
84  if (handle == NULL) {
85  status = VXLIB_ERR_NULL_POINTER;
86  }
87  else if (!(VXLIB_HISTOGRAM_I8U_O32U)) {
88  status = VXLIB_ERR_INVALID_TYPE;
89  }
90  else if ((strideIn < widthIn)) {
92  }
93  else if (((offset + range) > VXLIB_HISTOGRAM_MAX_PIXEL_VALUE) || (numBins > VXLIB_HISTOGRAM_MAX_PIXEL_VALUE)) {
94  status = VXLIB_ERR_INVALID_VALUE;
95  }
96  else if ((lastBlock != 0) && (lastBlock != 1)) {
97  status = VXLIB_ERR_INVALID_VALUE;
98  }
99  else {
100  status = VXLIB_SUCCESS;
101  }
102 
103  return status;
104 }
105 
106 /**********************************************************************************************************************/
107 /* */
108 /* VXLIB_histogram_exec_checkParams */
109 /* */
110 /**********************************************************************************************************************/
111 
112 // this method checks the execution parameters for the VXLIB_histogram kernel
114 VXLIB_histogram_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
115 {
116  VXLIB_STATUS status;
117 
118 #if VXLIB_DEBUGPRINT
119  printf("Enter VXLIB_histogram_exec_checkParams\n");
120 #endif
121  if ((handle == NULL) || (pIn == NULL) || (pOut == NULL)) {
122  status = VXLIB_ERR_NULL_POINTER;
123  }
124  else {
125  status = VXLIB_SUCCESS;
126  }
127 
128  return status;
129 }
130 
131 /**********************************************************************************************************************/
132 /* */
133 /* VXLIB_histogram_init */
134 /* */
135 /**********************************************************************************************************************/
136 
137 // this method is the user-level initialization function for the VXLIB_histogram kernel
139  VXLIB_bufParams2D_t *bufParamsIn,
140  VXLIB_bufParams1D_t *bufParamsOut,
141  const VXLIB_histogram_InitArgs *pKerInitArgs)
142 {
143  VXLIB_STATUS status = VXLIB_SUCCESS;
144  VXLIB_histogram_PrivArgs *pKerPrivArgs = (VXLIB_histogram_PrivArgs *) handle;
145 
146  // copy pKerinitArgs into pKerPrivargs
147  pKerPrivArgs->pKerInitArgs = *pKerInitArgs;
148 
149  // set width and height of image
150  pKerPrivArgs->width = bufParamsIn->dim_x;
151  pKerPrivArgs->height = bufParamsIn->dim_y;
152 
153  // compute stride in elements as SE/SA params are set to work with given element type
154  pKerPrivArgs->strideInElements = bufParamsIn->stride_y / VXLIB_sizeof(bufParamsIn->data_type);
155 
156 #if VXLIB_DEBUGPRINT
157  printf("VXLIB_DEBUGPRINT Enter VXLIB_histogram_init\n");
158 #endif
159 
160  // obtain buffer datatypes
161  uint32_t dTypeIn = bufParamsIn->data_type;
162  uint32_t dTypeOut = bufParamsOut->data_type;
163 
164  // determine natural C vs optimized function call
165  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
168  }
169  else {
170  status = VXLIB_ERR_INVALID_TYPE;
171  }
172  }
173  else { // Optimized function
175  status =
176  VXLIB_histogram_init_ci<VXLIB_HISTOGRAM_DTYPE_I8U_O32U>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
178  }
179  else {
180  status = VXLIB_ERR_INVALID_TYPE;
181  }
182  }
183 
184  return status;
185 }
186 
187 /**********************************************************************************************************************/
188 /* */
189 /* VXLIB_histogram_exec */
190 /* */
191 /**********************************************************************************************************************/
192 
193 // this method is the user-level execution function for the VXLIB_histogram kernel
195 VXLIB_histogram_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
196 {
197  VXLIB_STATUS status;
198 
199 #if VXLIB_DEBUGPRINT
200  printf("VXLIB_DEBUGPRINT Enter VXLIB_histogram_exec\n");
201 #endif
202 
203  VXLIB_histogram_PrivArgs *pKerPrivArgs = (VXLIB_histogram_PrivArgs *) handle;
204 
205  status = pKerPrivArgs->execute(handle, pIn, pOut);
206 
207  return status;
208 }
template VXLIB_STATUS VXLIB_histogram_init_ci< VXLIB_HISTOGRAM_DTYPE_I8U_O32U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams1D_t *bufParamsOut, const VXLIB_histogram_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_histogram_exec_ci< VXLIB_HISTOGRAM_TYPENAME_I8U_O32U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template VXLIB_STATUS VXLIB_histogram_exec_cn< VXLIB_HISTOGRAM_TYPENAME_I8U_O32U >(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see VXLIB_histogram.
#define VXLIB_HISTOGRAM_MAX_PIXEL_VALUE
Macros for maximum pixel value to be represented in distribution.
#define VXLIB_HISTOGRAM_I8U_O32U
Macros that will be useful to check for datatype combinations.
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_ERR_INVALID_VALUE
Definition: VXLIB_types.h:223
@ 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.
int32_t VXLIB_histogram_getHandleSize(VXLIB_histogram_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
VXLIB_STATUS VXLIB_histogram_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn, VXLIB_bufParams1D_t *bufParamsOut, const VXLIB_histogram_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_histogram_exec function is called....
VXLIB_STATUS VXLIB_histogram_exec_checkParams(VXLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
This function checks the validity of the parameters passed to VXLIB_histogram_exec function....
VXLIB_STATUS VXLIB_histogram_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn, const VXLIB_bufParams1D_t *bufParamsOut, const VXLIB_histogram_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_histogram_init function....
VXLIB_STATUS VXLIB_histogram_exec(VXLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main kernel compute function.
A structure for a 1 dimensional buffer descriptor.
uint32_t data_type
Values are of type VXLIB_data_type_e.
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.
uint16_t numBins
Parameter indicating distribution number of bins (<= 256)
uint8_t offset
Parameter indicating distribution offset.
uint16_t range
Parameter indicating distribution range (<= 256)
int8_t funcStyle
Variant of the function, refer to VXLIB_FUNCTION_STYLE
uint8_t lastBlock
Flag that indicates if the function call is the final call for the image (0: intermediate call,...
Structure that is reserved for internal use by the kernel.
VXLIB_histogram_InitArgs pKerInitArgs
Initargs of the kernel.
size_t height
Height of image
size_t strideInElements
Stride of input0 in elements.
size_t width
Width of image
pFxnVXLIB_histogram_exec execute
Function pointer to point to the right execution variant between VXLIB_histogram_exec_cn and VXLIB_hi...