VXLIB User Guide
VXLIB_absDiff_ci.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 "../common/c71/VXLIB_inlines.h"
41 #include "VXLIB_absDiff_priv.h"
42 
43 /*******************************************************************************
44  *
45  * DEFINES
46  *
47  ******************************************************************************/
48 
49 #define SE_PARAM_BASE (0x0000)
50 #define SE0_PARAM_OFFSET (SE_PARAM_BASE)
51 #define SE1_PARAM_OFFSET (SE0_PARAM_OFFSET + VXLIB_SE_PARAM_SIZE)
52 #define SA0_PARAM_OFFSET (SE1_PARAM_OFFSET + VXLIB_SE_PARAM_SIZE)
53 
54 /**********************************************************************************************************************/
55 /* */
56 /* VXLIB_absDiff_init_ci */
57 /* */
58 /**********************************************************************************************************************/
59 
60 // this method initializes the kernel-specific parameters
61 // mainly, the streaming engine and streaming address generators
62 template <uint32_t dTypeIn0>
64  const VXLIB_bufParams2D_t *bufParamsIn0,
65  const VXLIB_bufParams2D_t *bufParamsIn1,
66  const VXLIB_bufParams2D_t *bufParamsOut,
67  const VXLIB_absDiff_InitArgs *pKerInitArgs)
68 {
69  VXLIB_STATUS status = VXLIB_SUCCESS; // assign status to success by default
70 
71  // structs to hold SE and SA parameters
72  __SE_TEMPLATE_v1 se0Params = __gen_SE_TEMPLATE_v1();
73  __SE_TEMPLATE_v1 se1Params = __gen_SE_TEMPLATE_v1();
74  __SA_TEMPLATE_v1 sa0Params = __gen_SA_TEMPLATE_v1();
75 
76  VXLIB_absDiff_PrivArgs *pKerPrivArgs = (VXLIB_absDiff_PrivArgs *) handle;
77 
78  uint8_t *pBlock = pKerPrivArgs->bufPblock; // address to retrieve to store SE/SA params
79 
80  // set SE0, SE1, and SA0 params
81  pKerPrivArgs->numBlocks = VXLIB_SE0SE1SA0_init<dTypeIn0, dTypeIn0, dTypeIn0>(
82  &se0Params, &se1Params, &sa0Params, bufParamsIn0, bufParamsIn1, bufParamsOut);
83 
84  /**************************/
85  /* Store SE and SA params */
86  /**************************/
87 
88  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE0_PARAM_OFFSET) = se0Params;
89  *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE1_PARAM_OFFSET) = se1Params;
90  *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SA0_PARAM_OFFSET) = sa0Params;
91 
92  return status;
93 }
94 
95 /**********************************************************************************************************************/
96 /* */
97 /* Explicit instantiations for VXLIB_absDiff_init_ci */
98 /* */
99 /**********************************************************************************************************************/
100 
102  const VXLIB_bufParams2D_t *bufParamsIn0,
103  const VXLIB_bufParams2D_t *bufParamsIn1,
104  const VXLIB_bufParams2D_t *bufParamsOut,
105  const VXLIB_absDiff_InitArgs *pKerInitArgs);
106 
108  const VXLIB_bufParams2D_t *bufParamsIn0,
109  const VXLIB_bufParams2D_t *bufParamsIn1,
110  const VXLIB_bufParams2D_t *bufParamsOut,
111  const VXLIB_absDiff_InitArgs *pKerInitArgs);
112 
113 /**********************************************************************************************************************/
114 /* */
115 /* VXLIB_absDiff_calc */
116 /* */
117 /**********************************************************************************************************************/
118 
119 // calculates the absolute difference based on input type
120 template <typename dataType> inline dataType VXLIB_absDiff_calc(dataType vecA, dataType vecB);
121 
122 /**********************************************************************************************************************/
123 /* */
124 /* Explicit instantiations for VXLIB_absDiff_init_calc */
125 /* */
126 /**********************************************************************************************************************/
127 
128 // calculation for a uint8_t
129 template <> inline c7x::uchar_vec VXLIB_absDiff_calc<c7x::uchar_vec>(c7x::uchar_vec vecA, c7x::uchar_vec vecB)
130 {
131  c7x::uchar_vec absDiffOut = (__abs_diff(vecA, vecB));
132  return absDiffOut;
133 }
134 
135 // calculation for a int16_t with saturation
136 template <> inline c7x::short_vec VXLIB_absDiff_calc<c7x::short_vec>(c7x::short_vec vecA, c7x::short_vec vecB)
137 {
138  c7x::short_vec absDiffOut = __abs(__sub_sat(vecA, vecB));
139  return absDiffOut;
140 }
141 
142 /**********************************************************************************************************************/
143 /* */
144 /* VXLIB_absDiff_exec_ci */
145 /* */
146 /**********************************************************************************************************************/
147 
148 // this method performs pixel-wise absolute difference of two input images
149 template <typename dataType>
151 VXLIB_absDiff_exec_ci(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
152 {
153  VXLIB_absDiff_PrivArgs *pKerPrivArgs = (VXLIB_absDiff_PrivArgs *) handle;
154 
155  __SE_TEMPLATE_v1 se0Params;
156  __SE_TEMPLATE_v1 se1Params;
157  __SA_TEMPLATE_v1 sa0Params;
158 
159  dataType *restrict pInLocal0 = (dataType *) pIn0;
160  dataType *restrict pInLocal1 = (dataType *) pIn1;
161  dataType *restrict pOutLocal = (dataType *) pOut;
162 
163 #if VXLIB_DEBUGPRINT
164  printf("Enter VXLIB_add_exec_ci\n");
165 #endif
166 
167  typedef typename c7x::make_full_vector<dataType>::type vec;
168 
169 #if VXLIB_DEBUGPRINT
170  printf("Enter eleCount %d\n", eleCount);
171 #endif
172  uint8_t *pBlock = pKerPrivArgs->bufPblock;
173 
174  se0Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE0_PARAM_OFFSET);
175  se1Params = *(__SE_TEMPLATE_v1 *) ((uint8_t *) pBlock + SE1_PARAM_OFFSET);
176  sa0Params = *(__SA_TEMPLATE_v1 *) ((uint8_t *) pBlock + SA0_PARAM_OFFSET);
177 
178  // Input samples
179  __SE0_OPEN(pInLocal0, se0Params);
180  __SE1_OPEN(pInLocal1, se1Params);
181 
182  // Output samples
183  __SA0_OPEN(sa0Params);
184 
185  size_t numBlocks = pKerPrivArgs->numBlocks;
186 
187  vec out;
188  for (uint32_t counter = 0; counter < numBlocks; counter++) {
189  vec a = c7x::strm_eng<0, vec>::get_adv();
190  vec b = c7x::strm_eng<1, vec>::get_adv();
191 
192  out = VXLIB_absDiff_calc(a, b);
193 
194  __vpred tmp = c7x::strm_agen<0, vec>::get_vpred();
195  vec *addr = c7x::strm_agen<0, vec>::get_adv(pOutLocal);
196 
197  __vstore_pred(tmp, addr, out);
198  }
199  __SE0_CLOSE();
200  __SE1_CLOSE();
201  __SA0_CLOSE();
202 
203  return VXLIB_SUCCESS;
204 }
205 
206 /**********************************************************************************************************************/
207 /* */
208 /* Explicit instantiations for VXLIB_absDiff_exec_ci */
209 /* */
210 /**********************************************************************************************************************/
211 
213  void *restrict pIn0,
214  void *restrict pIn1,
215  void *restrict pOut);
216 
218  void *restrict pIn0,
219  void *restrict pIn1,
220  void *restrict pOut);
#define SE0_PARAM_OFFSET
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)
dataType VXLIB_absDiff_calc(dataType vecA, dataType vecB)
VXLIB_STATUS VXLIB_absDiff_exec_ci(VXLIB_kernelHandle handle, void *restrict pIn0, void *restrict pIn1, void *restrict pOut)
This function is the main execution function for the C7x implementation of the kernel....
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)
VXLIB_STATUS VXLIB_absDiff_init_ci(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 is the initialization function for the C7x implementation of the kernel....
#define SA0_PARAM_OFFSET
#define SE1_PARAM_OFFSET
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_SUCCESS
Definition: VXLIB_types.h:221
Structure containing the parameters to initialize the kernel.
Definition: VXLIB_absDiff.h:78
Structure that is reserved for internal use by the kernel.
size_t numBlocks
Number of blocks to be processed after simidfication.
uint8_t bufPblock[VXLIB_ABSDIFF_IXX_IXX_OXX_PBLOCK_SIZE]
A structure for a 2 dimensional buffer descriptor.