No longer sync TfLite OpResolver from upstream. (#2145)
With https://github.com/tensorflow/tflite-micro/pull/1818, TFLM does not need the TfLite OpResolver.
BUG=http://b/272808609
diff --git a/ci/tflite_files.txt b/ci/tflite_files.txt
index 7fa53c4..51381ce 100644
--- a/ci/tflite_files.txt
+++ b/ci/tflite_files.txt
@@ -5,7 +5,6 @@
tensorflow/lite/context_util.h
tensorflow/lite/core/api/error_reporter.cc
tensorflow/lite/core/api/flatbuffer_conversions.cc
-tensorflow/lite/core/api/op_resolver.cc
tensorflow/lite/core/api/tensor_utils.cc
tensorflow/lite/core/c/common.cc
tensorflow/lite/kernels/internal/common.cc
@@ -19,7 +18,6 @@
tensorflow/lite/c/common.h
tensorflow/lite/core/api/error_reporter.h
tensorflow/lite/core/api/flatbuffer_conversions.h
-tensorflow/lite/core/api/op_resolver.h
tensorflow/lite/core/api/tensor_utils.h
tensorflow/lite/core/c/builtin_op_data.h
tensorflow/lite/core/c/c_api_types.h
diff --git a/tensorflow/lite/core/api/BUILD b/tensorflow/lite/core/api/BUILD
index ce6cd1a..5457f2e 100644
--- a/tensorflow/lite/core/api/BUILD
+++ b/tensorflow/lite/core/api/BUILD
@@ -15,14 +15,12 @@
hdrs = [
"error_reporter.h",
"flatbuffer_conversions.h",
- "op_resolver.h",
"tensor_utils.h",
],
copts = tflite_copts() + micro_copts(),
visibility = ["//visibility:public"],
deps = [
":error_reporter",
- ":op_resolver",
"//tensorflow/lite/c:common",
"//tensorflow/lite/kernels/internal:compatibility",
"//tensorflow/lite/schema:schema_fbs",
@@ -31,29 +29,10 @@
],
)
-# We define separate targets for "op_resolver" and "error_reporter",
-# even though those headers are also exported by the "api" target,
-# so that targets which only want to depend on these small abstract base
-# class modules can express more fine-grained dependencies without
-# pulling in tensor_utils and flatbuffer_conversions.
-
-cc_library(
- name = "op_resolver",
- srcs = ["op_resolver.cc"],
- hdrs = ["op_resolver.h"],
- copts = tflite_copts() + micro_copts(),
- visibility = [
- "//visibility:public",
- ],
- deps = [
- ":error_reporter",
- "//tensorflow/lite/c:common",
- "//tensorflow/lite/schema:schema_fbs",
- "//tensorflow/lite/schema:schema_utils",
- "@flatbuffers//:runtime_cc",
- ],
-)
-
+# We define separate targets for "error_reporter", even though those headers are
+# also exported by the "api" target, so that targets which only want to depend
+# on these small abstract base class modules can express more fine-grained
+# dependencies without pulling in tensor_utils and flatbuffer_conversions.
cc_library(
name = "error_reporter",
srcs = ["error_reporter.cc"],
diff --git a/tensorflow/lite/core/api/op_resolver.cc b/tensorflow/lite/core/api/op_resolver.cc
deleted file mode 100644
index ce5ae4f..0000000
--- a/tensorflow/lite/core/api/op_resolver.cc
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-
-#include "tensorflow/lite/core/api/op_resolver.h"
-
-#include "flatbuffers/flatbuffers.h" // from @flatbuffers
-#include "tensorflow/lite/core/api/error_reporter.h"
-#include "tensorflow/lite/core/c/common.h"
-#include "tensorflow/lite/schema/schema_utils.h"
-
-namespace tflite {
-
-TfLiteStatus GetRegistrationFromOpCode(
- const OperatorCode* opcode, const OpResolver& op_resolver,
- ErrorReporter* error_reporter, const TfLiteRegistration** registration) {
- TfLiteStatus status = kTfLiteOk;
- *registration = nullptr;
- auto builtin_code = GetBuiltinCode(opcode);
- int version = opcode->version();
-
- if (builtin_code > BuiltinOperator_MAX) {
- TF_LITE_REPORT_ERROR(
- error_reporter,
- "Op builtin_code out of range: %d. Are you using old TFLite binary "
- "with newer model?",
- builtin_code);
- status = kTfLiteError;
- } else if (builtin_code != BuiltinOperator_CUSTOM) {
- *registration = op_resolver.FindOp(builtin_code, version);
- if (*registration == nullptr) {
- TF_LITE_REPORT_ERROR(
- error_reporter,
- "Didn't find op for builtin opcode '%s' version '%d'. "
- "An older version of this builtin might be supported. "
- "Are you using an old TFLite binary with a newer model?\n",
- EnumNameBuiltinOperator(builtin_code), version);
- status = kTfLiteError;
- }
- } else if (!opcode->custom_code()) {
- TF_LITE_REPORT_ERROR(
- error_reporter,
- "Operator with CUSTOM builtin_code has no custom_code.\n");
- status = kTfLiteError;
- } else {
- const char* name = opcode->custom_code()->c_str();
- *registration = op_resolver.FindOp(name, version);
- if (*registration == nullptr) {
- // Do not report error for unresolved custom op, we do the final check
- // while preparing ops.
- status = kTfLiteError;
- }
- }
- return status;
-}
-
-} // namespace tflite
diff --git a/tensorflow/lite/core/api/op_resolver.h b/tensorflow/lite/core/api/op_resolver.h
deleted file mode 100644
index e8a4e32..0000000
--- a/tensorflow/lite/core/api/op_resolver.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_
-#define TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_
-
-#include <functional>
-#include <memory>
-#include <vector>
-
-#include "tensorflow/lite/core/api/error_reporter.h"
-#include "tensorflow/lite/core/c/common.h"
-#include "tensorflow/lite/schema/schema_generated.h"
-
-namespace tflite {
-
-/// Abstract interface that returns TfLiteRegistrations given op codes or custom
-/// op names. This is the mechanism that ops being referenced in the flatbuffer
-/// model are mapped to executable function pointers (TfLiteRegistrations).
-///
-/// The lifetime of the TfLiteRegistration object whose address is
-/// returned by FindOp must exceed the lifetime of any InterpreterBuilder or
-/// Interpreter created with this OpResolver.
-/// Likewise the lifetime of the TfLiteRegistrationExternal object referenced
-/// from the TfLiteRegistration object, if any, must exceed the lifetime of
-/// any InterpreterBuilder or Interpreter created with this OpResolver.
-class OpResolver {
- public:
- /// Finds the op registration for a builtin operator by enum code.
- virtual const TfLiteRegistration* FindOp(tflite::BuiltinOperator op,
- int version) const = 0;
- /// Finds the op registration of a custom operator by op name.
- virtual const TfLiteRegistration* FindOp(const char* op,
- int version) const = 0;
-
- // Represents a sequence of delegates.
- using TfLiteDelegatePtrVector =
- std::vector<std::unique_ptr<TfLiteDelegate, void (*)(TfLiteDelegate*)>>;
-
- // Returns optional delegates for resolving and handling ops in the flatbuffer
- // model. This may be used in addition to the standard TfLiteRegistration
- // lookup for graph resolution.
- // WARNING: This API is deprecated, GetDelegateCreators is preferred.
- virtual TfLiteDelegatePtrVector GetDelegates(int num_threads) const {
- return {};
- }
-
- // Represents a function that creates a TfLite delegate instance.
- using TfLiteDelegateCreator =
- std::function<std::unique_ptr<TfLiteDelegate, void (*)(TfLiteDelegate*)>(
- TfLiteContext* /*context*/)>;
-
- // Represents a sequence of delegate creator functions.
- using TfLiteDelegateCreators = std::vector<TfLiteDelegateCreator>;
-
- // Returns a vector of delegate creators to create optional delegates for
- // resolving and handling ops in the flatbuffer model. This may be used in
- // addition to the standard TfLiteRegistration lookup for graph resolution.
- //
- // Note that this method is not used (will not be called) if you are using
- // TF Lite in Google Play Services; the GetOpaqueDelegateCreators method
- // (see below) is used for that case.
- virtual TfLiteDelegateCreators GetDelegateCreators() const { return {}; }
-
- // TODO(b/202712825): it would be nice if we could avoid the need for separate
- // "opaque" types & methods for use only with TF Lite in Google Play Services.
-
- // Represents an opaque delegate instance.
- // WARNING: Experimental interface, subject to change.
- using TfLiteOpaqueDelegatePtr =
- std::unique_ptr<TfLiteOpaqueDelegate, void (*)(TfLiteOpaqueDelegate*)>;
-
- // Represents a function that creates an opaque delegate instance.
- // WARNING: Experimental interface, subject to change.
- using TfLiteOpaqueDelegateCreator =
- std::function<TfLiteOpaqueDelegatePtr(int /*num_threads*/)>;
-
- // Represents a sequence of opaque delegate creator functions.
- // WARNING: Experimental interface, subject to change.
- using TfLiteOpaqueDelegateCreators = std::vector<TfLiteOpaqueDelegateCreator>;
-
- // Returns a vector of opaque delegate creators to create optional opaque
- // delegates for resolving and handling ops in the flatbuffer model. This may
- // be used in addition to the standard TfLiteRegistration lookup for graph
- // resolution.
- //
- // Note that this method will be called only if you are using TF Lite in
- // Google Play Services; if you are using regular TF Lite, GetDelegateCreators
- // (see above) is used instead.
- //
- // WARNING: Experimental interface, subject to change.
- virtual TfLiteOpaqueDelegateCreators GetOpaqueDelegateCreators() const {
- return {};
- }
-
- virtual ~OpResolver() {}
-
- private:
- /// Returns true if this OpResolver may contain any "user defined" ops.
- /// By "user defined" ops, we mean any op definitions other than those
- /// contained in tflite::ops::builtin::BuiltinOpResolver.
- ///
- /// If this method returns true, it doesn't necessarily mean that the
- /// OpResolver contains a user-defined op, just that the absence of
- /// user-defined ops can't be guaranteed.
- ///
- /// Note that "user-defined" ops are not the same as "custom" ops;
- /// BuiltinOpResolver may support certain "custom" ops, in addition to
- /// "builtin" ops, and may not support all of the "builtin" op enum values.
- virtual bool MayContainUserDefinedOps() const { return true; }
-
- friend class OpResolverInternal;
-};
-
-// Handles the logic for converting between an OperatorCode structure extracted
-// from a flatbuffer and information about a registered operator
-// implementation.
-TfLiteStatus GetRegistrationFromOpCode(const OperatorCode* opcode,
- const OpResolver& op_resolver,
- ErrorReporter* error_reporter,
- const TfLiteRegistration** registration);
-
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_