• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_INTERNAL_COMPATIBILITY_H_
16 #define TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_
17 
18 #include <cstdint>
19 
20 #include "tensorflow/lite/kernels/op_macros.h"
21 
22 #ifndef TFLITE_DCHECK
23 #define TFLITE_DCHECK(condition) (condition) ? (void)0 : TFLITE_ASSERT_FALSE
24 #endif
25 
26 #ifndef TFLITE_DCHECK_EQ
27 #define TFLITE_DCHECK_EQ(x, y) ((x) == (y)) ? (void)0 : TFLITE_ASSERT_FALSE
28 #endif
29 
30 #ifndef TFLITE_DCHECK_NE
31 #define TFLITE_DCHECK_NE(x, y) ((x) != (y)) ? (void)0 : TFLITE_ASSERT_FALSE
32 #endif
33 
34 #ifndef TFLITE_DCHECK_GE
35 #define TFLITE_DCHECK_GE(x, y) ((x) >= (y)) ? (void)0 : TFLITE_ASSERT_FALSE
36 #endif
37 
38 #ifndef TFLITE_DCHECK_GT
39 #define TFLITE_DCHECK_GT(x, y) ((x) > (y)) ? (void)0 : TFLITE_ASSERT_FALSE
40 #endif
41 
42 #ifndef TFLITE_DCHECK_LE
43 #define TFLITE_DCHECK_LE(x, y) ((x) <= (y)) ? (void)0 : TFLITE_ASSERT_FALSE
44 #endif
45 
46 #ifndef TFLITE_DCHECK_LT
47 #define TFLITE_DCHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ASSERT_FALSE
48 #endif
49 
50 // TODO(ahentz): Clean up: We should stick to the DCHECK versions.
51 #ifndef TFLITE_CHECK
52 #define TFLITE_CHECK(condition) (condition) ? (void)0 : TFLITE_ABORT
53 #endif
54 
55 #ifndef TFLITE_CHECK_EQ
56 #define TFLITE_CHECK_EQ(x, y) ((x) == (y)) ? (void)0 : TFLITE_ABORT
57 #endif
58 
59 #ifndef TFLITE_CHECK_NE
60 #define TFLITE_CHECK_NE(x, y) ((x) != (y)) ? (void)0 : TFLITE_ABORT
61 #endif
62 
63 #ifndef TFLITE_CHECK_GE
64 #define TFLITE_CHECK_GE(x, y) ((x) >= (y)) ? (void)0 : TFLITE_ABORT
65 #endif
66 
67 #ifndef TFLITE_CHECK_GT
68 #define TFLITE_CHECK_GT(x, y) ((x) > (y)) ? (void)0 : TFLITE_ABORT
69 #endif
70 
71 #ifndef TFLITE_CHECK_LE
72 #define TFLITE_CHECK_LE(x, y) ((x) <= (y)) ? (void)0 : TFLITE_ABORT
73 #endif
74 
75 #ifndef TFLITE_CHECK_LT
76 #define TFLITE_CHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ABORT
77 #endif
78 
79 #ifndef TF_LITE_STATIC_MEMORY
80 // TODO(b/162019032): Consider removing these type-aliases.
81 using int8 = std::int8_t;
82 using uint8 = std::uint8_t;
83 using int16 = std::int16_t;
84 using uint16 = std::uint16_t;
85 using int32 = std::int32_t;
86 using uint32 = std::uint32_t;
87 #endif  // !defined(TF_LITE_STATIC_MEMORY)
88 
89 // Allow for cross-compiler usage of function signatures - currently used for
90 // specifying named RUY profiler regions in templated methods.
91 #if defined(_MSC_VER)
92 #define TFLITE_PRETTY_FUNCTION __FUNCSIG__
93 #elif defined(__GNUC__)
94 #define TFLITE_PRETTY_FUNCTION __PRETTY_FUNCTION__
95 #else
96 #define TFLITE_PRETTY_FUNCTION __func__
97 #endif
98 
99 // TFLITE_DEPRECATED()
100 //
101 // Duplicated from absl/base/macros.h to avoid pulling in that library.
102 // Marks a deprecated class, struct, enum, function, method and variable
103 // declarations. The macro argument is used as a custom diagnostic message (e.g.
104 // suggestion of a better alternative).
105 //
106 // Example:
107 //
108 //   class TFLITE_DEPRECATED("Use Bar instead") Foo {...};
109 //   TFLITE_DEPRECATED("Use Baz instead") void Bar() {...}
110 //
111 // Every usage of a deprecated entity will trigger a warning when compiled with
112 // clang's `-Wdeprecated-declarations` option. This option is turned off by
113 // default, but the warnings will be reported by clang-tidy.
114 #if defined(__clang__) && __cplusplus >= 201103L
115 #define TFLITE_DEPRECATED(message) __attribute__((deprecated(message)))
116 #endif
117 
118 #ifndef TFLITE_DEPRECATED
119 #define TFLITE_DEPRECATED(message)
120 #endif
121 
122 #endif  // TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_
123