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