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 - http://www.ti.com/ *
8  * ALL RIGHTS RESERVED *
9  * *
10  ******************************************************************************/
11 
23 #ifndef COMMON_DSPLIB_TYPES_H_
24 #define COMMON_DSPLIB_TYPES_H_ 1
25 
26 /* This header is needed to be included in OpenCL programs which link
27  * against DSPLIB, 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 "DSPLIB_bufParams.h"
39 #include "TI_platforms.h"
40 
41 #include "c71/DSPLIB_defines.h"
42 
43 #include "c7100/DSPLIB_defines.h"
44 #include "c7100/DSPLIB_types.h"
45 
49 #if !defined(DSPLIB_DEBUGPRINT)
50 #define DSPLIB_DEBUGPRINT 0
51 #endif
52 
53 #if (defined(_HOST_BUILD) && (DSPLIB_COMPILER_VERSION < 1003999))
54 #define DSPLIB_const
55 #else
56 #define DSPLIB_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 DSPLIB_PRINTF(fmt,...) \
73  do { \
74  fprintf(stdout, fmt, __VA_ARGS__); \
75  } while (0)
76 
77 #if DSPLIB_DEBUGPRINT > 0
78 #define DSPLIB_DEBUGPRINTFN(N, fmt, ...) \
79  do { \
80  if (DSPLIB_DEBUGPRINT >= (N)) { \
81  fprintf(stdout, "DSPLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, \
82  __VA_ARGS__); \
83  } \
84  } while (0)
85 
86 #else // DSPLIB_DEBUGPRINT == 0
87 
88 #define DSPLIB_DEBUGPRINTFN(N, fmt, ...)
89 //#define DSPLIB_PRINTF(fmt, ...)
90 #endif // #if DSPLIB_DEBUGPRINT
91 
92 #else
93 
94 #if DSPLIB_DEBUGPRINT > 0
95 #define DSPLIB_DEBUGPRINTFN(N, fmt, ...) \
96  if (DSPLIB_DEBUGPRINT >= (N)) { \
97  fprintf(stderr, "DSPLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, \
98  __VA_ARGS__); \
99  } \
100 
101 #define DSPLIB_PRINTF(fmt, ...) \
102  fprintf(stderr, fmt, __VA_ARGS__)
103 
104 #else // DSPLIB_DEBUGPRINT == 0
105 
106 #define DSPLIB_DEBUGPRINTFN(N, fmt, ...)
107 #define DSPLIB_PRINTF(fmt, ...)
108 
109 #endif // #if DSPLIB_DEBUGPRINT
110 #endif // #if defined(EVM_TEST)
111 
112 #if defined(DSPLIB_MESSAGES)
113 // if enabled, display messages to the library user
114 // DSPLIB_MESSAGES should only be defined when TARGET_BUILD=debug or CHECKPARAMS=1
115 #define DSPLIB_MESG(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
116 #else
117 #define DSPLIB_MESG(fmt, ...)
118 #endif //#if defined(DSPLIB_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 DSPLIB_DEBUGPRINTFN(N, fmt, ...) \
123  do { \
124  if (DSPLIB_DEBUGPRINT >= (N)) { \
125  fprintf(stderr, "DSPLIB debug %s - %d: " fmt, __FUNCTION__, __LINE__, \
126  __VA_ARGS__); \
127  } \
128  } while (0)
129 
130 #define DSPLIB_PRINTF(fmt, ...) \
131  do { \
132  fprintf(stderr, fmt, __VA_ARGS__); \
133  } while (0)
134 #endif
135  */
136 
137 
138 #define DSPLIB_SOFT_MMA_RESET 0
139 
140 // switch to enable or disable static inline for DSPLIB functions defined in .c files (so not many functions)
141 #define DSPLIB_STATIC_INLINE static inline
142 
143 
144 #ifdef __cplusplus
145 #include <c7x_scalable.h> // for device scalability
146 
147 extern const c7x::uchar_vec DSPLIB_zeroVect_uchar_vec;
148 extern const c7x::ushort_vec DSPLIB_zeroVect_ushort_vec;
149 extern const c7x::uchar_vec DSPLIB_vperm_data_0_63;
150 
151 extern "C" {
152 #endif /* __cplusplus */
153 
161 /* @{ */
162 
163 /*******************************************************************************
164  *
165  * TYPEDEFS
166  *
167  ******************************************************************************/
168 
169 typedef double DSPLIB_D64;
170 typedef float DSPLIB_F32;
171 
173 typedef enum {
188  // DSPLIB_CNN_convolve_row
203  // DSPLIB_CNN_convolve_col_smallNo
219  // DSPLIB_CNN_deconvolve_row
229  // DSPLIB_CNN_fullyConnected
234  // DSPLIB_CNN_pixelShuffle_row
247  // DSPLIB_CNN_tensor_convert_ixX_oxX
256  // DSPLIB_LINALG_matrixMatrixMultiply
260  // DSPLIB_LINALG_matrixMatrixMultiplyAccumulate
264  // DSPLIB_LINALG_matrixTranspose
268  // DSPLIB_LINALG_pointwiseMatrixMatrixMultiply
273 
275 
276 typedef void *DSPLIB_kernelHandle;
277 
279 typedef enum {
285 
288 typedef enum {
293 } DSPLIB_buffer_mode_e; // formerly eMMABufferMode;
294 
296 typedef enum {
300 
301  typedef DSPLIB_tensor_format_e DSPLIB_tensor_format;
302 
303 /*******************************************************************************
304  *
305  * DEFINES
306  *
307  ******************************************************************************/
308 
309 #define DSPLIB_PARAM_SIZE 128
310 //#define DSPLIB_BYTE_WIDTH 64
311 #define DSPLIB_MMA_ACCUMULATOR_BYTE_WIDTH_8_BIT 4
312 #define DSPLIB_MMA_ACCUMULATOR_BYTE_WIDTH_16_BIT 8
313 #define DSPLIB_MMA_ACCUMULATOR_BYTE_WIDTH_32_BIT 16
314 
315 
316 /*******************************************************************************
317  *
318  * Macros
319  *
320  ******************************************************************************/
321 
322 #define DSPLIB_ALIGN_SHIFT_64BYTES \
323  6
324 #define DSPLIB_ALIGN_SHIFT_128BYTES \
325  7
326 #define DSPLIB_ALIGN_SHIFT_256BYTES \
327  8
328 
329 #define DSPLIB_ALIGN_64BYTES \
330  (1 << DSPLIB_ALIGN_SHIFT_64BYTES)
331 #define DSPLIB_ALIGN_128BYTES \
332  (1 << DSPLIB_ALIGN_SHIFT_128BYTES)
333 #define DSPLIB_ALIGN_256BYTES \
334  (1 << DSPLIB_ALIGN_SHIFT_256BYTES)
335 
336 #define DSPLIB_L2DATA_ALIGN_SHIFT \
337  DSPLIB_ALIGN_SHIFT_64BYTES
338 
339 
341 #define DSPLIB_L2DATA_ALIGNMENT (((uint32_t)1) << ((uint32_t)DSPLIB_L2DATA_ALIGN_SHIFT))
342 
343 /* ---------------------------------------------------------------- */
344 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
345 /* being addressed */
346 /* ---------------------------------------------------------------- */
349 /* #define DSPLIB_CALC_STRIDE(BYTES, ALIGN_SHIFT) \ */
350 /* (((((BYTES)-1) >> (ALIGN_SHIFT)) + 1) << (ALIGN_SHIFT)) */
351 
352 /* /\*! @brief Macro for DSPLIB shift amounts *\/ */
353 /* #define DSPLIB_MMA_SIZE_8_BIT_SHIFT \ */
354 /* 6 //!< Shift for MMA size when data type is 8-bit integers */
355 /* #define DSPLIB_MMA_SIZE_16_BIT_SHIFT \ */
356 /* 5 //!< Shift for MMA size when data type is 16-bit integers */
357 /* #define DSPLIB_MMA_SIZE_32_BIT_SHIFT \ */
358 /* 4 //!< Shift for MMA size when data type is 32-bit integers */
359 
360 /* /\*! @brief MMA size as a function of precision *\/ */
361 /* //#define DSPLIB_MMA_SIZE_1_BYTE 1 */
362 /* #define DSPLIB_MMA_SIZE_8_BIT \ */
363 /* ((uint32_t)(((uint32_t)1) \ */
364 /* << DSPLIB_MMA_SIZE_8_BIT_SHIFT)) //!< Shift for MMA size when data */
365 /* //!< type is 8-bit integers */
366 /* #define DSPLIB_MMA_SIZE_16_BIT \ */
367 /* ((uint32_t)(((uint32_t)1) \ */
368 /* << DSPLIB_MMA_SIZE_16_BIT_SHIFT)) //!< Shift for MMA size when data */
369 /* //!< type is 16-bit integers */
370 /* #define DSPLIB_MMA_SIZE_32_BIT \ */
371 /* ((int32_t)(((uint32_t)1) \ */
372 /* << DSPLIB_MMA_SIZE_32_BIT_SHIFT)) //!< Shift for MMA size when data */
373 /* //!< type is 32-bit integers */
374 
375 /* @} */
376 
377 /******************************************************************************
378  *
379  * Do not document these in the User Guide
380  ******************************************************************************/
381 
385 /* @{ */
386 
387 
388 /* ---------------------------------------------------------------- */
389 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
390 /* being addressed */
391 /* ---------------------------------------------------------------- */
392 // remove asm comments for Loki testing as they may add cycles
393 #if defined(QT_TEST) || defined(RTL_TEST) || defined(EVM_TEST)
394  #if defined(_HOST_BUILD)
395  #define DSPLIB_asm(string) ;
396  #else
397  #define DSPLIB_asm(string); asm(string);
398  #endif // _HOST_BUILD
399 #else
400  #define DSPLIB_asm(string) ;
401 #endif
402 
403 /* ---------------------------------------------------------------- */
404 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The advisory is not */
405 /* being addressed so as not to lose portability across different */
406 /* platforms. */
407 /* ---------------------------------------------------------------- */
408 // cl7x unroll attributes not recognized by gcc/gpp compiler and generate
409 // warnings. Remove them with macro
410 #if defined(_HOST_BUILD)
411 #define str(x) #x
412 #define xstr(x) str(x)
413 #ifdef WIN32
414 #define __attribute__()
415 #define DSPLIB_UNROLL(count)
416 #else
417 #define DSPLIB_UNROLL(count) _Pragma(str(UNROLL(count)))
418 #endif
419 #else
420 #define DSPLIB_UNROLL(COUNT) [[TI::unroll(COUNT)]]
421 #endif
422 
423 #if defined(_HOST_BUILD)
424 #ifdef WIN32
425 #define __attribute__()
426 #define DSPLIB_MUST_ITERATE(initial, max, multiple)
427 #else
428 #define DSPLIB_MUST_ITERATE(initial, max, multiple) _Pragma(str(MUST_ITERATE(initial, max, multiple)))
429 #endif
430 #else
431 #define DSPLIB_MUST_ITERATE(INTIAL, MAX, MULTIPLE) [[TI::must_iterate(INTIAL, MAX, MULTIPLE)]]
432 #endif
433 
434 #ifndef DSPLIB_NUMBER_RANDOM_DIM_TESTS
435 #define DSPLIB_NUMBER_RANDOM_DIM_TESTS 25
436 #endif
437 
438 #if defined(PERFORMANCE_TEST)
439 #define DSPLIB_PERFORMANCE_TEST_PATTERN SEQUENTIAL
440 #else
441 #define DSPLIB_PERFORMANCE_TEST_PATTERN RANDOM_SIGNED
442 #endif
443 
444 #define DSPLIB_TEST_OUTPUT_HEAP 0
445 #if defined(_HOST_BUILD)
446  // Valgrind works better when output is in the heap (it can't track statically allocated memory), so
447  // in host emulation mode, place test outputs in the heap rather than statically allocated MSMC
448  #define DSPLIB_TEST_OUTPUT_MSMC DSPLIB_TEST_OUTPUT_HEAP
449 #else
450  #define DSPLIB_TEST_OUTPUT_MSMC 1
451 #endif
452 
453 #define STRIDE_OPT_4CYCLE 1
454 
455 /*******************************************************************************
456  *
457  * MACROS
458  *
459  ******************************************************************************/
460 
461 /* ---------------------------------------------------------------- */
462 /* MISRAC Rule 4.9(DEFINE.FUNC) Deviation: The following */
463 /* function-like macros are intended to be used across different */
464 /* data types. */
465 /* ---------------------------------------------------------------- */
466 #define DSPLIB_min(x, y) \
467  (((x) < (y)) ? (x) : (y))
468 #define DSPLIB_max(x, y) \
469  (((x) < (y)) ? (y) : (x))
470 #define DSPLIB_ceilingDiv(x, y) \
471  (((x) + (y)-1) / \
472  (y))
475 /******************************************************************************
476  *
477  * COMMON MMA CONIFGURATIONS
478  *
479  ******************************************************************************/
480 
481  extern const DSPLIB_MMA_CONFIG_REG configRegisterStruct_i32s_i32s_o32s;
482 
483  extern const DSPLIB_MMA_CONFIG_REG configRegisterStruct_i16s_i16s_o16s;
484  extern const DSPLIB_MMA_CONFIG_REG configRegisterStruct_i16s_i16s_o16u;
485  extern const DSPLIB_MMA_CONFIG_REG configRegisterStruct_i16u_i16s_o16s;
486  extern const DSPLIB_MMA_CONFIG_REG configRegisterStruct_i16u_i16s_o16u;
487 
488  extern const DSPLIB_MMA_CONFIG_REG configRegisterStruct_i8s_i8s_o8s;
489  extern const DSPLIB_MMA_CONFIG_REG configRegisterStruct_i8s_i8s_o8u;
490  extern const DSPLIB_MMA_CONFIG_REG configRegisterStruct_i8u_i8s_o8s;
491  extern const DSPLIB_MMA_CONFIG_REG configRegisterStruct_i8u_i8s_o8u;
492 
493  extern const __HWA_OFFSET_REG offsetRegStruct_zeros;
494  extern const __HWA_OFFSET_REG offsetRegStruct_diagonal_32bit;
495  extern const __HWA_OFFSET_REG offsetRegStruct_diagonal_16bit;
496  extern const __HWA_OFFSET_REG offsetRegStruct_diagonal_8bit;
497 
498 
499 /* @} */
502 #ifdef __cplusplus
503 }
504 #endif /* __cplusplus */
505 #endif /* COMMON_DSPLIB_TYPES_H_ */
506 
507 /* ======================================================================== */
508 /* End of file: DSPLIB_types.h */
509 /* ======================================================================== */
DSPLIB_STATUS_NAME
The enumeration of all status codes.
Definition: DSPLIB_types.h:173
DSPLIB_buffer_mode_e
Buffer structure for input feature maps and coefficients of DSPLIB_CNN_convolve_row_ixX_ixX_oxX.
Definition: DSPLIB_types.h:288
Used when tensor is in NCHW format.
Definition: DSPLIB_types.h:297
Linear buffer.
Definition: DSPLIB_types.h:289
Circular buffer for coefficients.
Definition: DSPLIB_types.h:292
void * DSPLIB_kernelHandle
Handle type for DSPLIB operations.
Definition: DSPLIB_types.h:276
DSPLIB_FUNCTION_STYLE
Enumeration for the style of function implementation.
Definition: DSPLIB_types.h:279
DSPLIB_tensor_format_e
Tensor format.
Definition: DSPLIB_types.h:296
DSPLIB_tensor_format_e DSPLIB_tensor_format
Definition: DSPLIB_types.h:301
float DSPLIB_F32
Single precision floating point.
Definition: DSPLIB_types.h:170
double DSPLIB_D64
Double precision floating point.
Definition: DSPLIB_types.h:169
DSPLIB_STATUS_NAME DSPLIB_STATUS
Return value for DSPLIB functions.
Definition: DSPLIB_types.h:274
Used when tensor is in NHWC format.
Definition: DSPLIB_types.h:298