Imported Upstream version 1.18.0
[platform/core/ml/nnfw.git] / compiler / tflchef / core / src / CustomOp / AddV2.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  * Copyright 2015 The TensorFlow Authors. All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *    http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include "AddV2.h"
19
20 #include <flatbuffers/flexbuffers.h>
21
22 flatbuffers::Offset<void> AddV2Chef::value(flatbuffers::FlatBufferBuilder &fbb) const
23 {
24   return flatbuffers::Offset<void>();
25 }
26
27 flatbuffers::Offset<flatbuffers::Vector<uint8_t>>
28 AddV2Chef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const
29 {
30   auto &operation = (*_operation);
31
32   assert(operation.type() == "AddV2");
33
34   /**
35    * REGISTER_OP("AddV2")
36     .Input("x: T")
37     .Input("y: T")
38     .Output("z: T")
39     .Attr(
40         "T: {bfloat16, half, float, double, uint8, int8, int16, int32, int64, "
41         "complex64, complex128}")
42     .SetShapeFn(shape_inference::BroadcastBinaryOpShapeFn)
43     .SetIsAggregate()
44     .SetIsCommutative();
45    */
46
47   auto flex_buffers = std::make_unique<flexbuffers::Builder>();
48   size_t map_start = flex_buffers->StartMap();
49
50   // TODO Support more data types
51   flex_buffers->Int("T", tflite::TensorType_FLOAT32);
52
53   flex_buffers->EndMap(map_start);
54   flex_buffers->Finish();
55
56   auto circle_custom_options = fbb.CreateVector(flex_buffers->GetBuffer());
57   return circle_custom_options;
58 }
59
60 std::unique_ptr<OpChef> AddV2ChefFactory::create(const tflchef::Operation *operation) const
61 {
62   return std::unique_ptr<OpChef>{new AddV2Chef{operation}};
63 }