DSPLIB User Guide
DSPLIB_types.h
Go to the documentation of this file.
1 /******************************************************************************
2  * *
3  * module name :DSPLIB *
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 
12 #ifndef COMMON_DSPLIB_TYPES_H_
13 #define COMMON_DSPLIB_TYPES_H_ 1
14 
15 /* This header is needed to be included in OpenCL programs which link
16  * against DSPLIB, but OpenCL doesn't need the following headers */
17 #ifndef __OPENCL_VERSION__
18 #include <inttypes.h>
19 #include <stddef.h> // for NULL
20 #include <stdint.h>
21 #include <stdio.h> // for printf
22 #include <stdlib.h>
23 #endif
24 #include <c7x.h> // for streaming engine, streaming address gen.
25 
26 #include "DSPLIB_bufParams.h"
27 #include "TI_platforms.h"
28 
32 #if !defined(DSPLIB_DEBUGPRINT)
33 #define DSPLIB_DEBUGPRINT 0
34 #endif
35 
36 #if (defined(_HOST_BUILD) && (DSPLIB_COMPILER_VERSION < 1003999))
37 #define DSPLIB_const
38 #else
39 #define DSPLIB_const const
40 #endif
41 
42 #define __PRAGMA(x) _Pragma(#x)
43 #ifdef __cplusplus
44 #define __INLINE_FUNC(x) __PRAGMA(FUNC_ALWAYS_INLINE)
45 #else
46 #define __INLINE_FUNC(x) __PRAGMA(FUNC_ALWAYS_INLINE(x))
47 #endif
48 
49 /* ---------------------------------------------------------------- */
50 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The following two */
51 /* function-like macros do not have equivalent function */
52 /* implementations. */
53 /* ---------------------------------------------------------------- */
54 #if defined(EVM_TEST)
55 #define DSPLIB_PRINTF(fmt, ...) fprintf(stdout, fmt, __VA_ARGS__);
56 
57 #if DSPLIB_DEBUGPRINT > 0
58 #define DSPLIB_DEBUGPRINTFN(N, fmt, ...) \
59  do { \
60  if (DSPLIB_DEBUGPRINT >= (N)) { \
61  fprintf(stdout, "DSPLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, __VA_ARGS__); \
62  } \
63  } while (0)
64 
65 #else // DSPLIB_DEBUGPRINT == 0
66 
67 #define DSPLIB_DEBUGPRINTFN(N, fmt, ...)
68 //#define DSPLIB_PRINTF(fmt, ...)
69 #endif // #if DSPLIB_DEBUGPRINT
70 
71 #else
72 
73 #if DSPLIB_DEBUGPRINT > 0
74 #define DSPLIB_DEBUGPRINTFN(N, fmt, ...) \
75  if (DSPLIB_DEBUGPRINT >= (N)) { \
76  fprintf(stdout, "DSPLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, __VA_ARGS__); \
77  }
78 
79 #define DSPLIB_PRINTF(fmt, ...) fprintf(stdout, fmt, __VA_ARGS__)
80 
81 #else // DSPLIB_DEBUGPRINT == 0
82 
83 #define DSPLIB_DEBUGPRINTFN(N, fmt, ...)
84 #define DSPLIB_PRINTF(fmt, ...)
85 
86 #endif // #if DSPLIB_DEBUGPRINT
87 #endif // #if defined(EVM_TEST)
88 
89 #if defined(DSPLIB_MESSAGES)
90 // if enabled, display messages to the library user
91 // DSPLIB_MESSAGES should only be defined when TARGET_BUILD=debug or
92 // CHECKPARAMS=1
93 #define DSPLIB_MESG(fmt, ...) fprintf(stdout, fmt, __VA_ARGS__)
94 #else
95 #define DSPLIB_MESG(fmt, ...)
96 #endif //#if defined(DSPLIB_MESSAGES)
97 
98 /* Original implementation that had the benefit of always being compiled and
99 thus receiving error checking. However, the fprintf generates a MISRA-C
100 violation.
101 #define DSPLIB_DEBUGPRINTFN(N, fmt, ...) \
102  do { \
103  if (DSPLIB_DEBUGPRINT >= (N)) { \
104  fprintf(stdout, "DSPLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, \
105  __VA_ARGS__); \
106  } \
107  } while (0)
108 
109 #define DSPLIB_PRINTF(fmt, ...) \
110  do { \
111  fprintf(stdout, fmt, __VA_ARGS__); \
112  } while (0)
113 #endif
114  */
115 
116 #define DSPLIB_SOFT_MMA_RESET 0
117 
118 // switch to enable or disable static inline for DSPLIB functions defined in .c
119 // files (so not many functions)
120 #define DSPLIB_STATIC_INLINE static inline
121 
122 #ifdef __cplusplus
123 #include <c7x_scalable.h> // for device scalability
124 
125 extern const c7x::uchar_vec DSPLIB_zeroVect_uchar_vec;
126 extern const c7x::ushort_vec DSPLIB_zeroVect_ushort_vec;
127 extern const c7x::uchar_vec DSPLIB_vperm_data_0_63;
128 
129 extern "C" {
130 #endif /* __cplusplus */
131 
141 /*******************************************************************************
142  *
143  * TYPEDEFS
144  *
145  ******************************************************************************/
146 
147 typedef double DSPLIB_D64;
148 typedef float DSPLIB_F32;
149 
151 typedef enum {
167 
169 
171 
172 typedef void *DSPLIB_kernelHandle;
173 
175 typedef enum {
179  DSPLIB_FUNCTION_MAX = 128
181 
182 /*******************************************************************************
183  *
184  * DEFINES
185  *
186  ******************************************************************************/
187 
188 #define DSPLIB_PARAM_SIZE 128
189 
190 /*******************************************************************************
191  *
192  * Macros
193  *
194  ******************************************************************************/
195 
196 #define DSPLIB_ALIGN_SHIFT_64BYTES 6
197 #define DSPLIB_ALIGN_SHIFT_128BYTES 7
198 #define DSPLIB_ALIGN_SHIFT_256BYTES 8
199 
200 #define DSPLIB_ALIGN_64BYTES (1 << DSPLIB_ALIGN_SHIFT_64BYTES)
201 #define DSPLIB_ALIGN_128BYTES (1 << DSPLIB_ALIGN_SHIFT_128BYTES)
202 #define DSPLIB_ALIGN_256BYTES (1 << DSPLIB_ALIGN_SHIFT_256BYTES)
203 
204 #define DSPLIB_L2DATA_ALIGN_SHIFT DSPLIB_ALIGN_SHIFT_64BYTES
205 
208 #define DSPLIB_L2DATA_ALIGNMENT (((uint32_t) 1) << ((uint32_t) DSPLIB_L2DATA_ALIGN_SHIFT))
209 
210 /* ---------------------------------------------------------------- */
211 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
212 /* being addressed */
213 /* ---------------------------------------------------------------- */
214 
215 /* @} */
216 
217 /******************************************************************************
218  *
219  * Do not document these in the User Guide
220  ******************************************************************************/
221 
227 /* ---------------------------------------------------------------- */
228 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
229 /* being addressed */
230 /* ---------------------------------------------------------------- */
231 // remove asm comments for Loki testing as they may add cycles
232 #if defined(QT_TEST) || defined(RTL_TEST) || defined(EVM_TEST)
233 #if defined(_HOST_BUILD)
234 #define DSPLIB_asm(string) ;
235 #else
236 #define DSPLIB_asm(string) \
237  ; \
238  asm(string);
239 #endif // _HOST_BUILD
240 #else
241 #define DSPLIB_asm(string) ;
242 #endif
243 
244 /* ---------------------------------------------------------------- */
245 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
246 /* being addressed so as not to lose portability across different */
247 /* platforms. */
248 /* ---------------------------------------------------------------- */
249 // cl7x unroll attributes not recognized by gcc/gpp compiler and generate
250 // warnings. Remove them with macro
251 #if defined(_HOST_BUILD)
252 #define str(x) #x
253 #define xstr(x) str(x)
254 #ifdef WIN32
255 #define __attribute__()
256 #define DSPLIB_UNROLL(count)
257 #else
258 #define DSPLIB_UNROLL(count) _Pragma(str(UNROLL(count)))
259 #endif
260 #else
261 #define DSPLIB_UNROLL(COUNT) [[TI::unroll(COUNT)]]
262 #endif
263 
264 #if defined(_HOST_BUILD)
265 #ifdef WIN32
266 #define __attribute__()
267 #define DSPLIB_MUST_ITERATE(initial, max, multiple)
268 #else
269 #define DSPLIB_MUST_ITERATE(initial, max, multiple) _Pragma(str(MUST_ITERATE(initial, max, multiple)))
270 #endif
271 #else
272 #define DSPLIB_MUST_ITERATE(INTIAL, MAX, MULTIPLE) [[TI::must_iterate(INTIAL, MAX, MULTIPLE)]]
273 #endif
274 
275 #ifndef DSPLIB_NUMBER_RANDOM_DIM_TESTS
276 #define DSPLIB_NUMBER_RANDOM_DIM_TESTS 25
277 #endif
278 
279 #if defined(PERFORMANCE_TEST)
280 #define DSPLIB_PERFORMANCE_TEST_PATTERN SEQUENTIAL
281 #else
282 #define DSPLIB_PERFORMANCE_TEST_PATTERN RANDOM_SIGNED
283 #endif
284 
285 #define DSPLIB_TEST_OUTPUT_HEAP 0
286 #if defined(_HOST_BUILD)
287 // Valgrind works better when output is in the heap (it can't track statically
288 // allocated memory), so in host emulation mode, place test outputs in the heap
289 // rather than statically allocated MSMC
290 #define DSPLIB_TEST_OUTPUT_MSMC DSPLIB_TEST_OUTPUT_HEAP
291 #else
292 #define DSPLIB_TEST_OUTPUT_MSMC 1
293 #endif
294 
295 #define STRIDE_OPT_4CYCLE 1
296 
297 /* ---------------------------------------------------------------- */
298 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
299 /* being addressed */
300 /* ---------------------------------------------------------------- */
301 
302 #define DSPLIB_BYTE_WIDTH 32
303 #define DSPLIB_CALC_STRIDE(BYTES, ALIGN_SHIFT) (((((BYTES) -1) >> (ALIGN_SHIFT)) + 1) << (ALIGN_SHIFT))
304 
305 /*******************************************************************************
306  *
307  * MACROS
308  *
309  ******************************************************************************/
310 
311 /* ---------------------------------------------------------------- */
312 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The following */
313 /* function-like macros are intended to be used across different */
314 /* data types. */
315 /* ---------------------------------------------------------------- */
316 #define DSPLIB_min(x, y) (((x) < (y)) ? (x) : (y))
317 #define DSPLIB_max(x, y) (((x) < (y)) ? (y) : (x))
318 #define DSPLIB_ceilingDiv(x, y) \
319  (((x) + (y) -1) / (y))
324 #ifdef __cplusplus
325 }
326 #endif /* __cplusplus */
327 #endif /* COMMON_DSPLIB_TYPES_H_ */
328 
329 /* ======================================================================== */
330 /* End of file: DSPLIB_types.h */
331 /* ======================================================================== */
DSPLIB_FUNCTION_STYLE
Enumeration for the style of function implementation.
Definition: DSPLIB_types.h:175
DSPLIB_STATUS_NAME DSPLIB_STATUS
Return value for DSPLIB functions.
Definition: DSPLIB_types.h:170
double DSPLIB_D64
Double precision floating point.
Definition: DSPLIB_types.h:147
DSPLIB_STATUS_NAME
The enumeration of all status codes.
Definition: DSPLIB_types.h:151
float DSPLIB_F32
Single precision floating point.
Definition: DSPLIB_types.h:148
void * DSPLIB_kernelHandle
Handle type for DSPLIB operations.
Definition: DSPLIB_types.h:172
@ DSPLIB_FUNCTION_MAX
Definition: DSPLIB_types.h:179
@ DSPLIB_FUNCTION_OPTIMIZED
Definition: DSPLIB_types.h:177
@ DSPLIB_FUNCTION_NATC
Definition: DSPLIB_types.h:176
@ DSPLIB_ERR_INVALID_ACTIVATION
Definition: DSPLIB_types.h:164
@ DSPLIB_ERR_INVALID_SHIFT
Definition: DSPLIB_types.h:165
@ DSPLIB_ERR_BUFFER_TOO_SMALL
Definition: DSPLIB_types.h:163
@ DSPLIB_ERR_INVALID_VALUE
Definition: DSPLIB_types.h:154
@ DSPLIB_ERR_NOT_EQUAL_WIDTH_STRIDE
Definition: DSPLIB_types.h:159
@ DSPLIB_ERR_INVALID_DIMENSION
Definition: DSPLIB_types.h:156
@ DSPLIB_ERROR_MAX
Definition: DSPLIB_types.h:166
@ DSPLIB_SUCCESS
Definition: DSPLIB_types.h:152
@ DSPLIB_ERR_NULL_POINTER
Definition: DSPLIB_types.h:157
@ DSPLIB_ERR_NOT_IMPLEMENTED
Definition: DSPLIB_types.h:158
@ DSPLIB_ERR_FAILURE
Definition: DSPLIB_types.h:153
@ DSPLIB_ERR_INVALID_TYPE
Definition: DSPLIB_types.h:155
@ DSPLIB_ERR_NOT_ALIGNED_PTRS_STRIDES
Definition: DSPLIB_types.h:160
@ DSPLIB_ERR_NOT_ALIGNED_WIDTHS
Definition: DSPLIB_types.h:162