DSPLIB User Guide
DSPLIB_recip.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_recip_priv.h"
24 
26 {
27  int32_t privBufSize = sizeof(DSPLIB_recip_PrivArgs);
28  return privBufSize;
29 }
30 
32  const DSPLIB_bufParams1D_t *bufParamsIn,
33  const DSPLIB_bufParams1D_t *bufParamsOut,
34  const DSPLIB_recip_InitArgs *pKerInitArgs)
35 {
37 
38 #if DSPLIB_DEBUGPRINT
39  printf("Enter DSPLIB_recip_init_checkParams\n");
40 #endif
41  if (handle == NULL) {
42  status = DSPLIB_ERR_NULL_POINTER;
43  }
44 
45  if (status == DSPLIB_SUCCESS) {
46 
47  // only float, double and short datatype support for now
48  if ((bufParamsIn->data_type != DSPLIB_INT16) && (bufParamsIn->data_type != DSPLIB_FLOAT32) &&
49  (bufParamsIn->data_type != DSPLIB_FLOAT64)) {
50  status = DSPLIB_ERR_INVALID_TYPE;
51  }
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 DSPLIB_recip_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
66 {
67  DSPLIB_STATUS status;
68 
69 #if DSPLIB_DEBUGPRINT
70  printf("Enter DSPLIB_recip_exec_checkParams\n");
71 #endif
72  if ((pIn == NULL) || (pOut == NULL)) {
73  status = DSPLIB_ERR_NULL_POINTER;
74  }
75  else {
76  status = DSPLIB_SUCCESS;
77  }
78 
79  return status;
80 }
81 
83  DSPLIB_bufParams1D_t *bufParamsIn,
84  DSPLIB_bufParams1D_t *bufParamsOut,
85  const DSPLIB_recip_InitArgs *pKerInitArgs)
86 {
88  DSPLIB_recip_PrivArgs *pKerPrivArgs = (DSPLIB_recip_PrivArgs *) handle;
89 
90 #if DSPLIB_DEBUGPRINT
91  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_recip_init\n");
92 #endif
93  pKerPrivArgs->blockSize = pKerInitArgs->dataSize;
94 
95 #if DSPLIB_DEBUGPRINT
96  printf("DSPLIB_DEBUGPRINT DSPLIB_recip_init pKerPrivArgs->blockSize %d bufParamsIn->data_type %d\n",
97  pKerPrivArgs->blockSize, bufParamsIn->data_type);
98 #endif
99 
100  // fill private args with init args
101  pKerPrivArgs->initArgs = *pKerInitArgs;
102 
103  if (pKerInitArgs->funcStyle == DSPLIB_FUNCTION_NATC) {
104  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
106  }
107  else if (bufParamsIn->data_type == DSPLIB_INT16) {
109  }
110  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
112  }
113 
114  else {
115  status = DSPLIB_ERR_INVALID_TYPE;
116 #if DSPLIB_DEBUGPRINT
117  printf("DSPLIB_DEBUGPRINT CP 2 status %d\n", status);
118 #endif
119  }
120  }
121  else {
122  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
123 #if DSPLIB_DEBUGPRINT
124  printf("DSPLIB_DEBUGPRINT bufParamsIn->data_type == DSPLIB_FLOAT32\n");
125 #endif
127  status = DSPLIB_recip_init_ci<float>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
128  }
129  else if (bufParamsIn->data_type == DSPLIB_INT16) {
131  status = DSPLIB_recip_init_ci<int16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
132  }
133  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
135  status = DSPLIB_recip_init_ci<double>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
136  }
137 
138  else {
139  status = DSPLIB_ERR_INVALID_TYPE;
140  }
141  }
142 #if DSPLIB_DEBUGPRINT
143  printf("DSPLIB_DEBUGPRINT CP 3 status %d\n", status);
144 #endif
145  return status;
146 }
147 
148 DSPLIB_STATUS DSPLIB_recip_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
149 {
150  DSPLIB_STATUS status;
151 
152 #if DSPLIB_DEBUGPRINT
153  printf("DSPLIB_DEBUGPRINT Enter DSPLIB_recip_exec\n");
154 #endif
155 
156  DSPLIB_recip_PrivArgs *pKerPrivArgs = (DSPLIB_recip_PrivArgs *) handle;
157 
158 #if DSPLIB_DEBUGPRINT
159  printf("DSPLIB_DEBUGPRINT pKerPrivArgs->blockSize %d\n", pKerPrivArgs->blockSize);
160 #endif
161  status = pKerPrivArgs->execute(handle, pIn, pOut);
162 
163  return status;
164 }
template DSPLIB_STATUS DSPLIB_recip_exec_ci< double, DSPLIB_FLOAT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_recip_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_recip_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_recip_exec_ci< float, DSPLIB_FLOAT32 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_recip_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_recip_InitArgs *pKerInitArgs)
template DSPLIB_STATUS DSPLIB_recip_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_recip_InitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_recip_exec_ci< int16_t, DSPLIB_INT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_recip_exec_cn< double, DSPLIB_FLOAT64 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_recip_exec_cn< int16_t, DSPLIB_INT16 >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_recip_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_recip.
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_INT16
@ DSPLIB_FLOAT32
@ DSPLIB_FLOAT64
@ 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_recip_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main kernel compute function.
int32_t DSPLIB_recip_getHandleSize(DSPLIB_recip_InitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
DSPLIB_STATUS DSPLIB_recip_init_checkParams(DSPLIB_kernelHandle handle, const DSPLIB_bufParams1D_t *bufParamsIn, const DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_recip_InitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to DSPLIB_recip_init function....
DSPLIB_STATUS DSPLIB_recip_init(DSPLIB_kernelHandle handle, DSPLIB_bufParams1D_t *bufParamsIn, DSPLIB_bufParams1D_t *bufParamsOut, const DSPLIB_recip_InitArgs *pKerInitArgs)
This function should be called before the DSPLIB_recip_exec function is called. This function takes c...
DSPLIB_STATUS DSPLIB_recip_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
This function checks the validity of the parameters passed to DSPLIB_recip_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_recip.h:120
int8_t funcStyle
Variant of the function refer to DSPLIB_FUNCTION_STYLE
Definition: DSPLIB_recip.h:122
uint32_t dataSize
Size of input data
Definition: DSPLIB_recip.h:124
Structure that is reserved for internal use by the kernel.
int32_t blockSize
Size of input buffer for different batches DSPLIB_recip_init that will be retrieved and used by DSPLI...
pFxnDSPLIB_recip_exec execute
Function pointer to point to the right execution variant between DSPLIB_recip_exec_cn and DSPLIB_reci...
DSPLIB_recip_InitArgs initArgs