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 - http://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 <stdint.h>
30 #include <stdlib.h>
31 #include <inttypes.h>
32 #include <stddef.h> // for NULL
33 #include <stdio.h> // for printf
34 #endif
35 #include <c7x.h> // for streaming engine, streaming address gen.
36 
37 
38 #include "FFTLIB_bufParams.h"
39 #include "TI_platforms.h"
40 
41 #include "c71/FFTLIB_defines.h"
42 
43 #include "c7100/FFTLIB_defines.h"
44 #include "c7100/FFTLIB_types.h"
45 
49 #if !defined(FFTLIB_DEBUGPRINT)
50 #define FFTLIB_DEBUGPRINT 0
51 #endif
52 
53 #if (defined(_HOST_BUILD) && (FFTLIB_COMPILER_VERSION < 1003999))
54 #define FFTLIB_const
55 #else
56 #define FFTLIB_const const
57 #endif
58 
59 #define __PRAGMA(x) _Pragma(#x)
60 #ifdef __cplusplus
61 # define __INLINE_FUNC(x) __PRAGMA(FUNC_ALWAYS_INLINE)
62 #else
63 # define __INLINE_FUNC(x) __PRAGMA(FUNC_ALWAYS_INLINE(x))
64 #endif
65 
66 /* ---------------------------------------------------------------- */
67 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The following two */
68 /* function-like macros do not have equivalent function */
69 /* implementations. */
70 /* ---------------------------------------------------------------- */
71 #if defined(EVM_TEST)
72 #define FFTLIB_PRINTF(fmt,...) \
73  do { \
74  fprintf(stdout, fmt, __VA_ARGS__); \
75  } while (0)
76 
77 #if FFTLIB_DEBUGPRINT > 0
78 #define FFTLIB_DEBUGPRINTFN(N, fmt, ...) \
79  do { \
80  if (FFTLIB_DEBUGPRINT >= (N)) { \
81  fprintf(stdout, "FFTLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, \
82  __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__, \
98  __VA_ARGS__); \
99  } \
100 
101 #define FFTLIB_PRINTF(fmt, ...) \
102  fprintf(stderr, fmt, __VA_ARGS__)
103 
104 #else // FFTLIB_DEBUGPRINT == 0
105 
106 #define FFTLIB_DEBUGPRINTFN(N, fmt, ...)
107 #define FFTLIB_PRINTF(fmt, ...)
108 
109 #endif // #if FFTLIB_DEBUGPRINT
110 #endif // #if defined(EVM_TEST)
111 
112 #if defined(FFTLIB_MESSAGES)
113 // if enabled, display messages to the library user
114 // FFTLIB_MESSAGES should only be defined when TARGET_BUILD=debug or CHECKPARAMS=1
115 #define FFTLIB_MESG(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
116 #else
117 #define FFTLIB_MESG(fmt, ...)
118 #endif //#if defined(FFTLIB_MESSAGES)
119 
120 /* Original implementation that had the benefit of always being compiled and thus
121  receiving error checking. However, the fprintf generates a MISRA-C violation.
122 #define FFTLIB_DEBUGPRINTFN(N, fmt, ...) \
123  do { \
124  if (FFTLIB_DEBUGPRINT >= (N)) { \
125  fprintf(stderr, "FFTLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, \
126  __VA_ARGS__); \
127  } \
128  } while (0)
129 
130 #define FFTLIB_PRINTF(fmt, ...) \
131  do { \
132  fprintf(stderr, fmt, __VA_ARGS__); \
133  } while (0)
134 #endif
135  */
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 
144 #ifdef __cplusplus
145 #include <c7x_scalable.h> // for device scalability
146 
147 extern const c7x::uchar_vec FFTLIB_zeroVect_uchar_vec;
148 extern const c7x::ushort_vec FFTLIB_zeroVect_ushort_vec;
149 extern const c7x::uchar_vec FFTLIB_vperm_data_0_63;
150 
151 extern "C" {
152 #endif /* __cplusplus */
153 
161 /* @{ */
162 
163 /*******************************************************************************
164  *
165  * TYPEDEFS
166  *
167  ******************************************************************************/
168 
169 typedef double FFTLIB_D64;
170 typedef float FFTLIB_F32;
171 
173 typedef enum {
188 
189  // FFTLIB_LINALG_matrixMatrixMultiply
193  // FFTLIB_LINALG_matrixMatrixMultiplyAccumulate
197  // FFTLIB_LINALG_matrixTranspose
201  // FFTLIB_LINALG_pointwiseMatrixMatrixMultiply
206 
208 
209 typedef void *FFTLIB_kernelHandle;
210 
212 typedef enum {
218 
219 /*******************************************************************************
220  *
221  * DEFINES
222  *
223  ******************************************************************************/
224 
225 #define FFTLIB_PARAM_SIZE 128
226 //#define FFTLIB_BYTE_WIDTH 64
227 #define FFTLIB_MMA_ACCUMULATOR_BYTE_WIDTH_8_BIT 4
228 #define FFTLIB_MMA_ACCUMULATOR_BYTE_WIDTH_16_BIT 8
229 #define FFTLIB_MMA_ACCUMULATOR_BYTE_WIDTH_32_BIT 16
230 
231 
232 /*******************************************************************************
233  *
234  * Macros
235  *
236  ******************************************************************************/
237 
238 #define FFTLIB_ALIGN_SHIFT_64BYTES \
239  6
240 #define FFTLIB_ALIGN_SHIFT_128BYTES \
241  7
242 #define FFTLIB_ALIGN_SHIFT_256BYTES \
243  8
244 
245 #define FFTLIB_ALIGN_64BYTES \
246  (1 << FFTLIB_ALIGN_SHIFT_64BYTES)
247 #define FFTLIB_ALIGN_128BYTES \
248  (1 << FFTLIB_ALIGN_SHIFT_128BYTES)
249 #define FFTLIB_ALIGN_256BYTES \
250  (1 << FFTLIB_ALIGN_SHIFT_256BYTES)
251 
252 #define FFTLIB_L2DATA_ALIGN_SHIFT \
253  FFTLIB_ALIGN_SHIFT_64BYTES
254 
255 
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 /* ---------------------------------------------------------------- */
305 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
306 /* being addressed */
307 /* ---------------------------------------------------------------- */
308 // remove asm comments for Loki testing as they may add cycles
309 #if defined(QT_TEST) || defined(RTL_TEST) || defined(EVM_TEST)
310  #if defined(_HOST_BUILD)
311  #define FFTLIB_asm(string) ;
312  #else
313  #define FFTLIB_asm(string); asm(string);
314  #endif // _HOST_BUILD
315 #else
316  #define FFTLIB_asm(string) ;
317 #endif
318 
319 /* ---------------------------------------------------------------- */
320 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
321 /* being addressed so as not to lose portability across different */
322 /* platforms. */
323 /* ---------------------------------------------------------------- */
324 // cl7x unroll attributes not recognized by gcc/gpp compiler and generate
325 // warnings. Remove them with macro
326 #if defined(_HOST_BUILD)
327 #define str(x) #x
328 #define xstr(x) str(x)
329 #ifdef WIN32
330 #define __attribute__()
331 #define FFTLIB_UNROLL(count)
332 #else
333 #define FFTLIB_UNROLL(count) _Pragma(str(UNROLL(count)))
334 #endif
335 #else
336 #define FFTLIB_UNROLL(COUNT) [[TI::unroll(COUNT)]]
337 #endif
338 
339 #if defined(_HOST_BUILD)
340 #ifdef WIN32
341 #define __attribute__()
342 #define FFTLIB_MUST_ITERATE(initial, max, multiple)
343 #else
344 #define FFTLIB_MUST_ITERATE(initial, max, multiple) _Pragma(str(MUST_ITERATE(initial, max, multiple)))
345 #endif
346 #else
347 #define FFTLIB_MUST_ITERATE(INTIAL, MAX, MULTIPLE) [[TI::must_iterate(INTIAL, MAX, MULTIPLE)]]
348 #endif
349 
350 #ifndef FFTLIB_NUMBER_RANDOM_DIM_TESTS
351 #define FFTLIB_NUMBER_RANDOM_DIM_TESTS 25
352 #endif
353 
354 #if defined(PERFORMANCE_TEST)
355 #define FFTLIB_PERFORMANCE_TEST_PATTERN SEQUENTIAL
356 #else
357 #define FFTLIB_PERFORMANCE_TEST_PATTERN RANDOM_SIGNED
358 #endif
359 
360 #define FFTLIB_TEST_OUTPUT_HEAP 0
361 #if defined(_HOST_BUILD)
362  // Valgrind works better when output is in the heap (it can't track statically allocated memory), so
363  // in host emulation mode, place test outputs in the heap rather than statically allocated MSMC
364  #define FFTLIB_TEST_OUTPUT_MSMC FFTLIB_TEST_OUTPUT_HEAP
365 #else
366  #define FFTLIB_TEST_OUTPUT_MSMC 1
367 #endif
368 
369 #define STRIDE_OPT_4CYCLE 1
370 
371 /*******************************************************************************
372  *
373  * MACROS
374  *
375  ******************************************************************************/
376 
377 /* ---------------------------------------------------------------- */
378 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The following */
379 /* function-like macros are intended to be used across different */
380 /* data types. */
381 /* ---------------------------------------------------------------- */
382 #define FFTLIB_min(x, y) \
383  (((x) < (y)) ? (x) : (y))
384 #define FFTLIB_max(x, y) \
385  (((x) < (y)) ? (y) : (x))
386 #define FFTLIB_ceilingDiv(x, y) \
387  (((x) + (y)-1) / \
388  (y))
391 /******************************************************************************
392  *
393  * COMMON MMA CONIFGURATIONS
394  *
395  ******************************************************************************/
396 
397  extern const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i32s_i32s_o32s;
398 
399  extern const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i16s_i16s_o16s;
400  extern const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i16s_i16s_o16u;
401  extern const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i16u_i16s_o16s;
402  extern const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i16u_i16s_o16u;
403 
404  extern const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i8s_i8s_o8s;
405  extern const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i8s_i8s_o8u;
406  extern const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i8u_i8s_o8s;
407  extern const FFTLIB_MMA_CONFIG_REG configRegisterStruct_i8u_i8s_o8u;
408 
409  extern const __HWA_OFFSET_REG offsetRegStruct_zeros;
410  extern const __HWA_OFFSET_REG offsetRegStruct_diagonal_32bit;
411  extern const __HWA_OFFSET_REG offsetRegStruct_diagonal_16bit;
412  extern const __HWA_OFFSET_REG offsetRegStruct_diagonal_8bit;
413 
414 
415 /* @} */
418 #ifdef __cplusplus
419 }
420 #endif /* __cplusplus */
421 #endif /* COMMON_FFTLIB_TYPES_H_ */
422 
423 /* ======================================================================== */
424 /* End of file: FFTLIB_types.h */
425 /* ======================================================================== */
FFTLIB_STATUS_NAME
The enumeration of all status codes.
Definition: FFTLIB_types.h:173
FFTLIB_FUNCTION_STYLE
Enumeration for the style of function implementation.
Definition: FFTLIB_types.h:212
void * FFTLIB_kernelHandle
Handle type for FFTLIB operations.
Definition: FFTLIB_types.h:209
float FFTLIB_F32
Single precision floating point.
Definition: FFTLIB_types.h:170
FFTLIB_STATUS_NAME FFTLIB_STATUS
Return value for FFTLIB functions.
Definition: FFTLIB_types.h:207
double FFTLIB_D64
Double precision floating point.
Definition: FFTLIB_types.h:169