DSPLIB User Guide
DSPLIB_fir.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * *
3  * module name :DSPLIB *
4  * *
5  * module descripton :Matrix Multiply Accelerator Library module for C7x+MMA *
6  * *
7  * Copyright (C) 2017-2018 Texas Instruments Incorporated - https://www.ti.com/ *
8  * ALL RIGHTS RESERVED *
9  * *
10  ******************************************************************************/
11 
23 #include "DSPLIB_fir_priv.h"
24 
26 {
27  int32_t privBufSize = sizeof(DSPLIB_fir_PrivArgs);
28  return privBufSize;
29 }
30 
33  const DSPLIB_bufParams2D_t *bufParamsIn,
34  const DSPLIB_bufParams2D_t *bufParamsFilter,
35  const DSPLIB_bufParams2D_t *bufParamsOut,
36  const DSPLIB_fir_InitArgs *pKerInitArgs)
37 {
39  DSPLIB_bufParams2D_t bufParamsFilterLocal;
40  DSPLIB_bufParams2D_t bufParamsInLocal, bufParamsOutLocal;
41 
42 #if DSPLIB_DEBUGPRINT
43  printf("Enter DSPLIB_fir_init_checkParams\n");
44 #endif
45  if (handle == NULL) {
46  status = DSPLIB_ERR_NULL_POINTER;
47  }
48  else {
49  if (bufParamsIn->data_type == DSPLIB_INT16) {
50  status =
51  DSPLIB_fir_getSizes<int16_t>(pKerInitArgs, &bufParamsInLocal, &bufParamsFilterLocal, &bufParamsOutLocal);
52  }
53  else if (bufParamsIn->data_type == DSPLIB_INT32) {
54  status =
55  DSPLIB_fir_getSizes<int32_t>(pKerInitArgs, &bufParamsInLocal, &bufParamsFilterLocal, &bufParamsOutLocal);
56  }
57  else if (bufParamsIn->data_type == DSPLIB_INT8) {
58 
59  status =
60  DSPLIB_fir_getSizes<int8_t>(pKerInitArgs, &bufParamsInLocal, &bufParamsFilterLocal, &bufParamsOutLocal);
61  }
62  else if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
63  status =
64  DSPLIB_fir_getSizes<float>(pKerInitArgs, &bufParamsInLocal, &bufParamsFilterLocal, &bufParamsOutLocal);
65  }
66  else {
67  status = DSPLIB_ERR_INVALID_TYPE;
68  }
69  }
70 
71  if (status == DSPLIB_SUCCESS) {
72  // if ((bufParamsIn->data_type != DSPLIB_INT16) && (bufParamsIn->data_type != DSPLIB_INT32) &&
73  // (bufParamsIn->data_type != DSPLIB_INT8) && (bufParamsIn->data_type != DSPLIB_FLOAT32)) {
74  // status = DSPLIB_ERR_INVALID_TYPE;
75  // }
76  if (bufParamsIn->data_type != bufParamsOut->data_type) {
77  status = DSPLIB_ERR_INVALID_TYPE;
78  }
79  else if (bufParamsIn->data_type != bufParamsFilter->data_type) {
80  status = DSPLIB_ERR_INVALID_TYPE;
81  }
82  else {
83  /* Nothing to do here */
84  }
85  }
86 
87  return status;
88 }
89 
91  DSPLIB_bufParams2D_t *bufParamsIn,
92  DSPLIB_bufParams2D_t *bufParamsFilter,
93  DSPLIB_bufParams2D_t *bufParamsOut)
94 {
95  DSPLIB_STATUS status;
96 
97 #if DSPLIB_DEBUGPRINT
98  printf("Enter DSPLIB_fir_getSizes\n");
99 #endif
100  if (bufParamsIn->data_type == DSPLIB_INT16) {
101  status = DSPLIB_fir_getSizes<int16_t>(pKerInitArgs, bufParamsIn, bufParamsFilter, bufParamsOut);
102  }
103  else if (bufParamsIn->data_type == DSPLIB_INT32) {
104  status = DSPLIB_fir_getSizes<int32_t>(pKerInitArgs, bufParamsIn, bufParamsFilter, bufParamsOut);
105  }
106  else if (bufParamsIn->data_type == DSPLIB_INT8) {
107  status = DSPLIB_fir_getSizes<int8_t>(pKerInitArgs, bufParamsIn, bufParamsFilter, bufParamsOut);
108  }
109  else if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
110  status = DSPLIB_fir_getSizes<float>(pKerInitArgs, bufParamsIn, bufParamsFilter, bufParamsOut);
111  }
112  else {
114  }
115 
116  return status;
117 }
118 
120  const void *restrict pIn,
121  const void *restrict pFilter,
122  const void *restrict pOut)
123 {
124  DSPLIB_STATUS status;
125 
126 #if DSPLIB_DEBUGPRINT
127  printf("Enter DSPLIB_fir_exec_checkParams\n");
128 #endif
129  if ((pIn == NULL) || (pFilter == NULL) || (pOut == NULL)) {
130  status = DSPLIB_ERR_NULL_POINTER;
131  }
132  else {
133  status = DSPLIB_SUCCESS;
134  }
135 
136  return status;
137 }
138 
140  DSPLIB_bufParams2D_t *bufParamsIn,
141  DSPLIB_bufParams2D_t *bufParamsFilter,
142  DSPLIB_bufParams2D_t *bufParamsOut,
143  DSPLIB_fir_InitArgs *pKerInitArgs)
144 {
145  DSPLIB_STATUS status;
146  DSPLIB_fir_PrivArgs *pKerPrivArgs = (DSPLIB_fir_PrivArgs *) handle;
147 
148 #if DSPLIB_DEBUGPRINT
149  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_fir_init\n");
150 #endif
151  pKerPrivArgs->initArgs = *pKerInitArgs;
152 
153  int32_t ele_size = 0;
154 
155  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
156  ele_size = 4;
157  }
158  else if (bufParamsIn->data_type == DSPLIB_INT32 || bufParamsIn->data_type == DSPLIB_UINT32) {
159  ele_size = 4;
160  }
161  else if (bufParamsIn->data_type == DSPLIB_INT16 || bufParamsIn->data_type == DSPLIB_UINT16) {
162  ele_size = 2;
163  }
164  else if (bufParamsIn->data_type == DSPLIB_INT8 || bufParamsIn->data_type == DSPLIB_UINT8) {
165  ele_size = 1;
166  }
167  else {
168  status = DSPLIB_ERR_INVALID_TYPE;
169  }
170 
171  if (ele_size != 0) {
172  pKerPrivArgs->dataBufferInPitch = bufParamsIn->stride_y / ele_size;
173  pKerPrivArgs->dataBufferOutPitch = bufParamsOut->stride_y / ele_size;
174  pKerPrivArgs->outputSize = bufParamsOut->dim_x;
175  pKerPrivArgs->filterPitch = bufParamsFilter->stride_y / ele_size;
176  }
177 
178  if (pKerInitArgs->funcStyle == DSPLIB_FUNCTION_NATC) {
179  status = DSPLIB_fir_init_cn(handle, bufParamsIn, bufParamsFilter, bufParamsOut, pKerInitArgs);
180  if (bufParamsIn->data_type == DSPLIB_INT16) {
182  }
183  else if (bufParamsIn->data_type == DSPLIB_INT32) {
185  }
186  else if (bufParamsIn->data_type == DSPLIB_INT8) {
188  }
189  else if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
191  }
192  else {
193  status = DSPLIB_ERR_INVALID_TYPE;
194  }
195  }
196  else {
197  if (bufParamsIn->data_type == DSPLIB_INT16) {
198  pKerPrivArgs->execute = DSPLIB_fir_exec_ci<int16_t>;
199  status = DSPLIB_fir_init_ci<int16_t>(handle, bufParamsIn, bufParamsFilter, bufParamsOut, pKerInitArgs);
200  }
201  else if (bufParamsIn->data_type == DSPLIB_INT32) {
202  pKerPrivArgs->execute = DSPLIB_fir_exec_ci<int32_t>;
203  status = DSPLIB_fir_init_ci<int32_t>(handle, bufParamsIn, bufParamsFilter, bufParamsOut, pKerInitArgs);
204  }
205  else if (bufParamsIn->data_type == DSPLIB_INT8) {
206  pKerPrivArgs->execute = DSPLIB_fir_exec_ci<int8_t>;
207  status = DSPLIB_fir_init_ci<int8_t>(handle, bufParamsIn, bufParamsFilter, bufParamsOut, pKerInitArgs);
208  }
209  else if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
210 #if DSPLIB_DEBUGPRINT
211  printf("DSPLIB_DEBUGPRINT bufParamsIn->data_type == DSPLIB_FLOAT32\n");
212 #endif
213  pKerPrivArgs->execute = DSPLIB_fir_exec_ci<float>;
214  status = DSPLIB_fir_init_ci<float>(handle, bufParamsIn, bufParamsFilter, bufParamsOut, pKerInitArgs);
215  }
216  else {
217  status = DSPLIB_ERR_INVALID_TYPE;
218  }
219  }
220 
221  return status;
222 }
223 
225 DSPLIB_fir_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
226 {
227  DSPLIB_STATUS status;
228 
229 #if DSPLIB_DEBUGPRINT
230  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_fir_exec\n");
231 #endif
232 
233  DSPLIB_fir_PrivArgs *pKerPrivArgs = (DSPLIB_fir_PrivArgs *) handle;
234 
235  status = pKerPrivArgs->execute(handle, pIn, pFilter, pOut);
236 
237  return status;
238 }
template DSPLIB_STATUS DSPLIB_fir_exec_ci< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_fir_getSizes< float >(const DSPLIB_fir_InitArgs *pKerInitArgs, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams2D_t *bufParamsFilter, DSPLIB_bufParams2D_t *bufParamsOut)
template DSPLIB_STATUS DSPLIB_fir_exec_ci< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_fir_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsFilter, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_fir_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_fir_exec_ci< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_fir_getSizes< int8_t >(const DSPLIB_fir_InitArgs *pKerInitArgs, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams2D_t *bufParamsFilter, DSPLIB_bufParams2D_t *bufParamsOut)
template DSPLIB_STATUS DSPLIB_fir_getSizes< int32_t >(const DSPLIB_fir_InitArgs *pKerInitArgs, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams2D_t *bufParamsFilter, DSPLIB_bufParams2D_t *bufParamsOut)
template DSPLIB_STATUS DSPLIB_fir_getSizes< int16_t >(const DSPLIB_fir_InitArgs *pKerInitArgs, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams2D_t *bufParamsFilter, DSPLIB_bufParams2D_t *bufParamsOut)
template DSPLIB_STATUS DSPLIB_fir_exec_ci< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_fir_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsFilter, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_fir_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_fir_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsFilter, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_fir_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_fir_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsFilter, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_fir_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_fir_exec_cn< int16_t, int64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_fir_exec_cn< int8_t, int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
DSPLIB_STATUS DSPLIB_fir_init_cn(DSPLIB_kernelHandle handle, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams2D_t *bufParamsFilter, DSPLIB_bufParams2D_t *bufParamsOut, DSPLIB_fir_InitArgs *pKerInitArgs)
This function is the initialization function for the natural C implementation of the kernel....
template DSPLIB_STATUS DSPLIB_fir_exec_cn< int32_t, DSPLIB_int128_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_fir_exec_cn< float, int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_fir.
DSPLIB_STATUS_NAME
The enumeration of all status codes.
Definition: DSPLIB_types.h:151
void * DSPLIB_kernelHandle
Handle type for DSPLIB operations.
Definition: DSPLIB_types.h:172
@ DSPLIB_FUNCTION_NATC
Definition: DSPLIB_types.h:176
@ DSPLIB_UINT8
@ DSPLIB_UINT16
@ DSPLIB_INT32
@ DSPLIB_INT16
@ DSPLIB_FLOAT32
@ DSPLIB_UINT32
@ DSPLIB_INT8
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152
@ DSPLIB_ERR_NULL_POINTER
Definition: DSPLIB_types.h:157
@ DSPLIB_ERR_NOT_IMPLEMENTED
Definition: DSPLIB_types.h:158
@ DSPLIB_ERR_INVALID_TYPE
Definition: DSPLIB_types.h:155
DSPLIB_STATUS DSPLIB_fir_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pFilter, void *restrict pOut)
This function is the main kernel compute function.
Definition: DSPLIB_fir.cpp:225
DSPLIB_STATUS DSPLIB_fir_getSizes(const DSPLIB_fir_InitArgs *pKerInitArgs, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams2D_t *bufParamsFilter, DSPLIB_bufParams2D_t *bufParamsOut)
This is a query function to calculate the sizes of input, filter and the output buffers.
Definition: DSPLIB_fir.cpp:90
DSPLIB_STATUS DSPLIB_fir_init_checkParams(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsFilter, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_fir_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to DSPLIB_fir_init function....
Definition: DSPLIB_fir.cpp:32
int32_t DSPLIB_fir_getHandleSize(DSPLIB_fir_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
Definition: DSPLIB_fir.cpp:25
DSPLIB_STATUS DSPLIB_fir_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pFilter, const void *restrict pOut)
This function checks the validity of the parameters passed to DSPLIB_fir_exec function....
Definition: DSPLIB_fir.cpp:119
DSPLIB_STATUS DSPLIB_fir_init(DSPLIB_kernelHandle handle, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams2D_t *bufParamsFilter, DSPLIB_bufParams2D_t *bufParamsOut, DSPLIB_fir_InitArgs *pKerInitArgs)
This function should be called before the DSPLIB_fir_exec function is called. This function takes car...
Definition: DSPLIB_fir.cpp:139
A structure for a 2 dimensional buffer descriptor.
uint32_t data_type
Values are of type DSPLIB_data_type_e.
int32_t stride_y
Stride in Y dimension in bytes.
uint32_t dim_x
Width of buffer in X dimension in elements.
Structure containing the parameters to initialize the kernel.
Definition: DSPLIB_fir.h:105
int8_t funcStyle
Variant of the function refer to DSPLIB_FUNCTION_STYLE
Definition: DSPLIB_fir.h:107
Structure that is reserved for internal use by the kernel.
uint32_t dataBufferOutPitch
Pitch of output buffer for different batches DSPLIB_fir_init that will be retrieved and used by DSPLI...
uint32_t filterPitch
Pitch of filter coefficient buffer for different batches DSPLIB_fir_init that will be retrieved and u...
uint32_t dataBufferInPitch
Pitch of input buffer for different batches DSPLIB_fir_init that will be retrieved and used by DSPLIB...
DSPLIB_fir_InitArgs initArgs
Structure holding initialization parameters
pFxnDSPLIB_fir_exec execute
Function pointer to point to the right execution variant between DSPLIB_fir_exec_cn and DSPLIB_fir_ex...