diff options
author | Pete Warden <petewarden@google.com> | 2018-09-07 17:36:59 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2018-09-07 17:40:10 -0700 |
commit | 9982fd6c8831cbd2f58954f79ea71f26660393bc (patch) | |
tree | 108907bde953d0d70ee5d3b8323a99bb9b681563 /tensorflow/contrib/lite/mutable_op_resolver.cc | |
parent | edda5e39e4e93ba60e4d31b6ecb1c295dead29c8 (diff) |
Modularize TF Lite interface definitions and reorganize file structure
PiperOrigin-RevId: 212064501
Diffstat (limited to 'tensorflow/contrib/lite/mutable_op_resolver.cc')
-rw-r--r-- | tensorflow/contrib/lite/mutable_op_resolver.cc | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tensorflow/contrib/lite/mutable_op_resolver.cc b/tensorflow/contrib/lite/mutable_op_resolver.cc new file mode 100644 index 0000000000..8ee63d2a02 --- /dev/null +++ b/tensorflow/contrib/lite/mutable_op_resolver.cc @@ -0,0 +1,56 @@ +/* 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/contrib/lite/mutable_op_resolver.h" + +namespace tflite { + +const TfLiteRegistration* MutableOpResolver::FindOp(tflite::BuiltinOperator op, + int version) const { + auto it = builtins_.find(std::make_pair(op, version)); + return it != builtins_.end() ? &it->second : nullptr; +} + +const TfLiteRegistration* MutableOpResolver::FindOp(const char* op, + int version) const { + auto it = custom_ops_.find(std::make_pair(op, version)); + return it != custom_ops_.end() ? &it->second : nullptr; +} + +void MutableOpResolver::AddBuiltin(tflite::BuiltinOperator op, + TfLiteRegistration* registration, + int min_version, int max_version) { + for (int version = min_version; version <= max_version; ++version) { + TfLiteRegistration new_registration = *registration; + new_registration.builtin_code = op; + new_registration.version = version; + auto op_key = std::make_pair(op, version); + builtins_[op_key] = new_registration; + } +} + +void MutableOpResolver::AddCustom(const char* name, + TfLiteRegistration* registration, + int min_version, int max_version) { + for (int version = min_version; version <= max_version; ++version) { + TfLiteRegistration new_registration = *registration; + new_registration.builtin_code = BuiltinOperator_CUSTOM; + new_registration.version = version; + auto op_key = std::make_pair(name, version); + custom_ops_[op_key] = new_registration; + } +} + +} // namespace tflite |