DSPLIB User Guide
DSPLIB_minerror.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_minerror_priv.h"
24 
26 {
27  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
28  int32_t privBufSize = sizeof(DSPLIB_minerror_PrivArgs);
29  DSPLIB_DEBUGPRINTFN(0, "Exit function with privBufSize: %d\n", privBufSize);
30  return privBufSize;
31 }
32 
34  const DSPLIB_bufParams2D_t *bufParamsIn,
35  const DSPLIB_bufParams1D_t *bufParamsErrCoefs,
36  const DSPLIB_bufParams1D_t *bufParamsOutIndex,
37  const DSPLIB_bufParams1D_t *bufParamsOutVal,
38  const DSPLIB_minerror_InitArgs *pKerInitArgs)
39 {
40  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
42 
43  if (handle == NULL) {
44  status = DSPLIB_ERR_NULL_POINTER;
45  }
46 
47  if (status == DSPLIB_SUCCESS) {
48  if ((bufParamsIn->data_type != DSPLIB_INT8) && (bufParamsIn->data_type != DSPLIB_UINT8) &&
49  (bufParamsIn->data_type != DSPLIB_INT16) && (bufParamsIn->data_type != DSPLIB_UINT16) &&
50  (bufParamsIn->data_type != DSPLIB_INT32) && (bufParamsIn->data_type != DSPLIB_UINT32) &&
51  (bufParamsIn->data_type != DSPLIB_INT64) && (bufParamsIn->data_type != DSPLIB_UINT64) &&
52  (bufParamsIn->data_type != DSPLIB_FLOAT32) && (bufParamsIn->data_type != DSPLIB_FLOAT64)) {
53  status = DSPLIB_ERR_INVALID_TYPE;
54  }
55  else if (bufParamsIn->data_type != bufParamsErrCoefs->data_type) {
56  status = DSPLIB_ERR_INVALID_TYPE;
57  }
58  else if (bufParamsIn->data_type != bufParamsOutVal->data_type) {
59  status = DSPLIB_ERR_INVALID_TYPE;
60  }
61  else {
62  /* Nothing to do here */
63  }
64  }
65 
66  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
67  return status;
68 }
69 
71  const void *restrict pIn,
72  const void *restrict pErrCoefs,
73  const int *restrict pMaxIndex,
74  const void *restrict pMaxVal)
75 {
76  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
77  DSPLIB_STATUS status;
78 
79  if ((pIn == NULL) || (pErrCoefs == NULL) || (pMaxIndex == NULL) || (pMaxVal == NULL)) {
80  status = DSPLIB_ERR_NULL_POINTER;
81  }
82  else {
83  status = DSPLIB_SUCCESS;
84  }
85 
86  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
87  return status;
88 }
89 
91  DSPLIB_bufParams2D_t *bufParamsIn,
92  DSPLIB_bufParams1D_t *bufParamsErrCoefs,
93  DSPLIB_bufParams1D_t *bufParamsOutIndex,
94  DSPLIB_bufParams1D_t *bufParamsOutVal,
95  DSPLIB_minerror_InitArgs *pKerInitArgs)
96 {
97  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
99  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
100 
101  pKerPrivArgs->vecInSize = pKerInitArgs->vecInSize;
102  pKerPrivArgs->errCoefsSize = pKerInitArgs->errCoefsSize;
103  pKerPrivArgs->strideIn = pKerInitArgs->strideIn;
104 
105  DSPLIB_DEBUGPRINTFN(0, "pKerPrivArgs->vecInSize %d pKerPrivArgs->errCoefsSize %d bufParamsIn->data_type %d\n",
106  pKerPrivArgs->vecInSize, pKerPrivArgs->errCoefsSize, bufParamsIn->data_type);
107 
108 
109  if (pKerInitArgs->funcStyle == DSPLIB_FUNCTION_NATC) {
110  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
111  pKerPrivArgs->execute = DSPLIB_minerror_exec_cn<float>;
112  }
113  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
115  }
116  else if (bufParamsIn->data_type == DSPLIB_INT8) {
118  }
119  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
121  }
122  else if (bufParamsIn->data_type == DSPLIB_INT16) {
124  }
125  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
127  }
128  else if (bufParamsIn->data_type == DSPLIB_INT32) {
130  }
131  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
133  }
134  else if (bufParamsIn->data_type == DSPLIB_INT64) {
136  }
137  else if (bufParamsIn->data_type == DSPLIB_UINT64) {
139  }
140  else {
141  status = DSPLIB_ERR_INVALID_TYPE;
142  DSPLIB_DEBUGPRINTFN(0, "Invalid data Type status: %d", status);
143  }
144  }
145  else {
146  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
147  pKerPrivArgs->execute = DSPLIB_minerror_exec_ci<float>;
148  status = DSPLIB_minerror_init_ci<float>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
149  bufParamsOutVal, pKerInitArgs);
150  }
151  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
153  status = DSPLIB_minerror_init_ci<double>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
154  bufParamsOutVal, pKerInitArgs);
155  }
156  else if (bufParamsIn->data_type == DSPLIB_INT8) {
158  status = DSPLIB_minerror_init_ci<int8_t>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
159  bufParamsOutVal, pKerInitArgs);
160  }
161  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
163  status = DSPLIB_minerror_init_ci<uint8_t>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
164  bufParamsOutVal, pKerInitArgs);
165  }
166  else if (bufParamsIn->data_type == DSPLIB_INT16) {
168  status = DSPLIB_minerror_init_ci<int16_t>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
169  bufParamsOutVal, pKerInitArgs);
170  }
171  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
173  status = DSPLIB_minerror_init_ci<uint16_t>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
174  bufParamsOutVal, pKerInitArgs);
175  }
176  else if (bufParamsIn->data_type == DSPLIB_INT32) {
178  status = DSPLIB_minerror_init_ci<int32_t>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
179  bufParamsOutVal, pKerInitArgs);
180  }
181  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
183  status = DSPLIB_minerror_init_ci<uint32_t>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
184  bufParamsOutVal, pKerInitArgs);
185  }
186  else if (bufParamsIn->data_type == DSPLIB_INT64) {
188  status = DSPLIB_minerror_init_ci<int64_t>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
189  bufParamsOutVal, pKerInitArgs);
190  }
191  else if (bufParamsIn->data_type == DSPLIB_UINT64) {
193  status = DSPLIB_minerror_init_ci<uint64_t>(handle, bufParamsIn, bufParamsErrCoefs, bufParamsOutIndex,
194  bufParamsOutVal, pKerInitArgs);
195  }
196  else {
197  status = DSPLIB_ERR_INVALID_TYPE;
198  DSPLIB_DEBUGPRINTFN(0, "Invalid data Type status: %d", status);
199  }
200  }
201  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
202  return status;
203 }
204 
206  void *restrict pIn,
207  void *restrict pErrCoefs,
208  int *restrict pMaxIndex,
209  void *restrict pMaxVal)
210 {
211  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
212  DSPLIB_STATUS status;
213 
214 
215  DSPLIB_minerror_PrivArgs *pKerPrivArgs = (DSPLIB_minerror_PrivArgs *) handle;
216 
217  DSPLIB_DEBUGPRINTFN(0, "DSPLIB_DEBUGPRINT pKerPrivArgs->vecInSize %d pKerPrivArgs->errCoefsSize %d\n",
218  pKerPrivArgs->vecInSize, pKerPrivArgs->errCoefsSize);
219 
220  status = pKerPrivArgs->execute(handle, pIn, pErrCoefs, pMaxIndex, pMaxVal);
221 
222  DSPLIB_DEBUGPRINTFN(0, "Exit function with status: %d\n", status);
223  return status;
224 }
DSPLIB_STATUS DSPLIB_minerror_exec_ci< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_minerror_exec_ci< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< int64_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_minerror_exec_ci< double >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< uint8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_minerror_exec_ci< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_ci< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< uint64_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_minerror_exec_ci< int64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_ci< uint64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_ci< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< uint32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_minerror_init_ci< uint16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_minerror_exec_ci< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_ci< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< uint64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< int64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
DSPLIB_STATUS DSPLIB_minerror_exec_cn< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_minerror.
#define DSPLIB_DEBUGPRINTFN(N, fmt,...)
Definition: DSPLIB_types.h:83
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_UINT64
@ DSPLIB_UINT8
@ DSPLIB_UINT16
@ DSPLIB_INT32
@ DSPLIB_INT16
@ DSPLIB_FLOAT32
@ DSPLIB_INT64
@ DSPLIB_FLOAT64
@ DSPLIB_UINT32
@ DSPLIB_INT8
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152
@ DSPLIB_ERR_NULL_POINTER
Definition: DSPLIB_types.h:157
@ DSPLIB_ERR_INVALID_TYPE
Definition: DSPLIB_types.h:155
int32_t DSPLIB_minerror_getHandleSize(DSPLIB_minerror_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
DSPLIB_STATUS DSPLIB_minerror_init_checkParams(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsErrCoefs, const DSPLIB_bufParams1D_t *bufParamsOutIndex, const DSPLIB_bufParams1D_t *bufParamsOutVal, const DSPLIB_minerror_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to DSPLIB_minerror_init function....
DSPLIB_STATUS DSPLIB_minerror_init(DSPLIB_kernelHandle handle, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams1D_t *bufParamsErrCoefs, DSPLIB_bufParams1D_t *bufParamsOutIndex, DSPLIB_bufParams1D_t *bufParamsOutVal, DSPLIB_minerror_InitArgs *pKerInitArgs)
This function should be called before the DSPLIB_minerror_exec function is called....
DSPLIB_STATUS DSPLIB_minerror_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pErrCoefs, const int *restrict pMaxIndex, const void *restrict pMaxVal)
This function checks the validity of the parameters passed to DSPLIB_minerror_exec function....
DSPLIB_STATUS DSPLIB_minerror_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pErrCoefs, int *restrict pMaxIndex, void *restrict pMaxVal)
This function is the main kernel compute function.
A structure for a 1 dimensional buffer descriptor.
uint32_t data_type
Values are of type DSPLIB_data_type_e.
A structure for a 2 dimensional buffer descriptor.
uint32_t data_type
Values are of type DSPLIB_data_type_e.
Structure containing the parameters to initialize the kernel.
uint32_t errCoefsSize
Size of error coefficients vector
int8_t funcStyle
Variant of the function refer to DSPLIB_FUNCTION_STYLE
uint32_t vecInSize
Size of input data
Structure that is reserved for internal use by the kernel.
uint32_t errCoefsSize
Size of error coefficients vector
pFxnDSPLIB_minerror_exec execute
Function pointer to point to the right execution variant between DSPLIB_minerror_exec_cn and DSPLIB_m...
uint32_t vecInSize
Size of input data DSPLIB_minerror_init that will be retrieved and used by DSPLIB_minerror_exec