FFTLIB User Guide
FFTLIB_FFT_dftLarge_ixX_cxX_oxX_ci.cpp
Go to the documentation of this file.
1 /******************************************************************************/
5 /* Copyright (C) 2017 Texas Instruments Incorporated - https://www.ti.com/
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution.
18  *
19  * Neither the name of Texas Instruments Incorporated nor the names of
20  * its contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  ******************************************************************************/
36 
37 
38 /*******************************************************************************
39  *
40  * INCLUDES
41  *
42  ******************************************************************************/
43 
44 #include "../FFTLIB_FFT_dftLarge_ixX_cxX_oxX_priv.h"
45 #include "../../../common/c71/FFTLIB_inlines.h"
46 
47 
48 /*******************************************************************************
49  *
50  * DEFINES
51  *
52  ******************************************************************************/
54  const FFTLIB_bufParams1D_t *bufParamsX,
55  const FFTLIB_bufParams1D_t *bufParamsY,
56  const FFTLIB_bufParams1D_t *bufParamsW,
57  uint32_t fftSize,
58  uint32_t batchSize,
59  uint64_t *archCycles,
60  uint64_t *estCycles)
61 {
62  FFTLIB_bufParams2D_t bufParamsMatrixData, bufParamsMatrixW;
63  int32_t caseNumber;
64  int32_t startupCycles, teardownCycles;
65 
66  bufParamsMatrixData.dim_x = fftSize*2;
67  bufParamsMatrixData.dim_y = batchSize;
68  bufParamsMatrixData.stride_y = fftSize*2*FFTLIB_sizeof(bufParamsX->data_type);
69  bufParamsMatrixData.data_type = bufParamsX->data_type;
70  bufParamsMatrixW.dim_x = fftSize*2;
71  bufParamsMatrixW.dim_y = fftSize*2;
72  bufParamsMatrixW.stride_y = fftSize*2*FFTLIB_sizeof(bufParamsW->data_type);
73  bufParamsMatrixW.data_type = bufParamsW->data_type;
74 
75  startupCycles =
76  3; // dftLarge exec()
77 
79  &bufParamsMatrixData,
80  &bufParamsMatrixW,
81  &bufParamsMatrixData,
82  archCycles,
83  estCycles,
84  &caseNumber);
85 
86  teardownCycles =
87  3; // dftLarge exec()
88 
89 
90  *archCycles = startupCycles + *archCycles + teardownCycles;
91  *estCycles = startupCycles + *estCycles + teardownCycles;
92 
93  return;
94 }
95 
96 template <uint32_t dataType>
98  const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs * pKerInitArgs,
99  FFTLIB_bufParams1D_t * bufParamsX,
100  FFTLIB_bufParams1D_t * bufParamsW,
101  FFTLIB_bufParams1D_t * bufParamsY)
102 {
103  uint32_t fftSize = pKerInitArgs->fftSize;
104  uint32_t batchSize = pKerInitArgs->batchSize;
105  uint32_t MMA_SIZE;
106  FFTLIB_STATUS status = FFTLIB_SUCCESS;
107 
108  if (dataType == FFTLIB_INT32) {
109  MMA_SIZE = FFTLIB_MMA_SIZE_32_BIT;
110  } else if (dataType == FFTLIB_INT16) {
111  MMA_SIZE = FFTLIB_MMA_SIZE_16_BIT;
112  } else {
114  }
115 
116  if (fftSize <= MMA_SIZE/2) {
118  }
119 
120  if (status == FFTLIB_SUCCESS) {
121  bufParamsX->dim_x = batchSize*fftSize*2;
122  bufParamsY->dim_x = batchSize*fftSize*2;
123  bufParamsW->dim_x = fftSize*2*fftSize*2;
124  }
125 
126  return status;
127 }
128 
130  FFTLIB_INT16>(
131  const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs * pKerInitArgs,
132  FFTLIB_bufParams1D_t * bufParamsX,
133  FFTLIB_bufParams1D_t * bufParamsW,
134  FFTLIB_bufParams1D_t * bufParamsY);
136  FFTLIB_INT32>(
137  const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs * pKerInitArgs,
138  FFTLIB_bufParams1D_t * bufParamsX,
139  FFTLIB_bufParams1D_t * bufParamsW,
140  FFTLIB_bufParams1D_t * bufParamsY);
141 
142 template <typename dataType>
144  const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs * pKerInitArgs,
145  void *restrict pW,
146  const FFTLIB_bufParams1D_t * bufParamsW)
147 {
148  FFTLIB_STATUS status = FFTLIB_SUCCESS;
149  uint32_t j, k;
150  const FFTLIB_D64 PI = 3.141592654;
151  FFTLIB_D64 twF2sScale;
152  FFTLIB_bufParams1D_t bufParamsXLocal, bufParamsYLocal, bufParamsWLocal;
153  dataType *pWLocal = (dataType *)pW;
154  uint32_t fftSize = pKerInitArgs->fftSize;
155  uint32_t interleave = pKerInitArgs->interleave;
156 
157  if (sizeof(dataType) == 4) {
159  &bufParamsXLocal,
160  &bufParamsWLocal,
161  &bufParamsYLocal);
162  } else if (sizeof(dataType) == 2) {
164  &bufParamsXLocal,
165  &bufParamsWLocal,
166  &bufParamsYLocal);
167  } else {
169  }
170 
171  if (bufParamsW->dim_x != bufParamsWLocal.dim_x) {
173  }
174 
175  if (status == FFTLIB_SUCCESS) {
176  twF2sScale = ((uint32_t)1 << ((uint32_t)(sizeof(dataType)*8-2))) - 1;
177  twF2sScale += ((uint32_t)1 << ((uint32_t)(sizeof(dataType)*8-2)));
178  twF2sScale += 0.5;
179  if (interleave) {
180  for (j = 0; j < fftSize; j++) {
181  for (k = 0; k < fftSize; k++) {
182  pWLocal[j*2*fftSize*2+k*2] =
183  FFTLIB_UTIL_cos_i64f_oxX<dataType>(
184  2*PI*j*k/fftSize, twF2sScale);
185  pWLocal[j*2*fftSize*2+k*2+1] =
186  -FFTLIB_UTIL_sin_i64f_oxX<dataType>(
187  2*PI*j*k/fftSize, twF2sScale);
188  }
189  for (k = 0; k < fftSize; k++) {
190  pWLocal[(j*2+1)*fftSize*2+k*2] =
191  FFTLIB_UTIL_sin_i64f_oxX<dataType>(
192  2*PI*j*k/fftSize, twF2sScale);
193  pWLocal[(j*2+1)*fftSize*2+k*2+1] =
194  FFTLIB_UTIL_cos_i64f_oxX<dataType>(
195  2*PI*j*k/fftSize, twF2sScale);
196  }
197  }
198  } else {
199  for (j = 0; j < fftSize; j++) {
200  for (k = 0; k < fftSize; k++) {
201  pWLocal[j*fftSize*2+k] =
202  FFTLIB_UTIL_cos_i64f_oxX<dataType>(
203  2*PI*j*k/fftSize, twF2sScale);
204  pWLocal[j*fftSize*2+fftSize+k] =
205  -FFTLIB_UTIL_sin_i64f_oxX<dataType>(
206  2*PI*j*k/fftSize, twF2sScale);
207  }
208  for (k = 0; k < fftSize; k++) {
209  pWLocal[fftSize*fftSize*2+j*fftSize*2+k] =
210  FFTLIB_UTIL_sin_i64f_oxX<dataType>(
211  2*PI*j*k/fftSize, twF2sScale);
212  pWLocal[fftSize*fftSize*2+j*fftSize*2+fftSize+k] =
213  FFTLIB_UTIL_cos_i64f_oxX<dataType>(
214  2*PI*j*k/fftSize, twF2sScale);
215  }
216  }
217  }
218  }
219 
220  return status;
221 }
222 
224  int16_t>(
225  const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs * pKerInitArgs,
226  void *restrict pW,
227  const FFTLIB_bufParams1D_t * bufParamsW);
228 
230  int32_t>(
231  const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs * pKerInitArgs,
232  void *restrict pW,
233  const FFTLIB_bufParams1D_t * bufParamsW);
234 
template FFTLIB_STATUS FFTLIB_FFT_dftLarge_ixX_cxX_oxX_getSizes< FFTLIB_INT16 >(const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs *pKerInitArgs, FFTLIB_bufParams1D_t *bufParamsX, FFTLIB_bufParams1D_t *bufParamsW, FFTLIB_bufParams1D_t *bufParamsY)
template FFTLIB_STATUS FFTLIB_FFT_dftLarge_ixX_cxX_oxX_getSizes< FFTLIB_INT32 >(const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs *pKerInitArgs, FFTLIB_bufParams1D_t *bufParamsX, FFTLIB_bufParams1D_t *bufParamsW, FFTLIB_bufParams1D_t *bufParamsY)
FFTLIB_STATUS FFTLIB_FFT_dftLarge_ixX_cxX_oxX_twGen(const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs *pKerInitArgs, void *restrict pW, const FFTLIB_bufParams1D_t *bufParamsW)
This is a utility function that generates the DFT computational matrix into the provided buffer.
void FFTLIB_LINALG_matrixMatrixMultiply_ixX_ixX_oxX_perfEst(FFTLIB_kernelHandle handle, const FFTLIB_bufParams2D_t *src0_addr, const FFTLIB_bufParams2D_t *src1_addr, const FFTLIB_bufParams2D_t *dst_addr, uint64_t *archCycles, uint64_t *estCycles, int32_t *caseNumber)
This function estimates the cycles consumed for the kernel execution.
@ FFTLIB_INT16
@ FFTLIB_INT32
static int32_t FFTLIB_sizeof(uint32_t type)
Inline function returns number of bytes per element given a type of _FFTLIB_data_type_e.
double FFTLIB_D64
Double precision floating point.
Definition: FFTLIB_types.h:168
void * FFTLIB_kernelHandle
Handle type for FFTLIB operations.
Definition: FFTLIB_types.h:217
FFTLIB_STATUS_NAME
The enumeration of all status codes.
Definition: FFTLIB_types.h:172
@ FFTLIB_ERR_NOT_IMPLEMENTED
Definition: FFTLIB_types.h:179
@ FFTLIB_ERR_INVALID_DIMENSION
Definition: FFTLIB_types.h:177
@ FFTLIB_SUCCESS
Definition: FFTLIB_types.h:173
#define FFTLIB_MMA_SIZE_16_BIT
type is 16-bit integers
#define FFTLIB_MMA_SIZE_32_BIT
type is 32-bit integers
FFTLIB_STATUS FFTLIB_FFT_dftLarge_ixX_cxX_oxX_getSizes(const FFTLIB_FFT_dftLarge_ixX_cxX_oxX_InitArgs *pKerInitArgs, FFTLIB_bufParams1D_t *bufParamsX, FFTLIB_bufParams1D_t *bufParamsW, FFTLIB_bufParams1D_t *bufParamsY)
This is a query function to calculate the sizes of input, output and the DFT computational matrix buf...
void FFTLIB_FFT_dftLarge_ixX_cxX_oxX_perfEst(FFTLIB_kernelHandle handle, const FFTLIB_bufParams1D_t *bufParamsX, const FFTLIB_bufParams1D_t *bufParamsY, const FFTLIB_bufParams1D_t *bufParamsW, uint32_t fftSize, uint32_t batchSize, uint64_t *archCycles, uint64_t *estCycles)
This is a utility function that gives an estimate of the cycles consumed for the kernel execution.
Structure containing the parameters for DFT computation.
uint32_t interleave
Flag to indicate if the real and imaginary parts of data are interleaved or not. A value of 1 indicat...
uint32_t batchSize
Size of the batch in terms of number of channels of DFT's.
uint32_t fftSize
Size of each channel's data in terms of number of complex points.
A structure for a 1 dimensional buffer descriptor.
uint32_t data_type
Values are of type FFTLIB_data_type_e.
uint32_t dim_x
Width of buffer in X dimension in elements.
A structure for a 2 dimensional buffer descriptor.
uint32_t dim_y
Height of buffer in Y dimension in elements.
uint32_t dim_x
Width of buffer in X dimension in elements.
int32_t stride_y
Stride in Y dimension in bytes.
uint32_t data_type
Values are of type FFTLIB_data_type_e.