Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
624e6e0b
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,发现更多精彩内容 >>
提交
624e6e0b
编写于
7月 04, 2018
作者:
李
李寅
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add build-standalone-lib script.
Fix ndk compile warning
上级
539692be
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
84 addition
and
210 deletion
+84
-210
mace/BUILD
mace/BUILD
+9
-17
mace/core/runtime/hexagon/hexagon_control_wrapper.cc
mace/core/runtime/hexagon/hexagon_control_wrapper.cc
+39
-20
tools/build-standalone-lib.sh
tools/build-standalone-lib.sh
+36
-0
tools/export_lib.sh
tools/export_lib.sh
+0
-173
未找到文件。
mace/BUILD
浏览文件 @
624e6e0b
...
...
@@ -24,14 +24,6 @@ config_setting(
visibility
=
[
"//visibility:public"
],
)
config_setting
(
name
=
"production_mode"
,
define_values
=
{
"production"
:
"true"
,
},
visibility
=
[
"//visibility:public"
],
)
config_setting
(
name
=
"neon_enabled"
,
define_values
=
{
...
...
@@ -62,27 +54,27 @@ config_setting(
cc_binary
(
name
=
"libmace.so"
,
linkshared
=
1
,
linkstatic
=
0
,
linkopts
=
[
"-Wl,-soname,libmace.so"
,
"-Wl,--version-script"
,
"mace_version_script.lds"
,
],
linkshared
=
1
,
linkstatic
=
0
,
deps
=
[
"//mace/ops"
,
":mace_version_script.lds"
,
"//mace/ops"
,
],
)
cc_library
(
name
=
"libmace"
,
srcs
=
[
"libmace.so"
],
visibility
=
[
"//visibility:public"
],
name
=
"libmace"
,
srcs
=
[
"libmace.so"
],
visibility
=
[
"//visibility:public"
],
)
cc_library
(
name
=
"libmace_static"
,
srcs
=
[
"libmace.a"
],
visibility
=
[
"//visibility:public"
],
name
=
"libmace_static"
,
srcs
=
[
"libmace.a"
],
visibility
=
[
"//visibility:public"
],
)
mace/core/runtime/hexagon/hexagon_control_wrapper.cc
浏览文件 @
624e6e0b
...
...
@@ -339,16 +339,28 @@ bool HexagonControlWrapper::ExecuteGraph(const Tensor &input_tensor,
std
::
vector
<
uint32_t
>
output_shape
(
4
);
uint32_t
output_bytes
;
int
res
=
hexagon_nn_execute
(
nn_id_
,
input_tensor
.
shape
()[
0
],
input_tensor
.
shape
()[
1
],
input_tensor
.
shape
()[
2
],
input_tensor
.
shape
()[
3
],
nn_id_
,
static_cast
<
uint32_t
>
(
input_tensor
.
shape
()[
0
]),
static_cast
<
uint32_t
>
(
input_tensor
.
shape
()[
1
]),
static_cast
<
uint32_t
>
(
input_tensor
.
shape
()[
2
]),
static_cast
<
uint32_t
>
(
input_tensor
.
shape
()[
3
]),
reinterpret_cast
<
const
unsigned
char
*>
(
input_tensor
.
raw_data
()),
input_tensor
.
raw_size
(),
&
output_shape
[
0
],
&
output_shape
[
1
],
&
output_shape
[
2
],
&
output_shape
[
3
],
static_cast
<
int
>
(
input_tensor
.
raw_size
()),
&
output_shape
[
0
],
&
output_shape
[
1
],
&
output_shape
[
2
],
&
output_shape
[
3
],
reinterpret_cast
<
unsigned
char
*>
(
output_tensor
->
raw_mutable_data
()),
output_tensor
->
raw_size
(),
&
output_bytes
);
static_cast
<
int
>
(
output_tensor
->
raw_size
()),
&
output_bytes
);
MACE_CHECK
(
res
==
0
,
"execute error"
);
MACE_ASSERT
(
output_shape
==
output_shapes_
[
0
],
"wrong output shape inferred"
);
MACE_ASSERT
(
output_shape
.
size
()
==
output_shapes_
[
0
].
size
(),
"wrong output shape inferred"
);
for
(
size_t
i
=
0
;
i
<
output_shape
.
size
();
++
i
)
{
MACE_ASSERT
(
static_cast
<
index_t
>
(
output_shape
[
i
])
==
output_shapes_
[
0
][
i
],
"wrong output shape inferred"
);
}
MACE_ASSERT
(
output_bytes
==
output_tensor
->
raw_size
(),
"wrong output bytes inferred."
);
return
res
==
0
;
...
...
@@ -358,44 +370,51 @@ bool HexagonControlWrapper::ExecuteGraphNew(
const
std
::
vector
<
Tensor
>
&
input_tensors
,
std
::
vector
<
Tensor
>
*
output_tensors
)
{
LOG
(
INFO
)
<<
"Execute graph new: "
<<
nn_id_
;
int
num_inputs
=
input_tensors
.
size
(
);
int
num_outputs
=
output_tensors
->
size
(
);
uint32_t
num_inputs
=
static_cast
<
uint32_t
>
(
input_tensors
.
size
()
);
uint32_t
num_outputs
=
static_cast
<
uint32_t
>
(
output_tensors
->
size
()
);
MACE_ASSERT
(
num_inputs_
==
num_inputs
,
"Wrong inputs num"
);
MACE_ASSERT
(
num_outputs_
==
num_outputs
,
"Wrong outputs num"
);
hexagon_nn_tensordef
*
inputs
=
new
hexagon_nn_tensordef
[
num_inputs
];
hexagon_nn_tensordef
*
outputs
=
new
hexagon_nn_tensordef
[
num_outputs
];
for
(
in
t
i
=
0
;
i
<
num_inputs
;
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
num_inputs
;
++
i
)
{
std
::
vector
<
index_t
>
input_shape
=
input_tensors
[
i
].
shape
();
inputs
[
i
].
batches
=
input_shape
[
0
]
;
inputs
[
i
].
height
=
input_shape
[
1
]
;
inputs
[
i
].
width
=
input_shape
[
2
]
;
inputs
[
i
].
depth
=
input_shape
[
3
]
;
inputs
[
i
].
batches
=
static_cast
<
uint32_t
>
(
input_shape
[
0
])
;
inputs
[
i
].
height
=
static_cast
<
uint32_t
>
(
input_shape
[
1
])
;
inputs
[
i
].
width
=
static_cast
<
uint32_t
>
(
input_shape
[
2
])
;
inputs
[
i
].
depth
=
static_cast
<
uint32_t
>
(
input_shape
[
3
])
;
inputs
[
i
].
data
=
const_cast
<
unsigned
char
*>
(
reinterpret_cast
<
const
unsigned
char
*>
(
input_tensors
[
i
].
raw_data
()));
inputs
[
i
].
dataLen
=
input_tensors
[
i
].
raw_size
();
inputs
[
i
].
data_valid_len
=
input_tensors
[
i
].
raw_size
();
inputs
[
i
].
dataLen
=
static_cast
<
int
>
(
input_tensors
[
i
].
raw_size
());
inputs
[
i
].
data_valid_len
=
static_cast
<
uint32_t
>
(
input_tensors
[
i
].
raw_size
());
inputs
[
i
].
unused
=
0
;
}
for
(
in
t
i
=
0
;
i
<
num_outputs
;
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
num_outputs
;
++
i
)
{
(
*
output_tensors
)[
i
].
SetDtype
(
output_data_types_
[
i
]);
(
*
output_tensors
)[
i
].
Resize
(
output_shapes_
[
i
]);
outputs
[
i
].
data
=
reinterpret_cast
<
unsigned
char
*>
(
(
*
output_tensors
)[
i
].
raw_mutable_data
());
outputs
[
i
].
dataLen
=
(
*
output_tensors
)[
i
].
raw_size
(
);
outputs
[
i
].
dataLen
=
static_cast
<
int
>
((
*
output_tensors
)[
i
].
raw_size
()
);
}
int
res
=
hexagon_nn_execute_new
(
nn_id_
,
inputs
,
num_inputs
,
outputs
,
num_outputs
);
for
(
in
t
i
=
0
;
i
<
num_outputs
;
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
num_outputs
;
++
i
)
{
std
::
vector
<
uint32_t
>
output_shape
{
outputs
[
i
].
batches
,
outputs
[
i
].
height
,
outputs
[
i
].
width
,
outputs
[
i
].
depth
};
MACE_ASSERT
(
output_shape
==
output_shapes_
[
i
]
,
MACE_ASSERT
(
output_shape
.
size
()
==
output_shapes_
[
i
].
size
()
,
"wrong output shape inferred"
);
MACE_ASSERT
(
outputs
[
i
].
data_valid_len
==
(
*
output_tensors
)[
i
].
raw_size
(),
for
(
size_t
j
=
0
;
j
<
output_shape
.
size
();
++
j
)
{
MACE_ASSERT
(
static_cast
<
index_t
>
(
output_shape
[
j
])
==
output_shapes_
[
i
][
j
],
"wrong output shape inferred"
);
}
MACE_ASSERT
(
static_cast
<
index_t
>
(
outputs
[
i
].
data_valid_len
)
==
(
*
output_tensors
)[
i
].
raw_size
(),
"wrong output bytes inferred."
);
}
...
...
tools/build-standalone-lib.sh
0 → 100755
浏览文件 @
624e6e0b
#!/bin/bash
set
-e
LIB_DIR
=
build/lib
INCLUDE_DIR
=
build/include/mace/public
mkdir
-p
$LIB_DIR
mkdir
-p
$INCLUDE_DIR
# copy include headers
cp
mace/public/
*
.h
$INCLUDE_DIR
/
echo
"build lib for armeabi-v7a"
mkdir
-p
$LIB_DIR
/armeabi-v7a
rm
-f
$LIB_DIR
/armeabi-v7a/
*
bazel build
--config
android mace:libmace
--define
neon
=
true
--define
openmp
=
true
--define
hexagon
=
true
--cpu
=
armeabi-v7a
cp
bazel-bin/mace/libmace.so
$LIB_DIR
/armeabi-v7a/
cp
third_party/nnlib/
*
so
$LIB_DIR
/armeabi-v7a/
echo
"build lib for arm64-v8a"
mkdir
-p
$LIB_DIR
/arm64-v8a
rm
-f
$LIB_DIR
/arm64-v8a/
*
bazel build
--config
android mace:libmace
--define
neon
=
true
--define
openmp
=
true
--cpu
=
arm64-v8a
cp
bazel-bin/mace/libmace.so
$LIB_DIR
/arm64-v8a/
echo
"build lib for linux-x86-64"
mkdir
-p
$LIB_DIR
/linux-x86-64
rm
-f
$LIB_DIR
/linux-x86-64/
*
bazel build mace:libmace
--define
openmp
=
true
cp
bazel-bin/mace/libmace.so
$LIB_DIR
/linux-x86-64/
tools/export_lib.sh
已删除
100755 → 0
浏览文件 @
539692be
#!/bin/bash
set
-e
Usage
()
{
echo
"Usage: ./tools/export_lib.sh target_abi[armeabi-v7a | arm64-v8a | host] runtime[gpu | dsp] export_include_dir export_lib_dir"
echo
"eg: ./tools/export_lib.sh armeabi-v7a gpu ../include ../lib/libmace-armeabi-v7a"
}
if
[
$#
-lt
4
]
;
then
Usage
exit
1
fi
TARGET_ABI
=
$1
RUNTIME
=
$2
EXPORT_INCLUDE_DIR
=
$3
EXPORT_LIB_DIR
=
$4
if
[
x
"
${
RUNTIME
}
"
=
x
"dsp"
]
;
then
DSP_MODE_BUILD_FLAGS
=
"--define hexagon=true"
fi
MACE_SOURCE_DIR
=
`
/bin/pwd
`
CODEGEN_DIR
=
${
MACE_SOURCE_DIR
}
/mace/codegen
CL_CODEGEN_DIR
=
${
CODEGEN_DIR
}
/opencl
VERSION_CODEGEN_DIR
=
${
CODEGEN_DIR
}
/version
STRIP
=
"--strip always"
# TO REMOVE
LIBMACE_TEMP_DIR
=
`
mktemp
-d
-t
libmace.XXXX
`
LIBMACE_NAME
=
"libmace"
LIBMACE_DEV_NAME
=
"libmace_dev"
LIBMACE_PROD_NAME
=
"libmace_prod"
libmace_targets
=(
"//mace/ops:ops"
"//mace/kernels:kernels"
"//mace/codegen:generated_version"
"//mace/core:core"
"//mace/utils:utils"
)
libmace_dev_targets
=(
"//mace/codegen:generated_opencl_dev"
"//mace/core:opencl_dev"
"//mace/utils:utils_dev"
)
libmace_prod_targets
=(
"//mace/core:opencl_prod"
"//mace/utils:utils_prod"
)
all_targets
=(
${
libmace_targets
[*]
}
${
libmace_dev_targets
[*]
}
${
libmace_prod_targets
[*]
}
)
build_target
()
{
BAZEL_TARGET
=
$1
bazel build
--verbose_failures
-c
opt
--strip
always
$BAZEL_TARGET
\
--crosstool_top
=
//external:android/crosstool
\
--host_crosstool_top
=
@bazel_tools//tools/cpp:toolchain
\
--cpu
=
$TARGET_ABI
\
--copt
=
"-std=c++11"
\
--copt
=
"-D_GLIBCXX_USE_C99_MATH_TR1"
\
--copt
=
"-Werror=return-type"
\
--copt
=
"-DMACE_OBFUSCATE_LITERALS"
\
--copt
=
"-O3"
\
--define
neon
=
true
\
--define
openmp
=
true
\
$DSP_MODE_BUILD_FLAGS
||
exit
1
}
build_host_target
()
{
BAZEL_TARGET
=
$1
bazel build
--verbose_failures
-c
opt
--strip
always
$BAZEL_TARGET
\
--copt
=
"-std=c++11"
\
--copt
=
"-D_GLIBCXX_USE_C99_MATH_TR1"
\
--copt
=
"-Werror=return-type"
\
--copt
=
"-DMACE_OBFUSCATE_LITERALS"
\
--copt
=
"-O3"
\
--define
openmp
=
true
||
exit
1
}
merge_libs
()
{
CREATE_LIB_NAME
=
$1
LIBS_LIST
=
$2
echo
"create
${
LIBMACE_TEMP_DIR
}
/
${
CREATE_LIB_NAME
}
.a"
>
${
LIBMACE_TEMP_DIR
}
/
${
CREATE_LIB_NAME
}
.mri
||
exit
1
for
lib_target
in
${
LIBS_LIST
[*]
}
do
lib_dir
=
`
echo
${
lib_target
}
|
cut
-d
:
-f1
`
lib_dir
=
${
lib_dir
#//
}
lib_name_prefix
=
lib
`
echo
${
lib_target
}
|
cut
-d
:
-f2
`
bin_path
=
"
${
MACE_SOURCE_DIR
}
/bazel-bin/
${
lib_dir
}
/
${
lib_name_prefix
}
"
if
[
x
"
${
RUNTIME
}
"
=
x
"local"
]
;
then
if
[
-f
"
${
bin_path
}
.pic.a"
]
;
then
bin_path
=
"
${
bin_path
}
.pic.a"
else
bin_path
=
"
${
bin_path
}
.pic.lo"
fi
else
if
[
-f
"
${
bin_path
}
.a"
]
;
then
bin_path
=
"
${
bin_path
}
.a"
else
bin_path
=
"
${
bin_path
}
.lo"
fi
fi
echo
"addlib
${
bin_path
}
"
>>
${
LIBMACE_TEMP_DIR
}
/
${
CREATE_LIB_NAME
}
.mri
||
exit
1
done
echo
"save"
>>
${
LIBMACE_TEMP_DIR
}
/
${
CREATE_LIB_NAME
}
.mri
||
exit
1
echo
"end"
>>
${
LIBMACE_TEMP_DIR
}
/
${
CREATE_LIB_NAME
}
.mri
||
exit
1
$ANDROID_NDK_HOME
/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar
\
-M
<
${
LIBMACE_TEMP_DIR
}
/
${
CREATE_LIB_NAME
}
.mri
||
exit
1
}
echo
"Step 1: Generate encrypted opencl source"
python mace/python/tools/encrypt_opencl_codegen.py
\
--cl_kernel_dir
=
./mace/kernels/opencl/cl/
\
--output_path
=
${
CODEGEN_DIR
}
/opencl/opencl_encrypt_program.cc
||
exit
1
echo
"Step 2: Generate version source"
rm
-rf
${
VERSION_CODEGEN_DIR
}
mkdir
${
VERSION_CODEGEN_DIR
}
bash mace/tools/git/gen_version_source.sh
${
CODEGEN_DIR
}
/version/version.cc
||
exit
1
echo
"Step 3: Build libmace targets"
bazel clean
if
[
x
"
${
TARGET_ABI
}
"
=
x
"host"
]
||
[
x
"
${
TARGET_ABI
}
"
=
x
"local"
]
;
then
for
target
in
${
all_targets
[*]
}
do
build_host_target
${
target
}
done
else
for
target
in
${
all_targets
[*]
}
do
build_target
${
target
}
done
fi
echo
"Step 4: Create mri files and generate merged libs"
merge_libs
"libmace"
"
${
libmace_targets
[*]
}
"
merge_libs
"libmace_dev"
"
${
libmace_dev_targets
[*]
}
"
merge_libs
"libmace_prod"
"
${
libmace_prod_targets
[*]
}
"
echo
"Step 5: Export lib"
rm
-rf
${
EXPORT_INCLUDE_DIR
}
mkdir
-p
${
EXPORT_INCLUDE_DIR
}
/mace/public
mkdir
-p
${
EXPORT_INCLUDE_DIR
}
/mace/utils
rm
-rf
${
EXPORT_LIB_DIR
}
mkdir
-p
${
EXPORT_LIB_DIR
}
cp
${
MACE_SOURCE_DIR
}
/mace/public/
*
.h
${
EXPORT_INCLUDE_DIR
}
/mace/public/
||
exit
1
# utils is not part of public API
cp
${
MACE_SOURCE_DIR
}
/mace/utils/env_time.h
${
EXPORT_INCLUDE_DIR
}
/mace/utils/
||
exit
1
cp
${
MACE_SOURCE_DIR
}
/mace/utils/logging.h
${
EXPORT_INCLUDE_DIR
}
/mace/utils/
||
exit
1
cp
${
MACE_SOURCE_DIR
}
/mace/utils/string_util.h
${
EXPORT_INCLUDE_DIR
}
/mace/utils/
||
exit
1
cp
${
LIBMACE_TEMP_DIR
}
/libmace.a
${
LIBMACE_TEMP_DIR
}
/libmace_dev.a
${
LIBMACE_TEMP_DIR
}
/libmace_prod.a
${
EXPORT_LIB_DIR
}
/
||
exit
1
echo
"Step 6: Remove temporary file"
rm
-rf
${
LIBMACE_TEMP_DIR
}
echo
"Done!"
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录