Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
691331bd
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,发现更多精彩内容 >>
提交
691331bd
编写于
7月 16, 2018
作者:
刘
刘琦
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'separate_opencl' into 'master'
separate opencl when only run on cpu See merge request !663
上级
37269759
731a2185
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
218 addition
and
125 deletion
+218
-125
docs/user_guide/advanced_usage.rst
docs/user_guide/advanced_usage.rst
+21
-0
mace/BUILD
mace/BUILD
+5
-51
mace/benchmark/BUILD
mace/benchmark/BUILD
+3
-2
mace/core/BUILD
mace/core/BUILD
+5
-4
mace/core/file_storage.cc
mace/core/file_storage.cc
+2
-28
mace/core/runtime/opencl/opencl_runtime.cc
mace/core/runtime/opencl/opencl_runtime.cc
+0
-2
mace/examples/cli/BUILD
mace/examples/cli/BUILD
+9
-3
mace/kernels/BUILD
mace/kernels/BUILD
+14
-6
mace/libmace/BUILD
mace/libmace/BUILD
+64
-2
mace/libmace/mace_runtime.cc
mace/libmace/mace_runtime.cc
+36
-2
mace/libmace/mace_version_script.lds
mace/libmace/mace_version_script.lds
+0
-0
mace/mace.bzl
mace/mace.bzl
+5
-0
mace/ops/BUILD
mace/ops/BUILD
+13
-5
mace/tools/validation/BUILD
mace/tools/validation/BUILD
+4
-4
tools/build-standalone-lib.sh
tools/build-standalone-lib.sh
+12
-12
tools/converter.py
tools/converter.py
+22
-4
tools/sh_commands.py
tools/sh_commands.py
+3
-0
未找到文件。
docs/user_guide/advanced_usage.rst
浏览文件 @
691331bd
...
...
@@ -362,3 +362,24 @@ Use ``-h`` to get detailed help.
python tools/converter.py build -h
python tools/converter.py run -h
python tools/converter.py benchmark -h
Reduce Library Size
-------------------
* **dynamic library**
The generated dynamic library by script ``tools/build-standalone-lib.sh`` is about ``1.6M`` for
``armeabi-v7a`` and ``2.1M`` for ``arm64-v8a``. It can be reduced by modifying some build options.
- If the models don't need to run on device ``dsp``, change the build option ``--define hexagon=true``
to ``false``. And the library will be decreased about ``100KB``.
- Futher more, if only ``cpu`` device needed, change ``--define opencl=true`` to ``false``. This way
will reduce half of library size to about ``700KB`` for ``armeabi-v7a`` and ``1000KB`` for ``arm64-v8a``
* **static library**
- The methods in dynamic library can be useful for static library too. In additional, the static
library may also contain model graph and model datas if the configs ``model_graph_format`` and
``model_data_format`` in deployment file are set to ``code``.
- It is recommended to use ``version script`` for ultimate binary. The effect is remarkable.
mace/BUILD
浏览文件 @
691331bd
...
...
@@ -52,56 +52,10 @@ config_setting(
visibility
=
[
"//visibility:public"
],
)
cc_binary
(
name
=
"libmace.so"
,
linkopts
=
[
"-Wl,-soname,libmace.so"
,
"-Wl,--version-script"
,
"mace_version_script.lds"
,
],
linkshared
=
1
,
linkstatic
=
0
,
deps
=
[
":mace_version_script.lds"
,
"//mace/libmace"
,
],
)
cc_library
(
name
=
"libmace"
,
srcs
=
[
"libmace.so"
],
visibility
=
[
"//visibility:public"
],
)
genrule
(
name
=
"libmace_static"
,
srcs
=
[
"//mace/codegen:generated_opencl"
,
"//mace/codegen:generated_version"
,
"//mace/core"
,
"//mace/kernels"
,
"//mace/ops"
,
"//mace/libmace"
,
"//mace/utils"
,
"//mace/proto:mace_cc"
,
"@com_google_protobuf//:protobuf_lite"
,
],
outs
=
[
"libmace.a"
],
cmd
=
"tmp_mri_file=$$(mktemp mace-static-lib-mri.XXXXXXXXXX);"
+
"mri_stream=$$(python $(location //mace/python/tools:archive_static_lib) "
+
"$(locations //mace/codegen:generated_opencl) "
+
"$(locations //mace/codegen:generated_version) "
+
"$(locations //mace/core:core) "
+
"$(locations //mace/kernels:kernels) "
+
"$(locations //mace/ops:ops) "
+
"$(locations //mace/libmace:libmace) "
+
"$(locations //mace/utils:utils) "
+
"$(locations //mace/proto:mace_cc) "
+
"$(locations @com_google_protobuf//:protobuf_lite) "
+
"$@ "
+
"$$tmp_mri_file);"
+
"$(AR) -M <$$tmp_mri_file;"
+
"rm -rf $$tmp_mri_file;"
,
tools
=
[
"//mace/python/tools:archive_static_lib"
],
config_setting
(
name
=
"opencl_enabled"
,
define_values
=
{
"opencl"
:
"true"
,
},
visibility
=
[
"//visibility:public"
],
)
mace/benchmark/BUILD
浏览文件 @
691331bd
...
...
@@ -5,6 +5,7 @@ load(
"if_hexagon_enabled"
,
"if_openmp_enabled"
,
"if_android"
,
"if_opencl_enabled"
,
)
licenses
([
"notice"
])
# Apache 2.0
...
...
@@ -28,7 +29,7 @@ cc_binary(
"-Werror"
,
"-Wextra"
,
"-Wno-missing-field-initializers"
,
]
+
if_
androi
d
([
"-DMACE_ENABLE_OPENCL"
]),
]
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
]),
linkopts
=
if_openmp_enabled
([
"-fopenmp"
]),
linkstatic
=
1
,
deps
=
[
...
...
@@ -56,7 +57,7 @@ cc_binary(
":statistics"
,
"//external:gflags_nothreads"
,
"//mace/codegen:generated_mace_engine_factory"
,
"//mace
:libmace
"
,
"//mace
/libmace:libmace_dynamic
"
,
],
)
...
...
mace/core/BUILD
浏览文件 @
691331bd
...
...
@@ -14,6 +14,7 @@ load(
"if_not_hexagon_enabled"
,
"if_openmp_enabled"
,
"if_neon_enabled"
,
"if_opencl_enabled"
,
)
cc_library
(
...
...
@@ -26,7 +27,7 @@ cc_library(
exclude
=
[
"*_test.cc"
,
],
)
+
if_
androi
d
(
glob
(
)
+
if_
opencl_enable
d
(
glob
(
[
"runtime/opencl/*.cc"
,
],
...
...
@@ -36,7 +37,7 @@ cc_library(
hdrs
=
glob
([
"*.h"
,
"runtime/cpu/*.h"
,
])
+
if_
androi
d
(
glob
(
])
+
if_
opencl_enable
d
(
glob
(
[
"runtime/opencl/*.h"
,
],
...
...
@@ -48,7 +49,7 @@ cc_library(
]
+
if_openmp_enabled
([
"-fopenmp"
,
"-DMACE_ENABLE_OPENMP"
,
])
+
if_
androi
d
([
])
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
])
+
if_hexagon_enabled
([
"-DMACE_ENABLE_HEXAGON"
,
...
...
@@ -63,7 +64,7 @@ cc_library(
"//mace/codegen:generated_version"
,
"//mace/proto:mace_cc"
,
"//mace/utils"
,
]
+
if_
androi
d
([
]
+
if_
opencl_enable
d
([
":opencl_headers"
,
"//mace/codegen:generated_opencl"
,
"@half//:half"
,
...
...
mace/core/file_storage.cc
浏览文件 @
691331bd
...
...
@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "mace/core/file_storage.h"
#include <fcntl.h>
#include <limits.h>
#include <sys/mman.h>
...
...
@@ -25,36 +23,12 @@
#include <memory>
#include <utility>
#include "mace/core/file_storage.h"
#include "mace/utils/logging.h"
namespace
mace
{
class
FileStorageFactory
::
Impl
{
public:
explicit
Impl
(
const
std
::
string
&
path
);
std
::
unique_ptr
<
KVStorage
>
CreateStorage
(
const
std
::
string
&
name
);
private:
std
::
string
path_
;
};
FileStorageFactory
::
Impl
::
Impl
(
const
std
::
string
&
path
)
:
path_
(
path
)
{}
std
::
unique_ptr
<
KVStorage
>
FileStorageFactory
::
Impl
::
CreateStorage
(
const
std
::
string
&
name
)
{
return
std
::
move
(
std
::
unique_ptr
<
KVStorage
>
(
new
FileStorage
(
path_
+
"/"
+
name
)));
}
FileStorageFactory
::
FileStorageFactory
(
const
std
::
string
&
path
)
:
impl_
(
new
FileStorageFactory
::
Impl
(
path
))
{}
FileStorageFactory
::~
FileStorageFactory
()
=
default
;
std
::
unique_ptr
<
KVStorage
>
FileStorageFactory
::
CreateStorage
(
const
std
::
string
&
name
)
{
return
impl_
->
CreateStorage
(
name
);
}
std
::
shared_ptr
<
KVStorageFactory
>
kStorageFactory
=
nullptr
;
FileStorage
::
FileStorage
(
const
std
::
string
&
file_path
)
:
data_changed_
(
false
),
file_path_
(
file_path
)
{}
...
...
mace/core/runtime/opencl/opencl_runtime.cc
浏览文件 @
691331bd
...
...
@@ -33,8 +33,6 @@
namespace
mace
{
std
::
shared_ptr
<
KVStorageFactory
>
kStorageFactory
=
nullptr
;
std
::
string
kOpenCLParameterPath
;
// NOLINT(runtime/string)
extern
const
std
::
map
<
std
::
string
,
std
::
vector
<
unsigned
char
>>
...
...
mace/examples/cli/BUILD
浏览文件 @
691331bd
# Examples
load
(
"//mace:mace.bzl"
,
"if_openmp_enabled"
,
"if_android"
,
"if_hexagon_enabled"
)
load
(
"//mace:mace.bzl"
,
"if_openmp_enabled"
,
"if_android"
,
"if_hexagon_enabled"
,
"if_opencl_enabled"
,
)
cc_binary
(
name
=
"example_static"
,
...
...
@@ -7,7 +13,7 @@ cc_binary(
copts
=
[
"-Werror"
,
"-Wextra"
,
]
+
if_
androi
d
([
]
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
]),
linkopts
=
[
...
...
@@ -36,7 +42,7 @@ cc_binary(
"-Werror"
,
"-Wextra"
,
"-Wno-missing-field-initializers"
,
]
+
if_
androi
d
([
]
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
]),
linkopts
=
[
...
...
mace/kernels/BUILD
浏览文件 @
691331bd
...
...
@@ -7,7 +7,15 @@ package(
licenses
([
"notice"
])
# Apache 2.0
load
(
"//mace:mace.bzl"
,
"if_android"
,
"if_neon_enabled"
,
"if_openmp_enabled"
,
"if_android_armv7"
,
"if_hexagon_enabled"
)
load
(
"//mace:mace.bzl"
,
"if_android"
,
"if_neon_enabled"
,
"if_openmp_enabled"
,
"if_android_armv7"
,
"if_hexagon_enabled"
,
"if_opencl_enabled"
,
)
cc_library
(
name
=
"kernels"
,
...
...
@@ -21,7 +29,7 @@ cc_library(
"*_benchmark.cc"
,
"arm/*_test.cc"
,
],
)
+
if_
androi
d
(
glob
(
)
+
if_
opencl_enable
d
(
glob
(
[
"opencl/*.cc"
,
],
...
...
@@ -37,7 +45,7 @@ cc_library(
exclude
=
[
"buffer_to_image.h"
,
],
)
+
if_
androi
d
(
glob
([
)
+
if_
opencl_enable
d
(
glob
([
"opencl/*.h"
,
"buffer_to_image.h"
,
])),
...
...
@@ -53,7 +61,7 @@ cc_library(
"-mfpu=neon"
,
])
+
if_android_armv7
([
"-mfloat-abi=softfp"
,
])
+
if_
androi
d
([
])
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
])
+
if_hexagon_enabled
([
"-DMACE_ENABLE_HEXAGON"
,
...
...
@@ -86,7 +94,7 @@ cc_test(
])
+
if_android_armv7
([
"-mfpu=neon"
,
"-mfloat-abi=softfp"
,
])
+
if_
androi
d
([
])
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
])
+
if_hexagon_enabled
([
"-DMACE_ENABLE_HEXAGON"
,
...
...
@@ -116,7 +124,7 @@ cc_test(
])
+
if_android_armv7
([
"-mfpu=neon"
,
"-mfloat-abi=softfp"
,
])
+
if_
androi
d
([
])
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
])
+
if_hexagon_enabled
([
"-DMACE_ENABLE_HEXAGON"
,
...
...
mace/libmace/BUILD
浏览文件 @
691331bd
...
...
@@ -7,7 +7,15 @@ package(
licenses
([
"notice"
])
# Apache 2.0
load
(
"//mace:mace.bzl"
,
"if_android"
,
"if_neon_enabled"
,
"if_openmp_enabled"
,
"if_android_armv7"
,
"if_hexagon_enabled"
)
load
(
"//mace:mace.bzl"
,
"if_android"
,
"if_neon_enabled"
,
"if_openmp_enabled"
,
"if_android_armv7"
,
"if_hexagon_enabled"
,
"if_opencl_enabled"
,
)
cc_library
(
name
=
"libmace"
,
...
...
@@ -23,7 +31,7 @@ cc_library(
"-mfpu=neon"
,
])
+
if_android_armv7
([
"-mfloat-abi=softfp"
,
])
+
if_
androi
d
([
])
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
])
+
if_hexagon_enabled
([
"-DMACE_ENABLE_HEXAGON"
,
...
...
@@ -34,3 +42,57 @@ cc_library(
],
alwayslink
=
1
,
)
cc_binary
(
name
=
"libmace.so"
,
linkopts
=
[
"-Wl,-soname,libmace.so"
,
"-Wl,--version-script"
,
"mace_version_script.lds"
,
],
linkshared
=
1
,
linkstatic
=
0
,
deps
=
[
":mace_version_script.lds"
,
"//mace/libmace"
,
],
)
cc_library
(
name
=
"libmace_dynamic"
,
srcs
=
[
"libmace.so"
],
visibility
=
[
"//visibility:public"
],
)
genrule
(
name
=
"libmace_static"
,
srcs
=
[
"//mace/codegen:generated_opencl"
,
"//mace/codegen:generated_version"
,
"//mace/core"
,
"//mace/kernels"
,
"//mace/ops"
,
"//mace/libmace"
,
"//mace/utils"
,
"//mace/proto:mace_cc"
,
"@com_google_protobuf//:protobuf_lite"
,
],
outs
=
[
"libmace.a"
],
cmd
=
"tmp_mri_file=$$(mktemp mace-static-lib-mri.XXXXXXXXXX);"
+
"mri_stream=$$(python $(location //mace/python/tools:archive_static_lib) "
+
"$(locations //mace/codegen:generated_opencl) "
+
"$(locations //mace/codegen:generated_version) "
+
"$(locations //mace/core:core) "
+
"$(locations //mace/kernels:kernels) "
+
"$(locations //mace/ops:ops) "
+
"$(locations //mace/libmace:libmace) "
+
"$(locations //mace/utils:utils) "
+
"$(locations //mace/proto:mace_cc) "
+
"$(locations @com_google_protobuf//:protobuf_lite) "
+
"$@ "
+
"$$tmp_mri_file);"
+
"$(AR) -M <$$tmp_mri_file;"
+
"rm -rf $$tmp_mri_file;"
,
tools
=
[
"//mace/python/tools:archive_static_lib"
],
visibility
=
[
"//visibility:public"
],
)
mace/libmace/mace_runtime.cc
浏览文件 @
691331bd
...
...
@@ -13,15 +13,45 @@
// limitations under the License.
#include "mace/core/macros.h"
#include "mace/core/file_storage.h"
#include "mace/core/runtime/cpu/cpu_runtime.h"
#include "mace/public/mace_runtime.h"
#include "mace/utils/logging.h"
#ifdef MACE_ENABLE_OPENCL
#include "mace/core/runtime/opencl/opencl_runtime.h"
#endif // MACE_ENABLE_OPENCL
#include "mace/public/mace_runtime.h"
#include "mace/utils/logging.h"
namespace
mace
{
class
FileStorageFactory
::
Impl
{
public:
explicit
Impl
(
const
std
::
string
&
path
);
std
::
unique_ptr
<
KVStorage
>
CreateStorage
(
const
std
::
string
&
name
);
private:
std
::
string
path_
;
};
FileStorageFactory
::
Impl
::
Impl
(
const
std
::
string
&
path
)
:
path_
(
path
)
{}
std
::
unique_ptr
<
KVStorage
>
FileStorageFactory
::
Impl
::
CreateStorage
(
const
std
::
string
&
name
)
{
return
std
::
move
(
std
::
unique_ptr
<
KVStorage
>
(
new
FileStorage
(
path_
+
"/"
+
name
)));
}
FileStorageFactory
::
FileStorageFactory
(
const
std
::
string
&
path
)
:
impl_
(
new
FileStorageFactory
::
Impl
(
path
))
{}
FileStorageFactory
::~
FileStorageFactory
()
=
default
;
std
::
unique_ptr
<
KVStorage
>
FileStorageFactory
::
CreateStorage
(
const
std
::
string
&
name
)
{
return
impl_
->
CreateStorage
(
name
);
}
extern
std
::
shared_ptr
<
KVStorageFactory
>
kStorageFactory
;
void
SetKVStorageFactory
(
std
::
shared_ptr
<
KVStorageFactory
>
storage_factory
)
{
...
...
@@ -41,7 +71,11 @@ void SetOpenCLBinaryPaths(const std::vector<std::string> &paths) {
extern
std
::
string
kOpenCLParameterPath
;
void
SetOpenCLParameterPath
(
const
std
::
string
&
path
)
{
#ifdef MACE_ENABLE_OPENCL
kOpenCLParameterPath
=
path
;
#else
MACE_UNUSED
(
path
);
#endif // MACE_ENABLE_OPENCL
}
void
SetGPUHints
(
GPUPerfHint
gpu_perf_hint
,
GPUPriorityHint
gpu_priority_hint
)
{
...
...
mace/mace_version_script.lds
→
mace/
libmace/
mace_version_script.lds
浏览文件 @
691331bd
文件已移动
mace/mace.bzl
浏览文件 @
691331bd
...
...
@@ -48,6 +48,11 @@ def if_openmp_enabled(a):
"//conditions:default"
:
[],
})
def
if_opencl_enabled
(
a
):
return
select
({
"//mace:opencl_enabled"
:
a
,
"//conditions:default"
:
[],
})
def
mace_version_genrule
():
native
.
genrule
(
...
...
mace/ops/BUILD
浏览文件 @
691331bd
...
...
@@ -7,7 +7,15 @@ package(
licenses
([
"notice"
])
# Apache 2.0
load
(
"//mace:mace.bzl"
,
"if_android"
,
"if_neon_enabled"
,
"if_openmp_enabled"
,
"if_android_armv7"
,
"if_hexagon_enabled"
)
load
(
"//mace:mace.bzl"
,
"if_android"
,
"if_neon_enabled"
,
"if_openmp_enabled"
,
"if_android_armv7"
,
"if_hexagon_enabled"
,
"if_opencl_enabled"
,
)
cc_library
(
name
=
"test"
,
...
...
@@ -31,7 +39,7 @@ cc_library(
"buffer_to_image.cc"
,
"image_to_buffer.cc"
,
],
)
+
if_
androi
d
(
)
+
if_
opencl_enable
d
(
[
"buffer_to_image.cc"
,
"image_to_buffer.cc"
,
...
...
@@ -50,7 +58,7 @@ cc_library(
"-mfpu=neon"
,
])
+
if_android_armv7
([
"-mfloat-abi=softfp"
,
])
+
if_
androi
d
([
])
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
])
+
if_hexagon_enabled
([
"-DMACE_ENABLE_HEXAGON"
,
...
...
@@ -75,7 +83,7 @@ cc_test(
"-mfpu=neon"
,
])
+
if_android_armv7
([
"-mfloat-abi=softfp"
,
])
+
if_
androi
d
([
])
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
])
+
if_hexagon_enabled
([
"-DMACE_ENABLE_HEXAGON"
,
...
...
@@ -102,7 +110,7 @@ cc_test(
"-mfpu=neon"
,
])
+
if_android_armv7
([
"-mfloat-abi=softfp"
,
])
+
if_
androi
d
([
])
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
])
+
if_hexagon_enabled
([
"-DMACE_ENABLE_HEXAGON"
,
...
...
mace/tools/validation/BUILD
浏览文件 @
691331bd
# Examples
load
(
"//mace:mace.bzl"
,
"if_openmp_enabled"
,
"if_android"
)
load
(
"//mace:mace.bzl"
,
"if_openmp_enabled"
,
"if_android"
,
"if_opencl_enabled"
)
cc_binary
(
name
=
"mace_run_static"
,
...
...
@@ -7,7 +7,7 @@ cc_binary(
copts
=
[
"-Werror"
,
"-Wextra"
,
]
+
if_
androi
d
([
]
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
]),
linkopts
=
if_openmp_enabled
([
"-fopenmp"
]),
...
...
@@ -26,7 +26,7 @@ cc_binary(
copts
=
[
"-Werror"
,
"-Wextra"
,
]
+
if_
androi
d
([
]
+
if_
opencl_enable
d
([
"-DMACE_ENABLE_OPENCL"
,
]),
linkopts
=
[
"-lm"
,
"-pie"
,
"-fPIE"
]
+
if_openmp_enabled
([
"-fopenmp"
]),
...
...
@@ -34,7 +34,7 @@ cc_binary(
deps
=
[
"//external:gflags_nothreads"
,
"//mace/codegen:generated_mace_engine_factory"
,
"//mace
:libmace
"
,
"//mace
/libmace:libmace_dynamic
"
,
"//mace/utils:utils"
,
],
)
tools/build-standalone-lib.sh
浏览文件 @
691331bd
...
...
@@ -23,32 +23,32 @@ mkdir -p $LIB_DIR/linux-x86-64
# build shared libraries
echo
"build shared lib for armeabi-v7a"
bazel build
--config
android
--config
optimization mace
:libmace
--define
neon
=
true
--define
openmp
=
true
--define
hexagon
=
true
--cpu
=
armeabi-v7a
cp
bazel-bin/mace/libmace.so
$LIB_DIR
/armeabi-v7a/
bazel build
--config
android
--config
optimization mace
/libmace:libmace_dynamic
--define
neon
=
true
--define
openmp
=
true
--define
opencl
=
true
--define
hexagon
=
true
--cpu
=
armeabi-v7a
cp
bazel-bin/mace/libmace
/libmace
.so
$LIB_DIR
/armeabi-v7a/
cp
third_party/nnlib/
*
so
$LIB_DIR
/armeabi-v7a/
echo
"build shared lib for arm64-v8a"
bazel build
--config
android
--config
optimization mace
:libmace
--define
neon
=
true
--define
openmp
=
true
--cpu
=
arm64-v8a
cp
bazel-bin/mace/libmace.so
$LIB_DIR
/arm64-v8a/
bazel build
--config
android
--config
optimization mace
/libmace:libmace_dynamic
--define
neon
=
true
--define
openmp
=
true
--define
opencl
=
true
--cpu
=
arm64-v8a
cp
bazel-bin/mace/libmace
/libmace
.so
$LIB_DIR
/arm64-v8a/
echo
"build shared lib for linux-x86-64"
bazel build mace
:libmace
--config
optimization
--define
openmp
=
true
cp
bazel-bin/mace/libmace.so
$LIB_DIR
/linux-x86-64/
bazel build mace
/libmace:libmace_dynamic
--config
optimization
--define
openmp
=
true
cp
bazel-bin/mace/libmace
/libmace
.so
$LIB_DIR
/linux-x86-64/
# build static libraries
echo
"build static lib for armeabi-v7a"
bazel build
--config
android
--config
optimization mace
:libmace_static
--define
neon
=
true
--define
openmp
=
true
--define
hexagon
=
true
--cpu
=
armeabi-v7a
cp
bazel-genfiles/mace/libmace.a
$LIB_DIR
/armeabi-v7a/
bazel build
--config
android
--config
optimization mace
/libmace:libmace_static
--define
neon
=
true
--define
openmp
=
true
--define
opencl
=
true
--define
hexagon
=
true
--cpu
=
armeabi-v7a
cp
bazel-genfiles/mace/libmace
/libmace
.a
$LIB_DIR
/armeabi-v7a/
cp
third_party/nnlib/
*
so
$LIB_DIR
/armeabi-v7a/
echo
"build static lib for arm64-v8a"
bazel build
--config
android
--config
optimization mace
:libmace_static
--define
neon
=
true
--define
openmp
=
true
--cpu
=
arm64-v8a
cp
bazel-genfiles/mace/libmace.a
$LIB_DIR
/arm64-v8a/
bazel build
--config
android
--config
optimization mace
/libmace:libmace_static
--define
neon
=
true
--define
openmp
=
true
--define
opencl
=
true
--cpu
=
arm64-v8a
cp
bazel-genfiles/mace/libmace
/libmace
.a
$LIB_DIR
/arm64-v8a/
echo
"build static lib for linux-x86-64"
bazel build mace:libmace_static
--config
optimization
--define
openmp
=
true
cp
bazel-genfiles/mace/libmace.a
$LIB_DIR
/linux-x86-64/
bazel build mace
/libmace
:libmace_static
--config
optimization
--define
openmp
=
true
cp
bazel-genfiles/mace/libmace
/libmace
.a
$LIB_DIR
/linux-x86-64/
echo
"LIB PATH:
$LIB_DIR
"
echo
"INCLUDE FILE PATH:
$INCLUDE_DIR
"
tools/converter.py
浏览文件 @
691331bd
...
...
@@ -60,10 +60,10 @@ CODEGEN_BASE_DIR = 'mace/codegen'
MODEL_CODEGEN_DIR
=
CODEGEN_BASE_DIR
+
'/models'
ENGINE_CODEGEN_DIR
=
CODEGEN_BASE_DIR
+
'/engine'
LIB_CODEGEN_DIR
=
CODEGEN_BASE_DIR
+
'/lib'
LIBMACE_SO_TARGET
=
"//mace:libmace.so"
LIBMACE_STATIC_TARGET
=
"//mace:libmace_static"
LIBMACE_STATIC_PATH
=
"bazel-genfiles/mace/libmace.a"
LIBMACE_DYNAMIC_PATH
=
"bazel-bin/mace/libmace.so"
LIBMACE_SO_TARGET
=
"//mace
/libmace
:libmace.so"
LIBMACE_STATIC_TARGET
=
"//mace
/libmace
:libmace_static"
LIBMACE_STATIC_PATH
=
"bazel-genfiles/mace/libmace
/libmace
.a"
LIBMACE_DYNAMIC_PATH
=
"bazel-bin/mace/libmace
/libmace
.so"
MODEL_LIB_TARGET
=
"//mace/codegen:generated_models"
MODEL_LIB_PATH
=
"bazel-bin/mace/codegen/libgenerated_models.a"
MACE_RUN_STATIC_NAME
=
"mace_run_static"
...
...
@@ -247,6 +247,19 @@ def get_hexagon_mode(configs):
return
False
def
get_opencl_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
.
gpu
in
runtime_list
or
RuntimeType
.
cpu_gpu
in
runtime_list
:
return
True
return
False
def
md5sum
(
str
):
md5
=
hashlib
.
md5
()
md5
.
update
(
str
)
...
...
@@ -740,6 +753,7 @@ def build_model_lib(configs, address_sanitizer):
MODEL_LIB_TARGET
,
abi
=
target_abi
,
hexagon_mode
=
hexagon_mode
,
enable_opencl
=
get_opencl_mode
(
configs
),
address_sanitizer
=
address_sanitizer
)
...
...
@@ -849,6 +863,7 @@ def build_mace_run(configs, target_abi, enable_openmp, address_sanitizer,
abi
=
target_abi
,
hexagon_mode
=
hexagon_mode
,
enable_openmp
=
enable_openmp
,
enable_opencl
=
get_opencl_mode
(
configs
),
address_sanitizer
=
address_sanitizer
,
extra_args
=
build_arg
)
...
...
@@ -872,6 +887,7 @@ def build_example(configs, target_abi, enable_openmp, mace_lib_type):
sh_commands
.
bazel_build
(
libmace_target
,
abi
=
target_abi
,
enable_openmp
=
enable_openmp
,
enable_opencl
=
get_opencl_mode
(
configs
),
hexagon_mode
=
hexagon_mode
)
if
os
.
path
.
exists
(
LIB_CODEGEN_DIR
):
...
...
@@ -898,6 +914,7 @@ def build_example(configs, target_abi, enable_openmp, mace_lib_type):
sh_commands
.
bazel_build
(
example_target
,
abi
=
target_abi
,
enable_openmp
=
enable_openmp
,
enable_opencl
=
get_opencl_mode
(
configs
),
hexagon_mode
=
hexagon_mode
,
extra_args
=
build_arg
)
...
...
@@ -1244,6 +1261,7 @@ def build_benchmark_model(configs, target_abi, enable_openmp, mace_lib_type):
sh_commands
.
bazel_build
(
benchmark_target
,
abi
=
target_abi
,
enable_openmp
=
enable_openmp
,
enable_opencl
=
get_opencl_mode
(
configs
),
hexagon_mode
=
hexagon_mode
,
extra_args
=
build_arg
)
# clear tmp binary dir
...
...
tools/sh_commands.py
浏览文件 @
691331bd
...
...
@@ -283,6 +283,7 @@ def bazel_build(target,
hexagon_mode
=
False
,
enable_openmp
=
True
,
enable_neon
=
True
,
enable_opencl
=
True
,
address_sanitizer
=
False
,
extra_args
=
""
):
print
(
"* Build %s with ABI %s"
%
(
target
,
abi
))
...
...
@@ -305,6 +306,8 @@ def bazel_build(target,
"--define"
,
"openmp=%s"
%
str
(
enable_openmp
).
lower
(),
"--define"
,
"opencl=%s"
%
str
(
enable_opencl
).
lower
(),
"--define"
,
"hexagon=%s"
%
str
(
hexagon_mode
).
lower
())
if
address_sanitizer
:
bazel_args
+=
(
"--config"
,
"asan"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录