提交 61bd1d3b 编写于 作者: Y yejianwu

fix link for libmace.so and libmodels.a

上级 f291a048
......@@ -378,6 +378,9 @@ Reduce Library Size
- 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``
- About ``300KB`` can be reduced when add ``--config symbol_hidden`` building option. It will change
the visibility of inner apis of libmace.so and lead to linking error when load model(s) in ``code``.
* **static library**
- The methods in dynamic library can be useful for static library too. In additional, the static
......
......@@ -44,13 +44,7 @@ cc_library(
cc_library(
name = "generated_libmace",
srcs = glob(["lib/*.so"]),
visibility = ["//visibility:public"],
)
cc_library(
name = "generated_libmace_static",
srcs = glob(["lib/*.a"]),
srcs = glob(["lib/*"]),
linkstatic = 1,
visibility = ["//visibility:public"],
)
......@@ -29,7 +29,7 @@ cc_binary(
deps = [
"//external:gflags_nothreads",
"//mace/codegen:generated_mace_engine_factory",
"//mace/codegen:generated_libmace_static",
"//mace/codegen:generated_libmace",
] + if_hexagon_enabled([
"//third_party/nnlib:libhexagon",
]),
......
......@@ -12,6 +12,20 @@ mace {
*SetOpenMPThreadAffinity*;
*GetBigLittleCoreIDs*;
*MaceVersion*;
# api for static library of models
*mace*logging*LogMessage*;
*mace*NetDef*;
*mace*MemoryArena*;
*mace*InputInfo*;
*mace*OutputInfo*;
*mace*OutputShape*;
*mace*OperatorDef*;
*mace*ConstTensor*;
*mace*Argument*;
*mace*MemoryBlock*;
*google*protobuf*;
local:
*;
};
......@@ -42,7 +42,7 @@ cc_binary(
deps = [
"//external:gflags_nothreads",
"//mace/codegen:generated_mace_engine_factory",
"//mace/codegen:generated_models",
"//mace/libmace:libmace_dynamic",
"//mace/utils:utils",
],
)
......@@ -11,6 +11,9 @@ build --copt=-D_GLIBCXX_USE_C99_MATH_TR1
build --copt=-DMACE_OBFUSCATE_LITERALS
build --copt=-DGEMMLOWP_USE_OPENMP
# Usage example: bazel build --config symbol_hidden
build:symbol_hidden --copt=-fvisibility=hidden
# Usage example: bazel build --config android
build:android --crosstool_top=//external:android/crosstool
build:android --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
......@@ -23,7 +26,6 @@ build:optimization --linkopt=-Wl,--strip-all
build:optimization --copt=-ffunction-sections
build:optimization --copt=-fdata-sections
build:optimization --linkopt=-Wl,--gc-sections
build:optimization --copt=-fvisibility=hidden
# Address sanitizer
build:asan --strip=never
......
......@@ -44,16 +44,16 @@ fi
# build static libraries
echo "build static lib for armeabi-v7a + cpu_gpu_dsp"
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
bazel build --config android --config optimization mace/libmace:libmace_static --config symbol_hidden --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/cpu_gpu_dsp/
cp third_party/nnlib/*so $LIB_DIR/armeabi-v7a/cpu_gpu_dsp/
echo "build static lib for armeabi-v7a + cpu_gpu"
bazel build --config android --config optimization mace/libmace:libmace_static --define neon=true --define openmp=true --define opencl=true --cpu=armeabi-v7a
bazel build --config android --config optimization mace/libmace:libmace_static --config symbol_hidden --define neon=true --define openmp=true --define opencl=true --cpu=armeabi-v7a
cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/armeabi-v7a/cpu_gpu/
echo "build static lib for arm64-v8a + cpu_gpu"
bazel build --config android --config optimization mace/libmace:libmace_static --define neon=true --define openmp=true --define opencl=true --cpu=arm64-v8a
bazel build --config android --config optimization mace/libmace:libmace_static --config symbol_hidden --define neon=true --define openmp=true --define opencl=true --cpu=arm64-v8a
cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/arm64-v8a/cpu_gpu/
if [[ "$OSTYPE" != "darwin"* ]];then
......
......@@ -786,7 +786,8 @@ def build_model_lib(configs, address_sanitizer):
abi=target_abi,
hexagon_mode=hexagon_mode,
enable_opencl=get_opencl_mode(configs),
address_sanitizer=address_sanitizer
address_sanitizer=address_sanitizer,
symbol_hidden=True
)
sh.cp("-f", MODEL_LIB_PATH, model_lib_output_path)
......@@ -880,8 +881,10 @@ def build_mace_run(configs, target_abi, enable_openmp, address_sanitizer,
sh.rm("-rf", build_tmp_binary_dir)
os.makedirs(build_tmp_binary_dir)
symbol_hidden = True
mace_run_target = MACE_RUN_STATIC_TARGET
if mace_lib_type == MACELibType.dynamic:
symbol_hidden = False
mace_run_target = MACE_RUN_DYNAMIC_TARGET
build_arg = ""
if configs[YAMLKeyword.model_graph_format] == ModelFormat.code:
......@@ -897,6 +900,7 @@ def build_mace_run(configs, target_abi, enable_openmp, address_sanitizer,
enable_openmp=enable_openmp,
enable_opencl=get_opencl_mode(configs),
address_sanitizer=address_sanitizer,
symbol_hidden=symbol_hidden,
extra_args=build_arg
)
sh_commands.update_mace_run_binary(build_tmp_binary_dir,
......@@ -924,6 +928,7 @@ def build_quantize_stat(configs):
quantize_stat_target,
abi=ABIType.host,
enable_openmp=True,
symbol_hidden=True,
extra_args=build_arg
)
......@@ -943,36 +948,39 @@ def build_example(configs, target_abi, enable_openmp, mace_lib_type):
sh.rm("-rf", build_tmp_binary_dir)
os.makedirs(build_tmp_binary_dir)
symbol_hidden = True
libmace_target = LIBMACE_STATIC_TARGET
if mace_lib_type == MACELibType.dynamic:
symbol_hidden = False
libmace_target = LIBMACE_SO_TARGET
sh_commands.bazel_build(libmace_target,
abi=target_abi,
enable_openmp=enable_openmp,
enable_opencl=get_opencl_mode(configs),
hexagon_mode=hexagon_mode)
hexagon_mode=hexagon_mode,
symbol_hidden=symbol_hidden)
if os.path.exists(LIB_CODEGEN_DIR):
sh.rm("-rf", LIB_CODEGEN_DIR)
sh.mkdir("-p", LIB_CODEGEN_DIR)
build_arg = ""
if configs[YAMLKeyword.model_graph_format] == ModelFormat.code:
mace_check(os.path.exists(ENGINE_CODEGEN_DIR),
ModuleName.RUN,
"You should convert model first.")
model_lib_path = get_model_lib_output_path(library_name,
target_abi)
sh.cp("-f", model_lib_path, LIB_CODEGEN_DIR)
build_arg = "--per_file_copt=mace/examples/cli/example.cc@-DMODEL_GRAPH_FORMAT_CODE" # noqa
if mace_lib_type == MACELibType.dynamic:
example_target = EXAMPLE_DYNAMIC_TARGET
sh.cp("-f", LIBMACE_DYNAMIC_PATH, LIB_CODEGEN_DIR)
else:
sh.cp("-f", LIBMACE_STATIC_PATH, LIB_CODEGEN_DIR)
if configs[YAMLKeyword.model_graph_format] == ModelFormat.code:
mace_check(os.path.exists(ENGINE_CODEGEN_DIR),
ModuleName.RUN,
"You should convert model first.")
model_lib_path = get_model_lib_output_path(library_name,
target_abi)
sh.cp("-f", model_lib_path, LIB_CODEGEN_DIR)
build_arg = "--per_file_copt=mace/examples/cli/example.cc@-DMODEL_GRAPH_FORMAT_CODE" # noqa
example_target = EXAMPLE_STATIC_TARGET
sh.cp("-f", LIBMACE_STATIC_PATH, LIB_CODEGEN_DIR)
sh_commands.bazel_build(example_target,
abi=target_abi,
......@@ -1325,11 +1333,6 @@ def print_package_summary(package_path):
def run_mace(flags):
configs = format_model_config(flags)
if flags.mace_lib_type == MACELibType.dynamic and \
configs[YAMLKeyword.model_graph_format] == ModelFormat.code:
MaceLogger.error(ModuleName.YAML_CONFIG,
"If you want to link MACE dynamic library, "
"you must use file-type MACE model.")
clear_build_dirs(configs[YAMLKeyword.library_name])
......
......@@ -279,6 +279,7 @@ def bazel_build(target,
enable_neon=True,
enable_opencl=True,
address_sanitizer=False,
symbol_hidden=False,
extra_args=""):
print("* Build %s with ABI %s" % (target, abi))
if abi == "host":
......@@ -307,6 +308,8 @@ def bazel_build(target,
bazel_args += ("--config", "asan")
else:
bazel_args += ("--config", "optimization")
if symbol_hidden:
bazel_args += ("--config", "symbol_hidden")
if extra_args:
bazel_args += (extra_args, )
print bazel_args
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册