Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
07787144
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,发现更多精彩内容 >>
提交
07787144
编写于
6月 12, 2018
作者:
Y
yejianwu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update dynamic link
上级
cf6c7d7b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
62 addition
and
54 deletion
+62
-54
docs/getting_started/create_a_model_deployment.rst
docs/getting_started/create_a_model_deployment.rst
+2
-2
docs/getting_started/how_to_build.rst
docs/getting_started/how_to_build.rst
+2
-2
docs/getting_started/how_to_build_zh.rst
docs/getting_started/how_to_build_zh.rst
+3
-3
docs/getting_started/models/demo_app_models.yaml
docs/getting_started/models/demo_app_models.yaml
+1
-1
mace/tools/validation/BUILD
mace/tools/validation/BUILD
+2
-2
tools/converter.py
tools/converter.py
+28
-28
tools/sh_commands.py
tools/sh_commands.py
+24
-16
未找到文件。
docs/getting_started/create_a_model_deployment.rst
浏览文件 @
07787144
...
...
@@ -40,8 +40,8 @@ Configurations
- Whether embedding model weights as the code, default to 0.
* - build_type
- model build type, can be ['proto', 'code']. 'proto' for converting model to ProtoBuf file and 'code' for converting model to c++ code.
* -
dynamic_link
- [optional]
link mace library in dynamic method if set to 1
, default to 0.
* -
linkshared
- [optional]
Use dynamic linking for libmace library when setting to 1, or static linking when setting to 0
, default to 0.
* - model_name
- model name. should be unique if there are multiple models.
**LIMIT: if build_type is code, model_name will used in c++ code so that model_name must fulfill c++ name specification.**
...
...
docs/getting_started/how_to_build.rst
浏览文件 @
07787144
...
...
@@ -172,7 +172,7 @@ built-in tool when necessary.
3.1 Overview
-----------------
MiAI Compute Engine can build either static or shared library (which is
specified by ``
dynamic_link
`` in YAML model deployment file).
specified by ``
linkshared
`` in YAML model deployment file).
The followings are two use cases.
* **Build well tuned library for specific SoCs**
...
...
@@ -201,7 +201,7 @@ model conversion, compiling, test run, benchmark and correctness validation.
.. note::
1. ``tools/converter.py`` should be run at the root directory of this project.
2. When ``
dynamic_link
`` is set to ``1``, ``build_type`` should be ``proto``.
2. When ``
linkshared
`` is set to ``1``, ``build_type`` should be ``proto``.
And currently only android devices supported.
...
...
docs/getting_started/how_to_build_zh.rst
浏览文件 @
07787144
...
...
@@ -170,7 +170,7 @@ Caffe目前只支持最新版本,旧版本请使用Caffe的工具进行升级
3.1 简介
---------------------------------------
Mace目前提供静态库和动态库(可以在\ ``yaml``\ 文件中通过\ ``
dynamic_link
``\ 指定),有以下两种使用场景。
Mace目前提供静态库和动态库(可以在\ ``yaml``\ 文件中通过\ ``
linkshared
``\ 指定),有以下两种使用场景。
**特定SOC库**
...
...
@@ -195,7 +195,7 @@ Mace目前提供静态库和动态库(可以在\ ``yaml``\ 文件中通过\ ``
.. warning::
1. 必须在项目的根目录下运行\ ``tools/converter.py``\ 脚本。
2. 当\ ``
dynamic_link
``\ 被设置为1时,\ ``build_type``\ 必需设置为\ ``proto``\ 。当前动态链接的方式只支持安卓设备。
2. 当\ ``
linkshared
``\ 被设置为1时,\ ``build_type``\ 必需设置为\ ``proto``\ 。当前动态链接的方式只支持安卓设备。
---------------------------------------
...
...
@@ -331,7 +331,7 @@ Mace目前提供静态库和动态库(可以在\ ``yaml``\ 文件中通过\ ``
.. note::
当\ ``
dynamic_link
``\ 设置为1时生成动态链接库。
当\ ``
linkshared
``\ 设置为1时生成动态链接库。
* ``./build/${library_name}/library/${target_abi}/libhexagon_controller.so``
...
...
docs/getting_started/models/demo_app_models.yaml
浏览文件 @
07787144
...
...
@@ -8,7 +8,7 @@ embed_model_data: 1
# The build mode for model(s).
# 'code' stand for transfer model(s) into cpp code, 'proto' for model(s) in protobuf file(s).
build_type
:
code
dynamic_link
:
1
linkshared
:
1
# One yaml config file can contain multi models' config message.
models
:
model_name
:
# model tag, which will be used in model loading and must be specific.
...
...
mace/tools/validation/BUILD
浏览文件 @
07787144
...
...
@@ -2,7 +2,7 @@
load
(
"//mace:mace.bzl"
,
"if_openmp_enabled"
,
"if_android"
)
cc_binary
(
name
=
"mace_run"
,
name
=
"mace_run
_static
"
,
srcs
=
[
"mace_run.cc"
],
copts
=
if_android
([
"-DMACE_ENABLE_OPENCL"
,
...
...
@@ -17,7 +17,7 @@ cc_binary(
)
cc_binary
(
name
=
"mace_run_
deps_so
"
,
name
=
"mace_run_
shared
"
,
srcs
=
[
"mace_run.cc"
],
copts
=
if_android
([
"-DMACE_ENABLE_OPENCL"
,
...
...
tools/converter.py
浏览文件 @
07787144
...
...
@@ -51,8 +51,8 @@ CL_COMPILED_BINARY_FILE_NAME = "mace_cl_compiled_program.bin"
CODEGEN_BASE_DIR
=
'mace/codegen'
MODEL_CODEGEN_DIR
=
CODEGEN_BASE_DIR
+
'/models'
LIBMACE_SO_TARGET
=
"//mace:libmace.so"
MACE_RUN_
TARGET
=
"//mace/tools/validation:mace_run
"
MACE_RUN_
TARGET_DEPS_SO
=
"//mace/tools/validation:mace_run_deps_so
"
MACE_RUN_
STATIC_TARGET
=
"//mace/tools/validation:mace_run_static
"
MACE_RUN_
SHARED_TARGET
=
"//mace/tools/validation:mace_run_shared
"
ALL_SOC_TAG
=
'all'
ABITypeStrs
=
[
...
...
@@ -126,7 +126,7 @@ class YAMLKeyword(object):
target_socs
=
'target_socs'
build_type
=
'build_type'
embed_model_data
=
'embed_model_data'
dynamic_link
=
'dynamic_link
'
linkshared
=
'linkshared
'
models
=
'models'
platform
=
'platform'
model_file_path
=
'model_file_path'
...
...
@@ -282,19 +282,19 @@ def format_model_config(config_file_path):
if
build_type
==
BuildType
.
proto
:
configs
[
YAMLKeyword
.
embed_model_data
]
=
0
dynamic_link
=
configs
.
get
(
YAMLKeyword
.
dynamic_link
,
""
)
if
dynamic_link
==
""
:
configs
[
YAMLKeyword
.
dynamic_link
]
=
0
dynamic_link
=
0
if
not
isinstance
(
dynamic_link
,
int
)
or
dynamic_link
<
0
or
\
dynamic_link
>
1
:
linkshared
=
configs
.
get
(
YAMLKeyword
.
linkshared
,
""
)
if
linkshared
==
""
:
configs
[
YAMLKeyword
.
linkshared
]
=
0
linkshared
=
0
if
not
isinstance
(
linkshared
,
int
)
or
linkshared
<
0
or
\
linkshared
>
1
:
MaceLogger
.
error
(
ModuleName
.
YAML_CONFIG
,
"
dynamic_link
must be 0 or 1. "
"
linkshared
must be 0 or 1. "
"default is 0, for link mace lib statically, "
"1 for dynamic link."
)
if
build_type
==
BuildType
.
code
and
dynamic_link
==
1
:
"1 for dynamic link
ing
."
)
if
build_type
==
BuildType
.
code
and
linkshared
==
1
:
MaceLogger
.
error
(
ModuleName
.
YAML_CONFIG
,
"'
dynamic_link
== 1' only support when "
"'
linkshared
== 1' only support when "
"'build_type == proto'"
)
model_names
=
configs
.
get
(
YAMLKeyword
.
models
,
[])
...
...
@@ -500,8 +500,8 @@ def print_configuration(flags, configs):
configs
[
YAMLKeyword
.
build_type
]])
data
.
append
([
YAMLKeyword
.
embed_model_data
,
configs
[
YAMLKeyword
.
embed_model_data
]])
data
.
append
([
YAMLKeyword
.
dynamic_link
,
configs
[
YAMLKeyword
.
dynamic_link
]])
data
.
append
([
YAMLKeyword
.
linkshared
,
configs
[
YAMLKeyword
.
linkshared
]])
data
.
append
([
"Tuning"
,
flags
.
tuning
])
MaceLogger
.
summary
(
StringFormatter
.
table
(
header
,
data
,
title
))
...
...
@@ -651,7 +651,7 @@ def build_specific_lib(target_abi, target_soc, serial_num,
library_name
=
configs
[
YAMLKeyword
.
library_name
]
build_type
=
configs
[
YAMLKeyword
.
build_type
]
embed_model_data
=
configs
[
YAMLKeyword
.
embed_model_data
]
dynamic_link
=
configs
[
YAMLKeyword
.
dynamic_link
]
linkshared
=
configs
[
YAMLKeyword
.
linkshared
]
hexagon_mode
=
get_hexagon_mode
(
configs
)
model_output_dirs
=
[]
...
...
@@ -662,10 +662,10 @@ def build_specific_lib(target_abi, target_soc, serial_num,
os
.
makedirs
(
build_tmp_binary_dir
)
sh_commands
.
gen_tuning_param_code
(
model_output_dirs
)
if
dynamic_link
==
0
:
mace_run_target
=
MACE_RUN_TARGET
if
linkshared
==
0
:
mace_run_target
=
MACE_RUN_
STATIC_
TARGET
else
:
mace_run_target
=
MACE_RUN_
TARGET_DEPS_SO
mace_run_target
=
MACE_RUN_
SHARED_TARGET
sh_commands
.
bazel_build
(
LIBMACE_SO_TARGET
,
abi
=
target_abi
,
...
...
@@ -686,7 +686,7 @@ def build_specific_lib(target_abi, target_soc, serial_num,
enable_openmp
=
enable_openmp
,
address_sanitizer
=
address_sanitizer
)
sh_commands
.
update_mace_run_lib
(
build_tmp_binary_dir
,
dynamic_link
)
sh_commands
.
update_mace_run_lib
(
build_tmp_binary_dir
,
linkshared
)
binary_changed
=
False
for
model_name
in
configs
[
YAMLKeyword
.
models
]:
...
...
@@ -742,7 +742,7 @@ def build_specific_lib(target_abi, target_soc, serial_num,
build_type
=
build_type
,
opencl_binary_file
=
""
,
shared_library_dir
=
get_shared_library_dir
(
library_name
,
target_abi
),
# noqa
dynamic_link
=
dynamic_link
,
linkshared
=
linkshared
,
)
pull_opencl_binary_and_tuning_param
(
target_abi
,
serial_num
,
...
...
@@ -765,7 +765,7 @@ def build_specific_lib(target_abi, target_soc, serial_num,
enable_openmp
=
enable_openmp
,
address_sanitizer
=
address_sanitizer
)
sh_commands
.
update_mace_run_lib
(
build_tmp_binary_dir
,
dynamic_link
)
sh_commands
.
update_mace_run_lib
(
build_tmp_binary_dir
,
linkshared
)
if
target_abi
==
ABIType
.
host
:
sh_commands
.
build_host_libraries
(
build_type
,
target_abi
)
...
...
@@ -774,10 +774,10 @@ def build_specific_lib(target_abi, target_soc, serial_num,
sh_commands
.
build_benchmark_model
(
target_abi
,
build_tmp_binary_dir
,
hexagon_mode
,
dynamic_link
)
linkshared
)
# generate library
if
dynamic_link
==
0
:
if
linkshared
==
0
:
sh_commands
.
merge_libs
(
target_soc
,
serial_num
,
target_abi
,
...
...
@@ -913,7 +913,7 @@ def run_specific_target(flags, configs, target_abi,
build_type
=
configs
[
YAMLKeyword
.
build_type
]
embed_model_data
=
configs
[
YAMLKeyword
.
embed_model_data
]
opencl_output_bin_path
=
""
dynamic_link
=
configs
[
YAMLKeyword
.
dynamic_link
]
linkshared
=
configs
[
YAMLKeyword
.
linkshared
]
if
not
configs
[
YAMLKeyword
.
target_socs
]:
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
None
,
None
)
...
...
@@ -1002,7 +1002,7 @@ def run_specific_target(flags, configs, target_abi,
address_sanitizer
=
flags
.
address_sanitizer
,
opencl_binary_file
=
opencl_output_bin_path
,
shared_library_dir
=
get_shared_library_dir
(
library_name
,
target_abi
),
# noqa
dynamic_link
=
dynamic_link
,
linkshared
=
linkshared
,
)
if
flags
.
validate
:
model_file_path
,
weight_file_path
=
get_model_files_path
(
...
...
@@ -1062,7 +1062,7 @@ def bm_specific_target(flags, configs, target_abi, target_soc, serial_num):
build_type
=
configs
[
YAMLKeyword
.
build_type
]
embed_model_data
=
configs
[
YAMLKeyword
.
embed_model_data
]
opencl_output_bin_path
=
""
dynamic_link
=
configs
[
YAMLKeyword
.
dynamic_link
]
linkshared
=
configs
[
YAMLKeyword
.
linkshared
]
if
not
configs
[
YAMLKeyword
.
target_socs
]:
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
None
,
None
)
...
...
@@ -1142,7 +1142,7 @@ def bm_specific_target(flags, configs, target_abi, target_soc, serial_num):
gpu_priority_hint
=
flags
.
gpu_priority_hint
,
opencl_binary_file
=
opencl_output_bin_path
,
shared_library_dir
=
get_shared_library_dir
(
library_name
,
target_abi
),
# noqa
dynamic_link
=
dynamic_link
)
linkshared
=
linkshared
)
def
benchmark_model
(
flags
):
...
...
tools/sh_commands.py
浏览文件 @
07787144
...
...
@@ -561,16 +561,20 @@ def gen_random_input(model_output_dir,
sh
.
cp
(
"-f"
,
input_file_list
[
i
],
dst_input_file
)
def
update_mace_run_lib
(
build_tmp_binary_dir
,
dynamic_link
=
0
):
mace_run_filepath
=
build_tmp_binary_dir
+
"/mace_run"
def
update_mace_run_lib
(
build_tmp_binary_dir
,
linkshared
=
0
):
if
linkshared
==
0
:
mace_run_filepath
=
build_tmp_binary_dir
+
"/mace_run_static"
else
:
mace_run_filepath
=
build_tmp_binary_dir
+
"/mace_run_shared"
if
os
.
path
.
exists
(
mace_run_filepath
):
sh
.
rm
(
"-rf"
,
mace_run_filepath
)
if
dynamic_link
==
0
:
sh
.
cp
(
"-f"
,
"bazel-bin/mace/tools/validation/mace_run"
,
if
linkshared
==
0
:
sh
.
cp
(
"-f"
,
"bazel-bin/mace/tools/validation/mace_run
_static
"
,
build_tmp_binary_dir
)
else
:
sh
.
cp
(
"-f"
,
"bazel-bin/mace/tools/validation/mace_run_
deps_so
"
,
"%s/mace_run"
%
build_tmp_binary_dir
)
sh
.
cp
(
"-f"
,
"bazel-bin/mace/tools/validation/mace_run_
shared
"
,
build_tmp_binary_dir
)
def
touch_tuned_file_flag
(
build_tmp_binary_dir
):
...
...
@@ -641,7 +645,7 @@ def tuning_run(abi,
output_file_name
=
"model_out"
,
runtime_failure_ratio
=
0.0
,
address_sanitizer
=
False
,
dynamic_link
=
0
):
linkshared
=
0
):
print
(
"* Run '%s' with round=%s, restart_round=%s, tuning=%s, "
"out_of_range_check=%s, omp_num_threads=%s, cpu_affinity_policy=%s, "
"gpu_perf_hint=%s, gpu_priority_hint=%s"
%
...
...
@@ -651,13 +655,17 @@ def tuning_run(abi,
mace_model_path
=
""
if
build_type
==
BuildType
.
proto
:
mace_model_path
=
"%s/%s.pb"
%
(
mace_model_dir
,
model_tag
)
if
linkshared
==
0
:
mace_run_target
=
"mace_run_static"
else
:
mace_run_target
=
"mace_run_shared"
if
abi
==
"host"
:
p
=
subprocess
.
Popen
(
[
"env"
,
"MACE_CPP_MIN_VLOG_LEVEL=%s"
%
vlog_level
,
"MACE_RUNTIME_FAILURE_RATIO=%f"
%
runtime_failure_ratio
,
"%s/
mace_run"
%
mace_run_dir
,
"%s/
%s"
%
(
mace_run_dir
,
mace_run_target
)
,
"--model_name=%s"
%
model_tag
,
"--input_node=%s"
%
","
.
join
(
input_nodes
),
"--output_node=%s"
%
","
.
join
(
output_nodes
),
...
...
@@ -713,14 +721,14 @@ def tuning_run(abi,
mace_model_phone_path
,
serialno
)
if
dynamic_link
==
1
:
if
linkshared
==
1
:
adb_push
(
"%s/libmace.so"
%
shared_library_dir
,
phone_data_dir
,
serialno
)
adb_push
(
"%s/libgnustl_shared.so"
%
shared_library_dir
,
phone_data_dir
,
serialno
)
adb_push
(
"%s/
mace_run"
%
mace_run_dir
,
phone_data_dir
,
adb_push
(
"%s/
%s"
%
(
mace_run_dir
,
mace_run_target
)
,
phone_data_dir
,
serialno
)
stdout_buff
=
[]
...
...
@@ -741,7 +749,7 @@ def tuning_run(abi,
asan_rt_library_names
(
abi
))
])
adb_cmd
.
extend
([
"%s/
mace_run"
%
phone_data_dir
,
"%s/
%s"
%
(
phone_data_dir
,
mace_run_target
)
,
"--model_name=%s"
%
model_tag
,
"--input_node=%s"
%
","
.
join
(
input_nodes
),
"--output_node=%s"
%
","
.
join
(
output_nodes
),
...
...
@@ -1040,12 +1048,12 @@ def packaging_lib(libmace_output_dir, project_name):
def
build_benchmark_model
(
abi
,
model_output_dir
,
hexagon_mode
,
dynamic_link
=
False
):
linkshared
=
False
):
benchmark_binary_file
=
"%s/benchmark_model"
%
model_output_dir
if
os
.
path
.
exists
(
benchmark_binary_file
):
sh
.
rm
(
"-rf"
,
benchmark_binary_file
)
if
dynamic_link
==
0
:
if
linkshared
==
0
:
benchmark_target
=
"//mace/benchmark:benchmark_model"
else
:
benchmark_target
=
"//mace/benchmark:benchmark_model_deps_so"
...
...
@@ -1054,7 +1062,7 @@ def build_benchmark_model(abi,
hexagon_mode
=
hexagon_mode
)
target_bin
=
"/"
.
join
(
bazel_target_to_bin
(
benchmark_target
))
if
dynamic_link
==
0
:
if
linkshared
==
0
:
sh
.
cp
(
"-f"
,
target_bin
,
model_output_dir
)
else
:
sh
.
cp
(
"-f"
,
target_bin
,
"%s/benchmark_model"
%
model_output_dir
)
...
...
@@ -1082,7 +1090,7 @@ def benchmark_model(abi,
gpu_perf_hint
=
3
,
gpu_priority_hint
=
3
,
input_file_name
=
"model_input"
,
dynamic_link
=
0
):
linkshared
=
0
):
print
(
"* Benchmark for %s"
%
model_tag
)
mace_model_path
=
""
...
...
@@ -1132,7 +1140,7 @@ def benchmark_model(abi,
mace_model_phone_path
,
serialno
)
if
dynamic_link
==
1
:
if
linkshared
==
1
:
adb_push
(
"%s/libmace.so"
%
shared_library_dir
,
phone_data_dir
,
serialno
)
adb_push
(
"%s/libgnustl_shared.so"
%
shared_library_dir
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录