ONE - On-device Neural Engine
Loading...
Searching...
No Matches
exo Namespace Reference

Namespaces

namespace  circle_detail
 
namespace  test
 
namespace  tflite_detail
 

Data Structures

class  AvgPool2DConverter
 Convert loco::AvgPool2D to locoex::TFLAveragePool2D. More...
 
class  CanonicalNodeConverter
 Class to convert a canonical node to TFL node. More...
 
class  CircleExporter
 
class  ConstGenConverter
 
class  Conv2DConverter
 Convert loco::Conv2D to locoex::TFLConv2D. More...
 
class  DepthwiseConv2DConverter
 Convert loco::DepthwiseConv2D to locoex::TFLDepthwiseConv2D and auxiliary. More...
 
class  DomainConverter
 Class to handle domain conversion while converting a canonical node to TFL node(s) More...
 
class  EltwiseAddConverter
 Convert loco::EltwiseAdd to TFLAdd. More...
 
class  EltwiseDivConverter
 Convert loco::EltwiseDiv to TFLDiv. More...
 
class  EltwiseMaxConverter
 Convert loco::EltwiseMax to TFLMaximum. More...
 
class  EltwiseMulConverter
 Convert loco::EltwiseMul to TFLMul. More...
 
class  EltwiseSqrtConverter
 Convert loco::EltwiseSqrt to TFLSqrt. More...
 
class  EltwiseSubConverter
 Convert loco::EltwiseSub to TFLSub. More...
 
class  FeatureBiasAddConverter
 
struct  FoldReshapeOfConstPass
 Class to fuse TFLReshape + TFLConst into one equivalent TFLConst. More...
 
struct  FoldTransposeOfConstPass
 Class to fuse TFLTranspose + TFLConst into one equivalent TFLConst. More...
 
struct  FuseBiasAddPass
 Class to fuse TFLAdd or TFLSub into Bias input of the following ops: More...
 
struct  FuseInstanceNormPass
 Class to fuse certain pattern of subgraph into CircleInstanceNorm with auxiliary nodes. More...
 
struct  FuseReluPass
 Class to fuse TFLRelu or TFLRelu6 into the TensorFlow Lite ops below: More...
 
struct  FuseRsqrtPass
 Class to fuse TFLSqrt that is divided(TFLDiv) by 1, into TFLRsqrt. More...
 
struct  FuseSquaredDifferencePass
 Class to fuse SquaredDifference pattern. More...
 
class  InputHandler
 Handles input(s) while converting a canonical node to TFL node(s). This class informs DomainConverter how to handle inputs of a specific canonical node. More...
 
struct  KnobTrait
 
class  Logger
 Logger Implementation. More...
 
class  LoggerConfig
 Logger Configuration. More...
 
struct  LoggingContext
 Global logging context. More...
 
class  MatMulConverter
 Convert loco::MatMul to locoex::TFLFullyConnected. More...
 
class  MaxPool2DConverter
 Convert loco::MaxPool2D to locoex::TFLMaxPool2D. More...
 
class  MergeConcatNodesPass
 Merge concat nodes whose axis and fusedActivationFunction are same. More...
 
class  NodeSummaryBuilder
 
class  NodeSummaryBuilderFactory
 
class  ProgressReporter
 
class  Relu6Converter
 Convert loco::Relu6 to TFLRelu6. More...
 
class  ReluConverter
 Convert loco::Relu to TFLRelu. More...
 
struct  ShapeDescription
 
struct  ShapeInference
 Get the shape of each node as a node annotation. More...
 
class  ShapeInferencePass
 Pass to infer shape of nodes. More...
 
class  TensorBroadcastConverter
 Pass to resolve TensorBroadcast IR. More...
 
class  TensorConcatConverter
 Convert loco::TensorConcat to TFLConcatenate. More...
 
class  TensorReduceConverter
 Convert loco::TensorReduce to appropriate TFL reduce operation. More...
 
class  TensorTransposeConverter
 Convert loco::TensorTranspose to locoex::TFLTranspose. More...
 
class  TFLExporter
 
class  TransposedConv2DConverter
 Convert loco::TransposedConv2D to locoex::TFLTransposeConv and auxiliary. More...
 
struct  TypeInference
 Get the type of each node as NodeAnnotation. More...
 
class  TypeInferencePass
 Pass to infer type of nodes. More...
 

Typedefs

using FormattedGraph = locop::FormattedGraphImpl< locop::Formatter::LinearV1 >
 

Enumerations

enum class  FeatureLayout { NHWC }
 feature layout of TFLITE file More...
 
enum class  FilterLayout { OHWI , HWIO }
 
enum class  DepthwiseFilterLayout { HWCM }
 
enum class  MatrixLayout { HW , WH }
 
enum class  Dialect { TFLITE , CIRCLE }
 
enum class  Knob { KNOB_BOOL }
 

Functions

circle::ActivationFunctionType to_circle_actfunc (locoex::FusedActFunc func)
 
template<class ELTWISEBIN , class TFLBIN >
bool EltwiseBinaryConvert (ELTWISEBIN *origin)
 
void convert_to_TFLNodes (loco::Graph *graph)
 
void optimize (loco::Graph *)
 Run passes for a graph after completion of converting canonical nodes into TFL nodes.
 
ShapeDescription to_shape_description (const loco::TensorShape &shape)
 
ShapeDescription to_shape_description (const loco::FeatureShape &shape)
 
ShapeDescription to_shape_description (const loco::FilterShape &shape)
 
ShapeDescription to_shape_description (const loco::DepthwiseFilterShape &shape)
 
ShapeDescription to_shape_description (const loco::BiasShape &shape)
 
ShapeDescription to_shape_description (const loco::MatrixShape &shape)
 
ShapeDescription to_shape_description (const loco::NodeShape &shape)
 
template<typename Permutation >
bool isNHWC (Permutation *perm)
 
template<>
bool isNHWC (loco::Permutation< loco::Domain::Feature > *perm)
 
template<>
bool isNHWC (loco::Permutation< loco::Domain::Filter > *perm)
 
template<FeatureLayout T>
loco::FeatureEncodemake_feature_encode (loco::Node *input_for_encode)
 Creates a loco::FeatureEncode with T layout (NHWC for tflite) and add it to graph.
 
template<FeatureLayout T>
loco::FeatureDecodemake_feature_decode (loco::Node *input_for_decode)
 Creates a loco::FeatureDecode with T layout (NHWC for tflite) and add it to graph.
 
template<FilterLayout T>
loco::FilterEncodemake_filter_encode (loco::Node *input_for_encode)
 Create a loco::FilterEncode of given layout.
 
template<FilterLayout T>
loco::FilterDecodemake_filter_decode (loco::Node *input_for_decode)
 Create a loco::FilterDecode of given layout.
 
template<DepthwiseFilterLayout T>
loco::DepthwiseFilterDecodemake_dw_filter_decode (loco::Node *input_for_decode)
 Create a loco::DepthwiseFilterDecode of given layout.
 
template<MatrixLayout T>
loco::MatrixEncodemake_matrix_encode (loco::Node *input_for_encode)
 Create a loco::MatrixEncode of given layout.
 
template<MatrixLayout T>
loco::MatrixDecodemake_matrix_decode (loco::Node *input_for_decode)
 Create a loco::MatrixDecode of given layout.
 
template loco::FeatureEncodemake_feature_encode< FeatureLayout::NHWC > (loco::Node *input_for_encode)
 
template loco::FeatureDecodemake_feature_decode< FeatureLayout::NHWC > (loco::Node *input_for_encode)
 
template loco::FilterEncodemake_filter_encode< FilterLayout::HWIO > (loco::Node *input_for_encode)
 
template loco::FilterDecodemake_filter_decode< FilterLayout::OHWI > (loco::Node *input_for_decode)
 
template loco::DepthwiseFilterDecodemake_dw_filter_decode< DepthwiseFilterLayout::HWCM > (loco::Node *input_for_decode)
 
template loco::MatrixEncodemake_matrix_encode< MatrixLayout::HW > (loco::Node *input_for_encode)
 
template loco::MatrixEncodemake_matrix_encode< MatrixLayout::WH > (loco::Node *input_for_encode)
 
template loco::MatrixDecodemake_matrix_decode< MatrixLayout::HW > (loco::Node *input_for_decode)
 
template loco::MatrixDecodemake_matrix_decode< MatrixLayout::WH > (loco::Node *input_for_decode)
 
void set (Dialect d)
 
template<Knob K>
KnobTrait< K >::ValueType get (void)
 
FormattedGraph fmt (loco::Graph *g)
 
tflite::ActivationFunctionType to_tflite_actfunc (locoex::FusedActFunc func)
 

Detailed Description

Some canonical nodes can have input of various loco::Domain, e.g., loco::Domain::Tensor, loco::Domain::Feature, etc. However, TFL node accepts only loco::Domain::Tensor. So, When converting such canonical node to TFL node and input(s) of a canonical node are not loco::Domain::Tensor, additional nodes need to be inserted.

The following two classes helps this insertion.

For example, in case of loco::Relu conversion,

Before:

A (output: feature) – loco::ReLU — B (input:feature)

After:

A – loco::FeatureDecode – locoex::TFLRelu – loco::FeatureEncode — B

          loco::ReLU (dead node)

Typedef Documentation

◆ FormattedGraph

Enumeration Type Documentation

◆ DepthwiseFilterLayout

enum class exo::DepthwiseFilterLayout
strong
Enumerator
HWCM 

Definition at line 54 of file GraphBlock.h.

◆ Dialect

enum class exo::Dialect
strong
Enumerator
TFLITE 
CIRCLE 

Definition at line 23 of file Knob.h.

24{
25 TFLITE,
26 CIRCLE
27};

◆ FeatureLayout

enum class exo::FeatureLayout
strong

feature layout of TFLITE file

Enumerator
NHWC 

Definition at line 31 of file GraphBlock.h.

32{
33 NHWC,
34};

◆ FilterLayout

enum class exo::FilterLayout
strong
Enumerator
OHWI 
HWIO 

Definition at line 42 of file GraphBlock.h.

43{
44 OHWI, // a.k.a., NHWC, Tensorflow Lite uses this layout for filter
45 HWIO, // a.k.a., HWCN, Tensorflow uses this layout for filter
46};

◆ Knob

enum class exo::Knob
strong
Enumerator
KNOB_BOOL 

Definition at line 29 of file Knob.h.

30{
31#define KNOB_BOOL(NAME, TFL_DEFAULT, CIRCLE_DEFAULT, DESC) NAME,
32#include "Knob.lst"
33#undef KNOB_BOOL
34};

◆ MatrixLayout

enum class exo::MatrixLayout
strong
Enumerator
HW 
WH 

Definition at line 63 of file GraphBlock.h.

Function Documentation

◆ convert_to_TFLNodes()

void exo::convert_to_TFLNodes ( loco::Graph graph)

Definition at line 40 of file Convert.cpp.

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
90 ProgressReporter prog(graph, logo::PhaseStrategy::Restart);
91 phase_runner.attach(&prog);
92 phase_runner.run(phase);
93
94 // TODO Assert if all canonical nodes are converted to TFL node
95}
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.

References loco::apply(), logo::Restart, and loco::ShapeInferenceSession::to().

◆ EltwiseBinaryConvert()

template<class ELTWISEBIN , class TFLBIN >
bool exo::EltwiseBinaryConvert ( ELTWISEBIN *  origin)

Definition at line 93 of file EltwiseBinaryConverter.h.

94{
95 EltwiseBinInputHandler<ELTWISEBIN, TFLBIN> input_handler;
97
98 auto tfl_node = domain_converter.template convert<FeatureLayout::NHWC>(origin, input_handler);
99
100 if (tfl_node == nullptr)
101 return false;
102
103 init_fused_act_func(tfl_node);
104
105 return true;
106}
Class to handle domain conversion while converting a canonical node to TFL node(s)
Definition GraphBlock.h:135

◆ fmt()

FormattedGraph exo::fmt ( loco::Graph g)

Definition at line 73 of file LogHelper.cpp.

74{
75 auto node_summary_builder = std::make_unique<NodeSummaryBuilderFactory>();
76 return std::move(locop::fmt<locop::LinearV1>(g).with(std::move(node_summary_builder)));
77}

Referenced by exo::ProgressReporter::notify(), and exo::ProgressReporter::notify().

◆ get()

template<Knob K>
KnobTrait< K >::ValueType exo::get ( void  )

◆ isNHWC() [1/3]

template<>
bool exo::isNHWC ( loco::Permutation< loco::Domain::Feature > *  perm)
inline

Definition at line 43 of file ExporterUtils.h.

44{
45 return perm->axis(loco::FeatureAxis::Count) == 0 && perm->axis(loco::FeatureAxis::Height) == 1 &&
46 perm->axis(loco::FeatureAxis::Width) == 2 && perm->axis(loco::FeatureAxis::Depth) == 3;
47}

References loco::Count, loco::Depth, loco::Height, and loco::Width.

◆ isNHWC() [2/3]

template<>
bool exo::isNHWC ( loco::Permutation< loco::Domain::Filter > *  perm)
inline

Definition at line 49 of file ExporterUtils.h.

50{
51 return perm->axis(loco::FilterAxis::Count) == 0 && perm->axis(loco::FilterAxis::Height) == 1 &&
52 perm->axis(loco::FilterAxis::Width) == 2 && perm->axis(loco::FilterAxis::Depth) == 3;
53}

References loco::Count, loco::Depth, loco::Height, and loco::Width.

◆ isNHWC() [3/3]

template<typename Permutation >
bool exo::isNHWC ( Permutation *  perm)
inline

◆ make_dw_filter_decode()

template<DepthwiseFilterLayout T>
loco::DepthwiseFilterDecode * exo::make_dw_filter_decode ( loco::Node input_for_decode)

Create a loco::DepthwiseFilterDecode of given layout.

Definition at line 177 of file GraphBlock.cpp.

178{
179 EXO_ASSERT(input_for_decode != nullptr, "filter should not be nullptr");
180 loco::Graph *g = input_for_decode->graph();
181
182 auto decoder = std::make_unique<loco::PermutingDecoder<loco::Domain::DepthwiseFilter>>();
183
184 decoder->perm(perm<T>());
185
186 auto dec = g->nodes()->create<loco::DepthwiseFilterDecode>();
187 dec->input(input_for_decode);
188 dec->decoder(std::move(decoder));
189
190 return dec;
191}
Create a tensor from a depthwise filter.
Definition Nodes.h:475
Node * input(void) const
Definition Nodes.h:477
A neural network graph.
Definition Graph.h:161
Graph * graph(void)
Definition Node.h:70
#define EXO_ASSERT(condition, msg)
Definition Check.h:28

References EXO_ASSERT, loco::Node::graph(), and loco::DepthwiseFilterDecode::input().

◆ make_dw_filter_decode< DepthwiseFilterLayout::HWCM >()

◆ make_feature_decode()

template<FeatureLayout T>
loco::FeatureDecode * exo::make_feature_decode ( loco::Node input_for_decode)

Creates a loco::FeatureDecode with T layout (NHWC for tflite) and add it to graph.

Definition at line 128 of file GraphBlock.cpp.

129{
130 EXO_ASSERT(input_for_decode != nullptr, "input should not be nullptr");
131 loco::Graph *g = input_for_decode->graph();
132
133 auto decoder = std::make_unique<loco::PermutingDecoder<loco::Domain::Feature>>();
134
135 decoder->perm(perm<T>());
136
137 auto dec = g->nodes()->create<loco::FeatureDecode>();
138 dec->input(input_for_decode);
139 dec->decoder(std::move(decoder));
140
141 return dec;
142}
Create a tensor from a feature map.
Definition Nodes.h:399
Node * input(void) const
Definition Nodes.h:401

References EXO_ASSERT, loco::Node::graph(), and loco::FeatureDecode::input().

◆ make_feature_decode< FeatureLayout::NHWC >()

◆ make_feature_encode()

template<FeatureLayout T>
loco::FeatureEncode * exo::make_feature_encode ( loco::Node input_for_encode)

Creates a loco::FeatureEncode with T layout (NHWC for tflite) and add it to graph.

Definition at line 112 of file GraphBlock.cpp.

113{
114 EXO_ASSERT(input_for_encode != nullptr, "input should not be nullptr");
115 loco::Graph *g = input_for_encode->graph();
116
117 auto encoder = std::make_unique<loco::PermutingEncoder<loco::Domain::Feature>>();
118
119 encoder->perm(perm<T>());
120
121 auto enc = g->nodes()->create<loco::FeatureEncode>();
122 enc->input(input_for_encode);
123 enc->encoder(std::move(encoder));
124
125 return enc;
126}
Create a feature map from a tensor.
Definition Nodes.h:380
Node * input(void) const
Definition Nodes.h:382

References EXO_ASSERT, loco::Node::graph(), and loco::FeatureEncode::input().

◆ make_feature_encode< FeatureLayout::NHWC >()

◆ make_filter_decode()

template<FilterLayout T>
loco::FilterDecode * exo::make_filter_decode ( loco::Node input_for_decode)

Create a loco::FilterDecode of given layout.

Definition at line 160 of file GraphBlock.cpp.

161{
162 EXO_ASSERT(input_for_decode != nullptr, "filter should not be nullptr");
163 loco::Graph *g = input_for_decode->graph();
164
165 auto decoder = std::make_unique<loco::PermutingDecoder<loco::Domain::Filter>>();
166
167 decoder->perm(perm<T>());
168
169 auto dec = g->nodes()->create<loco::FilterDecode>();
170 dec->input(input_for_decode);
171 dec->decoder(std::move(decoder));
172
173 return dec;
174}
Create a tensor from a filter.
Definition Nodes.h:437
Node * input(void) const
Definition Nodes.h:439

References EXO_ASSERT, loco::Node::graph(), and loco::FilterDecode::input().

◆ make_filter_decode< FilterLayout::OHWI >()

◆ make_filter_encode()

template<FilterLayout T>
loco::FilterEncode * exo::make_filter_encode ( loco::Node input_for_encode)

Create a loco::FilterEncode of given layout.

Definition at line 144 of file GraphBlock.cpp.

145{
146 EXO_ASSERT(input_for_encode != nullptr, "filter should not be nullptr");
147 loco::Graph *g = input_for_encode->graph();
148
149 auto encoder = std::make_unique<loco::PermutingEncoder<loco::Domain::Filter>>();
150
151 encoder->perm(perm<T>());
152
153 auto enc = g->nodes()->create<loco::FilterEncode>();
154 enc->input(input_for_encode);
155 enc->encoder(std::move(encoder));
156
157 return enc;
158}
Create a filter from a tensor.
Definition Nodes.h:418
Node * input(void) const
Definition Nodes.h:420

References EXO_ASSERT, loco::Node::graph(), and loco::FilterEncode::input().

◆ make_filter_encode< FilterLayout::HWIO >()

◆ make_matrix_decode()

template<MatrixLayout T>
loco::MatrixDecode * exo::make_matrix_decode ( loco::Node input_for_decode)

Create a loco::MatrixDecode of given layout.

Definition at line 209 of file GraphBlock.cpp.

210{
211 EXO_ASSERT(input_for_decode != nullptr, "input should not be nullptr");
212 loco::Graph *g = input_for_decode->graph();
213
214 auto decoder = std::make_unique<loco::PermutingDecoder<loco::Domain::Matrix>>();
215
216 decoder->perm(perm<T>());
217
218 auto dec = g->nodes()->create<loco::MatrixDecode>();
219 dec->input(input_for_decode);
220 dec->decoder(std::move(decoder));
221
222 return dec;
223}
Create Tensor from Matrix.
Definition Nodes.h:1042
Node * input(void) const
Definition Nodes.h:1047

References EXO_ASSERT, loco::Node::graph(), and loco::MatrixDecode::input().

◆ make_matrix_decode< MatrixLayout::HW >()

◆ make_matrix_decode< MatrixLayout::WH >()

◆ make_matrix_encode()

template<MatrixLayout T>
loco::MatrixEncode * exo::make_matrix_encode ( loco::Node input_for_encode)

Create a loco::MatrixEncode of given layout.

Definition at line 193 of file GraphBlock.cpp.

194{
195 EXO_ASSERT(input_for_encode != nullptr, "input should not be nullptr");
196 loco::Graph *g = input_for_encode->graph();
197
198 auto encoder = std::make_unique<loco::PermutingEncoder<loco::Domain::Matrix>>();
199
200 encoder->perm(perm<T>());
201
202 auto enc = g->nodes()->create<loco::MatrixEncode>();
203 enc->input(input_for_encode);
204 enc->encoder(std::move(encoder));
205
206 return enc;
207}
Create Matrix from Tensor.
Definition Nodes.h:1018
Node * input(void) const
Definition Nodes.h:1023

References EXO_ASSERT, loco::Node::graph(), and loco::MatrixEncode::input().

◆ make_matrix_encode< MatrixLayout::HW >()

◆ make_matrix_encode< MatrixLayout::WH >()

◆ optimize()

void exo::optimize ( loco::Graph )

Run passes for a graph after completion of converting canonical nodes into TFL nodes.

TODO Separate optimize pass dedicated to TFL and Circle dialect when necessary

Definition at line 30 of file ExoOptimize.cpp.

31{
32 logo::Phase phase;
33 {
34 // prepare type and shape before optimization
35 phase.emplace_back(std::make_unique<TypeInferencePass>());
36 phase.emplace_back(std::make_unique<ShapeInferencePass>());
37
38 phase.emplace_back(std::make_unique<FoldReshapeOfConstPass>());
39 phase.emplace_back(std::make_unique<FoldTransposeOfConstPass>());
40
41 if (get<Knob::UseFuseBiasAddPass>())
42 {
43 phase.emplace_back(std::make_unique<FuseBiasAddPass>());
44 }
45
46 if (get<Knob::UseFuseInstanceNormPass>())
47 {
48 phase.emplace_back(std::make_unique<FuseInstanceNormPass>());
49 }
50
51 if (get<Knob::UseFuseReluPass>())
52 {
53 phase.emplace_back(std::make_unique<FuseReluPass>());
54 }
55 phase.emplace_back(std::make_unique<FuseRsqrtPass>());
56
57 if (get<Knob::UseFuseSquaredDifferencePass>())
58 {
59 phase.emplace_back(std::make_unique<FuseSquaredDifferencePass>());
60 }
61
62 phase.emplace_back(std::make_unique<MergeConcatNodesPass>());
63
64 phase.emplace_back(std::make_unique<logo::RemoveDeadNodePass>());
65 }
66
68
69 ProgressReporter prog(g, logo::PhaseStrategy::Restart);
70 phase_runner.attach(&prog);
71 phase_runner.run(phase);
72}

References logo::Restart.

◆ set()

void exo::set ( Dialect  d)

Definition at line 100 of file Knob.cpp.

101{
102 ::knob_loader().dialect_set(d);
103 switch (d)
104 {
105 case Dialect::TFLITE:
106#define KNOB_BOOL(NAME, TFL_DEFAULT, CIRCLE_DEFAULT, DESC) \
107 ::knob_loader().knob_set(#NAME, TFL_DEFAULT);
108#include "Knob.lst"
109#undef KNOB_BOOL
110 break;
111 case Dialect::CIRCLE:
112#define KNOB_BOOL(NAME, TFL_DEFAULT, CIRCLE_DEFAULT, DESC) \
113 ::knob_loader().knob_set(#NAME, CIRCLE_DEFAULT);
114#include "Knob.lst"
115#undef KNOB_BOOL
116 break;
117 default:
118 std::runtime_error("UnKnown dialect");
119 }
120}

References CIRCLE, and TFLITE.

◆ to_circle_actfunc()

circle::ActivationFunctionType exo::to_circle_actfunc ( locoex::FusedActFunc  func)

Definition at line 24 of file CircleExporterUtils.cpp.

25{
26 switch (func)
27 {
29 return circle::ActivationFunctionType_NONE;
31 return circle::ActivationFunctionType_RELU;
33 return circle::ActivationFunctionType_RELU6;
34 default:
35 INTERNAL_EXN_V("trying to convert unsupported locoex::FusedActFunc", oops::to_uint32(func));
36 }
37}
#define INTERNAL_EXN_V(msg, val)
@ brief throw internal exception with message and value
Definition InternalExn.h:28
uint32_t to_uint32(T a)
Definition InternalExn.h:33

References INTERNAL_EXN_V, locoex::NONE, locoex::RELU, locoex::RELU6, and oops::to_uint32().

◆ to_shape_description() [1/7]

ShapeDescription exo::to_shape_description ( const loco::BiasShape shape)

Definition at line 91 of file ExporterUtils.cpp.

92{
94
95 res._rank_known = true;
96
97 res._dims.resize(1);
98 res._dims.at(0) = shape.length().value();
99
100 return res;
101}
const Dimension & length(void) const
Definition BiasShape.h:34
uint32_t value(void) const
Return the value.
Definition Dimension.h:51
std::vector< int32_t > _dims

References exo::ShapeDescription::_dims, exo::ShapeDescription::_rank_known, loco::BiasShape::length(), and loco::Dimension::value().

◆ to_shape_description() [2/7]

ShapeDescription exo::to_shape_description ( const loco::DepthwiseFilterShape shape)

Definition at line 75 of file ExporterUtils.cpp.

76{
78
79 res._rank_known = true;
80
81 // T/F Lite encodes a depthwise convolution filter as a [1, H, W, C*M] tensor
82 res._dims.resize(4);
83 res._dims.at(0) = 1;
84 res._dims.at(1) = shape.height().value();
85 res._dims.at(2) = shape.width().value();
86 res._dims.at(3) = shape.depth().value() * shape.multiplier().value();
87
88 return res;
89}
const Dimension & width(void) const
const Dimension & multiplier(void) const
const Dimension & depth(void) const
const Dimension & height(void) const

References exo::ShapeDescription::_dims, exo::ShapeDescription::_rank_known, loco::DepthwiseFilterShape::depth(), loco::DepthwiseFilterShape::height(), loco::DepthwiseFilterShape::multiplier(), loco::Dimension::value(), and loco::DepthwiseFilterShape::width().

◆ to_shape_description() [3/7]

ShapeDescription exo::to_shape_description ( const loco::FeatureShape shape)

Definition at line 43 of file ExporterUtils.cpp.

44{
46
47 res._rank_known = true;
48
49 // T/F Lite encodes a feature map as a NHWC tensor
50 res._dims.resize(4);
51 res._dims.at(0) = shape.count().value();
52 res._dims.at(1) = shape.height().value();
53 res._dims.at(2) = shape.width().value();
54 res._dims.at(3) = shape.depth().value();
55
56 return res;
57}
const Dimension & depth(void) const
const Dimension & height(void) const
const Dimension & width(void) const
const Dimension & count(void) const

References exo::ShapeDescription::_dims, exo::ShapeDescription::_rank_known, loco::FeatureShape::count(), loco::FeatureShape::depth(), loco::FeatureShape::height(), loco::Dimension::value(), and loco::FeatureShape::width().

◆ to_shape_description() [4/7]

ShapeDescription exo::to_shape_description ( const loco::FilterShape shape)

Definition at line 59 of file ExporterUtils.cpp.

60{
62
63 res._rank_known = true;
64
65 // T/F Lite encodes a convolution filter as a NHWC tensor
66 res._dims.resize(4);
67 res._dims.at(0) = shape.count().value();
68 res._dims.at(1) = shape.height().value();
69 res._dims.at(2) = shape.width().value();
70 res._dims.at(3) = shape.depth().value();
71
72 return res;
73}
const Dimension & count(void) const
Definition FilterShape.h:48
const Dimension & depth(void) const
Definition FilterShape.h:51
const Dimension & height(void) const
Definition FilterShape.h:54
const Dimension & width(void) const
Definition FilterShape.h:57

References exo::ShapeDescription::_dims, exo::ShapeDescription::_rank_known, loco::FilterShape::count(), loco::FilterShape::depth(), loco::FilterShape::height(), loco::Dimension::value(), and loco::FilterShape::width().

◆ to_shape_description() [5/7]

ShapeDescription exo::to_shape_description ( const loco::MatrixShape shape)

Definition at line 103 of file ExporterUtils.cpp.

104{
106
107 res._rank_known = true;
108
109 res._dims.resize(2);
110 res._dims.at(0) = shape.height().value();
111 res._dims.at(1) = shape.width().value();
112
113 return res;
114}
const Dimension & width(void) const
Definition MatrixShape.h:46
const Dimension & height(void) const
Definition MatrixShape.h:43

References exo::ShapeDescription::_dims, exo::ShapeDescription::_rank_known, loco::MatrixShape::height(), loco::Dimension::value(), and loco::MatrixShape::width().

◆ to_shape_description() [6/7]

ShapeDescription exo::to_shape_description ( const loco::NodeShape shape)

Definition at line 116 of file ExporterUtils.cpp.

117{
118 switch (shape.domain())
119 {
129 return to_shape_description(shape.as<loco::BiasShape>());
132 default:
133 break;
134 }
135
136 INTERNAL_EXN_V("Unsupported loco domain", oops::to_uint32(shape.domain()));
137}
Bias Shape.
Definition BiasShape.h:29
Feature Map Shape.
Filter Shape.
Definition FilterShape.h:43
Matrix Shape.
Definition MatrixShape.h:38
ShapeType as(void) const
const Domain & domain(void) const
Definition NodeShape.h:48
ShapeDescription to_shape_description(const loco::TensorShape &shape)

References loco::NodeShape::as(), loco::Bias, loco::DepthwiseFilter, loco::NodeShape::domain(), loco::Feature, loco::Filter, INTERNAL_EXN_V, loco::Matrix, loco::Tensor, to_shape_description(), and oops::to_uint32().

◆ to_shape_description() [7/7]

ShapeDescription exo::to_shape_description ( const loco::TensorShape shape)

Definition at line 26 of file ExporterUtils.cpp.

27{
29
30 res._rank_known = true;
31
32 res._dims.resize(shape.rank());
33 for (uint32_t axis = 0; axis < shape.rank(); ++axis)
34 {
35 // All the dimensions SHOULD be known
36 assert(shape.dim(axis).known());
37 res._dims.at(axis) = shape.dim(axis).value();
38 }
39
40 return res;
41}
bool known(void) const
Return whether the value is known (or not)
Definition Dimension.h:47
const Dimension & dim(uint32_t axis) const
Definition TensorShape.h:38
uint32_t rank(void) const
Definition TensorShape.h:35

References exo::ShapeDescription::_dims, exo::ShapeDescription::_rank_known, loco::TensorShape::dim(), loco::Dimension::known(), loco::TensorShape::rank(), and loco::Dimension::value().

Referenced by exo::ShapeInference::get(), and to_shape_description().

◆ to_tflite_actfunc()

tflite::ActivationFunctionType exo::to_tflite_actfunc ( locoex::FusedActFunc  func)

Definition at line 24 of file TFLExporterUtils.cpp.

25{
26 switch (func)
27 {
29 return tflite::ActivationFunctionType_NONE;
31 return tflite::ActivationFunctionType_RELU;
33 return tflite::ActivationFunctionType_RELU6;
34 default:
35 INTERNAL_EXN_V("Unsupported locoex FusedActFunc Type", oops::to_uint32(func));
36 }
37}

References INTERNAL_EXN_V, locoex::NONE, locoex::RELU, locoex::RELU6, and oops::to_uint32().