|
| 1 | +/** |
| 2 | + ****************************************************************************** |
| 3 | + * @file ai_datatypes_defines.h |
| 4 | + * @author AST Embedded Analytics Research Platform |
| 5 | + * @brief Definitions of AI platform private APIs types |
| 6 | + ****************************************************************************** |
| 7 | + * @attention |
| 8 | + * |
| 9 | + * Copyright (c) 2017 STMicroelectronics. |
| 10 | + * All rights reserved. |
| 11 | + * |
| 12 | + * This software is licensed under terms that can be found in the LICENSE file |
| 13 | + * in the root directory of this software component. |
| 14 | + * If no LICENSE file comes with this software, it is provided AS-IS. |
| 15 | + * |
| 16 | + ****************************************************************************** |
| 17 | + */ |
| 18 | +#ifndef AI_DATATYPES_DEFINES_H |
| 19 | +#define AI_DATATYPES_DEFINES_H |
| 20 | + |
| 21 | +#include "ai_platform.h" |
| 22 | +#include "core_assert.h" |
| 23 | + |
| 24 | + |
| 25 | +/*! |
| 26 | + * @defgroup datatypes_defines Internal Datatypes Defines Header |
| 27 | + * @brief Data structures used internally to implement neural networks |
| 28 | + * |
| 29 | + */ |
| 30 | + |
| 31 | +/* define to track datatypes used by codegen */ |
| 32 | +#define AI_INTERNAL_API /* AI_INTERNAL_API */ |
| 33 | + |
| 34 | +#define AI_CONST const |
| 35 | +#define AI_STATIC static |
| 36 | +#define AI_STATIC_CONST static const |
| 37 | + |
| 38 | +/******************************************************************************/ |
| 39 | +/* NOP operation used by codegen */ |
| 40 | +#define AI_NOP /* NOP */ |
| 41 | + |
| 42 | +#define AI_WRAP_FUNC(fn_) do { fn_ } while (0); |
| 43 | + |
| 44 | +#define AI_CAT(a, ...) AI_PRIMITIVE_CAT(a, __VA_ARGS__) |
| 45 | +#define AI_PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__ |
| 46 | + |
| 47 | +/******************************************************************************/ |
| 48 | +#define AI_ASSERT(expr) \ |
| 49 | + CORE_ASSERT(expr) |
| 50 | + |
| 51 | + |
| 52 | +/******************************************************************************/ |
| 53 | +#define AI_NO_PACKED_STRUCTS |
| 54 | + |
| 55 | +/* Macro for defining packed structures (compiler dependent). |
| 56 | + * This just reduces memory requirements, but is not required. |
| 57 | + */ |
| 58 | +#if defined(AI_NO_PACKED_STRUCTS) |
| 59 | + /* Disable struct packing */ |
| 60 | + #define AI_PACKED_STRUCT_START /* AI_PACKED_STRUCT_START */ |
| 61 | + #define AI_PACKED_STRUCT_END /* AI_PACKED_STRUCT_END */ |
| 62 | + #define AI_PACKED /* AI_PACKED */ |
| 63 | +#elif defined(__GNUC__) || defined(__clang__) |
| 64 | + /* For GCC and clang */ |
| 65 | + #define AI_PACKED_STRUCT_START /* AI_PACKED_STRUCT_START */ |
| 66 | + #define AI_PACKED_STRUCT_END /* AI_PACKED_STRUCT_END */ |
| 67 | + #define AI_PACKED __attribute__((packed)) |
| 68 | +#elif defined(__ICCARM__) || defined (__IAR_SYSTEMS_ICC__) || defined(__CC_ARM) |
| 69 | + /* For IAR ARM and Keil MDK-ARM compilers */ |
| 70 | + #define AI_PACKED_STRUCT_START _Pragma("pack(push, 1)") |
| 71 | + #define AI_PACKED_STRUCT_END _Pragma("pack(pop)") |
| 72 | + #define AI_PACKED /* AI_PACKED */ |
| 73 | +#elif defined(_MSC_VER) && (_MSC_VER >= 1500) |
| 74 | + /* For Microsoft Visual C++ */ |
| 75 | + #define AI_PACKED_STRUCT_START __pragma(pack(push, 1)) |
| 76 | + #define AI_PACKED_STRUCT_END __pragma(pack(pop)) |
| 77 | + #define AI_PACKED /* AI_PACKED */ |
| 78 | +#else |
| 79 | + /* Unknown compiler */ |
| 80 | + #define AI_PACKED_STRUCT_START /* AI_PACKED_STRUCT_START */ |
| 81 | + #define AI_PACKED_STRUCT_END /* AI_PACKED_STRUCT_END */ |
| 82 | + #define AI_PACKED /* AI_PACKED */ |
| 83 | +#endif /* AI_NO_PACKED_STRUCTS */ |
| 84 | + |
| 85 | +/******************************************************************************/ |
| 86 | +#define AI_STRINGIFY_ARG(contents) # contents |
| 87 | +#define AI_STRINGIFY(macro_or_string) AI_STRINGIFY_ARG (macro_or_string) |
| 88 | + |
| 89 | +/******************************************************************************/ |
| 90 | +#if defined(_MSC_VER) |
| 91 | + #define AI_DECLARE_STATIC static __inline |
| 92 | + // #define AI_FORCE_INLINE static __forceinline |
| 93 | + #define AI_FORCE_INLINE static __inline |
| 94 | + #define AI_HINT_INLINE static __inline |
| 95 | + #define AI_ALIGNED_TYPE(type, x) type __declspec(align(x)) |
| 96 | + #define AI_INTERFACE_ENTRY __declspec(dllexport) |
| 97 | +#elif defined(__ICCARM__) || defined (__IAR_SYSTEMS_ICC__) |
| 98 | + #define AI_DECLARE_STATIC static inline |
| 99 | + // #define AI_FORCE_INLINE static _Pragma("inline=forced") // TODO: check this definition! |
| 100 | + #define AI_FORCE_INLINE static inline |
| 101 | + #define AI_HINT_INLINE static inline |
| 102 | + #define AI_ALIGNED_TYPE(type, x) type |
| 103 | + #define AI_INTERFACE_ENTRY /* AI_INTERFACE_ENTRY */ |
| 104 | +#elif defined(__GNUC__) |
| 105 | + #define AI_DECLARE_STATIC static __inline |
| 106 | + #define AI_FORCE_INLINE static __inline |
| 107 | + #define AI_HINT_INLINE static __inline |
| 108 | + #define AI_ALIGNED_TYPE(type, x) type __attribute__ ((aligned(x))) |
| 109 | + #define AI_INTERFACE_ENTRY /* AI_INTERFACE_ENTRY */ |
| 110 | +#else /* _MSC_VER */ |
| 111 | + #define AI_DECLARE_STATIC static __inline |
| 112 | + // #define AI_FORCE_INLINE static __forceinline |
| 113 | + #define AI_FORCE_INLINE static __inline |
| 114 | + #define AI_HINT_INLINE static __inline |
| 115 | + #define AI_ALIGNED_TYPE(type, x) type __attribute__ ((aligned(x))) |
| 116 | + #define AI_INTERFACE_ENTRY __attribute__((visibility("default"))) |
| 117 | +#endif /* _MSC_VER */ |
| 118 | + |
| 119 | +/******************************************************************************/ |
| 120 | +#define AI_ALIGN_MASKED(value, mask) ( ((value)+(mask))&(~(mask)) ) |
| 121 | + |
| 122 | +#define AI_GET_VERSION_STRING(major, minor, micro) \ |
| 123 | + AI_STRINGIFY_ARG(major) "." \ |
| 124 | + AI_STRINGIFY_ARG(minor) "." \ |
| 125 | + AI_STRINGIFY_ARG(micro) \ |
| 126 | + |
| 127 | + |
| 128 | +#define AI_PACK_TENSORS_PTR(...) \ |
| 129 | + AI_PACK(__VA_ARGS__) |
| 130 | + |
| 131 | +#define AI_PACK_INFO(size_) (ai_tensor_info[1]) { { \ |
| 132 | + .buffer = (ai_buffer[size_])AI_STRUCT_INIT, \ |
| 133 | + .state = (ai_tensor_state[size_])AI_STRUCT_INIT, \ |
| 134 | +} } |
| 135 | + |
| 136 | +#define AI_CR "\r\n" |
| 137 | + |
| 138 | +#if (defined HAS_AI_DEBUG || defined HAS_DEBUG_LIB) |
| 139 | +#include <stdio.h> |
| 140 | +#define AI_DEBUG(...) __VA_ARGS__ |
| 141 | +#define AI_DEBUG_PRINT(fmt, ...) { printf(fmt, ##__VA_ARGS__); } |
| 142 | +#else |
| 143 | +#define AI_DEBUG(...) AI_WRAP_FUNC(/*AI_DEBUG*/) |
| 144 | +#define AI_DEBUG_PRINT(fmt, ...) AI_WRAP_FUNC(/*AI_DEBUG_PRINT*/) |
| 145 | +#endif |
| 146 | + |
| 147 | +#define AI_FLAG_SET(mask, flag) (mask) |= (flag) |
| 148 | +#define AI_FLAG_UNSET(mask, flag) (mask) &= (~(flag)) |
| 149 | +#define AI_FLAG_IS_SET(mask, flag) ((flag)==((mask)&(flag))) |
| 150 | + |
| 151 | +#endif /*AI_DATATYPES_DEFINES_H*/ |
0 commit comments