ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Maximum.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
23#include <memory>
24
25namespace
26{
27
28using namespace moco;
29
33class TFMaximumGraphUpdate final : public GraphUpdate
34{
35public:
36 TFMaximumGraphUpdate(TFMaximum *node, std::vector<TensorName> names) : _node(node), _names(names)
37 {
38 }
39
40 void input(const SymbolTable *) const override;
41
42private:
43 TFMaximum *_node;
44 std::vector<TensorName> _names;
45};
46
47void TFMaximumGraphUpdate::input(const SymbolTable *tensor_names) const
48{
49 assert(_names.size() == 2);
50
51 _node->x(tensor_names->node(_names[0]));
52 _node->y(tensor_names->node(_names[1]));
53}
54
55} // namespace
56
57namespace moco
58{
59
60bool MaximumGraphBuilder::validate(const tensorflow::NodeDef &node) const
61{
62 return node.input_size() == 2;
63}
64
65void MaximumGraphBuilder::build(const tensorflow::NodeDef &node, GraphBuilderContext *context) const
66{
67 assert(context != nullptr);
68
69 loco::Graph *graph = context->graph();
70 SymbolTable *tensor_names = context->tensor_names();
71 UpdateQueue *updates = context->updates();
72
73 // creating TF dialect Maximum node
74 auto tf_maximum = graph->nodes()->create<TFMaximum>();
75 tf_maximum->name(node.name());
76
77 TensorName output_name(node.name(), 0);
78 tensor_names->enroll(output_name, tf_maximum);
79
80 std::vector<TensorName> add_input_names;
81 add_input_names.push_back(TensorName(node.input(0))); // x
82 add_input_names.push_back(TensorName(node.input(1))); // y
83
84 auto tf_maximum_update = std::make_unique<TFMaximumGraphUpdate>(tf_maximum, add_input_names);
85 updates->enroll(std::move(tf_maximum_update));
86}
87
88} // namespace moco
A neural network graph.
Definition Graph.h:161
Class to store context to build loco graph IR from TensorFlow.
Interface to connect the graph.
virtual void input(const SymbolTable *) const =0
Do the graph input connections using the SymbolTable.
void build(const tensorflow::NodeDef &, GraphBuilderContext *) const override
Definition Maximum.cpp:65
bool validate(const tensorflow::NodeDef &) const override
Definition Maximum.cpp:60
Class to store and query loco::Node* with string name key.
void enroll(const TensorName &tensor_name, loco::Node *node)
Registers a name with corresponding loco::Node *.
loco::Node * node(const TensorName &tensor_name) const
Queries enrolled(registered) with name and return node if found Will throw runtime_error if not found...
Class to store GraphUpdate objects.
void enroll(std::unique_ptr< GraphUpdate > &&update)
Registers GraphUpdate objects.
Definition Log.h:23
NodeName name(void) const
Definition TFNodeDecl.h:50