Daniel Konegen / MNIST_example

Dependencies:   mbed-os

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers op_macros.h Source File

op_macros.h

00001 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
00002 
00003 Licensed under the Apache License, Version 2.0 (the "License");
00004 you may not use this file except in compliance with the License.
00005 You may obtain a copy of the License at
00006 
00007     http://www.apache.org/licenses/LICENSE-2.0
00008 
00009 Unless required by applicable law or agreed to in writing, software
00010 distributed under the License is distributed on an "AS IS" BASIS,
00011 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 See the License for the specific language governing permissions and
00013 limitations under the License.
00014 ==============================================================================*/
00015 #ifndef TENSORFLOW_LITE_KERNELS_OP_MACROS_H_
00016 #define TENSORFLOW_LITE_KERNELS_OP_MACROS_H_
00017 
00018 // If we're on a platform without standard IO functions, fall back to a
00019 // non-portable function.
00020 #ifdef TF_LITE_MCU_DEBUG_LOG
00021 
00022 #include "tensorflow/lite/experimental/micro/micro_error_reporter.h"
00023 
00024 #define DEBUG_LOG(x) \
00025   do {               \
00026     DebugLog(x);     \
00027   } while (0)
00028 
00029 inline void InfiniteLoop() {
00030   DEBUG_LOG("HALTED\n");
00031   while (1) {
00032   }
00033 }
00034 #define TFLITE_ASSERT_FALSE InfiniteLoop();
00035 #define TFLITE_ABORT InfiniteLoop();
00036 
00037 #else  // TF_LITE_MCU_DEBUG_LOG
00038 
00039 #include <cassert>
00040 #include <cstdio>
00041 #include <cstdlib>
00042 
00043 #define DEBUG_LOG(x)            \
00044   do {                          \
00045     fprintf(stderr, "%s", (x)); \
00046   } while (0)
00047 
00048 #define TFLITE_ABORT abort()
00049 
00050 #ifdef NDEBUG
00051 #define TFLITE_ASSERT_FALSE (static_cast<void>(0))
00052 #else
00053 #define TFLITE_ASSERT_FALSE TFLITE_ABORT
00054 #endif
00055 
00056 #endif  // TF_LITE_MCU_DEBUG_LOG
00057 
00058 #define TF_LITE_FATAL(msg)  \
00059   do {                      \
00060     DEBUG_LOG(msg);         \
00061     DEBUG_LOG("\nFATAL\n"); \
00062     TFLITE_ABORT;           \
00063   } while (0)
00064 
00065 #define TF_LITE_ASSERT(x)        \
00066   do {                           \
00067     if (!(x)) TF_LITE_FATAL(#x); \
00068   } while (0)
00069 
00070 #define TF_LITE_ASSERT_EQ(x, y)                            \
00071   do {                                                     \
00072     if ((x) != (y)) TF_LITE_FATAL(#x " didn't equal " #y); \
00073   } while (0)
00074 
00075 #endif  // TENSORFLOW_LITE_KERNELS_OP_MACROS_H_