Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
cefa3ab9
Mace
项目概览
Xiaomi
/
Mace
通知
106
Star
40
Fork
27
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cefa3ab9
编写于
1月 09, 2018
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Modify codegen code
上级
df04e03b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
57 addition
and
44 deletion
+57
-44
mace/examples/mace_run.cc
mace/examples/mace_run.cc
+7
-2
mace/python/tools/model.template
mace/python/tools/model.template
+22
-14
mace/python/tools/source_converter_lib.py
mace/python/tools/source_converter_lib.py
+4
-4
mace/python/tools/tf_converter.py
mace/python/tools/tf_converter.py
+3
-3
tools/validate_gcn.sh
tools/validate_gcn.sh
+12
-12
tools/validate_gcn_dsp.sh
tools/validate_gcn_dsp.sh
+9
-9
未找到文件。
mace/examples/mace_run.cc
浏览文件 @
cefa3ab9
...
...
@@ -28,8 +28,13 @@ using namespace std;
using
namespace
mace
;
namespace
mace
{
extern
NetDef
MACE_MODEL_FUNCTION
();
namespace
MACE_MODEL_TAG
{
extern
NetDef
CreateNet
();
}
}
void
ParseShape
(
const
string
&
str
,
vector
<
int64_t
>
*
shape
)
{
string
tmp
=
str
;
while
(
!
tmp
.
empty
())
{
...
...
@@ -149,7 +154,7 @@ int main(int argc, char **argv) {
// load model
int64_t
t0
=
utils
::
NowMicros
();
NetDef
net_def
=
mace
::
MACE_MODEL_
FUNCTION
();
NetDef
net_def
=
mace
::
MACE_MODEL_
TAG
::
CreateNet
();
int64_t
t1
=
utils
::
NowMicros
();
LOG
(
INFO
)
<<
"CreateNetDef duration: "
<<
t1
-
t0
<<
" us"
;
int64_t
init_micros
=
t1
-
t0
;
...
...
mace/python/tools/model.template
浏览文件 @
cefa3ab9
...
...
@@ -7,7 +7,8 @@
#include <vector>
#include "mace/core/public/mace.h"
namespace {{tag}}{
namespace mace {
namespace {{tag}} {
{% if tensor_info.data_type != 'DT_UINT8' %} alignas(4) {% endif %} unsigned char {{ tensor_info.name }}[] = {
{% for d in tensor_info.data %}{{"0x%02X, " % d }}{%endfor%}
...
...
@@ -19,7 +20,8 @@ void Create{{tensor.name}}(std::vector<mace::ConstTensor> &tensors) {
{ {{ tensor.dims|join(', ') }} }, {{ tensor.data_type }}, {{ tensor.node_id }}));
}
} // namespace {{tag}}
} // namespace {{tag}}
} // namespace mace
{% elif mode == 1 %}
#include <vector>
...
...
@@ -43,7 +45,8 @@ void UpdateOp(mace::OperatorDef &op,
}
}
namespace {{tag}}{
namespace mace {
namespace {{tag}} {
{% for i in range(start, end) %}
...
...
@@ -119,13 +122,15 @@ void CreateOperator{{i}}(mace::OperatorDef &op) {
{% endfor %}
} // namespace {{tag}}
} // namespace {{tag}}
} // namespace mace
{% else %}
#include <vector>
#include <string>
#include "mace/core/public/mace.h"
namespace mace {
namespace {{tag}} {
{% for tensor in tensors %}
...
...
@@ -137,13 +142,14 @@ extern void Create{{ tensor.name }}(std::vector<mace::ConstTensor> &tensors);
extern void CreateOperator{{i}}(mace::OperatorDef &op);
{% endfor %}
} // namespace {{ tag }}
} // namespace {{ tag }}
} // namespace mace
namespace {
{% if net.arg|length != 0 %}
static
void CreateNetArg(mace::NetDef &net_def) {
void CreateNetArg(mace::NetDef &net_def) {
net_def.mutable_arg().reserve({{ net.arg|length }});
mace::Argument *arg = nullptr;
{% for arg in net.arg %}
...
...
@@ -178,7 +184,7 @@ static void CreateNetArg(mace::NetDef &net_def) {
{% endif %}
{% if net.output_info | length > 0 %}
static
void CreateOutputInfo(mace::NetDef &net_def) {
void CreateOutputInfo(mace::NetDef &net_def) {
std::vector<std::vector<int>> dims { {{net.output_info | map(attribute='dims') | join(', ') | replace('[', '{') | replace(']', '}') }} };
std::vector<int> data_types_int { {{ net.output_info | map(attribute='data_type') | join(', ') }} };
...
...
@@ -194,28 +200,28 @@ static void CreateOutputInfo(mace::NetDef &net_def) {
}
{% endif %}
static
void CreateOperators(std::vector<mace::OperatorDef> &ops) {
void CreateOperators(std::vector<mace::OperatorDef> &ops) {
ops.resize({{ net.op|length }});
{% for i in range(net.op|length) %}
{{tag}}::CreateOperator{{i}}(ops[{{i}}]);
mace::
{{tag}}::CreateOperator{{i}}(ops[{{i}}]);
{% endfor %}
}
static
void CreateTensors(std::vector<mace::ConstTensor> &tensors) {
void CreateTensors(std::vector<mace::ConstTensor> &tensors) {
tensors.reserve({{ net.tensors|length }});
{% for tensor in net.tensors %}
{{tag}}::Create{{tensor.name}}(tensors);
mace::
{{tag}}::Create{{tensor.name}}(tensors);
{% endfor %}
}
{% if net.mem_arena.mem_block|length != 0 %}
static
void CreateMemoryArena(mace::MemoryArena &mem_arena) {
void CreateMemoryArena(mace::MemoryArena &mem_arena) {
std::vector<mace::MemoryBlock> &mem_block = mem_arena.mutable_mem_block();
mem_block.reserve({{ net.mem_arena.mem_block|length }});
...
...
@@ -231,8 +237,9 @@ static void CreateMemoryArena(mace::MemoryArena &mem_arena) {
}
namespace mace {
namespace {{tag}} {
NetDef
{{'Create' + tag}}
() {
NetDef
CreateNet
() {
NetDef net_def;
net_def.set_name("{{ net.name}}");
net_def.set_version("{{ net.version }}");
...
...
@@ -256,5 +263,6 @@ NetDef {{'Create' + tag}}() {
return net_def;
}
} // namespace mace
} // namespace {{tag}}
} // namespace mace
{% endif %}
mace/python/tools/source_converter_lib.py
浏览文件 @
cefa3ab9
...
...
@@ -42,7 +42,7 @@ def generate_in_out_map(ops, tensor_map):
in_out_map
[
output_name
]
=
generate_random_name
()
return
in_out_map
def
confus
e_name
(
net_def
):
def
obfuscat
e_name
(
net_def
):
input_node
=
"mace_input_node"
output_node
=
"mace_output_node"
tensor_map
=
generate_tensor_map
(
net_def
.
tensors
)
...
...
@@ -86,9 +86,9 @@ class TensorInfo:
def
stringfy
(
value
):
return
', '
.
join
(
'"{0}"'
.
format
(
w
)
for
w
in
value
)
def
convert_to_source
(
net_def
,
template
,
confus
e
,
model_tag
,
output
,
runtime
):
if
confus
e
:
confus
e_name
(
net_def
)
def
convert_to_source
(
net_def
,
template
,
obfuscat
e
,
model_tag
,
output
,
runtime
):
if
obfuscat
e
:
obfuscat
e_name
(
net_def
)
else
:
rename_tensor
(
net_def
)
...
...
mace/python/tools/tf_converter.py
浏览文件 @
cefa3ab9
...
...
@@ -29,7 +29,7 @@ def main(unused_args):
input_graph_def
,
FLAGS
.
input_node
,
FLAGS
.
output_node
,
FLAGS
.
data_type
,
FLAGS
.
runtime
)
if
FLAGS
.
output_type
==
'source'
:
source_converter_lib
.
convert_to_source
(
output_graph_def
,
FLAGS
.
template
,
FLAGS
.
confus
e
,
source_converter_lib
.
convert_to_source
(
output_graph_def
,
FLAGS
.
template
,
FLAGS
.
obfuscat
e
,
FLAGS
.
model_tag
,
FLAGS
.
output
,
FLAGS
.
runtime
)
else
:
with
gfile
.
GFile
(
FLAGS
.
output
,
"wb"
)
as
f
:
...
...
@@ -97,12 +97,12 @@ def parse_args():
default
=
""
,
help
=
"template path"
)
parser
.
add_argument
(
"--
confus
e"
,
"--
obfuscat
e"
,
type
=
str2bool
,
nargs
=
'?'
,
const
=
False
,
default
=
False
,
help
=
"
confus
e model names"
)
help
=
"
obfuscat
e model names"
)
parser
.
add_argument
(
"--model_tag"
,
type
=
str
,
...
...
tools/validate_gcn.sh
浏览文件 @
cefa3ab9
...
...
@@ -2,34 +2,34 @@
# Must run at root dir of mace project.
set
+x
Usage
()
{
echo
'Usage: bash tools/validate_gcn.sh tools/gcn.config tf_model_path image_size [tuning]'
echo
'Usage: bash tools/validate_gcn.sh tools/gcn.config tf_model_path
model_tag
image_size [tuning]'
}
if
[
$#
-lt
2
]
;
then
if
[
$#
-lt
4
]
;
then
Usage
exit
-1
fi
source
$1
VLOG_LEVEL
=
0
TF_MODEL_FILE_PATH
=
$2
MODEL_TAG
=
$3
IMAGE_SIZE
=
$4
TUNING_OR_NOT
=
${
5
:-
0
}
VLOG_LEVEL
=
0
MODEL_DIR
=
$(
dirname
${
TF_MODEL_FILE_PATH
}
)
MACE_SOURCE_DIR
=
`
/bin/pwd
`
MACE_MODEL_NAME
=
'mace_model.pb'
INPUT_FILE_NAME
=
'model_input'
OUTPUT_FILE_NAME
=
'gcn.out'
OUTPUT_LIST_FILE
=
'gcn.list'
PHONE_DATA_DIR
=
"/data/local/tmp/
${
M
ACE_MODEL_NAME
}
"
PHONE_DATA_DIR
=
"/data/local/tmp/
${
M
ODEL_TAG
}
"
KERNEL_DIR
=
"
${
PHONE_DATA_DIR
}
/cl/"
IMAGE_SIZE
=
$3
MODEL_TAG
=
GCN
${
IMAGE_SIZE
}
CODEGEN_DIR
=
${
MACE_SOURCE_DIR
}
/mace/codegen
MODEL_CODEGEN_DIR
=
${
CODEGEN_DIR
}
/models/
gcn-
$IMAGE_SIZE
MODEL_CODEGEN_DIR
=
${
CODEGEN_DIR
}
/models/
${
MODEL_TAG
}
CL_CODEGEN_DIR
=
${
CODEGEN_DIR
}
/opencl
CL_BIN_DIR
=
${
CODEGEN_DIR
}
/opencl_bin
TUNING_CODEGEN_DIR
=
${
CODEGEN_DIR
}
/tuning
TUNING_OR_NOT
=
${
4
:-
0
}
VERSION_SOURCE_PATH
=
${
CODEGEN_DIR
}
/version
build_and_run
()
...
...
@@ -46,7 +46,7 @@ build_and_run()
--copt
=
"-std=c++11"
\
--copt
=
"-D_GLIBCXX_USE_C99_MATH_TR1"
\
--copt
=
"-Werror=return-type"
\
--copt
=
"-DMACE_MODEL_
FUNCTION=Create
${
MODEL_TAG
}
"
\
--copt
=
"-DMACE_MODEL_
TAG=
${
MODEL_TAG
}
"
\
$PRODUCTION_MODE_BUILD_FLAGS
||
exit
-1
adb shell
"mkdir -p
${
PHONE_DATA_DIR
}
"
||
exit
-1
...
...
@@ -88,7 +88,7 @@ bazel build //mace/python/tools:tf_converter || exit -1
rm
-rf
${
MODEL_CODEGEN_DIR
}
mkdir
-p
${
MODEL_CODEGEN_DIR
}
bazel-bin/mace/python/tools/tf_converter
--input
=
${
TF_MODEL_FILE_PATH
}
\
--output
=
${
MODEL_CODEGEN_DIR
}
/m
ace_gcn
${
IMAGE_SIZE
}
.cc
\
--output
=
${
MODEL_CODEGEN_DIR
}
/m
odel
.cc
\
--input_node
=
${
TF_INPUT_NODE
}
\
--output_node
=
${
TF_OUTPUT_NODE
}
\
--data_type
=
DT_HALF
\
...
...
@@ -96,7 +96,7 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \
--output_type
=
source
\
--template
=
${
MACE_SOURCE_DIR
}
/mace/python/tools/model.template
\
--model_tag
=
${
MODEL_TAG
}
\
--
confus
e
=
True
||
exit
-1
--
obfuscat
e
=
True
||
exit
-1
echo
"Step 3: Generate version source"
rm
-rf
${
VERSION_SOURCE_PATH
}
...
...
tools/validate_gcn_dsp.sh
浏览文件 @
cefa3ab9
...
...
@@ -2,30 +2,30 @@
# Must run at root dir of mace project.
set
+x
Usage
()
{
echo
'Usage: bash tools/validate_gcn.sh tools/gcn.config tf_model_path image_size [tuning]'
echo
'Usage: bash tools/validate_gcn.sh tools/gcn.config tf_model_path
model_tag
image_size [tuning]'
}
if
[
$#
-lt
2
]
;
then
if
[
$#
-lt
4
]
;
then
Usage
exit
-1
fi
source
$1
VLOG_LEVEL
=
0
TF_MODEL_FILE_PATH
=
$2
MODEL_TAG
=
$3
IMAGE_SIZE
=
$4
VLOG_LEVEL
=
0
MODEL_DIR
=
$(
dirname
${
TF_MODEL_FILE_PATH
}
)
MACE_SOURCE_DIR
=
`
/bin/pwd
`
MACE_MODEL_NAME
=
'mace_model.pb'
INPUT_FILE_NAME
=
'model_input'
OUTPUT_FILE_NAME
=
'gcn.out'
OUTPUT_LIST_FILE
=
'gcn.list'
PHONE_DATA_DIR
=
"/data/local/tmp/
${
M
ACE_MODEL_NAME
}
"
PHONE_DATA_DIR
=
"/data/local/tmp/
${
M
ODEL_TAG
}
"
KERNEL_DIR
=
"
${
PHONE_DATA_DIR
}
/cl/"
IMAGE_SIZE
=
$3
MODEL_TAG
=
GCN
${
IMAGE_SIZE
}
CODEGEN_DIR
=
${
MACE_SOURCE_DIR
}
/mace/codegen
MODEL_CODEGEN_DIR
=
${
CODEGEN_DIR
}
/models/
gcn-
$IMAGE_SIZE
MODEL_CODEGEN_DIR
=
${
CODEGEN_DIR
}
/models/
${
MODEL_TAG
}
VERSION_SOURCE_PATH
=
${
CODEGEN_DIR
}
/version
build_and_run
()
...
...
@@ -73,7 +73,7 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \
--output_type
=
source
\
--template
=
${
MACE_SOURCE_DIR
}
/mace/python/tools/model.template
\
--model_tag
=
${
MODEL_TAG
}
\
--
confus
e
=
True
--
obfuscat
e
=
True
echo
"Step 3: Generate version source"
rm
-rf
${
VERSION_SOURCE_PATH
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录