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