ONE - On-device Neural Engine
Toggle main menu visibility
Main Page
Related Pages
Topics
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
w
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
Enumerations
a
b
c
d
e
f
i
k
l
m
n
o
p
q
r
s
t
u
Enumerator
a
b
c
d
e
f
g
i
k
l
m
n
o
p
r
s
u
v
w
y
Data Structures
Data Structures
Data Structure Index
Class Hierarchy
Data Fields
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
z
Enumerations
a
c
d
e
f
g
i
k
l
m
o
p
r
s
t
w
Enumerator
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Related Symbols
a
b
c
d
e
f
g
h
i
m
n
o
p
r
s
t
u
v
w
Files
File List
Globals
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
Functions
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
Variables
_
b
c
d
f
g
i
k
m
n
o
p
s
t
v
Typedefs
a
d
f
g
i
l
m
n
o
s
t
u
v
Enumerations
f
g
n
o
p
r
Enumerator
a
k
n
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
Examples
•
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
onnx2circle.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 "
exo/LoggingContext.h
"
18
#include "
exo/CircleExporter.h
"
19
20
#include "
mir2loco.h
"
21
#include "
ONNXImporterImpl.h
"
22
23
#include "
locop/FormattedGraph.h
"
24
25
#include "
hermes/ConsoleReporter.h
"
26
#include "
hermes/EnvConfig.h
"
27
28
#include <cassert>
29
#include <memory>
30
#include <iostream>
31
#include <stdexcept>
32
#include <string>
33
34
//
35
// Logging Support
36
//
37
namespace
38
{
39
40
struct
Logger final :
public
hermes::Source
41
{
42
Logger(
hermes::Context
*ctx) {
activate
(ctx->
sources
(), ctx->
bus
()); }
43
~Logger() {
deactivate
(); }
44
};
45
46
struct
LoggingContext
47
{
48
static
hermes::Context
*
get
(
void
)
49
{
50
using
EnvConfig =
hermes::EnvConfig<hermes::EnvFormat::BooleanNumber>
;
51
52
static
hermes::Context
*ctx =
nullptr
;
53
54
if
(ctx ==
nullptr
)
55
{
56
ctx =
new
hermes::Context
;
57
ctx->
sinks
()->
append
(std::make_unique<hermes::ConsoleReporter>());
58
ctx->
config
(std::make_unique<EnvConfig>(
"ONNX2CIRCLE_Log"
));
59
}
60
61
return
ctx;
62
}
63
};
64
65
void
print_help()
66
{
67
std::cerr <<
"Usage: onnx2circle <path/to/onnx> <path/to/circle/model> "
<< std::endl;
68
}
69
70
}
// namespace
71
72
#define LOGGER(name) \
73
::Logger name { ::LoggingContext::get() }
72
#define LOGGER(name) \
…
74
75
#define INFO(name) HERMES_INFO(name)
76
77
int
main
(
int
argc,
char
**argv)
78
{
79
using
EnvConfig =
hermes::EnvConfig<hermes::EnvFormat::BooleanNumber>
;
80
81
// This line allows users to control all the exo-circle loggers via ONNX2CIRCLE_Log_Backend
82
exo::LoggingContext::get
()->
config
(std::make_unique<EnvConfig>(
"ONNX2CIRCLE_Log_Backend"
));
83
84
LOGGER
(l);
85
86
// TODO We need better args parsing in future
87
if
(!(argc == 3))
88
{
89
print_help();
90
return
255;
91
}
92
93
std::string onnx_path{argv[1]};
// .pb file
94
std::string circle_path{argv[2]};
95
96
std::cout <<
"Import from '"
<< onnx_path <<
"'"
<< std::endl;
97
auto
mir_g =
mir_onnx::loadModel
(onnx_path);
98
auto
loco_g =
mir2loco::Transformer
().
transform
(mir_g.get());
99
std::cout <<
"Import from '"
<< onnx_path <<
"' - Done"
<< std::endl;
100
101
INFO
(l) <<
"Import Graph"
<< std::endl;
102
INFO
(l) << locop::fmt<locop::Formatter::LinearV1>(loco_g) << std::endl;
103
104
std::cout <<
"Export into '"
<< circle_path <<
"'"
<< std::endl;
105
exo::CircleExporter
(loco_g.get()).
dumpToFile
(circle_path.c_str());
106
std::cout <<
"Export into '"
<< circle_path <<
"' - Done"
<< std::endl;
107
108
return
0;
109
}
77
int
main
(
int
argc,
char
**argv) {
…
}
ConsoleReporter.h
EnvConfig.h
ONNXImporterImpl.h
main
int main(void)
Definition
circle-input-names.cpp:170
exo::CircleExporter
Definition
CircleExporter.h:41
exo::CircleExporter::dumpToFile
void dumpToFile(const char *path) const
write to a file
Definition
CircleExporter.cpp:36
hermes::Context
Logging controller.
Definition
Context.h:40
hermes::Context::sources
Source::Registry * sources(void)
Definition
Context.h:55
hermes::Context::sinks
Sink::Registry * sinks(void)
Definition
Context.h:64
hermes::Context::bus
MessageBus * bus(void)
Definition
Context.h:48
hermes::Context::config
const Config * config(void) const
Get the global configuration.
Definition
Context.cpp:24
hermes::EnvConfig
Definition
EnvConfig.h:36
hermes::Source
Message Source.
Definition
Source.h:35
hermes::Source::deactivate
void deactivate(void)
Definition
Source.cpp:49
hermes::Source::activate
void activate(Registry *, MessageBus *)
Definition
Source.cpp:37
mir2loco::Transformer
Definition
mir2loco.h:25
mir2loco::Transformer::transform
std::unique_ptr< loco::Graph > transform(mir::Graph *mir_graph)
Definition
mir2loco.cpp:710
CircleExporter.h
LoggingContext.h
FormattedGraph.h
mir2loco.h
exo::get
KnobTrait< K >::ValueType get(void)
mir_onnx::loadModel
std::unique_ptr< mir::Graph > loadModel(const std::string &filename)
Definition
ONNXImporterImpl.cpp:235
LOGGER
#define LOGGER(name)
Definition
onnx2circle.cpp:72
INFO
#define INFO(name)
Definition
onnx2circle.cpp:75
exo::LoggingContext::get
static hermes::Context * get(void)
Definition
LoggingContext.cpp:27
hermes::Sink::Registry::append
virtual void append(std::unique_ptr< Sink > &&)=0
compiler
onnx2circle
src
onnx2circle.cpp
Generated by
1.9.8