DSPLIB User Guide
DSPLIB_max.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_max_priv.h"
24 
26 {
27  int32_t privBufSize = sizeof(DSPLIB_max_PrivArgs);
28  return privBufSize;
29 }
30 
32  const DSPLIB_bufParams1D_t *bufParamsIn,
33  const DSPLIB_bufParams1D_t *bufParamsOut,
34  const DSPLIB_max_InitArgs *pKerInitArgs)
35 {
37 
38 #if DSPLIB_DEBUGPRINT
39  printf("Enter DSPLIB_max_init_checkParams\n");
40 #endif
41  if (handle == NULL) {
42  status = DSPLIB_ERR_NULL_POINTER;
43  }
44 
45  if (status == DSPLIB_SUCCESS) {
46 
47  if ((bufParamsIn->data_type != DSPLIB_INT16) && (bufParamsIn->data_type != DSPLIB_INT32) &&
48  (bufParamsIn->data_type != DSPLIB_INT8) && (bufParamsIn->data_type != DSPLIB_FLOAT32) &&
49  (bufParamsIn->data_type != DSPLIB_UINT16) && (bufParamsIn->data_type != DSPLIB_UINT32) &&
50  (bufParamsIn->data_type != DSPLIB_UINT8) && (bufParamsIn->data_type != DSPLIB_FLOAT64)) {
51  status = DSPLIB_ERR_INVALID_TYPE;
52  }
53 
54  else if (bufParamsIn->data_type != bufParamsOut->data_type) {
55  status = DSPLIB_ERR_INVALID_TYPE;
56  }
57  else {
58  /* Nothing to do here */
59  }
60 
61  }
62  else {
63  /* Nothing to do here */
64  }
65 
66 
67  return status;
68 }
69 
71 DSPLIB_max_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
72 {
73  DSPLIB_STATUS status;
74 
75 #if DSPLIB_DEBUGPRINT
76  printf("Enter DSPLIB_max_exec_checkParams\n");
77 #endif
78  if ((pIn == NULL) || (pOut == NULL)) {
79  status = DSPLIB_ERR_NULL_POINTER;
80  }
81  else {
82  status = DSPLIB_SUCCESS;
83  }
84 
85  return status;
86 }
87 
89  DSPLIB_bufParams1D_t *bufParamsIn,
90  DSPLIB_bufParams1D_t *bufParamsOut,
91  const DSPLIB_max_InitArgs *pKerInitArgs)
92 {
94  DSPLIB_max_PrivArgs *pKerPrivArgs = (DSPLIB_max_PrivArgs *) handle;
95 
96 #if DSPLIB_DEBUGPRINT
97  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_max_init\n");
98 #endif
99  pKerPrivArgs->blockSize = pKerInitArgs->dataSize;
100 
101 #if DSPLIB_DEBUGPRINT
102  printf("DSPLIB_DEBUGPRINT DSPLIB_max_init pKerPrivArgs->blockSize %d bufParamsIn->data_type %d\n",
103  pKerPrivArgs->blockSize, bufParamsIn->data_type);
104 #endif
105 
106  if (pKerInitArgs->funcStyle == DSPLIB_FUNCTION_NATC) {
107  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
109  }
110  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
112  }
113  else if (bufParamsIn->data_type == DSPLIB_INT8) {
115  }
116  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
118  }
119  else if (bufParamsIn->data_type == DSPLIB_INT16) {
121  }
122  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
124  }
125  else if (bufParamsIn->data_type == DSPLIB_INT32) {
127  }
128  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
130  }
131  else {
132  status = DSPLIB_ERR_INVALID_TYPE;
133 #if DSPLIB_DEBUGPRINT
134  printf("DSPLIB_DEBUGPRINT CP 2 status %d\n", status);
135 #endif
136  }
137  }
138  else {
139  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
140 #if DSPLIB_DEBUGPRINT
141  printf("DSPLIB_DEBUGPRINT bufParamsIn->data_type == DSPLIB_FLOAT32\n");
142 #endif
144  status = DSPLIB_max_init_ci<float>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
145  }
146  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
148  status = DSPLIB_max_init_ci<double>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
149  }
150  else if (bufParamsIn->data_type == DSPLIB_INT8) {
152  status = DSPLIB_max_init_ci<int8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
153  }
154  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
156  status = DSPLIB_max_init_ci<uint8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
157  }
158  else if (bufParamsIn->data_type == DSPLIB_INT16) {
160  status = DSPLIB_max_init_ci<int16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
161  }
162  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
164  status = DSPLIB_max_init_ci<uint16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
165  }
166  else if (bufParamsIn->data_type == DSPLIB_INT32) {
168  status = DSPLIB_max_init_ci<int32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
169  }
170  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
172  status = DSPLIB_max_init_ci<uint32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
173  }
174  else {
175  status = DSPLIB_ERR_INVALID_TYPE;
176  }
177  }
178 #if DSPLIB_DEBUGPRINT
179  printf("DSPLIB_DEBUGPRINT CP 3 status %d\n", status);
180 #endif
181  return status;
182 }
183 
185 DSPLIB_max_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
186 {
187  DSPLIB_STATUS status;
188 
189 #if DSPLIB_DEBUGPRINT
190  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_max_exec\n");
191 #endif
192 
193  DSPLIB_max_PrivArgs *pKerPrivArgs = (DSPLIB_max_PrivArgs *) handle;
194 
195 #if DSPLIB_DEBUGPRINT
196  printf("DSPLIB_DEBUGPRINT pKerPrivArgs->blockSize %d\n", pKerPrivArgs->blockSize);
197 #endif
198  status = pKerPrivArgs->execute(handle, pIn, pOut);
199 
200  return status;
201 }
template DSPLIB_STATUS DSPLIB_max_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_max_exec_ci< int8_t, DSPLIB_INT8 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_ci< float, DSPLIB_FLOAT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_max_exec_ci< uint16_t, DSPLIB_UINT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_max_init_ci< uint16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_max_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_max_init_ci< uint8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_max_exec_ci< uint32_t, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_max_init_ci< uint32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_max_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_max_exec_ci< int32_t, DSPLIB_INT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_max_exec_ci< uint8_t, DSPLIB_UINT8 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_ci< double, DSPLIB_FLOAT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_max_exec_ci< int16_t, DSPLIB_INT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_cn< double, DSPLIB_FLOAT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_cn< uint16_t, DSPLIB_UINT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_cn< int8_t, DSPLIB_INT8 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_cn< uint32_t, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_cn< int16_t, DSPLIB_INT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_cn< int32_t, DSPLIB_INT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_cn< uint8_t, DSPLIB_UINT8 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_max_exec_cn< float, DSPLIB_FLOAT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_max.
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
DSPLIB_STATUS DSPLIB_max_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main kernel compute function.
Definition: DSPLIB_max.cpp:185
DSPLIB_STATUS DSPLIB_max_init(DSPLIB_kernelHandle handle, DSPLIB_bufParams1D_t *bufParamsIn, DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
This function should be called before the DSPLIB_max_exec function is called. This function takes car...
Definition: DSPLIB_max.cpp:88
DSPLIB_STATUS DSPLIB_max_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
This function checks the validity of the parameters passed to DSPLIB_max_exec function....
Definition: DSPLIB_max.cpp:71
int32_t DSPLIB_max_getHandleSize(DSPLIB_max_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
Definition: DSPLIB_max.cpp:25
DSPLIB_STATUS DSPLIB_max_init_checkParams(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_max_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to DSPLIB_max_init function....
Definition: DSPLIB_max.cpp:31
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_max.h:105
uint32_t dataSize
Size of input data
Definition: DSPLIB_max.h:109
int8_t funcStyle
Variant of the function refer to DSPLIB_FUNCTION_STYLE
Definition: DSPLIB_max.h:107
Structure that is reserved for internal use by the kernel.
pFxnDSPLIB_max_exec execute
Function pointer to point to the right execution variant between DSPLIB_max_exec_cn and DSPLIB_max_ex...
int32_t blockSize
Size of input buffer for different batches DSPLIB_max_init that will be retrieved and used by DSPLIB_...