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