ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Convert.cpp
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#include "Convert.h"
18
19#include "Conversions.h"
22#include "ProgressReporter.h"
23#include "Knob.h"
24
25#include <loco.h>
29
33
34#include <logo/Phase.h>
35#include <memory>
36
37namespace exo
38{
39
41{
42 // run Shape and Type inference must be run before conversion
44 loco::apply(&shape_rule).to(graph);
45
47 loco::apply(&type_rule).to(graph);
48
49 logo::Phase phase;
50 {
51 // prepare type and shape before conversion
52 phase.emplace_back(std::make_unique<TypeInferencePass>());
53 phase.emplace_back(std::make_unique<ShapeInferencePass>());
54
55 // Add converters for canonical nodes. Note: Not all loco canonical nodes are listed.
56 phase.emplace_back(std::make_unique<AvgPool2DConverter>());
57 phase.emplace_back(std::make_unique<ConstGenConverter>());
58 phase.emplace_back(std::make_unique<Conv2DConverter>());
59 phase.emplace_back(std::make_unique<DepthwiseConv2DConverter>());
60 // TODO loco::DepthwiseFilterEncode
61 phase.emplace_back(std::make_unique<EltwiseAddConverter>());
62 phase.emplace_back(std::make_unique<EltwiseDivConverter>());
63 phase.emplace_back(std::make_unique<EltwiseMaxConverter>());
64 phase.emplace_back(std::make_unique<EltwiseMulConverter>());
65 phase.emplace_back(std::make_unique<EltwiseSqrtConverter>());
66 phase.emplace_back(std::make_unique<EltwiseSubConverter>());
67 phase.emplace_back(std::make_unique<FeatureBiasAddConverter>());
68 // TODO loco::FixedReshape
69 phase.emplace_back(std::make_unique<MatMulConverter>());
70 phase.emplace_back(std::make_unique<MaxPool2DConverter>());
71 phase.emplace_back(std::make_unique<ReluConverter>());
72 phase.emplace_back(std::make_unique<Relu6Converter>());
73 // TODO loco::Tanh
74 phase.emplace_back(std::make_unique<TensorConcatConverter>());
75 // TODO loco::TensorBiasAdd
76 phase.emplace_back(std::make_unique<TensorBroadcastConverter>());
77 phase.emplace_back(std::make_unique<TensorReduceConverter>());
78 // TODO loco::TensorSoftmax
79 phase.emplace_back(std::make_unique<TensorTransposeConverter>());
80 phase.emplace_back(std::make_unique<TransposedConv2DConverter>());
81
82 // Add optimization below
83 phase.emplace_back(std::make_unique<logo::SimplifyDomainConversionPass>());
84 phase.emplace_back(std::make_unique<logo::RemoveForwardNodePass>());
85 phase.emplace_back(std::make_unique<logo::RemoveDeadNodePass>());
86 }
87
89
91 phase_runner.attach(&prog);
92 phase_runner.run(phase);
93
94 // TODO Assert if all canonical nodes are converted to TFL node
95}
96
97} // namespace exo
A neural network graph.
Definition Graph.h:161
void convert_to_TFLNodes(loco::Graph *graph)
Definition Convert.cpp:40
ShapeInferenceSession apply(ShapeInferenceRule *r)
std::vector< std::unique_ptr< Pass > > Phase
Definition Phase.h:31
Shape inference rule for canonical dialect.
Type Inference Rule for Canonical Dialect.