ONE - On-device Neural Engine
Loading...
Searching...
No Matches
TestHelper.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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
17#ifndef __TEST_HELPER_H__
18#define __TEST_HELPER_H__
19
20#include <loco.h>
21
22#include <tensorflow/core/framework/graph.pb.h>
23
24#define STRING_CONTENT(content) #content
25
26namespace moco
27{
28namespace tf
29{
30namespace test
31{
32
33template <typename T> T *find_first_node_bytype(loco::Graph *g)
34{
35 T *first_node = nullptr;
36 loco::Graph::NodeContext *nodes = g->nodes();
37 uint32_t count = nodes->size();
38
39 for (uint32_t i = 0; i < count; ++i)
40 {
41 first_node = dynamic_cast<T *>(nodes->at(i));
42 if (first_node != nullptr)
43 break;
44 }
45
46 return first_node;
47}
48
49template <typename T> std::vector<T *> find_nodes_bytype(loco::Graph *g)
50{
51 std::vector<T *> find_nodes;
52 loco::Graph::NodeContext *nodes = g->nodes();
53 uint32_t count = nodes->size();
54
55 for (uint32_t i = 0; i < count; ++i)
56 {
57 auto node = dynamic_cast<T *>(nodes->at(i));
58 if (node != nullptr)
59 find_nodes.push_back(node);
60 }
61
62 return find_nodes;
63}
64
70void setup_output_node(loco::Graph *graph, loco::Node *last_node);
71
72} // namespace test
73} // namespace tf
74} // namespace moco
75
76#include <moco/IR/TFNode.h>
77
79
80#include <plier/tf/TestHelper.h>
81
82namespace moco
83{
84namespace tf
85{
86namespace test
87{
88
90{
91public:
93
94public:
95 void inputs(const std::vector<std::string> &names);
96 void output(const char *name);
98
99 void run(tensorflow::NodeDef &node_def, moco::GraphBuilder &graph_builder);
100
101private:
102 std::unique_ptr<moco::SymbolTable> _tensor_names;
103 std::unique_ptr<loco::Graph> _graph;
104
105 std::vector<moco::TFNode *> _inputs;
106 const char *_output{nullptr};
107};
108
109} // namespace test
110} // namespace tf
111} // namespace moco
112
113#endif // __TEST_HELPER_H__
A neural network graph.
Definition Graph.h:161
Logical unit of computation.
Definition Node.h:54
T * at(uint32_t n) const
Access N-th object.
Definition ObjectPool.h:41
uint32_t size(void) const
Return the number of objects.
Definition ObjectPool.h:38
Interface of convert TF NodeDef to loco::Node (e.g., Conv2DGraphBuilder)
void output(const char *name)
void inputs(const std::vector< std::string > &names)
void run(tensorflow::NodeDef &node_def, moco::GraphBuilder &graph_builder)
T * find_first_node_bytype(loco::Graph *g)
Definition TestHelper.h:33
std::vector< T * > find_nodes_bytype(loco::Graph *g)
Definition TestHelper.h:49
void setup_output_node(loco::Graph *graph, loco::Node *last_node)
Append setup output of graph by adding loco::Push node.
Definition Log.h:23