Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
174c999d
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,发现更多精彩内容 >>
提交
174c999d
编写于
6月 11, 2018
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix build for all socs bug.
上级
87cbeb31
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
70 addition
and
45 deletion
+70
-45
docs/getting_started/how_to_build.rst
docs/getting_started/how_to_build.rst
+8
-1
docs/getting_started/how_to_build_zh.rst
docs/getting_started/how_to_build_zh.rst
+10
-0
tools/converter.py
tools/converter.py
+48
-14
tools/sh_commands.py
tools/sh_commands.py
+4
-30
未找到文件。
docs/getting_started/how_to_build.rst
浏览文件 @
174c999d
...
@@ -366,7 +366,7 @@ The followings list the details.
...
@@ -366,7 +366,7 @@ The followings list the details.
``.pb`` file will be generated only when build_type is ``proto``.
``.pb`` file will be generated only when build_type is ``proto``.
**OpenCL compiled kernel binary file**
**OpenCL compiled kernel binary file**
* ``opencl/
compiled_kernel
.bin``
* ``opencl/
${target_abi}/${library_name}_compiled_opencl_kernel.${device_name}.${target_soc}
.bin``
.. note::
.. note::
...
@@ -376,6 +376,13 @@ The followings list the details.
...
@@ -376,6 +376,13 @@ The followings list the details.
This file rely on the OpenCL driver on the phone, you should update the file when OpenCL driver changed.
This file rely on the OpenCL driver on the phone, you should update the file when OpenCL driver changed.
**tar package**
* ``./build/${library_name}/libmace_${library_name}.tar.gz``
.. note::
This file package all the above files which used for deployment.
=============
=============
5. how to use
5. how to use
=============
=============
...
...
docs/getting_started/how_to_build_zh.rst
浏览文件 @
174c999d
...
@@ -364,6 +364,16 @@ Mace目前只提供静态库,有以下两种使用场景。
...
@@ -364,6 +364,16 @@ Mace目前只提供静态库,有以下两种使用场景。
pb文件紧当模型build_type设置为proto时才会产生。
pb文件紧当模型build_type设置为proto时才会产生。
**OpenCL预编译文件**
* ``opencl/${target_abi}/${library_name}_compiled_opencl_kernel.${device_name}.${target_soc}.bin``
.. note::
只有指定了``target_soc``并且``runtime==gpu``的情况下才会生成。
.. warning::
该文件依赖于手机上opencl驱动,如果OpenCL版本变化,请更新该文件。
**库文件tar包**
**库文件tar包**
* ``./build/${library_name}/libmace_${library_name}.tar.gz``
* ``./build/${library_name}/libmace_${library_name}.tar.gz``
...
...
tools/converter.py
浏览文件 @
174c999d
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
import
argparse
import
argparse
import
filelock
import
filelock
import
glob
import
hashlib
import
hashlib
import
os
import
os
import
re
import
re
...
@@ -40,11 +41,12 @@ from common import StringFormatter
...
@@ -40,11 +41,12 @@ from common import StringFormatter
BUILD_OUTPUT_DIR
=
'build'
BUILD_OUTPUT_DIR
=
'build'
PHONE_DATA_DIR
=
"/data/local/tmp/mace_run"
PHONE_DATA_DIR
=
"/data/local/tmp/mace_run"
MODEL_OUTPUT_DIR_NAME
=
'model'
MODEL_OUTPUT_DIR_NAME
=
'model'
MODEL_HEADER_DIR_PATH
=
'include/mace/public'
BUILD_TMP_DIR_NAME
=
'_tmp'
BUILD_TMP_DIR_NAME
=
'_tmp'
BUILD_TMP_GENERAL_OUTPUT_DIR_NAME
=
'general'
BUILD_TMP_GENERAL_OUTPUT_DIR_NAME
=
'general'
OUTPUT_LIBRARY_DIR_NAME
=
'library'
OUTPUT_LIBRARY_DIR_NAME
=
'library'
OUTPUT_OPENCL_BINARY_DIR_NAME
=
'opencl'
OUTPUT_OPENCL_BINARY_DIR_NAME
=
'opencl'
OUTPUT_OPENCL_BINARY_FILE_NAME
=
'compiled_opencl_kernel
.bin
'
OUTPUT_OPENCL_BINARY_FILE_NAME
=
'compiled_opencl_kernel'
CL_COMPILED_BINARY_FILE_NAME
=
"mace_cl_compiled_program.bin"
CL_COMPILED_BINARY_FILE_NAME
=
"mace_cl_compiled_program.bin"
CODEGEN_BASE_DIR
=
'mace/codegen'
CODEGEN_BASE_DIR
=
'mace/codegen'
MODEL_CODEGEN_DIR
=
CODEGEN_BASE_DIR
+
'/models'
MODEL_CODEGEN_DIR
=
CODEGEN_BASE_DIR
+
'/models'
...
@@ -434,12 +436,19 @@ def get_build_model_dirs(library_name, model_name, target_abi, target_soc,
...
@@ -434,12 +436,19 @@ def get_build_model_dirs(library_name, model_name, target_abi, target_soc,
return
model_output_base_dir
,
model_output_dir
,
mace_model_dir
return
model_output_base_dir
,
model_output_dir
,
mace_model_dir
def
get_opencl_binary_output_path
(
library_name
):
def
get_opencl_binary_output_path
(
library_name
,
target_abi
,
return
'%s/%s/%s/%s'
%
\
target_soc
,
serial_num
):
device_name
=
\
sh_commands
.
adb_get_device_name_by_serialno
(
serial_num
)
return
'%s/%s/%s/%s/%s_%s.%s.%s.bin'
%
\
(
BUILD_OUTPUT_DIR
,
(
BUILD_OUTPUT_DIR
,
library_name
,
library_name
,
OUTPUT_OPENCL_BINARY_DIR_NAME
,
OUTPUT_OPENCL_BINARY_DIR_NAME
,
library_name
+
'_'
+
OUTPUT_OPENCL_BINARY_FILE_NAME
)
target_abi
,
library_name
,
OUTPUT_OPENCL_BINARY_FILE_NAME
,
device_name
,
target_soc
)
################################
################################
...
@@ -513,9 +522,16 @@ def convert_model(configs):
...
@@ -513,9 +522,16 @@ def convert_model(configs):
model_output_dir
=
\
model_output_dir
=
\
'%s/%s/%s'
%
(
BUILD_OUTPUT_DIR
,
library_name
,
MODEL_OUTPUT_DIR_NAME
)
'%s/%s/%s'
%
(
BUILD_OUTPUT_DIR
,
library_name
,
MODEL_OUTPUT_DIR_NAME
)
model_header_dir
=
\
'%s/%s/%s'
%
(
BUILD_OUTPUT_DIR
,
library_name
,
MODEL_HEADER_DIR_PATH
)
if
os
.
path
.
exists
(
model_output_dir
):
if
os
.
path
.
exists
(
model_output_dir
):
sh
.
rm
(
"-rf"
,
model_output_dir
)
sh
.
rm
(
"-rf"
,
model_output_dir
)
os
.
makedirs
(
model_output_dir
)
os
.
makedirs
(
model_output_dir
)
if
os
.
path
.
exists
(
model_header_dir
):
sh
.
rm
(
"-rf"
,
model_header_dir
)
os
.
makedirs
(
model_header_dir
)
# copy header files
sh
.
cp
(
"-f"
,
glob
.
glob
(
"mace/public/*.h"
),
model_header_dir
)
embed_model_data
=
configs
[
YAMLKeyword
.
embed_model_data
]
embed_model_data
=
configs
[
YAMLKeyword
.
embed_model_data
]
...
@@ -583,14 +599,20 @@ def convert_model(configs):
...
@@ -583,14 +599,20 @@ def convert_model(configs):
configs
[
YAMLKeyword
.
build_type
],
configs
[
YAMLKeyword
.
build_type
],
data_type
)
data_type
)
# mv pb and data file to build/model_name/model
if
not
embed_model_data
:
if
not
embed_model_data
:
sh_commands
.
mv_model_file_to_output_dir
(
# mv pb and data file to build/model_name/model
model_build_type
=
configs
[
YAMLKeyword
.
build_type
],
sh
.
mv
(
"-f"
,
model_codegen_dir
=
model_codegen_dir
,
'%s/%s.data'
%
(
model_codegen_dir
,
model_name
),
model_name
=
model_name
,
model_output_dir
)
output_dir
=
model_output_dir
if
configs
[
YAMLKeyword
.
build_type
]
==
BuildType
.
proto
:
)
sh
.
mv
(
"-f"
,
'%s/%s.pb'
%
(
model_codegen_dir
,
model_name
),
model_output_dir
)
else
:
sh
.
cp
(
"-f"
,
glob
.
glob
(
"mace/codegen/engine/*.h"
),
model_header_dir
)
sh
.
cp
(
"-f"
,
glob
.
glob
(
"mace/codegen/models/*/*.h"
),
model_header_dir
)
MaceLogger
.
summary
(
MaceLogger
.
summary
(
StringFormatter
.
block
(
"Model %s converted"
%
model_name
))
StringFormatter
.
block
(
"Model %s converted"
%
model_name
))
...
@@ -682,9 +704,12 @@ def build_specific_lib(target_abi, target_soc, serial_num,
...
@@ -682,9 +704,12 @@ def build_specific_lib(target_abi, target_soc, serial_num,
binary_changed
=
True
binary_changed
=
True
if
binary_changed
:
if
binary_changed
:
opencl_output_bin_path
=
get_opencl_binary_output_path
(
library_name
,
target_abi
,
target_soc
,
serial_num
)
sh_commands
.
merge_opencl_binaries
(
sh_commands
.
merge_opencl_binaries
(
model_output_dirs
,
CL_COMPILED_BINARY_FILE_NAME
,
model_output_dirs
,
CL_COMPILED_BINARY_FILE_NAME
,
get_opencl_binary_output_path
(
library_name
)
)
opencl_output_bin_path
)
sh_commands
.
gen_tuning_param_code
(
model_output_dirs
)
sh_commands
.
gen_tuning_param_code
(
model_output_dirs
)
sh_commands
.
bazel_build
(
sh_commands
.
bazel_build
(
MACE_RUN_TARGET
,
MACE_RUN_TARGET
,
...
@@ -838,12 +863,16 @@ def run_specific_target(flags, configs, target_abi,
...
@@ -838,12 +863,16 @@ def run_specific_target(flags, configs, target_abi,
library_name
=
configs
[
YAMLKeyword
.
library_name
]
library_name
=
configs
[
YAMLKeyword
.
library_name
]
build_type
=
configs
[
YAMLKeyword
.
build_type
]
build_type
=
configs
[
YAMLKeyword
.
build_type
]
embed_model_data
=
configs
[
YAMLKeyword
.
embed_model_data
]
embed_model_data
=
configs
[
YAMLKeyword
.
embed_model_data
]
opencl_output_bin_path
=
""
if
not
configs
[
YAMLKeyword
.
target_socs
]:
if
not
configs
[
YAMLKeyword
.
target_socs
]:
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
None
,
None
)
None
,
None
)
else
:
else
:
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
target_soc
,
serial_num
)
target_soc
,
serial_num
)
opencl_output_bin_path
=
get_opencl_binary_output_path
(
library_name
,
target_abi
,
target_soc
,
serial_num
)
mace_check
(
os
.
path
.
exists
(
build_tmp_binary_dir
),
mace_check
(
os
.
path
.
exists
(
build_tmp_binary_dir
),
ModuleName
.
RUN
,
ModuleName
.
RUN
,
'You should build before run.'
)
'You should build before run.'
)
...
@@ -893,6 +922,7 @@ def run_specific_target(flags, configs, target_abi,
...
@@ -893,6 +922,7 @@ def run_specific_target(flags, configs, target_abi,
runtime_list
.
extend
([
model_runtime
])
runtime_list
.
extend
([
model_runtime
])
for
runtime
in
runtime_list
:
for
runtime
in
runtime_list
:
device_type
=
parse_device_type
(
runtime
)
device_type
=
parse_device_type
(
runtime
)
run_output
=
sh_commands
.
tuning_run
(
run_output
=
sh_commands
.
tuning_run
(
abi
=
target_abi
,
abi
=
target_abi
,
serialno
=
serial_num
,
serialno
=
serial_num
,
...
@@ -920,7 +950,7 @@ def run_specific_target(flags, configs, target_abi,
...
@@ -920,7 +950,7 @@ def run_specific_target(flags, configs, target_abi,
gpu_priority_hint
=
flags
.
gpu_priority_hint
,
gpu_priority_hint
=
flags
.
gpu_priority_hint
,
runtime_failure_ratio
=
flags
.
runtime_failure_ratio
,
runtime_failure_ratio
=
flags
.
runtime_failure_ratio
,
address_sanitizer
=
flags
.
address_sanitizer
,
address_sanitizer
=
flags
.
address_sanitizer
,
opencl_binary_file
=
get_opencl_binary_output_path
(
library_name
)
,
opencl_binary_file
=
opencl_output_bin_path
,
)
)
if
flags
.
validate
:
if
flags
.
validate
:
model_file_path
,
weight_file_path
=
get_model_files_path
(
model_file_path
,
weight_file_path
=
get_model_files_path
(
...
@@ -979,12 +1009,16 @@ def bm_specific_target(flags, configs, target_abi, target_soc, serial_num):
...
@@ -979,12 +1009,16 @@ def bm_specific_target(flags, configs, target_abi, target_soc, serial_num):
library_name
=
configs
[
YAMLKeyword
.
library_name
]
library_name
=
configs
[
YAMLKeyword
.
library_name
]
build_type
=
configs
[
YAMLKeyword
.
build_type
]
build_type
=
configs
[
YAMLKeyword
.
build_type
]
embed_model_data
=
configs
[
YAMLKeyword
.
embed_model_data
]
embed_model_data
=
configs
[
YAMLKeyword
.
embed_model_data
]
opencl_output_bin_path
=
""
if
not
configs
[
YAMLKeyword
.
target_socs
]:
if
not
configs
[
YAMLKeyword
.
target_socs
]:
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
None
,
None
)
None
,
None
)
else
:
else
:
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
build_tmp_binary_dir
=
get_build_binary_dir
(
library_name
,
target_abi
,
target_soc
,
serial_num
)
target_soc
,
serial_num
)
opencl_output_bin_path
=
get_opencl_binary_output_path
(
library_name
,
target_abi
,
target_soc
,
serial_num
)
mace_check
(
os
.
path
.
exists
(
build_tmp_binary_dir
),
mace_check
(
os
.
path
.
exists
(
build_tmp_binary_dir
),
ModuleName
.
BENCHMARK
,
ModuleName
.
BENCHMARK
,
'You should build before benchmark.'
)
'You should build before benchmark.'
)
...
@@ -1053,7 +1087,7 @@ def bm_specific_target(flags, configs, target_abi, target_soc, serial_num):
...
@@ -1053,7 +1087,7 @@ def bm_specific_target(flags, configs, target_abi, target_soc, serial_num):
cpu_affinity_policy
=
flags
.
cpu_affinity_policy
,
cpu_affinity_policy
=
flags
.
cpu_affinity_policy
,
gpu_perf_hint
=
flags
.
gpu_perf_hint
,
gpu_perf_hint
=
flags
.
gpu_perf_hint
,
gpu_priority_hint
=
flags
.
gpu_priority_hint
,
gpu_priority_hint
=
flags
.
gpu_priority_hint
,
opencl_binary_file
=
get_opencl_binary_output_path
(
library_name
)
)
opencl_binary_file
=
opencl_output_bin_path
)
def
benchmark_model
(
flags
):
def
benchmark_model
(
flags
):
...
...
tools/sh_commands.py
浏览文件 @
174c999d
...
@@ -400,9 +400,8 @@ def merge_opencl_binaries(binaries_dirs,
...
@@ -400,9 +400,8 @@ def merge_opencl_binaries(binaries_dirs,
cl_bin_dirs
.
append
(
os
.
path
.
join
(
d
,
"opencl_bin"
))
cl_bin_dirs
.
append
(
os
.
path
.
join
(
d
,
"opencl_bin"
))
# create opencl binary output dir
# create opencl binary output dir
opencl_binary_dir
=
os
.
path
.
dirname
(
output_file_path
)
opencl_binary_dir
=
os
.
path
.
dirname
(
output_file_path
)
if
os
.
path
.
exists
(
opencl_binary_dir
):
if
not
os
.
path
.
exists
(
opencl_binary_dir
):
sh
.
rm
(
"-rf"
,
opencl_binary_dir
)
sh
.
mkdir
(
"-p"
,
opencl_binary_dir
)
sh
.
mkdir
(
"-p"
,
opencl_binary_dir
)
kvs
=
{}
kvs
=
{}
for
binary_dir
in
cl_bin_dirs
:
for
binary_dir
in
cl_bin_dirs
:
binary_path
=
os
.
path
.
join
(
binary_dir
,
cl_compiled_program_file_name
)
binary_path
=
os
.
path
.
join
(
binary_dir
,
cl_compiled_program_file_name
)
...
@@ -578,20 +577,6 @@ def is_binary_tuned(build_tmp_binary_dir):
...
@@ -578,20 +577,6 @@ def is_binary_tuned(build_tmp_binary_dir):
return
os
.
path
.
exists
(
build_tmp_binary_dir
+
'/tuned'
)
return
os
.
path
.
exists
(
build_tmp_binary_dir
+
'/tuned'
)
def
mv_model_file_to_output_dir
(
model_build_type
,
model_codegen_dir
,
model_name
,
output_dir
):
if
model_build_type
==
BuildType
.
proto
:
sh
.
mv
(
"-f"
,
'%s/%s.pb'
%
(
model_codegen_dir
,
model_name
),
output_dir
)
sh
.
mv
(
"-f"
,
'%s/%s.data'
%
(
model_codegen_dir
,
model_name
),
output_dir
)
def
create_internal_storage_dir
(
serialno
,
phone_data_dir
):
def
create_internal_storage_dir
(
serialno
,
phone_data_dir
):
internal_storage_dir
=
"%s/interior/"
%
phone_data_dir
internal_storage_dir
=
"%s/interior/"
%
phone_data_dir
sh
.
adb
(
"-s"
,
serialno
,
"shell"
,
"mkdir"
,
"-p"
,
internal_storage_dir
)
sh
.
adb
(
"-s"
,
serialno
,
"shell"
,
"mkdir"
,
"-p"
,
internal_storage_dir
)
...
@@ -897,26 +882,15 @@ def merge_libs(target_soc,
...
@@ -897,26 +882,15 @@ def merge_libs(target_soc,
hexagon_mode
):
hexagon_mode
):
print
(
"* Merge mace lib"
)
print
(
"* Merge mace lib"
)
project_output_dir
=
"%s/%s"
%
(
build_output_dir
,
project_name
)
project_output_dir
=
"%s/%s"
%
(
build_output_dir
,
project_name
)
model_header_dir
=
"%s/include/mace/public"
%
project_output_dir
hexagon_lib_file
=
"third_party/nnlib/libhexagon_controller.so"
hexagon_lib_file
=
"third_party/nnlib/libhexagon_controller.so"
library_dir
=
"%s/%s"
%
(
project_output_dir
,
library_output_dir
)
library_dir
=
"%s/%s"
%
(
project_output_dir
,
library_output_dir
)
model_bin_dir
=
"%s/%s/"
%
(
library_dir
,
abi
)
model_bin_dir
=
"%s/%s/"
%
(
library_dir
,
abi
)
if
os
.
path
.
exists
(
model_bin_dir
):
if
not
os
.
path
.
exists
(
model_bin_dir
):
sh
.
rm
(
"-rf"
,
model_bin_dir
)
sh
.
mkdir
(
"-p"
,
model_bin_dir
)
sh
.
mkdir
(
"-p"
,
model_bin_dir
)
if
os
.
path
.
exists
(
model_header_dir
):
sh
.
rm
(
"-rf"
,
model_header_dir
)
sh
.
mkdir
(
"-p"
,
model_header_dir
)
# copy header files
sh
.
cp
(
"-f"
,
glob
.
glob
(
"mace/public/*.h"
),
model_header_dir
)
if
hexagon_mode
:
if
hexagon_mode
:
sh
.
cp
(
"-f"
,
hexagon_lib_file
,
library_dir
)
sh
.
cp
(
"-f"
,
hexagon_lib_file
,
library_dir
)
if
model_build_type
==
BuildType
.
code
:
sh
.
cp
(
"-f"
,
glob
.
glob
(
"mace/codegen/engine/*.h"
),
model_header_dir
)
sh
.
cp
(
"-f"
,
glob
.
glob
(
"mace/codegen/models/*/*.h"
),
model_header_dir
)
# make static library
# make static library
mri_stream
=
""
mri_stream
=
""
if
abi
==
"host"
:
if
abi
==
"host"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录