VXLIB User Guide
VXLIB_multiply.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_multiply_priv.h"
41 
42 /**********************************************************************************************************************/
43 /* */
44 /* VXLIB_multiply_getHandleSize */
45 /* */
46 /**********************************************************************************************************************/
47 
48 // this method calculates and returns the size of the handle for the VXLIB_multiply kernel
50 {
51  int32_t privBufSize = sizeof(VXLIB_multiply_PrivArgs);
52  return privBufSize;
53 }
54 
55 /**********************************************************************************************************************/
56 /* */
57 /* VXLIB_multiply_init_checkParams */
58 /* */
59 /**********************************************************************************************************************/
60 
61 // this method checks the initialization parameters for the VXLIB_multiply kernel
64  const VXLIB_bufParams2D_t * bufParamsIn0,
65  const VXLIB_bufParams2D_t * bufParamsIn1,
66  const VXLIB_bufParams2D_t * bufParamsOut,
67  const VXLIB_multiply_InitArgs *pKerInitArgs)
68 {
69  VXLIB_STATUS status = VXLIB_SUCCESS;
70 
71  // check for dimensions and datatype combinations
72  if ((handle == NULL) || (bufParamsIn0 == NULL) || (bufParamsIn1 == NULL) || (bufParamsOut == NULL) ||
73  (pKerInitArgs == NULL)) {
74  status = VXLIB_ERR_NULL_POINTER;
75  }
76 
77  if (status == VXLIB_SUCCESS) {
78  if ((bufParamsIn0->dim_x != bufParamsIn1->dim_x) || (bufParamsIn0->dim_x != bufParamsOut->dim_x) ||
79  (bufParamsIn0->dim_y != bufParamsIn1->dim_y) || (bufParamsIn0->dim_y != bufParamsOut->dim_y)) {
81  }
82  }
83 
84  if (status == VXLIB_SUCCESS) {
85  uint32_t strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
86  uint32_t strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
87  uint32_t strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
88  if ((strideIn0Elements < bufParamsIn0->dim_x) || (strideIn1Elements < bufParamsIn1->dim_x) ||
89  (strideOutElements < bufParamsOut->dim_x)) {
91  }
92  }
93 
94  if (status == VXLIB_SUCCESS) {
95  uint32_t dTypeIn0 = bufParamsIn0->data_type;
96  uint32_t dTypeIn1 = bufParamsIn1->data_type;
97  uint32_t dTypeOut = bufParamsOut->data_type;
98 
101  status = VXLIB_ERR_INVALID_TYPE;
102  }
103  }
104 
105  return status;
106 }
107 
108 /**********************************************************************************************************************/
109 /* */
110 /* VXLIB_multiply_exec_checkParams */
111 /* */
112 /**********************************************************************************************************************/
113 
114 // this method checks the execution parameters for the VXLIB_multiply kernel
116  const void *restrict pIn0,
117  const void *restrict pIn1,
118  const void *restrict pOut)
119 {
120  VXLIB_STATUS status;
121 
122 #if VXLIB_DEBUGPRINT
123  printf("Enter VXLIB_multiply_exec_checkParams\n");
124 #endif
125  if ((handle == NULL) || (pIn0 == NULL) || (pIn1 == NULL) || (pOut == NULL)) {
126  status = VXLIB_ERR_NULL_POINTER;
127  }
128  else {
129  status = VXLIB_SUCCESS;
130  }
131 
132  return status;
133 }
134 
135 /**********************************************************************************************************************/
136 /* */
137 /* VXLIB_multiply_init */
138 /* */
139 /**********************************************************************************************************************/
140 
141 // this method is the user-level initialization function for the VXLIB_multiply kernel
143  VXLIB_bufParams2D_t * bufParamsIn0,
144  VXLIB_bufParams2D_t * bufParamsIn1,
145  VXLIB_bufParams2D_t * bufParamsOut,
146  const VXLIB_multiply_InitArgs *pKerInitArgs)
147 {
148  VXLIB_STATUS status = VXLIB_SUCCESS;
149  VXLIB_multiply_PrivArgs *pKerPrivArgs = (VXLIB_multiply_PrivArgs *) handle;
150 
151  // copy pKerinitArgs into pKerPrivargs
152  pKerPrivArgs->pKerInitArgs = *pKerInitArgs;
153 
154  // set width and height of image
155  pKerPrivArgs->width = bufParamsIn0->dim_x;
156  pKerPrivArgs->height = bufParamsIn0->dim_y;
157 
158  // compute stride in elements as SE/SA params are set to work with given element type
159  pKerPrivArgs->strideIn0Elements = bufParamsIn0->stride_y / VXLIB_sizeof(bufParamsIn0->data_type);
160  pKerPrivArgs->strideIn1Elements = bufParamsIn1->stride_y / VXLIB_sizeof(bufParamsIn1->data_type);
161  pKerPrivArgs->strideOutElements = bufParamsOut->stride_y / VXLIB_sizeof(bufParamsOut->data_type);
162 #if VXLIB_DEBUGPRINT
163  printf("VXLIB_DEBUGPRINT Enter VXLIB_multiply_init\n");
164 #endif
165 
166  // obtain buffer datatypes
167  uint32_t dTypeIn0 = bufParamsIn0->data_type;
168  uint32_t dTypeIn1 = bufParamsIn1->data_type;
169  uint32_t dTypeOut = bufParamsOut->data_type;
170 
171  // determine natural C vs optimized function call
172  if (pKerInitArgs->funcStyle == VXLIB_FUNCTION_NATC) {
173 
174  // set function pointer for natural C function with appropriate template parameters based on datatypes
177  }
178  else if (VXLIB_MULTIPLY_I8U_I8U_O16S) {
180  }
181  else if (VXLIB_MULTIPLY_I8U_I16S_O16S) {
183  }
186  }
187  else {
188  status = VXLIB_ERR_INVALID_TYPE;
189  }
190  }
191  else { // Optimized function
192 
193  // set function pointer for natural C function with appropriate template parameters based on datatypes
196  status = VXLIB_multiply_init_ci<VXLIB_MULTIPLY_DTYPE_I8U_I8U_O8U>(handle, bufParamsIn0, bufParamsIn1,
197  bufParamsOut, pKerInitArgs);
198  }
199  else if (VXLIB_MULTIPLY_I8U_I8U_O16S) {
201  status = VXLIB_multiply_init_ci<VXLIB_MULTIPLY_DTYPE_I8U_I8U_O16S>(handle, bufParamsIn0, bufParamsIn1,
202  bufParamsOut, pKerInitArgs);
203  }
204  else if (VXLIB_MULTIPLY_I8U_I16S_O16S) {
206  status = VXLIB_multiply_init_ci<VXLIB_MULTIPLY_DTYPE_I8U_I16S_O16S>(handle, bufParamsIn0, bufParamsIn1,
207  bufParamsOut, pKerInitArgs);
208  }
211  status = VXLIB_multiply_init_ci<VXLIB_MULTIPLY_DTYPE_I16S_I16S_O16S>(handle, bufParamsIn0, bufParamsIn1,
212  bufParamsOut, pKerInitArgs);
213  }
214  else {
215  status = VXLIB_ERR_INVALID_TYPE;
216  }
217  }
218 
219  return status;
220 }
221 
222 /**********************************************************************************************************************/
223 /* */
224 /* VXLIB_multiply_exec */
225 /* */
226 /**********************************************************************************************************************/
227 
228 // this method is the user-level execution function for the VXLIB_multiply kernel
230 VXLIB_multiply_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
231 {
232  VXLIB_STATUS status;
233 
234 #if VXLIB_DEBUGPRINT
235  printf("VXLIB_DEBUGPRINT Enter VXLIB_multiply_exec\n");
236 #endif
237 
238  VXLIB_multiply_PrivArgs *pKerPrivArgs = (VXLIB_multiply_PrivArgs *) handle;
239 
240  status = pKerPrivArgs->execute(handle, pIn0, pIn1, pOut);
241 
242  return status;
243 }
244 
245 /* ======================================================================== */
246 /* End of file: VXLIB_multiply.cpp */
247 /* ======================================================================== */
template VXLIB_STATUS VXLIB_multiply_exec_ci< VXLIB_MULTIPLY_TYPENAME_I16S_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_multiply_exec_ci< VXLIB_MULTIPLY_TYPENAME_I8U_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_multiply_init_ci< VXLIB_MULTIPLY_DTYPE_I8U_I8U_O8U >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_multiply_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_multiply_init_ci< VXLIB_MULTIPLY_DTYPE_I8U_I8U_O16S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_multiply_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_multiply_exec_ci< VXLIB_MULTIPLY_TYPENAME_I8U_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_multiply_init_ci< VXLIB_MULTIPLY_DTYPE_I8U_I16S_O16S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_multiply_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_multiply_init_ci< VXLIB_MULTIPLY_DTYPE_I16S_I16S_O16S >(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_multiply_InitArgs *pKerInitArgs)
template VXLIB_STATUS VXLIB_multiply_exec_ci< VXLIB_MULTIPLY_TYPENAME_I8U_I8U_O16S >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_multiply_exec_cn< VXLIB_MULTIPLY_TYPENAME_I8U_I16S_O16S >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_multiply_exec_cn< VXLIB_MULTIPLY_TYPENAME_I8U_I8U_O8U >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_multiply_exec_cn< VXLIB_MULTIPLY_TYPENAME_I8U_I8U_O16S >(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
template VXLIB_STATUS VXLIB_multiply_exec_cn< VXLIB_MULTIPLY_TYPENAME_I16S_I16S_O16S >(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_multiply.
#define VXLIB_MULTIPLY_I16S_I16S_O16S
#define VXLIB_MULTIPLY_I8U_I8U_O8U
Macros that will be useful to check for datatype combinations.
#define VXLIB_MULTIPLY_I8U_I16S_O16S
#define VXLIB_MULTIPLY_I8U_I8U_O16S
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_STATUS VXLIB_multiply_init_checkParams(VXLIB_kernelHandle handle, const VXLIB_bufParams2D_t *bufParamsIn0, const VXLIB_bufParams2D_t *bufParamsIn1, const VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_multiply_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to VXLIB_multiply_init function....
int32_t VXLIB_multiply_getHandleSize(VXLIB_multiply_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
VXLIB_STATUS VXLIB_multiply_init(VXLIB_kernelHandle handle, VXLIB_bufParams2D_t *bufParamsIn0, VXLIB_bufParams2D_t *bufParamsIn1, VXLIB_bufParams2D_t *bufParamsOut, const VXLIB_multiply_InitArgs *pKerInitArgs)
This function should be called before the VXLIB_multiply_exec function is called. This function takes...
VXLIB_STATUS VXLIB_multiply_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_multiply_exec function....
VXLIB_STATUS VXLIB_multiply_exec(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
This function is the main kernel compute function.
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.
int8_t funcStyle
Variant of the function, refer to VXLIB_FUNCTION_STYLE
Structure that is reserved for internal use by the kernel.
pFxnVXLIB_multiply_exec execute
Function pointer to point to the right execution variant between VXLIB_multiply_exec_cn and VXLIB_mul...
size_t width
Width of image
size_t strideIn1Elements
Stride of input1 in elements.
VXLIB_multiply_InitArgs pKerInitArgs
Initargs of the kernel.
size_t strideOutElements
Stride of output in elements.
size_t strideIn0Elements
Stride of input0 in elements.
size_t height
Height of image