ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleSquaredDifference.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
18
20
21#include <loco.h>
22
23namespace luci
24{
25
27{
28 if (!GraphBuilder::validate(args, 2))
29 return false;
30
31 const auto &inputs = args.op.inputs;
32 const auto &outputs = args.op.outputs;
33 // Inputs must be one of the following types
34 // bfloat16, half(float16), float32, float64, int32, int64, complex64, complex128
35 const auto tensors = args.reader.tensors();
36 const auto tensor = tensors.at(inputs.at(0));
37 assert(tensor != nullptr);
38 switch (tensor->type())
39 {
40 case circle::TensorType_FLOAT16:
41 case circle::TensorType_FLOAT32:
42 case circle::TensorType_FLOAT64:
43 case circle::TensorType_INT32:
44 case circle::TensorType_INT64:
45 case circle::TensorType_COMPLEX64:
46 break;
47 // TODO support bfloat16, complex128
48 // Additional support for quantized tensors
49 case circle::TensorType_UINT8:
50 case circle::TensorType_INT16:
51 break;
52 default:
53 return false;
54 }
55
56 // Input types must match
57 assert(tensors.at(inputs.at(0)) != nullptr && tensors.at(inputs.at(1)) != nullptr);
58 if (tensors.at(inputs.at(0))->type() != tensors.at(inputs.at(1))->type())
59 return false;
60
61 // Input and output types must match
62 assert(tensors.at(outputs[0]) != nullptr);
63 if (tensors.at(inputs.at(0))->type() != tensors.at(outputs[0])->type())
64 return false;
65
66 return true;
67}
68
69CircleNode *CircleSquaredDifferenceGraphBuilder::build_node(const circle::OperatorT &,
70 const std::vector<CircleNode *> &inputs,
71 loco::Graph *graph) const
72{
73 auto *node = graph->nodes()->create<CircleSquaredDifference>();
74 node->x(inputs.at(0));
75 node->y(inputs.at(1));
76
77 return node;
78}
79
80} // namespace luci
A neural network graph.
Definition Graph.h:161
bool validate(const ValidateArgs &args) const final
SQUARED_DIFFERENCE in Circle.
bool validate(const ValidateArgs &args, size_t input_cnt) const