DSPLIB User Guide
DSPLIB_matTrans.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * *
3  * module name :DSPLIB *
4  * *
5  * module descripton :Digital Signal Processing 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_matTrans_priv.h"
24 
26 {
27  int32_t privBufSize = sizeof(DSPLIB_matTrans_PrivArgs);
28 
29  DSPLIB_DEBUGPRINTFN(0, "privBufSize: %d\n", privBufSize);
30 
31  return privBufSize;
32 }
33 
35  const DSPLIB_bufParams2D_t *bufParamsIn,
36  const DSPLIB_bufParams2D_t *bufParamsOut,
37  const DSPLIB_matTransInitArgs *pKerInitArgs)
38 {
39  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering Function");
40 
42 
43  if (handle == NULL) {
44  status = DSPLIB_ERR_NULL_POINTER;
45  }
46 
47  if (status == DSPLIB_SUCCESS) {
48 
49  /* Condition change */
50  if ((bufParamsIn->data_type != DSPLIB_INT64) && (bufParamsIn->data_type != DSPLIB_INT32) &&
51  (bufParamsIn->data_type != DSPLIB_INT16) && (bufParamsIn->data_type != DSPLIB_INT8) &&
52  (bufParamsIn->data_type != DSPLIB_UINT64) && (bufParamsIn->data_type != DSPLIB_UINT32) &&
53  (bufParamsIn->data_type != DSPLIB_UINT16) && (bufParamsIn->data_type != DSPLIB_UINT8) &&
54  (bufParamsIn->data_type != DSPLIB_FLOAT32) && (bufParamsIn->data_type != DSPLIB_FLOAT64)) {
55  status = DSPLIB_ERR_INVALID_TYPE;
56  }
57  else if (bufParamsIn->data_type != bufParamsOut->data_type) {
58  status = DSPLIB_ERR_INVALID_TYPE;
59  }
60  else if ((bufParamsIn->data_type == DSPLIB_UINT16 || bufParamsIn->data_type == DSPLIB_INT16) &&
61  (bufParamsIn->dim_x % 2 != 0)) {
62  status = DSPLIB_ERR_INVALID_VALUE;
63  }
64  else if ((bufParamsIn->data_type == DSPLIB_UINT8 || bufParamsIn->data_type == DSPLIB_INT8) &&
65  (bufParamsIn->dim_x % 4 != 0)) {
66  status = DSPLIB_ERR_INVALID_VALUE;
67  }
68  else {
69  /* Do nothing */
70  }
71  }
72 
73  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
74 
75  return status;
76 }
77 
79 DSPLIB_matTrans_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
80 {
81  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
82 
83  DSPLIB_STATUS status;
84 
85  if ((pIn == NULL) || (pOut == NULL)) {
86  status = DSPLIB_ERR_NULL_POINTER;
87  }
88  else {
89  status = DSPLIB_SUCCESS;
90  }
91  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
92 
93  return status;
94 }
95 
97  DSPLIB_bufParams2D_t *bufParamsIn,
98  DSPLIB_bufParams2D_t *bufParamsOut,
99  const DSPLIB_matTransInitArgs *pKerInitArgs)
100 {
101  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
102 
103  DSPLIB_STATUS status = DSPLIB_SUCCESS;
104  DSPLIB_matTrans_PrivArgs *pKerPrivArgs = (DSPLIB_matTrans_PrivArgs *) handle;
105 
106  pKerPrivArgs->widthIn = bufParamsIn->dim_x;
107  pKerPrivArgs->heightIn = bufParamsIn->dim_y;
108  pKerPrivArgs->strideIn = bufParamsIn->stride_y;
109  pKerPrivArgs->strideOut = bufParamsOut->stride_y;
110 
111  DSPLIB_DEBUGPRINTFN(0, "pKerInitArgs->funcStyle: %d bufParamsOut->data_type: %d\n", pKerInitArgs->funcStyle,
112  bufParamsOut->data_type);
113 
114  if (pKerInitArgs->funcStyle == DSPLIB_FUNCTION_NATC) {
115  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
116  pKerPrivArgs->execute = DSPLIB_matTrans_exec_cn<float>;
117  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
118  }
119  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
121  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
122  }
123  else if (bufParamsIn->data_type == DSPLIB_INT8) {
125  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
126  }
127  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
129  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
130  }
131  else if (bufParamsIn->data_type == DSPLIB_INT16) {
133  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
134  }
135  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
137  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
138  }
139  else if (bufParamsIn->data_type == DSPLIB_INT32) {
141  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
142  }
143  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
145  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
146  }
147  else if (bufParamsIn->data_type == DSPLIB_INT64) {
149  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
150  }
151  else if (bufParamsIn->data_type == DSPLIB_UINT64) {
153  status = DSPLIB_matTrans_init_cn(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
154  }
155 
156  else {
157  status = DSPLIB_ERR_INVALID_TYPE;
158  }
159  }
160  else {
161  if (bufParamsIn->data_type == DSPLIB_FLOAT32) {
162  pKerPrivArgs->execute = DSPLIB_matTrans_exec_ci<float>;
163  status = DSPLIB_matTrans_init_ci<float>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
164  }
165  else if (bufParamsIn->data_type == DSPLIB_FLOAT64) {
167  status = DSPLIB_matTrans_init_ci<double>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
168  }
169  else if (bufParamsIn->data_type == DSPLIB_INT8) {
171  status = DSPLIB_matTrans_init_ci<int8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
172  }
173  else if (bufParamsIn->data_type == DSPLIB_UINT8) {
175  status = DSPLIB_matTrans_init_ci<uint8_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
176  }
177  else if (bufParamsIn->data_type == DSPLIB_INT16) {
179  status = DSPLIB_matTrans_init_ci<int16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
180  }
181  else if (bufParamsIn->data_type == DSPLIB_UINT16) {
183  status = DSPLIB_matTrans_init_ci<uint16_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
184  }
185  else if (bufParamsIn->data_type == DSPLIB_INT32) {
187  status = DSPLIB_matTrans_init_ci<int32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
188  }
189  else if (bufParamsIn->data_type == DSPLIB_UINT32) {
191  status = DSPLIB_matTrans_init_ci<uint32_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
192  }
193  else if (bufParamsIn->data_type == DSPLIB_INT64) {
195  status = DSPLIB_matTrans_init_ci<int64_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
196  }
197  else if (bufParamsIn->data_type == DSPLIB_UINT64) {
199  status = DSPLIB_matTrans_init_ci<uint64_t>(handle, bufParamsIn, bufParamsOut, pKerInitArgs);
200  }
201  else {
202  status = DSPLIB_ERR_INVALID_TYPE;
203  }
204  }
205  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
206 
207  return status;
208 }
209 
210 DSPLIB_STATUS DSPLIB_matTrans_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
211 {
212  DSPLIB_DEBUGPRINTFN(0, "%s\n", "Entering function");
213 
214  DSPLIB_STATUS status;
215 
216  DSPLIB_matTrans_PrivArgs *pKerPrivArgs = (DSPLIB_matTrans_PrivArgs *) handle;
217 
218  DSPLIB_DEBUGPRINTFN(0, "widthIn: %d heightIn: %d strideIn: %d strideOut: %d\n", pKerPrivArgs->widthIn,
219  pKerPrivArgs->heightIn, pKerPrivArgs->strideIn, pKerPrivArgs->strideOut);
220 
221  status = pKerPrivArgs->execute(handle, pIn, pOut);
222 
223  DSPLIB_DEBUGPRINTFN(0, "Exiting function with return status: %d\n", status);
224 
225  return status;
226 }
DSPLIB_STATUS DSPLIB_matTrans_init_ci< int64_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_init_ci< double >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_init_ci< uint16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_init_ci< uint64_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_init_ci< uint32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_init_ci< int32_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_init_ci< int8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_init_ci< int16_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_init_ci< float >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< int64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_init_ci< uint8_t >(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< uint64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_exec_ci< double >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< uint64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
DSPLIB_STATUS DSPLIB_matTrans_init_cn(DSPLIB_kernelHandle handle, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
This function is the initialization function for the natural C implementation of the kernel....
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< int32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< uint32_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< int16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< uint8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< int64_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< uint16_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< double >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< float >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
template DSPLIB_STATUS DSPLIB_matTrans_exec_cn< int8_t >(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
Header file for kernel's internal use. For the kernel's interface, please see DSPLIB_mat_trans.
#define DSPLIB_DEBUGPRINTFN(N, fmt,...)
Definition: DSPLIB_types.h:83
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_UINT64
@ DSPLIB_UINT8
@ DSPLIB_UINT16
@ DSPLIB_INT32
@ DSPLIB_INT16
@ DSPLIB_FLOAT32
@ DSPLIB_INT64
@ DSPLIB_FLOAT64
@ DSPLIB_UINT32
@ DSPLIB_INT8
@ DSPLIB_ERR_INVALID_VALUE
Definition: DSPLIB_types.h:154
@ 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_matTrans_exec(DSPLIB_kernelHandle handle, void *restrict pIn, void *restrict pOut)
This function is the main kernel compute function.
DSPLIB_STATUS DSPLIB_matTrans_exec_checkParams(DSPLIB_kernelHandle handle, const void *restrict pIn, const void *restrict pOut)
This function checks the validity of the parameters passed to DSPLIB_matTrans_exec function....
DSPLIB_STATUS DSPLIB_matTrans_init(DSPLIB_kernelHandle handle, DSPLIB_bufParams2D_t *bufParamsIn, DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
This function should be called before the DSPLIB_matTrans_exec function is called....
DSPLIB_STATUS DSPLIB_matTrans_init_checkParams(DSPLIB_kernelHandle handle, const DSPLIB_bufParams2D_t *bufParamsIn, const DSPLIB_bufParams2D_t *bufParamsOut, const DSPLIB_matTransInitArgs *pKerInitArgs)
This function checks the validity of the parameters passed to DSPLIB_matTrans_init function....
int32_t DSPLIB_matTrans_getHandleSize(DSPLIB_matTransInitArgs *pKerInitArgs)
This is a query function to calculate the size of internal handle.
A structure for a 2 dimensional buffer descriptor.
uint32_t data_type
Values are of type DSPLIB_data_type_e.
int32_t stride_y
Stride in Y dimension in bytes.
uint32_t dim_x
Width of buffer in X dimension in elements.
uint32_t dim_y
Height of buffer in Y dimension in elements.
Structure containing the parameters to initialize the kernel.
int8_t funcStyle
Variant of the function refer to DSPLIB_FUNCTION_STYLE
Structure that is reserved for internal use by the kernel.
int32_t strideOut
Stride between rows of output data matrix
pFxnDSPLIB_matTrans_exec execute
Function pointer to point to the right execution variant between DSPLIB_matTrans_exec_cn and DSPLIB_m...
uint32_t heightIn
Height of input data matrix
int32_t strideIn
Stride between rows of input data matrix
uint32_t widthIn
Size of input buffer for different batches DSPLIB_matTrans_init that will be retrieved and used by DS...