Skip to content

Commit 7d584f6

Browse files
committed
tflite-micro-sync: Update esp-tflite-micro (synced from github)
1 parent 3e6970d commit 7d584f6

29 files changed

+2070
-37
lines changed

tensorflow/compiler/mlir/lite/core/c/tflite_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef enum {
6464
kTfLiteUInt16 = 17,
6565
kTfLiteInt4 = 18,
6666
kTfLiteBFloat16 = 19,
67+
kTfLiteInt2 = 20,
6768
} TfLiteType;
6869
// LINT.ThenChange(//tensorflow/lite/profiling/proto/model_runtime_info.proto:EdgeDataType)
6970

tensorflow/compiler/mlir/lite/schema/schema_utils.cc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ limitations under the License.
1515
#include "tensorflow/compiler/mlir/lite/schema/schema_utils.h"
1616

1717
#include <algorithm>
18+
#include <complex>
19+
#include <cstddef>
20+
#include <cstdint>
1821

1922
#include "tensorflow/compiler/mlir/lite/kernels/internal/compatibility_macros.h"
23+
#include "tensorflow/compiler/mlir/lite/schema/schema_generated.h"
2024

2125
namespace tflite {
2226

@@ -59,4 +63,51 @@ BuiltinOperator GetBuiltinCode(const OperatorCodeT* op_code) {
5963
op_code->deprecated_builtin_code));
6064
}
6165

66+
size_t TensorTypeGetSize(::tflite::TensorType data_type) {
67+
switch (data_type) {
68+
case ::tflite::TensorType_FLOAT32:
69+
static_assert(sizeof(float) == 4, "");
70+
return 4;
71+
case ::tflite::TensorType_FLOAT16:
72+
static_assert(sizeof(int16_t) == 2, "");
73+
return 2;
74+
case ::tflite::TensorType_INT32:
75+
static_assert(sizeof(int32_t) == 4, "");
76+
return 4;
77+
case ::tflite::TensorType_UINT8:
78+
static_assert(sizeof(uint8_t) == 1, "");
79+
return 1;
80+
case ::tflite::TensorType_INT64:
81+
static_assert(sizeof(int64_t) == 8, "");
82+
return 8;
83+
case ::tflite::TensorType_BOOL:
84+
return sizeof(bool);
85+
case ::tflite::TensorType_INT16:
86+
static_assert(sizeof(int16_t) == 2, "");
87+
return 2;
88+
case ::tflite::TensorType_COMPLEX64:
89+
static_assert(sizeof(std::complex<float>) == 8, "");
90+
return 8;
91+
case ::tflite::TensorType_INT8:
92+
static_assert(sizeof(int8_t) == 1, "");
93+
return 1;
94+
case ::tflite::TensorType_FLOAT64:
95+
static_assert(sizeof(double) == 8, "");
96+
return 8;
97+
case ::tflite::TensorType_COMPLEX128:
98+
static_assert(sizeof(std::complex<double>) == 16, "");
99+
return 16;
100+
case ::tflite::TensorType_UINT64:
101+
static_assert(sizeof(uint64_t) == 8, "");
102+
return 8;
103+
case ::tflite::TensorType_UINT32:
104+
static_assert(sizeof(uint32_t) == 4, "");
105+
return 4;
106+
case ::tflite::TensorType_UINT16:
107+
static_assert(sizeof(uint16_t) == 2, "");
108+
return 2;
109+
default:
110+
return 0;
111+
}
112+
}
62113
} // namespace tflite

tensorflow/compiler/mlir/lite/schema/schema_utils.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ limitations under the License.
1515
#ifndef TENSORFLOW_COMPILER_MLIR_LITE_SCHEMA_SCHEMA_UTILS_H_
1616
#define TENSORFLOW_COMPILER_MLIR_LITE_SCHEMA_SCHEMA_UTILS_H_
1717

18+
#include <cstddef>
19+
1820
#include "flatbuffers/flatbuffers.h"
1921
#include "tensorflow/compiler/mlir/lite/schema/schema_generated.h"
2022

@@ -28,6 +30,11 @@ BuiltinOperator GetBuiltinCode(const OperatorCode *op_code);
2830

2931
BuiltinOperator GetBuiltinCode(const OperatorCodeT *op_code);
3032

33+
// Returns the size of the given TensorType in bytes, or 0 if the TensorType is
34+
// not supported, this function should be aligned with TfLiteTypeGetSize in
35+
// lite/kernels/kernel_util.h.
36+
size_t TensorTypeGetSize(::tflite::TensorType data_type);
37+
3138
} // namespace tflite
3239

3340
#endif // TENSORFLOW_COMPILER_MLIR_LITE_SCHEMA_SCHEMA_UTILS_H_

tensorflow/lite/c/builtin_op_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616
#define TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
1717

1818
/// For documentation, see
19-
/// third_party/tensorflow/lite/core/c/builtin_op_data.h
19+
/// tensorflow/lite/core/c/builtin_op_data.h
2020

2121
#include "tensorflow/lite/core/c/builtin_op_data.h"
2222

tensorflow/lite/core/api/flatbuffer_conversions.cc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ TfLiteStatus ParseOpDataTfLite(const Operator* op, BuiltinOperator op_type,
269269
return ParseDiv(op, error_reporter, allocator, builtin_data);
270270
}
271271

272+
case BuiltinOperator_DYNAMIC_UPDATE_SLICE: {
273+
return ParseDynamicUpdateSlice(op, error_reporter, allocator,
274+
builtin_data);
275+
}
276+
272277
case BuiltinOperator_ELU: {
273278
return ParseElu(op, error_reporter, allocator, builtin_data);
274279
}
@@ -987,7 +992,6 @@ TfLiteStatus ParseOpDataTfLite(const Operator* op, BuiltinOperator op_type,
987992
case BuiltinOperator_COS:
988993
case BuiltinOperator_CUSTOM:
989994
case BuiltinOperator_DENSIFY:
990-
case BuiltinOperator_DYNAMIC_UPDATE_SLICE:
991995
case BuiltinOperator_EQUAL:
992996
case BuiltinOperator_HASHTABLE_FIND:
993997
case BuiltinOperator_HASHTABLE_IMPORT:
@@ -1088,6 +1092,9 @@ TfLiteStatus ConvertTensorType(TensorType tensor_type, TfLiteType* type,
10881092
case TensorType_INT4:
10891093
*type = kTfLiteInt4;
10901094
return kTfLiteOk;
1095+
case TensorType_INT2:
1096+
*type = kTfLiteInt2;
1097+
return kTfLiteOk;
10911098
default:
10921099
*type = kTfLiteNoType;
10931100
TF_LITE_REPORT_ERROR(error_reporter,
@@ -1466,6 +1473,14 @@ TfLiteStatus ParseDiv(const Operator* op, ErrorReporter* error_reporter,
14661473
return kTfLiteOk;
14671474
}
14681475

1476+
// We have this parse function instead of directly returning kTfLiteOk from the
1477+
// switch-case in ParseOpData because this function is used as part of the
1478+
// selective registration for the OpResolver implementation in micro.
1479+
TfLiteStatus ParseDynamicUpdateSlice(const Operator*, ErrorReporter*,
1480+
BuiltinDataAllocator*, void**) {
1481+
return kTfLiteOk;
1482+
}
1483+
14691484
// We have this parse function instead of directly returning kTfLiteOk from the
14701485
// switch-case in ParseOpData because this function is used as part of the
14711486
// selective registration for the OpResolver implementation in micro.

tensorflow/lite/core/api/flatbuffer_conversions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ TfLiteStatus ParseDequantize(const Operator* op, ErrorReporter* error_reporter,
148148
TfLiteStatus ParseDiv(const Operator* op, ErrorReporter* error_reporter,
149149
BuiltinDataAllocator* allocator, void** builtin_data);
150150

151+
TfLiteStatus ParseDynamicUpdateSlice(const Operator* op,
152+
ErrorReporter* error_reporter,
153+
BuiltinDataAllocator* allocator,
154+
void** builtin_data);
155+
151156
TfLiteStatus ParseElu(const Operator* op, ErrorReporter* error_reporter,
152157
BuiltinDataAllocator* allocator, void** builtin_data);
153158

tensorflow/lite/core/c/builtin_op_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ limitations under the License.
1414
==============================================================================*/
1515
/// WARNING: Users of TensorFlow Lite should not include this file directly,
1616
/// but should instead include
17-
/// "third_party/tensorflow/lite/c/builtin_op_data.h".
17+
/// "tensorflow/lite/c/builtin_op_data.h".
1818
/// Only the TensorFlow Lite implementation itself should include this
1919
/// file directly.
2020
#ifndef TENSORFLOW_LITE_CORE_C_BUILTIN_OP_DATA_H_

tensorflow/lite/core/c/c_api_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515
// WARNING: Users of TensorFlow Lite should not include this file directly, but
16-
// should instead include "third_party/tensorflow/lite/c/c_api_types.h".
16+
// should instead include "tensorflow/lite/c/c_api_types.h".
1717
// Only the TensorFlow Lite implementation itself should include this file
1818
// directly.
1919

@@ -31,7 +31,7 @@ limitations under the License.
3131
// NOLINTEND(whitespace/line_length)
3232
// clang-format on
3333

34-
// IWYU pragma: private, include "third_party/tensorflow/lite/c/c_api_types.h"
34+
// IWYU pragma: private, include "tensorflow/lite/c/c_api_types.h"
3535

3636
#ifndef TENSORFLOW_LITE_CORE_C_C_API_TYPES_H_
3737
#define TENSORFLOW_LITE_CORE_C_C_API_TYPES_H_

tensorflow/lite/core/c/common.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ const char* TfLiteTypeGetName(TfLiteType type) {
509509
return "VARIANT";
510510
case kTfLiteInt4:
511511
return "INT4";
512+
case kTfLiteInt2:
513+
return "INT2";
512514
}
513515
return "Unknown type";
514516
}

tensorflow/lite/core/c/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
1515
// WARNING: Users of TensorFlow Lite should not include this file directly, but
16-
// should instead include "third_party/tensorflow/lite/c/common.h".
16+
// should instead include "tensorflow/lite/c/common.h".
1717
// Only the TensorFlow Lite implementation itself should include this file
1818
// directly.
1919

@@ -47,7 +47,7 @@ limitations under the License.
4747
// NOLINTEND(whitespace/line_length)
4848
// clang-format on
4949

50-
// IWYU pragma: private, include "third_party/tensorflow/lite/c/common.h"
50+
// IWYU pragma: private, include "tensorflow/lite/c/common.h"
5151

5252
#ifndef TENSORFLOW_LITE_CORE_C_COMMON_H_
5353
#define TENSORFLOW_LITE_CORE_C_COMMON_H_

0 commit comments

Comments
 (0)