Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
毕竟曾有刹那
Mace
提交
5d9b931e
Mace
项目概览
毕竟曾有刹那
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
5d9b931e
编写于
5月 15, 2019
作者:
L
lichao18
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add cmake for apu
add converter run for apu
上级
ffb4acd0
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
91 addition
and
6 deletion
+91
-6
CMakeLists.txt
CMakeLists.txt
+8
-0
mace/core/CMakeLists.txt
mace/core/CMakeLists.txt
+5
-0
mace/python/tools/converter_tool/apu_converter.py
mace/python/tools/converter_tool/apu_converter.py
+10
-2
third_party/apu/apu.cmake
third_party/apu/apu.cmake
+13
-0
third_party/third_party.cmake
third_party/third_party.cmake
+4
-0
tools/bazel-build-standalone-lib.sh
tools/bazel-build-standalone-lib.sh
+11
-0
tools/cmake-build-android-arm64-v8a-cpu.sh
tools/cmake-build-android-arm64-v8a-cpu.sh
+1
-0
tools/cmake-build-android-arm64-v8a-full.sh
tools/cmake-build-android-arm64-v8a-full.sh
+1
-0
tools/cmake-build-android-armeabi-v7a-cpu.sh
tools/cmake-build-android-armeabi-v7a-cpu.sh
+1
-0
tools/cmake-build-android-armeabi-v7a-full.sh
tools/cmake-build-android-armeabi-v7a-full.sh
+1
-0
tools/converter.py
tools/converter.py
+19
-0
tools/device.py
tools/device.py
+4
-0
tools/sh_commands.py
tools/sh_commands.py
+13
-4
未找到文件。
CMakeLists.txt
浏览文件 @
5d9b931e
...
...
@@ -9,6 +9,7 @@ option(MACE_ENABLE_OPENCL "whether to enable OpenCL support" OFF)
option
(
MACE_ENABLE_CUDA
"whether to enable CUDA support"
OFF
)
option
(
MACE_ENABLE_HEXAGON_DSP
"whether to enable Hexagon DSP support"
OFF
)
option
(
MACE_ENABLE_HEXAGON_HTA
"whether to enable Hexagon HTA support"
OFF
)
option
(
MACE_ENABLE_MTK_APU
"whether to enable MTK APU support"
OFF
)
option
(
MACE_ENABLE_TESTS
"whether to build c++ unit tests"
OFF
)
option
(
MACE_ENABLE_BENCHMARKS
"whether to build c++ micro benchmarks"
OFF
)
option
(
MACE_ENABLE_EXAMPLES
"whether to build examples"
OFF
)
...
...
@@ -89,6 +90,13 @@ if(MACE_ENABLE_HEXAGON_HTA)
add_definitions
(
-DMACE_ENABLE_HEXAGON_HTA
)
endif
(
MACE_ENABLE_HEXAGON_HTA
)
if
(
MACE_ENABLE_MTK_APU
)
if
(
NOT ANDROID
)
message
(
FATAL_ERROR
"MTK APU is only supported on Android"
)
endif
(
NOT ANDROID
)
add_definitions
(
-DMACE_ENABLE_MTK_APU
)
endif
(
MACE_ENABLE_MTK_APU
)
if
(
MACE_ENABLE_OBFUSCATE
)
add_definitions
(
-DMACE_OBFUSCATE_LITERALS
)
endif
(
MACE_ENABLE_OBFUSCATE
)
...
...
mace/core/CMakeLists.txt
浏览文件 @
5d9b931e
...
...
@@ -40,6 +40,11 @@ if(MACE_ENABLE_HEXAGON_HTA)
set
(
EXTRA_LINK_LIBS
${
EXTRA_LINK_LIBS
}
hta_controller hta_hexagon_runtime npu
)
endif
(
MACE_ENABLE_HEXAGON_HTA
)
if
(
MACE_ENABLE_MTK_APU
)
set
(
CORE_SRCS
${
CORE_SRCS
}
runtime/apu/apu_wrapper.cc
)
set
(
EXTRA_LINK_LIBS
${
EXTRA_LINK_LIBS
}
apu-frontend
)
endif
(
MACE_ENABLE_MTK_APU
)
add_library
(
core STATIC
${
CORE_SRCS
}
)
target_link_libraries
(
core PRIVATE
proto
...
...
mace/python/tools/converter_tool/apu_converter.py
浏览文件 @
5d9b931e
...
...
@@ -397,12 +397,13 @@ class ApuConverter(base_converter.ConverterInterface):
_op
.
input
.
extend
([
tensor
.
name
])
def
use_uint8_in_out
(
self
):
replace_dict
=
{}
for
input_info
in
self
.
_model
.
input_info
:
if
input_info
.
data_type
==
mace_pb2
.
DT_FLOAT
:
for
op
in
self
.
_model
.
op
:
if
op
.
input
[
0
]
==
input_info
.
name
\
and
op
.
type
==
MaceOp
.
Quantize
.
name
:
input_info
.
name
=
op
.
output
[
0
]
replace_dict
[
op
.
output
[
0
]]
=
input_info
.
name
input_info
.
scale
=
op
.
quantize_info
[
0
].
scale
input_info
.
zero_point
=
op
.
quantize_info
[
0
].
zero_point
break
...
...
@@ -412,6 +413,13 @@ class ApuConverter(base_converter.ConverterInterface):
for
op
in
self
.
_model
.
op
:
if
op
.
output
[
0
]
==
output_info
.
name
\
and
op
.
type
==
MaceOp
.
Dequantize
.
name
:
output_info
.
name
=
op
.
input
[
0
]
replace_dict
[
op
.
input
[
0
]]
=
output_info
.
name
break
self
.
_model
.
op
.
remove
(
op
)
for
op
in
self
.
_model
.
op
:
for
i
,
op_input
in
enumerate
(
op
.
input
):
if
op_input
in
replace_dict
.
keys
():
op
.
input
[
i
]
=
replace_dict
[
op_input
]
for
i
,
op_output
in
enumerate
(
op
.
output
):
if
op_output
in
replace_dict
.
keys
():
op
.
output
[
i
]
=
replace_dict
[
op_output
]
third_party/apu/apu.cmake
0 → 100644
浏览文件 @
5d9b931e
set
(
APU_INSTALL_DIR
"
${
PROJECT_SOURCE_DIR
}
/third_party/apu"
)
set
(
APU_INCLUDE_DIR
"
${
APU_INSTALL_DIR
}
"
)
include_directories
(
SYSTEM
"
${
APU_INCLUDE_DIR
}
"
)
set
(
APU-FRONTEND
"
${
APU_INSTALL_DIR
}
/libapu-frontend.so"
)
add_library
(
apu-frontend SHARED IMPORTED GLOBAL
)
set_target_properties
(
apu-frontend PROPERTIES IMPORTED_LOCATION
${
APU-FRONTEND
}
)
install
(
FILES
${
APU-FRONTEND
}
DESTINATION lib
)
third_party/third_party.cmake
浏览文件 @
5d9b931e
...
...
@@ -58,3 +58,7 @@ endif(MACE_ENABLE_HEXAGON_DSP)
if
(
MACE_ENABLE_HEXAGON_HTA
)
include
(
${
PROJECT_SOURCE_DIR
}
/third_party/hta/hta.cmake
)
endif
(
MACE_ENABLE_HEXAGON_HTA
)
if
(
MACE_ENABLE_MTK_APU
)
include
(
${
PROJECT_SOURCE_DIR
}
/third_party/apu/apu.cmake
)
endif
(
MACE_ENABLE_MTK_APU
)
tools/bazel-build-standalone-lib.sh
浏览文件 @
5d9b931e
...
...
@@ -19,6 +19,7 @@ mkdir -p $LIB_DIR/armeabi-v7a/cpu_gpu
rm
-rf
$LIB_DIR
/arm64-v8a
mkdir
-p
$LIB_DIR
/arm64-v8a/cpu_gpu_dsp
mkdir
-p
$LIB_DIR
/arm64-v8a/cpu_gpu
mkdir
-p
$LIB_DIR
/arm64-v8a/cpu_gpu_apu
rm
-rf
$LIB_DIR
/linux-x86-64
mkdir
-p
$LIB_DIR
/linux-x86-64
...
...
@@ -42,6 +43,11 @@ bazel build --config android --config optimization mace/libmace:libmace_dynamic
cp
bazel-bin/mace/libmace/libmace.so
$LIB_DIR
/arm64-v8a/cpu_gpu_dsp/
cp
third_party/nnlib/arm64-v8a/
*
so
$LIB_DIR
/arm64-v8a/cpu_gpu_dsp/
echo
"build shared lib for arm64-v8a + cpu_gpu_apu"
bazel build
--config
android
--config
optimization mace/libmace:libmace_dynamic
--define
neon
=
true
--define
openmp
=
false
--define
opencl
=
true
--define
apu
=
true
--define
quantize
=
true
--cpu
=
arm64-v8a
cp
bazel-bin/mace/libmace/libmace.so
$LIB_DIR
/arm64-v8a/cpu_gpu_apu/
cp
third_party/apu/
*
so
$LIB_DIR
/arm64-v8a/cpu_gpu_apu/
echo
"build shared lib for armeabi-v7a + cpu_gpu"
bazel build
--config
android
--config
optimization mace/libmace:libmace_dynamic
--define
neon
=
true
--define
openmp
=
false
--define
opencl
=
true
--define
quantize
=
true
--cpu
=
armeabi-v7a
cp
bazel-bin/mace/libmace/libmace.so
$LIB_DIR
/armeabi-v7a/cpu_gpu/
...
...
@@ -75,6 +81,11 @@ bazel build --config android --config optimization mace/libmace:libmace_static -
cp
bazel-genfiles/mace/libmace/libmace.a
$LIB_DIR
/arm64-v8a/cpu_gpu_dsp/
cp
third_party/nnlib/arm64-v8a/
*
so
$LIB_DIR
/arm64-v8a/cpu_gpu_dsp/
echo
"build static lib for arm64-v8a + cpu_gpu_apu"
bazel build
--config
android
--config
optimization mace/libmace:libmace_static
--config
symbol_hidden
--define
neon
=
true
--define
openmp
=
false
--define
opencl
=
true
--define
apu
=
true
--define
quantize
=
true
--cpu
=
arm64-v8a
cp
bazel-genfiles/mace/libmace/libmace.a
$LIB_DIR
/arm64-v8a/cpu_gpu_apu/
cp
third_party/apu/
*
so
$LIB_DIR
/arm64-v8a/cpu_gpu_apu/
echo
"build static lib for armeabi-v7a + cpu_gpu"
bazel build
--config
android
--config
optimization mace/libmace:libmace_static
--config
symbol_hidden
--define
neon
=
true
--define
openmp
=
false
--define
opencl
=
true
--define
quantize
=
true
--cpu
=
armeabi-v7a
cp
bazel-genfiles/mace/libmace/libmace.a
$LIB_DIR
/armeabi-v7a/cpu_gpu/
...
...
tools/cmake-build-android-arm64-v8a-cpu.sh
浏览文件 @
5d9b931e
...
...
@@ -15,6 +15,7 @@ cmake -DANDROID_ABI="arm64-v8a" \
-DMACE_ENABLE_OPENCL
=
OFF
\
-DMACE_ENABLE_HEXAGON_DSP
=
OFF
\
-DMACE_ENABLE_HEXAGON_HTA
=
OFF
\
-DMACE_ENABLE_MTK_APU
=
OFF
\
-DMACE_ENABLE_OPT_SIZE
=
ON
\
-DMACE_ENABLE_OBFUSCATE
=
ON
\
-DCMAKE_INSTALL_PREFIX
=
install
\
...
...
tools/cmake-build-android-arm64-v8a-full.sh
浏览文件 @
5d9b931e
...
...
@@ -15,6 +15,7 @@ cmake -DANDROID_ABI="arm64-v8a" \
-DMACE_ENABLE_OPENCL
=
ON
\
-DMACE_ENABLE_HEXAGON_DSP
=
ON
\
-DMACE_ENABLE_HEXAGON_HTA
=
ON
\
-DMACE_ENABLE_MTK_APU
=
ON
\
-DMACE_ENABLE_OPT_SIZE
=
ON
\
-DMACE_ENABLE_OBFUSCATE
=
ON
\
-DCMAKE_INSTALL_PREFIX
=
install
\
...
...
tools/cmake-build-android-armeabi-v7a-cpu.sh
浏览文件 @
5d9b931e
...
...
@@ -16,6 +16,7 @@ cmake -DANDROID_ABI="armeabi-v7a" \
-DMACE_ENABLE_OPENCL
=
OFF
\
-DMACE_ENABLE_HEXAGON_DSP
=
OFF
\
-DMACE_ENABLE_HEXAGON_HTA
=
OFF
\
-DMACE_ENABLE_MTK_APU
=
OFF
\
-DMACE_ENABLE_OPT_SIZE
=
ON
\
-DMACE_ENABLE_OBFUSCATE
=
ON
\
-DCMAKE_INSTALL_PREFIX
=
install
\
...
...
tools/cmake-build-android-armeabi-v7a-full.sh
浏览文件 @
5d9b931e
...
...
@@ -16,6 +16,7 @@ cmake -DANDROID_ABI="armeabi-v7a" \
-DMACE_ENABLE_OPENCL
=
ON
\
-DMACE_ENABLE_HEXAGON_DSP
=
ON
\
-DMACE_ENABLE_HEXAGON_HTA
=
ON
\
-DMACE_ENABLE_MTK_APU
=
OFF
\
-DMACE_ENABLE_OPT_SIZE
=
ON
\
-DMACE_ENABLE_OBFUSCATE
=
ON
\
-DCMAKE_INSTALL_PREFIX
=
install
\
...
...
tools/converter.py
浏览文件 @
5d9b931e
...
...
@@ -189,6 +189,19 @@ def get_hta_mode(configs):
return
False
def
get_apu_mode
(
configs
):
runtime_list
=
[]
for
model_name
in
configs
[
YAMLKeyword
.
models
]:
model_runtime
=
\
configs
[
YAMLKeyword
.
models
][
model_name
].
get
(
YAMLKeyword
.
runtime
,
""
)
runtime_list
.
append
(
model_runtime
.
lower
())
if
RuntimeType
.
apu
in
runtime_list
:
return
True
return
False
def
get_opencl_mode
(
configs
):
runtime_list
=
[]
for
model_name
in
configs
[
YAMLKeyword
.
models
]:
...
...
@@ -575,6 +588,7 @@ def format_model_config(flags):
DeviceType
.
GPU
:
ValidationThreshold
.
gpu_threshold
,
DeviceType
.
HEXAGON
:
ValidationThreshold
.
quantize_threshold
,
DeviceType
.
HTA
:
ValidationThreshold
.
quantize_threshold
,
DeviceType
.
APU
:
ValidationThreshold
.
quantize_threshold
,
DeviceType
.
QUANTIZE
:
ValidationThreshold
.
quantize_threshold
,
}
for
k
,
v
in
six
.
iteritems
(
validation_threshold
):
...
...
@@ -816,6 +830,7 @@ def build_model_lib(configs, address_sanitizer, debug_mode):
toolchain
=
toolchain
,
enable_hexagon
=
get_hexagon_mode
(
configs
),
enable_hta
=
get_hta_mode
(
configs
),
enable_apu
=
get_apu_mode
(
configs
),
enable_opencl
=
get_opencl_mode
(
configs
),
enable_quantize
=
get_quantize_mode
(
configs
),
address_sanitizer
=
address_sanitizer
,
...
...
@@ -884,6 +899,7 @@ def build_mace_run(configs, target_abi, toolchain, enable_openmp,
toolchain
=
toolchain
,
enable_hexagon
=
get_hexagon_mode
(
configs
),
enable_hta
=
get_hta_mode
(
configs
),
enable_apu
=
get_apu_mode
(
configs
),
enable_openmp
=
enable_openmp
,
enable_opencl
=
get_opencl_mode
(
configs
),
enable_quantize
=
get_quantize_mode
(
configs
),
...
...
@@ -931,6 +947,7 @@ def build_example(configs, target_abi, toolchain, enable_openmp, mace_lib_type,
enable_quantize
=
get_quantize_mode
(
configs
),
enable_hexagon
=
get_hexagon_mode
(
configs
),
enable_hta
=
get_hta_mode
(
configs
),
enable_apu
=
get_apu_mode
(
configs
),
address_sanitizer
=
flags
.
address_sanitizer
,
symbol_hidden
=
get_symbol_hidden_mode
(
debug_mode
,
mace_lib_type
),
# noqa
debug_mode
=
debug_mode
)
...
...
@@ -964,6 +981,7 @@ def build_example(configs, target_abi, toolchain, enable_openmp, mace_lib_type,
enable_quantize
=
get_quantize_mode
(
configs
),
enable_hexagon
=
get_hexagon_mode
(
configs
),
enable_hta
=
get_hta_mode
(
configs
),
enable_apu
=
get_apu_mode
(
configs
),
address_sanitizer
=
flags
.
address_sanitizer
,
debug_mode
=
debug_mode
,
extra_args
=
build_arg
)
...
...
@@ -1072,6 +1090,7 @@ def build_benchmark_model(configs,
enable_quantize
=
get_quantize_mode
(
configs
),
enable_hexagon
=
get_hexagon_mode
(
configs
),
enable_hta
=
get_hta_mode
(
configs
),
enable_apu
=
get_apu_mode
(
configs
),
symbol_hidden
=
get_symbol_hidden_mode
(
debug_mode
,
mace_lib_type
),
# noqa
debug_mode
=
debug_mode
,
extra_args
=
build_arg
)
...
...
tools/device.py
浏览文件 @
5d9b931e
...
...
@@ -280,6 +280,10 @@ class DeviceWrapper:
"third_party/nnlib/%s/libhexagon_controller.so"
%
abi
,
self
.
data_dir
)
if
device_type
==
common
.
DeviceType
.
APU
:
self
.
push
(
"third_party/apu/libapu-frontend.so"
,
self
.
data_dir
)
mace_model_phone_path
=
""
if
model_graph_format
==
ModelFormat
.
file
:
mace_model_phone_path
=
"%s/%s.pb"
%
(
self
.
data_dir
,
...
...
tools/sh_commands.py
浏览文件 @
5d9b931e
...
...
@@ -264,6 +264,7 @@ def bazel_build(target,
toolchain
=
'android'
,
enable_hexagon
=
False
,
enable_hta
=
False
,
enable_apu
=
False
,
enable_openmp
=
False
,
enable_neon
=
True
,
enable_opencl
=
True
,
...
...
@@ -303,8 +304,9 @@ def bazel_build(target,
"--define"
,
"hexagon=%s"
%
str
(
enable_hexagon
).
lower
(),
"--define"
,
"hta=%s"
%
str
(
enable_hta
).
lower
())
"hta=%s"
%
str
(
enable_hta
).
lower
(),
"--define"
,
"apu=%s"
%
str
(
enable_apu
).
lower
())
if
address_sanitizer
:
bazel_args
+=
(
"--config"
,
"asan"
)
if
debug_mode
:
...
...
@@ -322,6 +324,7 @@ def bazel_build(target,
sh
.
bazel
(
_fg
=
True
,
*
bazel_args
)
six
.
print_
(
bazel_args
)
six
.
print_
(
"Build done!
\n
"
)
...
...
@@ -881,6 +884,7 @@ def build_run_throughput_test(abi,
cpu_model_tag
,
gpu_model_tag
,
dsp_model_tag
,
apu_model_tag
,
phone_data_dir
,
strip
=
"always"
,
input_file_name
=
"model_input"
):
...
...
@@ -896,7 +900,9 @@ def build_run_throughput_test(abi,
if
dsp_model_tag
:
model_tag_build_flag
+=
"--copt=-DMACE_DSP_MODEL_TAG=%s "
%
\
dsp_model_tag
if
apu_model_tag
:
model_tag_build_flag
+=
"--copt=-DMACE_APU_MODEL_TAG=%s "
%
\
apu_model_tag
sh
.
cp
(
"-f"
,
merged_lib_file
,
"mace/benchmark/libmace_merged.a"
)
sh
.
bazel
(
"build"
,
...
...
@@ -948,7 +954,10 @@ def build_run_throughput_test(abi,
adb_push
(
"third_party/nnlib/%s/libhexagon_controller.so"
%
abi
,
phone_data_dir
,
serialno
)
if
apu_model_tag
:
adb_push
(
"third_party/apu/libapu-frontend.so"
,
phone_data_dir
,
serialno
)
sh
.
adb
(
"-s"
,
serialno
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录