提交 a25bd499 编写于 作者: L Liangliang He

Fix generated lib and hexagon lib dependency issue

上级 56dbe745
...@@ -33,7 +33,15 @@ config_setting( ...@@ -33,7 +33,15 @@ config_setting(
) )
config_setting( config_setting(
name = "enable_neon", name = "production_mode",
define_values = {
"production": "true",
},
visibility = ["//visibility:public"],
)
config_setting(
name = "neon_enabled",
define_values = { define_values = {
"neon": "true", "neon": "true",
}, },
...@@ -41,9 +49,13 @@ config_setting( ...@@ -41,9 +49,13 @@ config_setting(
) )
config_setting( config_setting(
name = "embed_binary_program", name = "hexagon_enabled",
define_values = { define_values = {
"embed_binary_program": "true", "hexagon": "true",
},
values = {
"crosstool_top": "//external:android/crosstool",
"cpu": "armeabi-v7a",
}, },
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
) )
...@@ -5,52 +5,36 @@ package( ...@@ -5,52 +5,36 @@ package(
default_visibility = ["//visibility:public"], default_visibility = ["//visibility:public"],
) )
load("//mace:mace.bzl", "if_embed_binary_program", "if_use_source_program")
cc_library( cc_library(
name = "generated_models_lib", name = "generated_models",
srcs = glob(["models/*/*.cc"]), srcs = glob(["models/*/*.cc"]),
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
"//mace/core", "//mace/core",
"//mace/ops", "//mace/ops",
] + if_embed_binary_program(["//mace/core:opencl_binary_linkage"]) +
if_use_source_program(["//mace/core:opencl_source_linkage"]) + [
"//mace/codegen:version_lib",
"//mace/codegen:generated_opencl_source_lib",
"//mace/codegen:generated_opencl_compiled_lib",
"//mace/codegen:generated_tuning_lib",
], ],
) )
cc_library( cc_library(
name = "generated_opencl_source_lib", name = "generated_opencl_dev",
srcs = glob(["opencl/opencl_encrypt_program.cc"]), srcs = ["opencl/opencl_encrypt_program.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
) )
cc_library( cc_library(
name = "generated_opencl_compiled_lib", name = "generated_opencl_prod",
srcs = glob(["opencl/opencl_compiled_program.cc"]), srcs = ["opencl/opencl_compiled_program.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
) )
cc_library( cc_library(
name = "generated_tuning_lib", name = "generated_tuning_params",
srcs = glob(["tuning/*.cc"]), srcs = ["tuning/tuning_params.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
) )
cc_library( cc_library(
name = "version_lib", name = "generated_version",
srcs = glob(["version/*.cc"]), srcs = ["version/version.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
deps = [
"//mace/core",
]
) )
...@@ -7,25 +7,34 @@ package( ...@@ -7,25 +7,34 @@ package(
licenses(["notice"]) # Apache 2.0 licenses(["notice"]) # Apache 2.0
load("//mace:mace.bzl", "if_android", "if_android_armv7", "if_android_arm64", load(
"if_profiling_enabled") "//mace:mace.bzl",
"if_android",
"if_profiling_enabled",
"if_hexagon_enabled",
"if_not_hexagon_enabled",
"if_production_mode",
"if_not_production_mode",
)
cc_library( cc_library(
name = "core", name = "core",
srcs = glob([ srcs = glob(
"*.cc", [
"runtime/opencl/*.cc", "*.cc",
"runtime/hexagon/*.cc", "runtime/opencl/*.cc",
], "runtime/hexagon/*.cc",
exclude = [ ],
"runtime/opencl/opencl_binary_linkage.cc", exclude = [
"runtime/opencl/opencl_source_linkage.cc", "runtime/opencl/opencl_prod.cc",
"*_test.cc", "runtime/opencl/opencl_dev.cc",
"*_test.cc",
"runtime/hexagon/hexagon_controller_dummy.cc",
],
) + if_not_hexagon_enabled([
"runtime/hexagon/hexagon_controller_dummy.cc", "runtime/hexagon/hexagon_controller_dummy.cc",
]) + if_android_armv7([ ]) + if_hexagon_enabled([
"runtime/hexagon/libhexagon_controller.so", "runtime/hexagon/libhexagon_controller.so",
]) + if_android_arm64([
"runtime/hexagon/hexagon_controller_dummy.cc",
]), ]),
hdrs = glob([ hdrs = glob([
"*.h", "*.h",
...@@ -34,13 +43,31 @@ cc_library( ...@@ -34,13 +43,31 @@ cc_library(
"runtime/opencl/*.h", "runtime/opencl/*.h",
"runtime/hexagon/*.h", "runtime/hexagon/*.h",
]), ]),
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"] + copts = if_profiling_enabled(["-DMACE_OPENCL_PROFILING"]) + if_hexagon_enabled(["-DMACE_HEXAGON_ENABLED"]),
if_profiling_enabled(["-DMACE_OPENCL_PROFILING"]), linkopts = if_android([
linkopts = if_android(["-pie", "-ldl"]), "-pie",
"-ldl",
]),
deps = [ deps = [
"//mace/utils:utils_hdrs", ":opencl_headers",
"//mace/utils:logging", "//mace/utils:logging",
"//mace/utils:tuner", "//mace/utils:tuner",
"//mace/utils:utils_hdrs",
"//mace/codegen:generated_version",
] + if_production_mode([
"//mace/core:opencl_prod",
]) + if_not_production_mode([
"//mace/core:opencl_dev",
]),
)
cc_library(
name = "opencl_headers",
hdrs = glob([
"runtime/opencl/cl2.hpp",
"runtime/opencl/*.h",
]),
deps = [
"@opencl_headers//:opencl20_headers", "@opencl_headers//:opencl20_headers",
], ],
) )
...@@ -48,37 +75,37 @@ cc_library( ...@@ -48,37 +75,37 @@ cc_library(
cc_library( cc_library(
name = "test_benchmark_main", name = "test_benchmark_main",
testonly = 1, testonly = 1,
hdrs = [
"testing/test_benchmark.h",
],
srcs = [ srcs = [
"testing/test_benchmark.cc", "testing/test_benchmark.cc",
"testing/test_benchmark_main.cc", "testing/test_benchmark_main.cc",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"], hdrs = [
alwayslink = 1, "testing/test_benchmark.h",
],
deps = [ deps = [
":core", ":core",
"//mace/utils:utils_hdrs", "//mace/utils:utils_hdrs",
], ],
alwayslink = 1,
) )
cc_library( cc_library(
name = "opencl_source_linkage", name = "opencl_dev",
srcs = ["runtime/opencl/opencl_source_linkage.cc"], srcs = ["runtime/opencl/opencl_development.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
":core", ":opencl_headers",
"//mace/codegen:generated_opencl_dev",
], ],
) )
cc_library( cc_library(
name = "opencl_binary_linkage", name = "opencl_prod",
srcs = ["runtime/opencl/opencl_binary_linkage.cc"], srcs = ["runtime/opencl/opencl_production.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
":core", ":opencl_headers",
"//mace/codegen:generated_opencl_prod",
"//mace/codegen:generated_tuning_params",
], ],
) )
...@@ -11,6 +11,28 @@ ...@@ -11,6 +11,28 @@
namespace mace { namespace mace {
#define MACE_MAJOR_VERSION 0
#define MACE_MINOR_VERSION 1
#define MACE_PATCH_VERSION 0
// MACE_VERSION_SUFFIX is non-empty for pre-releases (e.g. "-alpha", "-alpha.1",
// "-beta", "-rc", "-rc.1")
#define MACE_VERSION_SUFFIX ""
#define MACE_STR_HELPER(x) #x
#define MACE_STR(x) MACE_STR_HELPER(x)
// e.g. "0.5.0" or "0.6.0-alpha".
#define MACE_VERSION_STRING \
(MACE_STR(MACE_MAJOR_VERSION) "." MACE_STR(MACE_MINOR_VERSION) "." MACE_STR( \
MACE_PATCH_VERSION) MACE_VERSION_SUFFIX)
inline const char *MaceVersion() {
return MACE_VERSION_STRING;
}
extern const char *MaceGitVersion();
enum NetMode { enum NetMode {
INIT = 0, INIT = 0,
NORMAL = 1 NORMAL = 1
......
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#ifndef MACE_CORE_PUBLIC_VERSION_H_
#define MACE_CORE_PUBLIC_VERSION_H_
#define MACE_MAJOR_VERSION 0
#define MACE_MINOR_VERSION 1
#define MACE_PATCH_VERSION 0
// MACE_VERSION_SUFFIX is non-empty for pre-releases (e.g. "-alpha", "-alpha.1",
// "-beta", "-rc", "-rc.1")
#define MACE_VERSION_SUFFIX ""
#define MACE_STR_HELPER(x) #x
#define MACE_STR(x) MACE_STR_HELPER(x)
// e.g. "0.5.0" or "0.6.0-alpha".
#define MACE_VERSION_STRING \
(MACE_STR(MACE_MAJOR_VERSION) "." MACE_STR(MACE_MINOR_VERSION) "." MACE_STR( \
MACE_PATCH_VERSION) MACE_VERSION_SUFFIX)
extern const char *MaceVersion();
extern const char *MaceGitVersion();
#endif // MACE_CORE_PUBLIC_VERSION_H_
...@@ -49,18 +49,17 @@ bool GetTuningParams(const char *path, ...@@ -49,18 +49,17 @@ bool GetTuningParams(const char *path,
if (path != nullptr) { if (path != nullptr) {
std::ifstream ifs(path, std::ios::binary | std::ios::in); std::ifstream ifs(path, std::ios::binary | std::ios::in);
if (ifs.is_open()) { if (ifs.is_open()) {
int32_t key_size = 0; int64_t num_params = 0;
int32_t params_size = 0; ifs.read(reinterpret_cast<char *>(&num_params), sizeof(num_params));
int32_t params_count = 0; while (num_params--) {
int64_t num_pramas = 0; int32_t key_size = 0;
ifs.read(reinterpret_cast<char *>(&num_pramas), sizeof(num_pramas));
while (num_pramas--) {
ifs.read(reinterpret_cast<char *>(&key_size), sizeof(key_size)); ifs.read(reinterpret_cast<char *>(&key_size), sizeof(key_size));
std::string key(key_size, ' '); std::string key(key_size, ' ');
ifs.read(&key[0], key_size); ifs.read(&key[0], key_size);
int32_t params_size = 0;
ifs.read(reinterpret_cast<char *>(&params_size), sizeof(params_size)); ifs.read(reinterpret_cast<char *>(&params_size), sizeof(params_size));
params_count = params_size / sizeof(unsigned int); int32_t params_count = params_size / sizeof(unsigned int);
std::vector<unsigned int> params(params_count); std::vector<unsigned int> params(params_count);
for (int i = 0; i < params_count; ++i) { for (int i = 0; i < params_count; ++i) {
ifs.read(reinterpret_cast<char *>(&params[i]), sizeof(unsigned int)); ifs.read(reinterpret_cast<char *>(&params[i]), sizeof(unsigned int));
......
# Examples # Examples
load("//mace:mace.bzl", "if_android", "if_enable_neon") load("//mace:mace.bzl", "if_android", "if_neon_enabled")
cc_binary( cc_binary(
name = "helloworld", name = "helloworld",
srcs = [ srcs = [
"helloworld.cc", "helloworld.cc",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"], linkopts = if_neon_enabled(["-fopenmp"]),
linkopts = if_enable_neon(["-fopenmp"]),
deps = [ deps = [
"//mace/core", "//mace/core",
"//mace/ops", "//mace/ops",
...@@ -18,8 +17,7 @@ cc_test( ...@@ -18,8 +17,7 @@ cc_test(
name = "benchmark_example", name = "benchmark_example",
testonly = 1, testonly = 1,
srcs = ["benchmark_example.cc"], srcs = ["benchmark_example.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"], linkopts = if_neon_enabled(["-fopenmp"]),
linkopts = if_enable_neon(["-fopenmp"]),
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
"//mace/core", "//mace/core",
...@@ -30,11 +28,10 @@ cc_test( ...@@ -30,11 +28,10 @@ cc_test(
cc_binary( cc_binary(
name = "mace_run", name = "mace_run",
srcs = ["mace_run.cc"], srcs = ["mace_run.cc"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"], linkopts = if_neon_enabled(["-fopenmp"]),
linkopts = if_enable_neon(["-fopenmp"]),
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
"//mace/codegen:generated_models_lib", "//mace/codegen:generated_models",
"//mace/utils:command_line_flags", "//mace/utils:command_line_flags",
], ],
) )
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "mace/utils/logging.h" #include "mace/utils/logging.h"
#include "mace/core/public/mace.h" #include "mace/core/public/mace.h"
#include "mace/core/public/version.h"
using namespace std; using namespace std;
using namespace mace; using namespace mace;
......
...@@ -7,22 +7,23 @@ package( ...@@ -7,22 +7,23 @@ package(
licenses(["notice"]) # Apache 2.0 licenses(["notice"]) # Apache 2.0
load("//mace:mace.bzl", "if_android", "if_enable_neon") load("//mace:mace.bzl", "if_android", "if_neon_enabled")
cc_library( cc_library(
name = "kernels", name = "kernels",
srcs = glob(["*.cc", "opencl/*.cc"]) + if_enable_neon(glob([ srcs = glob([
"*.cc",
"opencl/*.cc",
]) + if_neon_enabled(glob([
"neon/*.cc", "neon/*.cc",
])), ])),
hdrs = glob(["*.h", "opencl/*.h"]) + if_enable_neon(glob([ hdrs = glob([
"*.h",
"opencl/*.h",
]) + if_neon_enabled(glob([
"neon/*.h", "neon/*.h",
])), ])),
copts = [ copts = if_neon_enabled(["-fopenmp"]),
"-std=c++11",
"-D_GLIBCXX_USE_C99_MATH_TR1",
"-Werror=return-type",
] +
if_enable_neon(["-fopenmp"]),
linkopts = if_android(["-lm"]), linkopts = if_android(["-lm"]),
deps = [ deps = [
"//mace/core", "//mace/core",
...@@ -34,7 +35,6 @@ cc_test( ...@@ -34,7 +35,6 @@ cc_test(
name = "kernel_test", name = "kernel_test",
testonly = 1, testonly = 1,
srcs = glob(["test/*.cc"]), srcs = glob(["test/*.cc"]),
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkopts = if_android(["-pie"]), linkopts = if_android(["-pie"]),
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
...@@ -48,7 +48,6 @@ cc_test( ...@@ -48,7 +48,6 @@ cc_test(
name = "benchmark", name = "benchmark",
testonly = 1, testonly = 1,
srcs = glob(["benchmark/*.cc"]), srcs = glob(["benchmark/*.cc"]),
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
":kernels", ":kernels",
......
...@@ -30,20 +30,32 @@ def if_profiling_enabled(a): ...@@ -30,20 +30,32 @@ def if_profiling_enabled(a):
"//conditions:default": [], "//conditions:default": [],
}) })
def if_embed_binary_program(a): def if_production_mode(a):
return select({ return select({
"//mace:embed_binary_program": a, "//mace:production_mode": a,
"//conditions:default": [], "//conditions:default": [],
}) })
def if_use_source_program(a): def if_not_production_mode(a):
return select({ return select({
"//mace:embed_binary_program": [], "//mace:production_mode": [],
"//conditions:default": a, "//conditions:default": a,
}) })
def if_enable_neon(a): def if_neon_enabled(a):
return select({ return select({
"//mace:enable_neon": a, "//mace:neon_enabled": a,
"//conditions:default": [], "//conditions:default": [],
}) })
def if_hexagon_enabled(a):
return select({
"//mace:hexagon_enabled": a,
"//conditions:default": [],
})
def if_not_hexagon_enabled(a):
return select({
"//mace:hexagon_enabled": [],
"//conditions:default": a,
})
...@@ -7,7 +7,7 @@ package( ...@@ -7,7 +7,7 @@ package(
licenses(["notice"]) # Apache 2.0 licenses(["notice"]) # Apache 2.0
load("//mace:mace.bzl", "if_android", "if_enable_neon") load("//mace:mace.bzl", "if_android", "if_neon_enabled")
cc_library( cc_library(
name = "test", name = "test",
...@@ -34,8 +34,7 @@ cc_library( ...@@ -34,8 +34,7 @@ cc_library(
["*.h"], ["*.h"],
exclude = ["ops_test_util.h"], exclude = ["ops_test_util.h"],
), ),
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"] + copts = if_neon_enabled(["-DMACE_ENABLE_NEON"]),
if_enable_neon(["-DMACE_ENABLE_NEON"]),
deps = [ deps = [
"//mace/kernels", "//mace/kernels",
], ],
...@@ -48,7 +47,6 @@ cc_test( ...@@ -48,7 +47,6 @@ cc_test(
srcs = glob( srcs = glob(
["*_test.cc"], ["*_test.cc"],
), ),
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkopts = ["-fopenmp"], linkopts = ["-fopenmp"],
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
...@@ -62,7 +60,6 @@ cc_test( ...@@ -62,7 +60,6 @@ cc_test(
name = "ops_benchmark", name = "ops_benchmark",
testonly = 1, testonly = 1,
srcs = glob(["*_benchmark.cc"]), srcs = glob(["*_benchmark.cc"]),
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkopts = ["-fopenmp"], linkopts = ["-fopenmp"],
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
......
...@@ -7,7 +7,6 @@ cc_library( ...@@ -7,7 +7,6 @@ cc_library(
name = "stat_summarizer", name = "stat_summarizer",
srcs = ["stat_summarizer.cc"], srcs = ["stat_summarizer.cc"],
hdrs = ["stat_summarizer.h"], hdrs = ["stat_summarizer.h"],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
"//mace/core", "//mace/core",
...@@ -19,7 +18,6 @@ cc_binary( ...@@ -19,7 +18,6 @@ cc_binary(
srcs = [ srcs = [
"benchmark_model.cc", "benchmark_model.cc",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
":stat_summarizer", ":stat_summarizer",
......
...@@ -18,7 +18,13 @@ else ...@@ -18,7 +18,13 @@ else
fi fi
cat <<EOF > ${OUTPUT_FILENAME} cat <<EOF > ${OUTPUT_FILENAME}
#include "mace/core/public/version.h" //
const char *MaceVersion() { return MACE_VERSION_STRING; } // Copyright (c) 2017 XiaoMi All rights reserved.
const char *MaceGitVersion() { return "${GIT_VERSION}"; } //
// This is a generated file, DO NOT EDIT
namespace mace {
const char *MaceGitVersion() { return "${GIT_VERSION}"; }
} // namespace mace
EOF EOF
...@@ -17,7 +17,6 @@ cc_library( ...@@ -17,7 +17,6 @@ cc_library(
hdrs = [ hdrs = [
"logging.h", "logging.h",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
linkopts = if_android([ linkopts = if_android([
"-llog", "-llog",
]), ]),
...@@ -31,7 +30,6 @@ cc_library( ...@@ -31,7 +30,6 @@ cc_library(
hdrs = [ hdrs = [
"command_line_flags.h", "command_line_flags.h",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
deps = [ deps = [
":logging", ":logging",
], ],
...@@ -40,13 +38,12 @@ cc_library( ...@@ -40,13 +38,12 @@ cc_library(
cc_library( cc_library(
name = "tuner", name = "tuner",
hdrs = [ hdrs = [
"tuner.h",
"timer.h", "timer.h",
"tuner.h",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
deps = [ deps = [
":utils_hdrs",
":logging", ":logging",
":utils_hdrs",
], ],
) )
...@@ -56,8 +53,10 @@ cc_test( ...@@ -56,8 +53,10 @@ cc_test(
srcs = [ srcs = [
"tuner_test.cc", "tuner_test.cc",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"], linkopts = if_android([
linkopts = if_android(["-pie", "-lm"]), "-pie",
"-lm",
]),
linkstatic = 1, linkstatic = 1,
deps = [ deps = [
":tuner", ":tuner",
...@@ -69,19 +68,17 @@ cc_test( ...@@ -69,19 +68,17 @@ cc_test(
cc_library( cc_library(
name = "utils_hdrs", name = "utils_hdrs",
hdrs = [ hdrs = [
"utils.h",
"env_time.h", "env_time.h",
"utils.h",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
) )
cc_library( cc_library(
name = "utils", name = "utils",
deps = [ deps = [
":utils_hdrs",
":tuner",
":command_line_flags", ":command_line_flags",
":logging", ":logging",
":tuner",
":utils_hdrs",
], ],
copts = ["-std=c++11", "-D_GLIBCXX_USE_C99_MATH_TR1", "-Werror=return-type"],
) )
...@@ -6,7 +6,7 @@ if [ "$#" -lt 1 ]; then ...@@ -6,7 +6,7 @@ if [ "$#" -lt 1 ]; then
fi fi
MACE_SOURCE_DIR=`/bin/pwd` MACE_SOURCE_DIR=`/bin/pwd`
CL_CODEGEN_DIR=${MACE_SOURCE_DIR}/mace/codegen/opencl CODEGEN_DIR=${MACE_SOURCE_DIR}/mace/codegen
DEVICE_PATH=/data/local/tmp/mace DEVICE_PATH=/data/local/tmp/mace
DEVICE_CL_PATH=$DEVICE_PATH/cl/ DEVICE_CL_PATH=$DEVICE_PATH/cl/
BAZEL_TARGET=$1 BAZEL_TARGET=$1
...@@ -24,25 +24,28 @@ STRIP="--strip always" ...@@ -24,25 +24,28 @@ STRIP="--strip always"
VLOG_LEVEL=0 VLOG_LEVEL=0
PROFILINE="--define profiling=true" PROFILINE="--define profiling=true"
BRANCH=$(git symbolic-ref --short HEAD)
COMMIT_ID=$(git rev-parse --short HEAD)
echo "Step 1: Generate encrypted opencl source" echo "Step 1: Generate encrypted opencl source"
python mace/python/tools/encrypt_opencl_codegen.py \ python mace/python/tools/encrypt_opencl_codegen.py \
--cl_kernel_dir=./mace/kernels/opencl/cl/ --output_path=${CL_CODEGEN_DIR}/opencl_encrypt_program.cc --cl_kernel_dir=./mace/kernels/opencl/cl/ --output_path=${CODEGEN_DIR}/opencl/opencl_encrypt_program.cc
echo "Step 2: Generate version source"
bash mace/tools/git/gen_version_source.sh ${CODEGEN_DIR}/version/version.cc
echo "Step 2: Build target" echo "Step 3: Build target"
bazel build -c opt $STRIP --verbose_failures $BAZEL_TARGET \ bazel build -c opt $STRIP --verbose_failures $BAZEL_TARGET \
--crosstool_top=//external:android/crosstool \ --crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=$ANDROID_ABI \ --cpu=$ANDROID_ABI \
--copt="-std=c++11" \
--copt="-D_GLIBCXX_USE_C99_MATH_TR1" \
--copt="-Werror=return-type" \
--define neon=false --define neon=false
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
echo "Step 3: Run target" echo "Step 4: Run target"
du -hs $BAZEL_BIN_PATH/$BIN_NAME du -hs $BAZEL_BIN_PATH/$BIN_NAME
for device in `adb devices | grep "^[A-Za-z0-9]\+[[:space:]]\+device$"| cut -f1`; do for device in `adb devices | grep "^[A-Za-z0-9]\+[[:space:]]\+device$"| cut -f1`; do
...@@ -50,6 +53,7 @@ for device in `adb devices | grep "^[A-Za-z0-9]\+[[:space:]]\+device$"| cut -f1` ...@@ -50,6 +53,7 @@ for device in `adb devices | grep "^[A-Za-z0-9]\+[[:space:]]\+device$"| cut -f1`
echo "Run on device: ${device}" echo "Run on device: ${device}"
adb -s ${device} shell "rm -rf $DEVICE_PATH" adb -s ${device} shell "rm -rf $DEVICE_PATH"
adb -s ${device} shell "mkdir -p $DEVICE_PATH" adb -s ${device} shell "mkdir -p $DEVICE_PATH"
adb -s ${device} shell "mkdir -p $DEVICE_PATH/cl"
adb -s ${device} push $BAZEL_BIN_PATH/$BIN_NAME $DEVICE_PATH && \ adb -s ${device} push $BAZEL_BIN_PATH/$BIN_NAME $DEVICE_PATH && \
adb -s ${device} shell "MACE_KERNEL_PATH=$DEVICE_CL_PATH MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL $DEVICE_PATH/$BIN_NAME $@" adb -s ${device} shell "MACE_KERNEL_PATH=$DEVICE_CL_PATH MACE_CPP_MIN_VLOG_LEVEL=$VLOG_LEVEL $DEVICE_PATH/$BIN_NAME $@"
done done
...@@ -39,19 +39,22 @@ build_and_run() ...@@ -39,19 +39,22 @@ build_and_run()
EMBED_OPENCL_BINARY_BUILD_FLAGS="--define embed_binary_program=true" EMBED_OPENCL_BINARY_BUILD_FLAGS="--define embed_binary_program=true"
fi fi
bazel build -c opt --strip always mace/examples:mace_run \ bazel build --verbose_failures -c opt --strip always mace/examples:mace_run \
--crosstool_top=//external:android/crosstool \ --crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=arm64-v8a \ --cpu=arm64-v8a \
$EMBED_OPENCL_BINARY_BUILD_FLAGS \ --copt="-std=c++11" \
--copt=-DMACE_MODEL_FUNCTION=Create${MODEL_TAG} --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \
--copt="-Werror=return-type" \
--copt="-DMACE_MODEL_FUNCTION=Create${MODEL_TAG}" \
$EMBED_OPENCL_BINARY_BUILD_FLAGS || exit -1
adb shell "mkdir -p ${PHONE_DATA_DIR}" adb shell "mkdir -p ${PHONE_DATA_DIR}" || exit -1
if [ "$EMBED_OPENCL_BINARY" = false ]; then if [ "$EMBED_OPENCL_BINARY" = false ]; then
adb shell "mkdir -p ${KERNEL_DIR}" adb shell "mkdir -p ${KERNEL_DIR}" || exit -1
fi fi
adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR} adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR} || exit -1
adb push bazel-bin/mace/examples/mace_run ${PHONE_DATA_DIR} adb push bazel-bin/mace/examples/mace_run ${PHONE_DATA_DIR} || exit -1
if [[ "${TUNING_OR_NOT}" != "0" && "$EMBED_OPENCL_BINARY" != true ]];then if [[ "${TUNING_OR_NOT}" != "0" && "$EMBED_OPENCL_BINARY" != true ]];then
tuning_flag=1 tuning_flag=1
...@@ -71,17 +74,17 @@ build_and_run() ...@@ -71,17 +74,17 @@ build_and_run()
--input_file=${PHONE_DATA_DIR}/${INPUT_FILE_NAME} \ --input_file=${PHONE_DATA_DIR}/${INPUT_FILE_NAME} \
--output_file=${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME} \ --output_file=${PHONE_DATA_DIR}/${OUTPUT_FILE_NAME} \
--device=OPENCL \ --device=OPENCL \
--round=$round --round=$round || exit -1
} }
echo "Step 1: Generate input data" echo "Step 1: Generate input data"
rm -rf ${MODEL_DIR}/${INPUT_FILE_NAME} rm -rf ${MODEL_DIR}/${INPUT_FILE_NAME}
python tools/validate.py --generate_data true \ python tools/validate.py --generate_data true \
--input_file=${MODEL_DIR}/${INPUT_FILE_NAME} \ --input_file=${MODEL_DIR}/${INPUT_FILE_NAME} \
--input_shape="${IMAGE_SIZE},${IMAGE_SIZE},3" --input_shape="${IMAGE_SIZE},${IMAGE_SIZE},3" || exit -1
echo "Step 2: Convert tf model to mace model and optimize memory" echo "Step 2: Convert tf model to mace model and optimize memory"
bazel build //mace/python/tools:tf_converter bazel build //mace/python/tools:tf_converter || exit -1
rm -rf ${MODEL_CODEGEN_DIR} rm -rf ${MODEL_CODEGEN_DIR}
mkdir -p ${MODEL_CODEGEN_DIR} mkdir -p ${MODEL_CODEGEN_DIR}
bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \
...@@ -93,7 +96,7 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \ ...@@ -93,7 +96,7 @@ bazel-bin/mace/python/tools/tf_converter --input=${TF_MODEL_FILE_PATH} \
--output_type=source \ --output_type=source \
--template=${MACE_SOURCE_DIR}/mace/python/tools/model.template \ --template=${MACE_SOURCE_DIR}/mace/python/tools/model.template \
--model_tag=${MODEL_TAG} \ --model_tag=${MODEL_TAG} \
--confuse=False --confuse=False || exit -1
echo "Step 3: Generate version source" echo "Step 3: Generate version source"
rm -rf ${VERSION_SOURCE_PATH} rm -rf ${VERSION_SOURCE_PATH}
......
...@@ -34,7 +34,9 @@ build_and_run() ...@@ -34,7 +34,9 @@ build_and_run()
--crosstool_top=//external:android/crosstool \ --crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=armeabi-v7a \ --cpu=armeabi-v7a \
--copt=-DMACE_MODEL_FUNCTION=Create${MODEL_TAG} --copt="-std=c++11" \
--copt="-D_GLIBCXX_USE_C99_MATH_TR1" \
--copt="-Werror=return-type"
adb shell "mkdir -p ${PHONE_DATA_DIR}" adb shell "mkdir -p ${PHONE_DATA_DIR}"
adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR} adb push ${MODEL_DIR}/${INPUT_FILE_NAME} ${PHONE_DATA_DIR}
...@@ -92,4 +94,4 @@ python tools/validate.py --model_file ${TF_MODEL_FILE_PATH} \ ...@@ -92,4 +94,4 @@ python tools/validate.py --model_file ${TF_MODEL_FILE_PATH} \
--input_node ${TF_INPUT_NODE} \ --input_node ${TF_INPUT_NODE} \
--output_node ${TF_OUTPUT_NODE} \ --output_node ${TF_OUTPUT_NODE} \
--input_shape "${IMAGE_SIZE},${IMAGE_SIZE},3" \ --input_shape "${IMAGE_SIZE},${IMAGE_SIZE},3" \
--output_shape "1,${IMAGE_SIZE},${IMAGE_SIZE},2" --output_shape "1,${IMAGE_SIZE},${IMAGE_SIZE},2"
\ No newline at end of file
文件模式从 100644 更改为 100755
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册