1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #ifndef TENSORFLOW_LITE_KERNELS_OP_MACROS_H_
16 #define TENSORFLOW_LITE_KERNELS_OP_MACROS_H_
17
18 // If we're on a platform without standard IO functions, fall back to a
19 // non-portable function.
20 #ifdef TF_LITE_MCU_DEBUG_LOG
21
22 #include "tensorflow/lite/micro/debug_log.h"
23
24 #define DEBUG_LOG(x) \
25 do { \
26 DebugLog(x); \
27 } while (0)
28
InfiniteLoop()29 inline void InfiniteLoop() {
30 DEBUG_LOG("HALTED\n");
31 while (1) {
32 }
33 }
34
35 #define TFLITE_ABORT InfiniteLoop();
36
37 #else // TF_LITE_MCU_DEBUG_LOG
38
39 #include <cstdio>
40 #include <cstdlib>
41
42 #define DEBUG_LOG(x) \
43 do { \
44 fprintf(stderr, "%s", (x)); \
45 } while (0)
46
47 // Report Error for unsupported type by op 'op_name' and returns kTfLiteError.
48 #define TF_LITE_UNSUPPORTED_TYPE(context, type, op_name) \
49 do { \
50 TF_LITE_KERNEL_LOG((context), "%s:%d Type %s is unsupported by op %s.", \
51 __FILE__, __LINE__, TfLiteTypeGetName(type), \
52 (op_name)); \
53 return kTfLiteError; \
54 } while (0)
55
56 #define TFLITE_ABORT abort()
57
58 #endif // TF_LITE_MCU_DEBUG_LOG
59
60 #if defined(NDEBUG) || defined(ARDUINO)
61 #define TFLITE_ASSERT_FALSE (static_cast<void>(0))
62 #else
63 #define TFLITE_ASSERT_FALSE TFLITE_ABORT
64 #endif
65
66 #define TF_LITE_FATAL(msg) \
67 do { \
68 DEBUG_LOG(msg); \
69 DEBUG_LOG("\nFATAL\n"); \
70 TFLITE_ABORT; \
71 } while (0)
72
73 #define TF_LITE_ASSERT(x) \
74 do { \
75 if (!(x)) TF_LITE_FATAL(#x); \
76 } while (0)
77
78 #define TF_LITE_ASSERT_EQ(x, y) \
79 do { \
80 if ((x) != (y)) TF_LITE_FATAL(#x " didn't equal " #y); \
81 } while (0)
82
83 #endif // TENSORFLOW_LITE_KERNELS_OP_MACROS_H_
84