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/delegates/gpu/common/custom_parsers.h"
17
18 #include <cstdint>
19 #include <memory>
20 #include <string>
21
22 #include "absl/memory/memory.h"
23 #include "absl/strings/str_cat.h"
24 #include "absl/strings/string_view.h"
25 #include "absl/types/any.h"
26 #include "tensorflow/lite/delegates/gpu/common/operation_parser.h"
27 #include "tensorflow/lite/delegates/gpu/common/shape.h"
28 #include "tensorflow/lite/delegates/gpu/common/status.h"
29
30 namespace tflite {
31 namespace gpu {
32 namespace {
33
34 class UnimplementedCustomOperationParser : public TFLiteOperationParser {
35 public:
UnimplementedCustomOperationParser(absl::string_view op_name)36 explicit UnimplementedCustomOperationParser(absl::string_view op_name)
37 : op_name_(op_name) {}
38
IsSupported(const TfLiteContext * context,const TfLiteNode * tflite_node,const TfLiteRegistration * registration)39 absl::Status IsSupported(const TfLiteContext* context,
40 const TfLiteNode* tflite_node,
41 const TfLiteRegistration* registration) final {
42 return absl::UnimplementedError(op_name_);
43 }
44
Parse(const TfLiteNode * tflite_node,const TfLiteRegistration * registration,GraphFloat32 * graph,ObjectReader * reader)45 absl::Status Parse(const TfLiteNode* tflite_node,
46 const TfLiteRegistration* registration,
47 GraphFloat32* graph, ObjectReader* reader) final {
48 return absl::UnimplementedError(op_name_);
49 }
50
51 private:
52 std::string op_name_;
53 };
54
55 } // namespace
56
NewCustomOperationParser(absl::string_view op_name)57 std::unique_ptr<TFLiteOperationParser> NewCustomOperationParser(
58 absl::string_view op_name) {
59 return absl::make_unique<UnimplementedCustomOperationParser>(op_name);
60 }
61
ParseCustomAttributes(absl::string_view op_name,int version,const void * data,uint32_t data_size,absl::any * attr,BHWC * output_shape)62 absl::Status ParseCustomAttributes(absl::string_view op_name, int version,
63 const void* data, uint32_t data_size,
64 absl::any* attr, BHWC* output_shape) {
65 return absl::UnimplementedError(absl::StrCat(
66 "Attributes parsing is not enabled for ", op_name, " operation."));
67 }
68
69 } // namespace gpu
70 } // namespace tflite
71