DSPLIB User Guide
DSPLIB_sqr.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_sqr_priv.h"
24 
26 {
27  int32_t privBufSize = sizeof(DSPLIB_sqr_PrivArgs);
28  return privBufSize;
29 }
30 
32  const DSPLIB_bufParams1D_t *bufParamsIn,
33  const DSPLIB_bufParams1D_t *bufParamsOut,
34  const DSPLIB_sqr_InitArgs *pKerInitArgs)
35 {
37 
38 #if DSPLIB_DEBUGPRINT
39  printf("Enter DSPLIB_sqr_init_checkParams\n");
40 #endif
41  if (handle == NULL) {
42  status = DSPLIB_ERR_NULL_POINTER;
43  }
44 
45  if (status == DSPLIB_SUCCESS) {
46  if ((bufParamsIn->data_type != DSPLIB_INT16) && (bufParamsIn->data_type != DSPLIB_INT32) &&
47  (bufParamsIn->data_type != DSPLIB_INT8) && (bufParamsIn->data_type != DSPLIB_FLOAT32) &&
48  (bufParamsIn->data_type != DSPLIB_FLOAT64) && (bufParamsIn->data_type != DSPLIB_UINT8) &&
49  (bufParamsIn->data_type != DSPLIB_UINT16) && (bufParamsIn->data_type != DSPLIB_UINT32)) {
50  status = DSPLIB_ERR_INVALID_TYPE;
51  }
52  else if (bufParamsIn->data_type != bufParamsOut->data_type) {
53  status = DSPLIB_ERR_INVALID_TYPE;
54  }
55  else {
56  /* Nothing to do here */
57  }
58  }
59 
60  return status;
61 }
62 
64 DSPLIB_sqr_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
65 {
66  DSPLIB_STATUS status;
67 
68 #if DSPLIB_DEBUGPRINT
69  printf("Enter DSPLIB_sqr_exec_checkParams\n");
70 #endif
71  if ((pIn == NULL) || (pOut == NULL)) {
72  status = DSPLIB_ERR_NULL_POINTER;
73  }
74  else {
75  status = DSPLIB_SUCCESS;
76  }
77 
78  return status;
79 }
80 
82  DSPLIB_bufParams1D_t *bufParamsIn,
83  DSPLIB_bufParams1D_t *bufParamsOut,
84  const DSPLIB_sqr_InitArgs *pKerInitArgs)
85 {
87  DSPLIB_sqr_PrivArgs *pKerPrivArgs = (DSPLIB_sqr_PrivArgs *) handle;
88 
89 #if DSPLIB_DEBUGPRINT
90  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_sqr_init\n");
91 #endif
92  pKerPrivArgs->blockSize = pKerInitArgs->dataSize;
93 
94 #if DSPLIB_DEBUGPRINT
95  printf("DSPLIB_DEBUGPRINT DSPLIB_sqr_init pKerPrivArgs->blockSize %d bufParamsIn->data_type %d\n",
96  pKerPrivArgs->blockSize, bufParamsIn->data_type);
97 #endif
98 
99  if (pKerInitArgs->funcStyle == DSPLIB_FUNCTION_NATC) {
100  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
102  }
103  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
105  }
106  else if (bufParamsIn->data_type == DSPLIB_INT8) {
108  }
109  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
111  }
112  else if (bufParamsIn->data_type == DSPLIB_INT16) {
114  }
115  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
117  }
118  else if (bufParamsIn->data_type == DSPLIB_INT32) {
120  }
121  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
123  }
124  else {
125  status = DSPLIB_ERR_INVALID_TYPE;
126 #if DSPLIB_DEBUGPRINT
127  printf("DSPLIB_DEBUGPRINT CP 2 status %d\n", status);
128 #endif
129  }
130  }
131  else {
132  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
133 #if DSPLIB_DEBUGPRINT
134  printf("DSPLIB_DEBUGPRINT bufParamsIn->data_type == DSPLIB_FLOAT32\n");
135 #endif
137  status = DSPLIB_sqr_init_ci<float>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
138  }
139  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
141  status = DSPLIB_sqr_init_ci<double>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
142  }
143  else if (bufParamsIn->data_type == DSPLIB_INT8) {
145  status = DSPLIB_sqr_init_ci<int8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
146  }
147  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
149  status = DSPLIB_sqr_init_ci<uint8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
150  }
151  else if (bufParamsIn->data_type == DSPLIB_INT16) {
153  status = DSPLIB_sqr_init_ci<int16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
154  }
155  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
157  status = DSPLIB_sqr_init_ci<uint16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
158  }
159  else if (bufParamsIn->data_type == DSPLIB_INT32) {
161  status = DSPLIB_sqr_init_ci<int32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
162  }
163  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
165  status = DSPLIB_sqr_init_ci<uint32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
166  }
167  else {
168  status = DSPLIB_ERR_INVALID_TYPE;
169  }
170  }
171 #if DSPLIB_DEBUGPRINT
172  printf("DSPLIB_DEBUGPRINT CP 3 status %d\n", status);
173 #endif
174  return status;
175 }
176 
177 DSPLIB_STATUS DSPLIB_sqr_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
178 {
179  DSPLIB_STATUS status;
180 
181 #if DSPLIB_DEBUGPRINT
182  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_sqr_exec\n");
183 #endif
184 
185  DSPLIB_sqr_PrivArgs *pKerPrivArgs = (DSPLIB_sqr_PrivArgs *) handle;
186 
187 #if DSPLIB_DEBUGPRINT
188  printf("DSPLIB_DEBUGPRINT pKerPrivArgs->blockSize %d\n", pKerPrivArgs->blockSize);
189 #endif
190  status = pKerPrivArgs->execute(handle, pIn, pOut);
191 
192  return status;
193 }
template DSPLIB_STATUS DSPLIB_sqr_exec_ci< int32_t, DSPLIB_INT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_init_ci< uint8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_sqr_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_sqr_exec_ci< int16_t, DSPLIB_INT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_ci< float, DSPLIB_FLOAT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_ci< uint16_t, DSPLIB_UINT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_sqr_init_ci< uint16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_sqr_exec_ci< uint8_t, DSPLIB_UINT8 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_ci< int8_t, DSPLIB_INT8 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_sqr_init_ci< uint32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_sqr_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_sqr_exec_ci< double, DSPLIB_FLOAT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_sqr_exec_ci< uint32_t, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_cn< uint32_t, DSPLIB_UINT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_cn< int16_t, DSPLIB_INT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_cn< float, DSPLIB_FLOAT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_cn< uint8_t, DSPLIB_UINT8 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_cn< int8_t, DSPLIB_INT8 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_cn< uint16_t, DSPLIB_UINT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_cn< double, DSPLIB_FLOAT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_sqr_exec_cn< int32_t, DSPLIB_INT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_sqr.
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_sqr_init_checkParams(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to DSPLIB_sqr_init function....
Definition: DSPLIB_sqr.cpp:31
DSPLIB_STATUS DSPLIB_sqr_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main kernel compute function.
Definition: DSPLIB_sqr.cpp:177
DSPLIB_STATUS DSPLIB_sqr_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
This function checks the validity of the parameters passed to DSPLIB_sqr_exec function....
Definition: DSPLIB_sqr.cpp:64
DSPLIB_STATUS DSPLIB_sqr_init(DSPLIB_kernelHandle handle, DSPLIB_bufParams1D_t *bufParamsIn, DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_sqr_InitArgs *pKerInitArgs)
This function should be called before the DSPLIB_sqr_exec function is called. This function takes car...
Definition: DSPLIB_sqr.cpp:81
int32_t DSPLIB_sqr_getHandleSize(DSPLIB_sqr_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
Definition: DSPLIB_sqr.cpp:25
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_sqr.h:105
int8_t funcStyle
Variant of the function refer to DSPLIB_FUNCTION_STYLE
Definition: DSPLIB_sqr.h:107
uint32_t dataSize
Size of input data
Definition: DSPLIB_sqr.h:109
Structure that is reserved for internal use by the kernel.
pFxnDSPLIB_sqr_exec execute
Function pointer to point to the right execution variant between DSPLIB_sqr_exec_cn and DSPLIB_sqr_ex...
int32_t blockSize
Size of input buffer for different batches DSPLIB_sqr_init that will be retrieved and used by DSPLIB_...