• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 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 
16 #include "tensorflow_lite_support/cc/port/default/tflite_wrapper.h"
17 
18 #include "absl/status/status.h"
19 #include "tensorflow_lite_support/cc/port/status_macros.h"
20 
21 namespace tflite {
22 namespace support {
23 
InitializeWithFallback(std::function<absl::Status (std::unique_ptr<tflite::Interpreter> *)> interpreter_initializer,const tflite::proto::ComputeSettings & compute_settings)24 absl::Status TfLiteInterpreterWrapper::InitializeWithFallback(
25     std::function<absl::Status(std::unique_ptr<tflite::Interpreter>*)>
26         interpreter_initializer,
27     const tflite::proto::ComputeSettings& compute_settings) {
28   if (compute_settings.has_preference() ||
29       compute_settings.has_tflite_settings()) {
30     return absl::UnimplementedError(
31         "Acceleration via ComputeSettings is not supported yet.");
32   }
33   RETURN_IF_ERROR(interpreter_initializer(&interpreter_));
34   return interpreter_->AllocateTensors() != kTfLiteOk
35              ? absl::InternalError(
36                    "TFLite interpreter: AllocateTensors() failed.")
37              : absl::OkStatus();
38 }
39 
InvokeWithFallback(const std::function<absl::Status (tflite::Interpreter * interpreter)> & set_inputs)40 absl::Status TfLiteInterpreterWrapper::InvokeWithFallback(
41     const std::function<absl::Status(tflite::Interpreter* interpreter)>&
42         set_inputs) {
43   RETURN_IF_ERROR(set_inputs(interpreter_.get()));
44   return interpreter_->Invoke() != kTfLiteOk
45              ? absl::InternalError("TFLite interpreter: Invoke() failed.")
46              : absl::OkStatus();
47 }
48 
InvokeWithoutFallback()49 absl::Status TfLiteInterpreterWrapper::InvokeWithoutFallback() {
50   return interpreter_->Invoke() != kTfLiteOk
51              ? absl::InternalError("TFLite interpreter: Invoke() failed.")
52              : absl::OkStatus();
53 }
54 
Cancel()55 void TfLiteInterpreterWrapper::Cancel() {
56   // NOP
57 }
58 
59 }  // namespace support
60 }  // namespace tflite
61