DSPLIB User Guide
DSPLIB_w_vec.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_w_vec_priv.h"
24 
26 {
27  int32_t privBufSize = sizeof(DSPLIB_w_vec_PrivArgs);
28  return privBufSize;
29 }
30 
33  const DSPLIB_bufParams1D_t *bufParamsIn,
34  const DSPLIB_bufParams1D_t *bufParamsOut,
35  const DSPLIB_w_vec_InitArgs *pKerInitArgs)
36 {
38 
39 #if DSPLIB_DEBUGPRINT
40  printf("Enter DSPLIB_w_vec_init_checkParams\n");
41 #endif
42  if (handle == NULL) {
43  status = DSPLIB_ERR_NULL_POINTER;
44  }
45 
46  if (status == DSPLIB_SUCCESS) {
47  if ((bufParamsIn->data_type != DSPLIB_INT16) && (bufParamsIn->data_type != DSPLIB_INT32) &&
48  (bufParamsIn->data_type != DSPLIB_INT8) && (bufParamsIn->data_type != DSPLIB_FLOAT32)) {
49  status = DSPLIB_ERR_INVALID_TYPE;
50  }
51  else if (bufParamsIn->data_type != bufParamsOut->data_type) {
52  status = DSPLIB_ERR_INVALID_TYPE;
53  }
54  else {
55  /* Nothing to do here */
56  }
57  }
58 
59  return status;
60 }
61 
63  const void *restrict pIn1,
64  const void *restrict pIn2,
65  const void *restrict pM,
66  const void *restrict pOut)
67 {
68  DSPLIB_STATUS status;
69 
70 #if DSPLIB_DEBUGPRINT
71  printf("Enter DSPLIB_w_vec_exec_checkParams\n");
72 #endif
73  if ((pIn1 == NULL) || (pIn2 == NULL) || (pM == NULL) || (pOut == NULL)) {
74  status = DSPLIB_ERR_NULL_POINTER;
75  }
76  else {
77  status = DSPLIB_SUCCESS;
78  }
79 
80  return status;
81 }
82 
84  DSPLIB_bufParams1D_t *bufParamsIn,
85  DSPLIB_bufParams1D_t *bufParamsOut,
86  const DSPLIB_w_vec_InitArgs *pKerInitArgs)
87 {
89  DSPLIB_w_vec_PrivArgs *pKerPrivArgs = (DSPLIB_w_vec_PrivArgs *) handle;
90 
91 #if DSPLIB_DEBUGPRINT
92  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_w_vec_init\n");
93 #endif
94  pKerPrivArgs->blockSize = pKerInitArgs->dataSize;
95 
96 #if DSPLIB_DEBUGPRINT
97  printf("DSPLIB_DEBUGPRINT DSPLIB_w_vec_init pKerPrivArgs->blockSize %d "
98  "bufParamsIn->data_type %d\n",
99  pKerPrivArgs->blockSize, bufParamsIn->data_type);
100 #endif
101 
102  // fill private args with init args
103  pKerPrivArgs->initArgs = *pKerInitArgs;
104 
105  if (pKerInitArgs->funcStyle == DSPLIB_FUNCTION_NATC) {
106  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
107  pKerPrivArgs->execute = DSPLIB_w_vec_exec_cn<float>;
108  }
109  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
110  pKerPrivArgs->execute = DSPLIB_w_vec_exec_cn<double>;
111  }
112  else if (bufParamsIn->data_type == DSPLIB_INT8) {
113  pKerPrivArgs->execute = DSPLIB_w_vec_exec_cn<int8_t>;
114  }
115  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
116  pKerPrivArgs->execute = DSPLIB_w_vec_exec_cn<uint8_t>;
117  }
118  else if (bufParamsIn->data_type == DSPLIB_INT16) {
119  pKerPrivArgs->execute = DSPLIB_w_vec_exec_cn<int16_t>;
120  }
121  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
122  pKerPrivArgs->execute = DSPLIB_w_vec_exec_cn<uint16_t>;
123  }
124  else if (bufParamsIn->data_type == DSPLIB_INT32) {
125  pKerPrivArgs->execute = DSPLIB_w_vec_exec_cn<int32_t>;
126  }
127  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
128  pKerPrivArgs->execute = DSPLIB_w_vec_exec_cn<uint32_t>;
129  }
130  else {
131  status = DSPLIB_ERR_INVALID_TYPE;
132 #if DSPLIB_DEBUGPRINT
133  printf("DSPLIB_DEBUGPRINT CP 2 status %d\n", status);
134 #endif
135  }
136  }
137  else {
138  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
139 #if DSPLIB_DEBUGPRINT
140  printf("DSPLIB_DEBUGPRINT bufParamsIn->data_type == DSPLIB_FLOAT32\n");
141 #endif
142  pKerPrivArgs->execute = DSPLIB_w_vec_exec_ci<float>;
143 
144  status = DSPLIB_w_vec_init_ci<float>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
145  }
146  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
147  pKerPrivArgs->execute = DSPLIB_w_vec_exec_ci<double>;
148 
149  status = DSPLIB_w_vec_init_ci<double>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
150  }
151  else if (bufParamsIn->data_type == DSPLIB_INT8) {
152  pKerPrivArgs->execute = DSPLIB_w_vec_exec_ci<int8_t>;
153 
154  status = DSPLIB_w_vec_init_ci<int8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
155  }
156  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
157  pKerPrivArgs->execute = DSPLIB_w_vec_exec_ci<uint8_t>;
158 
159  status = DSPLIB_w_vec_init_ci<uint8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
160  }
161  else if (bufParamsIn->data_type == DSPLIB_INT16) {
162  pKerPrivArgs->execute = DSPLIB_w_vec_exec_ci<int16_t>;
163 
164  status = DSPLIB_w_vec_init_ci<int16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
165  }
166  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
167  pKerPrivArgs->execute = DSPLIB_w_vec_exec_ci<uint16_t>;
168 
169  status = DSPLIB_w_vec_init_ci<uint16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
170  }
171  else if (bufParamsIn->data_type == DSPLIB_INT32) {
172  pKerPrivArgs->execute = DSPLIB_w_vec_exec_ci<int32_t>;
173 
174  status = DSPLIB_w_vec_init_ci<int32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
175  }
176  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
177  pKerPrivArgs->execute = DSPLIB_w_vec_exec_ci<uint32_t>;
178 
179  status = DSPLIB_w_vec_init_ci<uint32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
180  }
181  else {
182  status = DSPLIB_ERR_INVALID_TYPE;
183  }
184  }
185 #if DSPLIB_DEBUGPRINT
186  printf("DSPLIB_DEBUGPRINT CP 3 status %d\n", status);
187 #endif
188  return status;
189 }
190 
192  void *restrict pIn1,
193  void *restrict pIn2,
194  void *restrict pM,
195  void *restrict pOut)
196 {
197  DSPLIB_STATUS status;
198 
199 #if DSPLIB_DEBUGPRINT
200  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_w_vec_exec\n");
201 #endif
202 
203  DSPLIB_w_vec_PrivArgs *pKerPrivArgs = (DSPLIB_w_vec_PrivArgs *) handle;
204 
205 #if DSPLIB_DEBUGPRINT
206  printf("DSPLIB_DEBUGPRINT pKerPrivArgs->blockSize %d\n", pKerPrivArgs->blockSize);
207 #endif
208 
209  status = pKerPrivArgs->execute(handle, pIn1, pIn2, pM, pOut);
210 
211  return status;
212 }
template DSPLIB_STATUS DSPLIB_w_vec_exec_ci< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_init_ci< uint32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_w_vec_exec_ci< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_ci< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_init_ci< uint16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_w_vec_exec_ci< float >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_w_vec_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_w_vec_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_w_vec_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_w_vec_init_ci< uint8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_w_vec_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_w_vec_exec_ci< double >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_ci< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_ci< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_ci< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_cn< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_cn< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_cn< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_cn< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_cn< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_w_vec_exec_cn< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_w_vec.
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_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_w_vec_getHandleSize(DSPLIB_w_vec_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
DSPLIB_STATUS DSPLIB_w_vec_init(DSPLIB_kernelHandle handle, DSPLIB_bufParams1D_t *bufParamsIn, DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
This function should be called before the DSPLIB_w_vec_exec function is called. This function takes c...
DSPLIB_STATUS DSPLIB_w_vec_init_checkParams(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_w_vec_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to DSPLIB_w_vec_init function....
DSPLIB_STATUS DSPLIB_w_vec_exec(DSPLIB_kernelHandle handle, void *restrict pIn1, void *restrict pIn2, void *restrict pM, void *restrict pOut)
This function is the main kernel compute function.
DSPLIB_STATUS DSPLIB_w_vec_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn1, const void *restrict pIn2, const void *restrict pM, const void *restrict pOut)
This function checks the validity of the parameters passed to DSPLIB_w_vec_exec function....
A structure for a 1 dimensional buffer descriptor.
uint32_t data_type
Values are of type DSPLIB_data_type_e.
Structure containing the parameters to initialize the kernel.
Definition: DSPLIB_w_vec.h:117
int8_t funcStyle
Variant of the function refer to DSPLIB_FUNCTION_STYLE
Definition: DSPLIB_w_vec.h:119
uint32_t dataSize
Size of input data
Definition: DSPLIB_w_vec.h:121
Structure that is reserved for internal use by the kernel.
pFxnDSPLIB_w_vec_exec execute
Function pointer to point to the right execution variant between DSPLIB_w_vec_exec_cn DSPLIB_w_vec_ex...
DSPLIB_w_vec_InitArgs initArgs
int32_t blockSize
Size of input buffer for different batches DSPLIB_w_vec_init that will be retrieved and used by DSPLI...