1 /* Copyright 2019 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 #include "tensorflow/lite/delegates/hexagon/builders/neg_op_builder.h"
16
17 #include <limits>
18
19 namespace tflite {
20 namespace delegates {
21 namespace hexagon {
PopulateSubGraph(const TfLiteIntArray * inputs,const TfLiteIntArray * outputs,TfLiteContext * context)22 TfLiteStatus NegOpBuilder::PopulateSubGraph(const TfLiteIntArray* inputs,
23 const TfLiteIntArray* outputs,
24 TfLiteContext* context) {
25 // Input data tensor.
26 int tensor_id = inputs->data[0];
27 const auto& input_tensor = context->tensors[tensor_id];
28 AddInput(graph_builder_->GetHexagonTensorId(tensor_id));
29 TF_LITE_ENSURE_STATUS(ComputeAndAddMinAndMax(context, input_tensor));
30
31 // Hexagon outputs for this node.
32 int output_batch_size, output_height_size, output_width_size,
33 output_depth_size;
34 GetDims(&output_batch_size, &output_height_size, &output_width_size,
35 &output_depth_size, context->tensors[outputs->data[0]].dims);
36 node_output_ = AddOutput(sizeof(uint8_t), 4,
37 {output_batch_size, output_height_size,
38 output_width_size, output_depth_size});
39 AddOutput(sizeof(float), 4, kScalarShape);
40 AddOutput(sizeof(float), 4, kScalarShape);
41
42 return kTfLiteOk;
43 }
44
RegisterOutputs(const TfLiteIntArray * outputs,TfLiteContext * context)45 TfLiteStatus NegOpBuilder::RegisterOutputs(const TfLiteIntArray* outputs,
46 TfLiteContext* context) {
47 // Should be only 1 output.
48 graph_builder_->AddTensorWithID(outputs->data[0], node_output_.first,
49 node_output_.second);
50
51 return kTfLiteOk;
52 }
53
CreateNegOpBuilder(GraphBuilder * graph_builder,int op_type)54 OpBuilder* CreateNegOpBuilder(GraphBuilder* graph_builder, int op_type) {
55 return new NegOpBuilder(graph_builder, op_type);
56 }
57
58 } // namespace hexagon
59 } // namespace delegates
60 } // namespace tflite
61