op_macros.h 2.1 KB

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