Skip to content

Commit 6bcc0f4

Browse files
committed
Merge branch 'ci/sync_gh_tflite-micro' into 'master'
Sync esp-tflite-micro from github - 810089 See merge request app-frameworks/esp-tflite-micro!155
2 parents 07c014e + be48391 commit 6bcc0f4

23 files changed

+457
-145
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(compiler_mlir_dir "${CMAKE_CURRENT_SOURCE_DIR}/tensorflow/compiler/mlir/")
88
set(tfmicro_dir "${tflite_dir}/micro")
99
set(tfmicro_frontend_dir "${tflite_dir}/experimental/microfrontend/lib")
1010
set(tfmicro_kernels_dir "${tfmicro_dir}/kernels")
11+
set(tfmicro_compiler_dir "${tfmicro_dir}/compiler")
1112

1213
set(srcs_micro
1314
"${tfmicro_dir}/debug_log.cc"
@@ -83,7 +84,6 @@ set(lib_srcs
8384
"${tflite_dir}/micro/arena_allocator/recording_single_arena_buffer_allocator.cc"
8485
"${tflite_dir}/micro/arena_allocator/single_arena_buffer_allocator.cc"
8586
"${tflite_dir}/core/c/common.cc"
86-
"${tflite_dir}/core/api/error_reporter.cc"
8787
"${tflite_dir}/core/api/flatbuffer_conversions.cc"
8888
"${tflite_dir}/core/api/tensor_utils.cc"
8989
"${tflite_dir}/kernels/internal/common.cc"
@@ -93,6 +93,7 @@ set(lib_srcs
9393
"${tflite_dir}/kernels/internal/tensor_ctypes.cc"
9494
"${tflite_dir}/kernels/internal/reference/portable_tensor_utils.cc"
9595
"${tflite_dir}/kernels/internal/reference/comparisons.cc"
96+
"${compiler_mlir_dir}/lite/core/api/error_reporter.cc"
9697
"${compiler_mlir_dir}/lite/schema/schema_utils.cc")
9798

9899
set(priv_req)

tensorflow/lite/core/api/error_reporter.cc renamed to tensorflow/compiler/mlir/lite/core/api/error_reporter.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15-
#include "tensorflow/lite/core/api/error_reporter.h"
15+
#include "tensorflow/compiler/mlir/lite/core/api/error_reporter.h"
16+
1617
#include <cstdarg>
1718

1819
namespace tflite {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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_COMPILER_MLIR_LITE_CORE_API_ERROR_REPORTER_H_
16+
#define TENSORFLOW_COMPILER_MLIR_LITE_CORE_API_ERROR_REPORTER_H_
17+
18+
#include <cstdarg>
19+
20+
namespace tflite {
21+
22+
/// A functor that reports error to supporting system. Invoked similar to
23+
/// printf.
24+
///
25+
/// Usage:
26+
/// ErrorReporter foo;
27+
/// foo.Report("test %d", 5);
28+
/// or
29+
/// va_list args;
30+
/// foo.Report("test %d", args); // where args is va_list
31+
///
32+
/// Subclass ErrorReporter to provide another reporting destination.
33+
/// For example, if you have a GUI program, you might redirect to a buffer
34+
/// that drives a GUI error log box.
35+
class ErrorReporter {
36+
public:
37+
virtual ~ErrorReporter() = default;
38+
/// Converts `args` to character equivalents according to `format` string,
39+
/// constructs the error string and report it.
40+
/// Returns number of characters written or zero on success, and negative
41+
/// number on error.
42+
virtual int Report(const char* format, va_list args) = 0;
43+
44+
/// Converts arguments to character equivalents according to `format` string,
45+
/// constructs the error string and report it.
46+
/// Returns number of characters written or zero on success, and negative
47+
/// number on error.
48+
int Report(const char* format, ...);
49+
50+
/// Equivalent to `Report` above. The additional `void*` parameter is unused.
51+
/// This method is for compatibility with macros that takes `TfLiteContext`,
52+
/// like TF_LITE_ENSURE and related macros.
53+
int ReportError(void*, const char* format, ...);
54+
};
55+
56+
} // namespace tflite
57+
58+
// You should not make bare calls to the error reporter, instead use the
59+
// TF_LITE_REPORT_ERROR macro, since this allows message strings to be
60+
// stripped when the binary size has to be optimized. If you are looking to
61+
// reduce binary size, define TF_LITE_STRIP_ERROR_STRINGS when compiling and
62+
// every call will be stubbed out, taking no memory.
63+
#ifndef TF_LITE_STRIP_ERROR_STRINGS
64+
#define TF_LITE_REPORT_ERROR(reporter, ...) \
65+
do { \
66+
static_cast<::tflite::ErrorReporter*>(reporter)->Report(__VA_ARGS__); \
67+
} while (false)
68+
#else // TF_LITE_STRIP_ERROR_STRINGS
69+
#define TF_LITE_REPORT_ERROR(reporter, ...)
70+
#endif // TF_LITE_STRIP_ERROR_STRINGS
71+
72+
#endif // TENSORFLOW_COMPILER_MLIR_LITE_CORE_API_ERROR_REPORTER_H_

tensorflow/lite/builtin_ops.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ typedef enum {
234234
kTfLiteBuiltinStablehloRngBitGenerator = 204,
235235
kTfLiteBuiltinReduceWindow = 205,
236236
kTfLiteBuiltinStablehloComposite = 206,
237+
kTfLiteBuiltinStablehloShiftLeft = 207,
238+
kTfLiteBuiltinStablehloCbrt = 208,
237239
} TfLiteBuiltinOperator;
238240

239241
#ifdef __cplusplus

tensorflow/lite/core/api/error_reporter.h

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,6 @@ limitations under the License.
1515
#ifndef TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_
1616
#define TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_
1717

18-
#include <cstdarg>
19-
20-
namespace tflite {
21-
22-
/// A functor that reports error to supporting system. Invoked similar to
23-
/// printf.
24-
///
25-
/// Usage:
26-
/// ErrorReporter foo;
27-
/// foo.Report("test %d", 5);
28-
/// or
29-
/// va_list args;
30-
/// foo.Report("test %d", args); // where args is va_list
31-
///
32-
/// Subclass ErrorReporter to provide another reporting destination.
33-
/// For example, if you have a GUI program, you might redirect to a buffer
34-
/// that drives a GUI error log box.
35-
class ErrorReporter {
36-
public:
37-
virtual ~ErrorReporter() = default;
38-
/// Converts `args` to character equivalents according to `format` string,
39-
/// constructs the error string and report it.
40-
/// Returns number of characters written or zero on success, and negative
41-
/// number on error.
42-
virtual int Report(const char* format, va_list args) = 0;
43-
44-
/// Converts arguments to character equivalents according to `format` string,
45-
/// constructs the error string and report it.
46-
/// Returns number of characters written or zero on success, and negative
47-
/// number on error.
48-
int Report(const char* format, ...);
49-
50-
/// Equivalent to `Report` above. The additional `void*` parameter is unused.
51-
/// This method is for compatibility with macros that takes `TfLiteContext`,
52-
/// like TF_LITE_ENSURE and related macros.
53-
int ReportError(void*, const char* format, ...);
54-
};
55-
56-
} // namespace tflite
57-
58-
// You should not make bare calls to the error reporter, instead use the
59-
// TF_LITE_REPORT_ERROR macro, since this allows message strings to be
60-
// stripped when the binary size has to be optimized. If you are looking to
61-
// reduce binary size, define TF_LITE_STRIP_ERROR_STRINGS when compiling and
62-
// every call will be stubbed out, taking no memory.
63-
#ifndef TF_LITE_STRIP_ERROR_STRINGS
64-
#define TF_LITE_REPORT_ERROR(reporter, ...) \
65-
do { \
66-
static_cast<::tflite::ErrorReporter*>(reporter)->Report(__VA_ARGS__); \
67-
} while (false)
68-
#else // TF_LITE_STRIP_ERROR_STRINGS
69-
#define TF_LITE_REPORT_ERROR(reporter, ...)
70-
#endif // TF_LITE_STRIP_ERROR_STRINGS
18+
#include "tensorflow/compiler/mlir/lite/core/api/error_reporter.h" // IWYU pragma: export
7119

7220
#endif // TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_

tensorflow/lite/core/api/flatbuffer_conversions.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ limitations under the License.
2020
#include <cstdint>
2121
#include <memory>
2222

23-
#include "flatbuffers/flatbuffers.h" // from @flatbuffers
2423
#include "flatbuffers/vector.h" // from @flatbuffers
25-
#include "tensorflow/lite/core/api/error_reporter.h"
24+
#include "tensorflow/compiler/mlir/lite/core/api/error_reporter.h"
2625
#include "tensorflow/lite/core/c/builtin_op_data.h"
2726
#include "tensorflow/lite/core/c/common.h"
2827
#include "tensorflow/lite/kernels/internal/compatibility.h"
@@ -925,6 +924,10 @@ TfLiteStatus ParseOpDataTfLite(const Operator* op, BuiltinOperator op_type,
925924
return ParseStablehloComposite(op, error_reporter, allocator,
926925
builtin_data);
927926
}
927+
case BuiltinOperator_STABLEHLO_SHIFT_LEFT: {
928+
return ParseStablehloShiftLeft(op, error_reporter, allocator,
929+
builtin_data);
930+
}
928931
// TODO: skip param parsing for now since ops below don't have kernels
929932
case BuiltinOperator_STABLEHLO_SLICE:
930933
case BuiltinOperator_STABLEHLO_BROADCAST_IN_DIM:
@@ -963,6 +966,7 @@ TfLiteStatus ParseOpDataTfLite(const Operator* op, BuiltinOperator op_type,
963966
case BuiltinOperator_STABLEHLO_SORT:
964967
case BuiltinOperator_STABLEHLO_WHILE:
965968
case BuiltinOperator_STABLEHLO_TRANSPOSE:
969+
case BuiltinOperator_STABLEHLO_CBRT:
966970

967971
// Below are the ops with no builtin_data structure.
968972
// TODO(aselle): Implement call in BuiltinOptions, but nullptrs are
@@ -2410,6 +2414,13 @@ TfLiteStatus ParseStablehloComposite(const Operator* op,
24102414
return kTfLiteError;
24112415
}
24122416

2417+
TfLiteStatus ParseStablehloShiftLeft(const Operator* op,
2418+
ErrorReporter* error_reporter,
2419+
BuiltinDataAllocator* allocator,
2420+
void** builtin_data) {
2421+
return kTfLiteOk;
2422+
}
2423+
24132424
// We have this parse function instead of directly returning kTfLiteOk from the
24142425
// switch-case in ParseOpData because this function is used as part of the
24152426
// selective registration for the OpResolver implementation in micro.

tensorflow/lite/core/api/flatbuffer_conversions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ limitations under the License.
2323
#include <new>
2424
#include <type_traits>
2525

26+
#include "tensorflow/compiler/mlir/lite/core/api/error_reporter.h"
2627
#include "tensorflow/lite/core/api/error_reporter.h"
2728
#include "tensorflow/lite/core/c/common.h"
2829
#include "tensorflow/lite/schema/schema_generated.h"
@@ -450,6 +451,11 @@ TfLiteStatus ParseStablehloComposite(const Operator* op,
450451
BuiltinDataAllocator* allocator,
451452
void** builtin_data);
452453

454+
TfLiteStatus ParseStablehloShiftLeft(const Operator* op,
455+
ErrorReporter* error_reporter,
456+
BuiltinDataAllocator* allocator,
457+
void** builtin_data);
458+
453459
} // namespace tflite
454460

455461
#endif // TENSORFLOW_LITE_CORE_API_FLATBUFFER_CONVERSIONS_H_

tensorflow/lite/core/c/c_api_types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,17 @@ typedef enum TfLiteStatus {
110110
// TODO(b/250636993): Cancellation triggered by `SetCancellationFunction`
111111
// should also return this status code.
112112
kTfLiteCancelled = 8,
113+
114+
// This status is returned by Prepare when the output shape cannot be
115+
// determined but the size of the output tensor is known. For example, the
116+
// output of reshape is always the same size as the input. This means that
117+
// such ops may be
118+
// done in place.
119+
kTfLiteOutputShapeNotKnown = 9,
113120
} TfLiteStatus;
114121

115122
/// Types supported by tensor
123+
// LINT.IfChange
116124
typedef enum {
117125
kTfLiteNoType = 0,
118126
kTfLiteFloat32 = 1,
@@ -135,6 +143,7 @@ typedef enum {
135143
kTfLiteInt4 = 18,
136144
kTfLiteBFloat16 = 19,
137145
} TfLiteType;
146+
// LINT.ThenChange(//tensorflow/lite/profiling/proto/model_runtime_info.proto:EdgeDataType)
138147

139148
/// Legacy. Will be deprecated in favor of `TfLiteAffineQuantization`.
140149
/// If per-layer quantization is specified this field will still be populated in

tensorflow/lite/core/c/common.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,9 @@ TfLiteStatus TfLiteTensorResizeMaybeCopy(size_t num_bytes, TfLiteTensor* tensor,
295295
#ifdef TF_LITE_TENSORFLOW_PROFILER
296296
tflite::PauseHeapMonitoring(/*pause=*/true);
297297
#endif
298-
size_t alloc_bytes = num_bytes;
298+
// This buffer may be consumed by XNNPack.
299+
size_t alloc_bytes = num_bytes + /*XNN_EXTRA_BYTES=*/16;
299300
// TODO(b/145340303): Tensor data should be aligned.
300-
#ifdef TFLITE_KERNEL_USE_XNNPACK
301-
alloc_bytes += 16; // XNNPACK_EXTRA_BYTES = 16
302-
#endif
303301
if (!tensor->data.data) {
304302
tensor->data.data = (char*)malloc(alloc_bytes);
305303
#ifdef TF_LITE_TENSORFLOW_PROFILER

tensorflow/lite/core/c/common.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,17 @@ void TfLiteFloatArrayFree(TfLiteFloatArray* a);
283283
} \
284284
} while (0)
285285

286+
// `std::unreachable` not available until CC23.
287+
#ifdef __GNUC__ // GCC, Clang, ICC
288+
289+
#define TFL_UNREACHABLE() (__builtin_unreachable())
290+
291+
#elif defined(_MSC_VER) // MSVC
292+
293+
#define TFL_UNREACHABLE() (__assume(false))
294+
295+
#endif
296+
286297
/// Single-precision complex data type compatible with the C99 definition.
287298
typedef struct TfLiteComplex64 {
288299
float re, im; /// real and imaginary parts, respectively.

0 commit comments

Comments
 (0)