compatibility.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_INTERNAL_COMPATIBILITY_H_
  13. #define TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_
  14. #include <cstdint>
  15. #include "tensorflow/lite/kernels/op_macros.h"
  16. #ifndef TFLITE_DCHECK
  17. #define TFLITE_DCHECK(condition) (condition) ? (void)0 : TFLITE_ASSERT_FALSE
  18. #endif
  19. #ifndef TFLITE_DCHECK_EQ
  20. #define TFLITE_DCHECK_EQ(x, y) ((x) == (y)) ? (void)0 : TFLITE_ASSERT_FALSE
  21. #endif
  22. #ifndef TFLITE_DCHECK_NE
  23. #define TFLITE_DCHECK_NE(x, y) ((x) != (y)) ? (void)0 : TFLITE_ASSERT_FALSE
  24. #endif
  25. #ifndef TFLITE_DCHECK_GE
  26. #define TFLITE_DCHECK_GE(x, y) ((x) >= (y)) ? (void)0 : TFLITE_ASSERT_FALSE
  27. #endif
  28. #ifndef TFLITE_DCHECK_GT
  29. #define TFLITE_DCHECK_GT(x, y) ((x) > (y)) ? (void)0 : TFLITE_ASSERT_FALSE
  30. #endif
  31. #ifndef TFLITE_DCHECK_LE
  32. #define TFLITE_DCHECK_LE(x, y) ((x) <= (y)) ? (void)0 : TFLITE_ASSERT_FALSE
  33. #endif
  34. #ifndef TFLITE_DCHECK_LT
  35. #define TFLITE_DCHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ASSERT_FALSE
  36. #endif
  37. // TODO(ahentz): Clean up: We should stick to the DCHECK versions.
  38. #ifndef TFLITE_CHECK
  39. #define TFLITE_CHECK(condition) (condition) ? (void)0 : TFLITE_ABORT
  40. #endif
  41. #ifndef TFLITE_CHECK_EQ
  42. #define TFLITE_CHECK_EQ(x, y) ((x) == (y)) ? (void)0 : TFLITE_ABORT
  43. #endif
  44. #ifndef TFLITE_CHECK_NE
  45. #define TFLITE_CHECK_NE(x, y) ((x) != (y)) ? (void)0 : TFLITE_ABORT
  46. #endif
  47. #ifndef TFLITE_CHECK_GE
  48. #define TFLITE_CHECK_GE(x, y) ((x) >= (y)) ? (void)0 : TFLITE_ABORT
  49. #endif
  50. #ifndef TFLITE_CHECK_GT
  51. #define TFLITE_CHECK_GT(x, y) ((x) > (y)) ? (void)0 : TFLITE_ABORT
  52. #endif
  53. #ifndef TFLITE_CHECK_LE
  54. #define TFLITE_CHECK_LE(x, y) ((x) <= (y)) ? (void)0 : TFLITE_ABORT
  55. #endif
  56. #ifndef TFLITE_CHECK_LT
  57. #define TFLITE_CHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ABORT
  58. #endif
  59. #ifndef TF_LITE_STATIC_MEMORY
  60. // TODO(b/162019032): Consider removing these type-aliases.
  61. using int8 = std::int8_t;
  62. using uint8 = std::uint8_t;
  63. using int16 = std::int16_t;
  64. using uint16 = std::uint16_t;
  65. using int32 = std::int32_t;
  66. using uint32 = std::uint32_t;
  67. #endif // !defined(TF_LITE_STATIC_MEMORY)
  68. // TFLITE_DEPRECATED()
  69. //
  70. // Duplicated from absl/base/macros.h to avoid pulling in that library.
  71. // Marks a deprecated class, struct, enum, function, method and variable
  72. // declarations. The macro argument is used as a custom diagnostic message (e.g.
  73. // suggestion of a better alternative).
  74. //
  75. // Example:
  76. //
  77. // class TFLITE_DEPRECATED("Use Bar instead") Foo {...};
  78. // TFLITE_DEPRECATED("Use Baz instead") void Bar() {...}
  79. //
  80. // Every usage of a deprecated entity will trigger a warning when compiled with
  81. // clang's `-Wdeprecated-declarations` option. This option is turned off by
  82. // default, but the warnings will be reported by clang-tidy.
  83. #if defined(__clang__) && __cplusplus >= 201103L
  84. #define TFLITE_DEPRECATED(message) __attribute__((deprecated(message)))
  85. #endif
  86. #ifndef TFLITE_DEPRECATED
  87. #define TFLITE_DEPRECATED(message)
  88. #endif
  89. #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_