FFTLIB User Guide
FFTLIB_types.h
Go to the documentation of this file.
1 /******************************************************************************
2  * *
3  * module name :FFTLIB *
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 #ifndef COMMON_FFTLIB_TYPES_H_
24 #define COMMON_FFTLIB_TYPES_H_ 1
25 
26 /* This header is needed to be included in OpenCL programs which link
27  * against FFTLIB, but OpenCL doesn't need the following headers */
28 #ifndef __OPENCL_VERSION__
29 #include <inttypes.h>
30 #include <stddef.h> // for NULL
31 #include <stdint.h>
32 #include <stdio.h> // for printf
33 #include <stdlib.h>
34 #endif
35 #include <c7x.h> // for streaming engine, streaming address gen.
36 
37 #include "FFTLIB_bufParams.h"
38 #include "TI_platforms.h"
39 
40 #if defined(__C7100__) || defined(__C7120__) || defined(__C7502__) || defined(__C7504__) || defined(__C7508__) || \
41  defined(__C7524__)
42 #include "c71/FFTLIB_defines.h"
43 #else
44 #error invalid target
45 #endif
46 
47 #include "c7120/FFTLIB_defines.h"
48 #include "c7120/FFTLIB_types.h"
49 
53 #if !defined(FFTLIB_DEBUGPRINT)
54 #define FFTLIB_DEBUGPRINT 0
55 #endif
56 
57 #if (defined(_HOST_BUILD) && (FFTLIB_COMPILER_VERSION < 1003999))
58 #define FFTLIB_const
59 #else
60 #define FFTLIB_const const
61 #endif
62 
63 #define __PRAGMA(x) _Pragma(#x)
64 #ifdef __cplusplus
65 #define __INLINE_FUNC(x) __PRAGMA(FUNC_ALWAYS_INLINE)
66 #else
67 #define __INLINE_FUNC(x) __PRAGMA(FUNC_ALWAYS_INLINE(x))
68 #endif
69 
70 /* ---------------------------------------------------------------- */
71 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The following two */
72 /* function-like macros do not have equivalent function */
73 /* implementations. */
74 /* ---------------------------------------------------------------- */
75 #if defined(EVM_TEST)
76 #define FFTLIB_PRINTF(fmt, ...) \
77  do { \
78  fprintf(stdout, fmt, __VA_ARGS__); \
79  } while (0)
80 
81 #if FFTLIB_DEBUGPRINT > 0
82 #define FFTLIB_DEBUGPRINTFN(N, fmt, ...) \
83  do { \
84  if (FFTLIB_DEBUGPRINT >= (N)) { \
85  fprintf(stdout, "FFTLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, __VA_ARGS__); \
86  } \
87  } while (0)
88 
89 #else // FFTLIB_DEBUGPRINT == 0
90 
91 #define FFTLIB_DEBUGPRINTFN(N, fmt, ...)
92 //#define FFTLIB_PRINTF(fmt, ...)
93 #endif // #if FFTLIB_DEBUGPRINT
94 
95 #else
96 
97 #if FFTLIB_DEBUGPRINT > 0
98 #define FFTLIB_DEBUGPRINTFN(N, fmt, ...) \
99  if (FFTLIB_DEBUGPRINT >= (N)) { \
100  fprintf(stderr, "FFTLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, __VA_ARGS__); \
101  }
102 
103 #define FFTLIB_PRINTF(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
104 
105 #else // FFTLIB_DEBUGPRINT == 0
106 
107 #define FFTLIB_DEBUGPRINTFN(N, fmt, ...)
108 #define FFTLIB_PRINTF(fmt, ...)
109 
110 #endif // #if FFTLIB_DEBUGPRINT
111 #endif // #if defined(EVM_TEST)
112 
113 #if defined(FFTLIB_MESSAGES)
114 // if enabled, display messages to the library user
115 // FFTLIB_MESSAGES should only be defined when TARGET_BUILD=debug or CHECKPARAMS=1
116 #define FFTLIB_MESG(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
117 #else
118 #define FFTLIB_MESG(fmt, ...)
119 #endif //#if defined(FFTLIB_MESSAGES)
120 
121 /* Original implementation that had the benefit of always being compiled and thus
122  receiving error checking. However, the fprintf generates a MISRA-C violation.
123 #define FFTLIB_DEBUGPRINTFN(N, fmt, ...) \
124  do { \
125  if (FFTLIB_DEBUGPRINT >= (N)) { \
126  fprintf(stderr, "FFTLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, \
127  __VA_ARGS__); \
128  } \
129  } while (0)
130 
131 #define FFTLIB_PRINTF(fmt, ...) \
132  do { \
133  fprintf(stderr, fmt, __VA_ARGS__); \
134  } while (0)
135 #endif
136  */
137 
138 #define FFTLIB_SOFT_MMA_RESET 0
139 
140 // switch to enable or disable static inline for FFTLIB functions defined in .c files (so not many functions)
141 #define FFTLIB_STATIC_INLINE static inline
142 
143 #ifdef __cplusplus
144 #include <c7x_scalable.h> // for device scalability
145 
146 extern const c7x::uchar_vec FFTLIB_zeroVect_uchar_vec;
147 extern const c7x::ushort_vec FFTLIB_zeroVect_ushort_vec;
148 extern const c7x::uchar_vec FFTLIB_vperm_data_0_63;
149 
150 extern "C" {
151 #endif /* __cplusplus */
152 
160 /* @{ */
161 
162 /*******************************************************************************
163  *
164  * TYPEDEFS
165  *
166  ******************************************************************************/
167 
168 typedef double FFTLIB_D64;
169 typedef float FFTLIB_F32;
170 
172 typedef enum {
188  14, /* FFTLIB_fft1dBatched_i32f_c32fc_o32fc: Outmode flag must be full (1) or half (0) */
189  // FFTLIB_LINALG_matrixMatrixMultiply
193  10002,
194  // FFTLIB_LINALG_matrixMatrixMultiplyAccumulate
196  11000,
198  11001,
200  11002,
201  // FFTLIB_LINALG_matrixTranspose
205  12002,
206  // FFTLIB_LINALG_pointwiseMatrixMatrixMultiply
208  13000,
210  13001,
212  13002,
214 
216 
217 typedef void *FFTLIB_kernelHandle;
218 
220 typedef enum {
224  FFTLIB_FUNCTION_MAX = 128
226 
227 /*******************************************************************************
228  *
229  * DEFINES
230  *
231  ******************************************************************************/
232 
233 #define FFTLIB_PARAM_SIZE 128
234 //#define FFTLIB_BYTE_WIDTH 64 //!< MMA width in bytes
235 #define FFTLIB_MMA_ACCUMULATOR_BYTE_WIDTH_8_BIT 4
236 #define FFTLIB_MMA_ACCUMULATOR_BYTE_WIDTH_16_BIT 8
237 #define FFTLIB_MMA_ACCUMULATOR_BYTE_WIDTH_32_BIT 16
238 
239 /*******************************************************************************
240  *
241  * Macros
242  *
243  ******************************************************************************/
244 
245 #define FFTLIB_ALIGN_SHIFT_64BYTES 6
246 #define FFTLIB_ALIGN_SHIFT_128BYTES 7
247 #define FFTLIB_ALIGN_SHIFT_256BYTES 8
248 
249 #define FFTLIB_ALIGN_64BYTES (1 << FFTLIB_ALIGN_SHIFT_64BYTES)
250 #define FFTLIB_ALIGN_128BYTES (1 << FFTLIB_ALIGN_SHIFT_128BYTES)
251 #define FFTLIB_ALIGN_256BYTES (1 << FFTLIB_ALIGN_SHIFT_256BYTES)
252 
253 #define FFTLIB_L2DATA_ALIGN_SHIFT FFTLIB_ALIGN_SHIFT_64BYTES
254 
257 #define FFTLIB_L2DATA_ALIGNMENT (((uint32_t) 1) << ((uint32_t) FFTLIB_L2DATA_ALIGN_SHIFT))
258 
259 /* ---------------------------------------------------------------- */
260 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
261 /* being addressed */
262 /* ---------------------------------------------------------------- */
265 /* #define FFTLIB_CALC_STRIDE(BYTES, ALIGN_SHIFT) \ */
266 /* (((((BYTES)-1) >> (ALIGN_SHIFT)) + 1) << (ALIGN_SHIFT)) */
267 
268 /* /\*! @brief Macro for FFTLIB shift amounts *\/ */
269 /* #define FFTLIB_MMA_SIZE_8_BIT_SHIFT \ */
270 /* 6 //!< Shift for MMA size when data type is 8-bit integers */
271 /* #define FFTLIB_MMA_SIZE_16_BIT_SHIFT \ */
272 /* 5 //!< Shift for MMA size when data type is 16-bit integers */
273 /* #define FFTLIB_MMA_SIZE_32_BIT_SHIFT \ */
274 /* 4 //!< Shift for MMA size when data type is 32-bit integers */
275 
276 /* /\*! @brief MMA size as a function of precision *\/ */
277 /* //#define FFTLIB_MMA_SIZE_1_BYTE 1 */
278 /* #define FFTLIB_MMA_SIZE_8_BIT \ */
279 /* ((uint32_t)(((uint32_t)1) \ */
280 /* << FFTLIB_MMA_SIZE_8_BIT_SHIFT)) //!< Shift for MMA size when data */
281 /* //!< type is 8-bit integers */
282 /* #define FFTLIB_MMA_SIZE_16_BIT \ */
283 /* ((uint32_t)(((uint32_t)1) \ */
284 /* << FFTLIB_MMA_SIZE_16_BIT_SHIFT)) //!< Shift for MMA size when data */
285 /* //!< type is 16-bit integers */
286 /* #define FFTLIB_MMA_SIZE_32_BIT \ */
287 /* ((int32_t)(((uint32_t)1) \ */
288 /* << FFTLIB_MMA_SIZE_32_BIT_SHIFT)) //!< Shift for MMA size when data */
289 /* //!< type is 32-bit integers */
290 
291 /* @} */
292 
293 /******************************************************************************
294  *
295  * Do not document these in the User Guide
296  ******************************************************************************/
297 
301 /* @{ */
302 
303 /* ---------------------------------------------------------------- */
304 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
305 /* being addressed */
306 /* ---------------------------------------------------------------- */
307 // remove asm comments for Loki testing as they may add cycles
308 #if defined(QT_TEST) || defined(RTL_TEST) || defined(EVM_TEST)
309 #if defined(_HOST_BUILD)
310 #define FFTLIB_asm(string) ;
311 #else
312 #define FFTLIB_asm(string) \
313  ; \
314  asm(string);
315 #endif // _HOST_BUILD
316 #else
317 #define FFTLIB_asm(string) ;
318 #endif
319 
320 /* ---------------------------------------------------------------- */
321 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
322 /* being addressed so as not to lose portability across different */
323 /* platforms. */
324 /* ---------------------------------------------------------------- */
325 // cl7x unroll attributes not recognized by gcc/gpp compiler and generate
326 // warnings. Remove them with macro
327 #if defined(_HOST_BUILD)
328 #define str(x) #x
329 #define xstr(x) str(x)
330 #ifdef WIN32
331 #define __attribute__()
332 #define FFTLIB_UNROLL(count)
333 #else
334 #define FFTLIB_UNROLL(count) _Pragma(str(UNROLL(count)))
335 #endif
336 #else
337 #define FFTLIB_UNROLL(COUNT) [[TI::unroll(COUNT)]]
338 #endif
339 
340 #if defined(_HOST_BUILD)
341 #ifdef WIN32
342 #define __attribute__()
343 #define FFTLIB_MUST_ITERATE(initial, max, multiple)
344 #else
345 #define FFTLIB_MUST_ITERATE(initial, max, multiple) _Pragma(str(MUST_ITERATE(initial, max, multiple)))
346 #endif
347 #else
348 #define FFTLIB_MUST_ITERATE(INTIAL, MAX, MULTIPLE) [[TI::must_iterate(INTIAL, MAX, MULTIPLE)]]
349 #endif
350 
351 #ifndef FFTLIB_NUMBER_RANDOM_DIM_TESTS
352 #define FFTLIB_NUMBER_RANDOM_DIM_TESTS 25
353 #endif
354 
355 #if defined(PERFORMANCE_TEST)
356 #define FFTLIB_PERFORMANCE_TEST_PATTERN SEQUENTIAL
357 #else
358 #define FFTLIB_PERFORMANCE_TEST_PATTERN RANDOM_SIGNED
359 #endif
360 
361 #define FFTLIB_TEST_OUTPUT_HEAP 0
362 #if defined(_HOST_BUILD)
363 // Valgrind works better when output is in the heap (it can't track statically allocated memory), so
364 // in host emulation mode, place test outputs in the heap rather than statically allocated MSMC
365 #define FFTLIB_TEST_OUTPUT_MSMC FFTLIB_TEST_OUTPUT_HEAP
366 #else
367 #define FFTLIB_TEST_OUTPUT_MSMC 1
368 #endif
369 
370 #define STRIDE_OPT_4CYCLE 1
371 
372 /*******************************************************************************
373  *
374  * MACROS
375  *
376  ******************************************************************************/
377 
378 /* ---------------------------------------------------------------- */
379 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The following */
380 /* function-like macros are intended to be used across different */
381 /* data types. */
382 /* ---------------------------------------------------------------- */
383 #define FFTLIB_min(x, y) (((x) < (y)) ? (x) : (y))
384 #define FFTLIB_max(x, y) (((x) < (y)) ? (y) : (x))
385 #define FFTLIB_ceilingDiv(x, y) \
386  (((x) + (y) -1) / (y))
388 /******************************************************************************
389  *
390  * COMMON MMA CONIFGURATIONS
391  *
392  ******************************************************************************/
393 
395 
400 
405 
406 extern const __HWA_OFFSET_REG offsetRegStruct_zeros;
407 extern const __HWA_OFFSET_REG offsetRegStruct_diagonal_32bit;
408 extern const __HWA_OFFSET_REG offsetRegStruct_diagonal_16bit;
409 extern const __HWA_OFFSET_REG offsetRegStruct_diagonal_8bit;
410 
411 /* @} */
414 #ifdef __cplusplus
415 }
416 #endif /* __cplusplus */
417 #endif /* COMMON_FFTLIB_TYPES_H_ */
418 
419 /* ======================================================================== */
420 /* End of file: FFTLIB_types.h */
421 /* ======================================================================== */
File to hold buffer parameter related info for FFTLIB.
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_FAILURE
Definition: FFTLIB_types.h:174
@ FFTLIB_ERR_INVALID_ACTIVATION
Definition: FFTLIB_types.h:184
@ FFTLIB_ERR_INVALID_TYPE
Definition: FFTLIB_types.h:176
@ FFTLIB_ERR_MATRIX_MATRIX_MULTIPLY_ACCUMULATE_UNSUPPORTED_TYPE_COMBINATION
Definition: FFTLIB_types.h:199
@ FFTLIB_ERR_NOT_EQUAL_WIDTH_STRIDE
Definition: FFTLIB_types.h:180
@ FFTLIB_ERR_MATRIX_MATRIX_MULTIPLY_UNSUPPORTED_TYPE_COMBINATION
Definition: FFTLIB_types.h:192
@ FFTLIB_ERR_MATRIX_MATRIX_MULTIPLY_ACCUMULATE_UNSUPPORTED_INPUT_TYPE
Definition: FFTLIB_types.h:195
@ FFTLIB_ERR_POINTWISE_MATRIX_MATRIX_MULTIPLY_UNSUPPORTED_OUTPUT_TYPE
Definition: FFTLIB_types.h:209
@ FFTLIB_ERROR_MAX
Definition: FFTLIB_types.h:186
@ FFTLIB_ERR_NULL_POINTER
Definition: FFTLIB_types.h:178
@ FFTLIB_ERR_INVALID_DIMENSION
Definition: FFTLIB_types.h:177
@ FFTLIB_ERR_MATRIX_TRANSPOSE_UNSUPPORTED_TYPE_COMBINATION
Definition: FFTLIB_types.h:204
@ FFTLIB_ERR_POINTWISE_MATRIX_MATRIX_MULTIPLY_UNSUPPORTED_TYPE_COMBINATION
Definition: FFTLIB_types.h:211
@ FFTLIB_ERR_MATRIX_TRANSPOSE_UNSUPPORTED_INPUT_TYPE
Definition: FFTLIB_types.h:202
@ FFTLIB_ERR_MATRIX_MATRIX_MULTIPLY_UNSUPPORTED_OUTPUT_TYPE
Definition: FFTLIB_types.h:191
@ FFTLIB_ERR_INVALID_SHIFT
Definition: FFTLIB_types.h:185
@ FFTLIB_ERR_BUFFER_TOO_SMALL
Definition: FFTLIB_types.h:183
@ FFTLIB_ERR_MATRIX_TRANSPOSE_UNSUPPORTED_OUTPUT_TYPE
Definition: FFTLIB_types.h:203
@ FFTLIB_ERR_INVALID_OUTMODE
Definition: FFTLIB_types.h:187
@ FFTLIB_ERR_MATRIX_MATRIX_MULTIPLY_ACCUMULATE_UNSUPPORTED_OUTPUT_TYPE
Definition: FFTLIB_types.h:197
@ FFTLIB_ERR_POINTWISE_MATRIX_MATRIX_MULTIPLY_UNSUPPORTED_INPUT_TYPE
Definition: FFTLIB_types.h:207
@ FFTLIB_ERR_INVALID_VALUE
Definition: FFTLIB_types.h:175
@ FFTLIB_ERR_NOT_ALIGNED_WIDTHS
Definition: FFTLIB_types.h:182
@ FFTLIB_SUCCESS
Definition: FFTLIB_types.h:173
@ FFTLIB_ERR_NOT_ALIGNED_PTRS_STRIDES
Definition: FFTLIB_types.h:181
@ FFTLIB_ERR_MATRIX_MATRIX_MULTIPLY_UNSUPPORTED_INPUT_TYPE
Definition: FFTLIB_types.h:190
float FFTLIB_F32
Single precision floating point.
Definition: FFTLIB_types.h:169
FFTLIB_STATUS_NAME FFTLIB_STATUS
Return value for FFTLIB functions.
Definition: FFTLIB_types.h:215
FFTLIB_FUNCTION_STYLE
Enumeration for the style of function implementation.
Definition: FFTLIB_types.h:220
@ FFTLIB_FUNCTION_MAX
Definition: FFTLIB_types.h:224
@ FFTLIB_FUNCTION_OPTIMIZED
Definition: FFTLIB_types.h:222
@ FFTLIB_FUNCTION_NATC
Definition: FFTLIB_types.h:221
const __HWA_OFFSET_REG offsetRegStruct_zeros
const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i16s_i16s_o16u
const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i16s_i16s_o16s
const __HWA_OFFSET_REG offsetRegStruct_diagonal_16bit
const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i32s_i32s_o32s
const __HWA_OFFSET_REG offsetRegStruct_diagonal_8bit
const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i8u_i8s_o8u
const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i8s_i8s_o8s
const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i16u_i16s_o16s
const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i8u_i8s_o8s
const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i16u_i16s_o16u
const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i8s_i8s_o8u
const __HWA_OFFSET_REG offsetRegStruct_diagonal_32bit
#define FFTLIB_MMA_CONFIG_REG
File to hold common structure, enums, macros and functions for FFTLIB.
const c7x::ushort_vec FFTLIB_zeroVect_ushort_vec
const c7x::uchar_vec FFTLIB_zeroVect_uchar_vec