diff --git a/mace/core/BUILD b/mace/core/BUILD index 1fbeed2f2da0ba71dc8c763b88f4802420941424..be9e15d7ca9802f351beb009bb95356b2dc1ed54 100644 --- a/mace/core/BUILD +++ b/mace/core/BUILD @@ -47,6 +47,7 @@ cc_library( linkopts = if_android([ "-pie", "-ldl", + "-lm", ]), deps = [ ":opencl_headers", @@ -55,8 +56,10 @@ cc_library( "//mace/utils:utils_hdrs", "//mace/codegen:generated_version", ] + if_production_mode([ + "//mace/utils:tuner_prod", "//mace/core:opencl_prod", ]) + if_not_production_mode([ + "//mace/utils:tuner_dev", "//mace/core:opencl_dev", ]), ) @@ -107,6 +110,5 @@ cc_library( deps = [ ":opencl_headers", "//mace/codegen:generated_opencl_prod", - "//mace/codegen:generated_tuning_params", ], ) diff --git a/mace/core/runtime/opencl/opencl_development.cc b/mace/core/runtime/opencl/opencl_development.cc index 2b0fd27e13b5315ddc3ae70f60e50e1f1796dbab..43127e798fd950dbbb769ace7834cc1551a0556a 100644 --- a/mace/core/runtime/opencl/opencl_development.cc +++ b/mace/core/runtime/opencl/opencl_development.cc @@ -7,7 +7,6 @@ #include "mace/core/runtime/opencl/cl2_header.h" #include "mace/utils/utils.h" - namespace mace { bool GetSourceOrBinaryProgram(const std::string &program_name, @@ -30,34 +29,4 @@ bool GetSourceOrBinaryProgram(const std::string &program_name, return true; } -bool GetTuningParams(const char *path, - std::unordered_map> *param_table) { - if (path != nullptr) { - std::ifstream ifs(path, std::ios::binary | std::ios::in); - if (ifs.is_open()) { - int64_t num_params = 0; - ifs.read(reinterpret_cast(&num_params), sizeof(num_params)); - while (num_params--) { - int32_t key_size = 0; - ifs.read(reinterpret_cast(&key_size), sizeof(key_size)); - std::string key(key_size, ' '); - ifs.read(&key[0], key_size); - - int32_t params_size = 0; - ifs.read(reinterpret_cast(¶ms_size), sizeof(params_size)); - int32_t params_count = params_size / sizeof(unsigned int); - std::vector params(params_count); - for (int i = 0; i < params_count; ++i) { - ifs.read(reinterpret_cast(¶ms[i]), sizeof(unsigned int)); - } - param_table->emplace(key, params); - } - ifs.close(); - } else { - return false; - } - } - return true; -} - } // namespace mace diff --git a/mace/core/runtime/opencl/opencl_production.cc b/mace/core/runtime/opencl/opencl_production.cc index de2c8aa35e4473d49158133144e47ae474c808f4..11a793e7a7765dc1dc3cbd835877f3082a4924cd 100644 --- a/mace/core/runtime/opencl/opencl_production.cc +++ b/mace/core/runtime/opencl/opencl_production.cc @@ -23,13 +23,4 @@ bool GetSourceOrBinaryProgram(const std::string &program_name, return true; } -bool GetTuningParams(const char *path, - std::unordered_map> *param_table) { - extern const std::map> kTuningParamsData; - for (auto it = kTuningParamsData.begin(); it != kTuningParamsData.end(); ++it) { - param_table->emplace(it->first, std::vector(it->second.begin(), it->second.end())); - } - return true; -} - } // namespace mace diff --git a/mace/utils/BUILD b/mace/utils/BUILD index 7f5079e209615a027fb8b2ea5fe69f128bce22fd..fbd6e037d4f0802dbab2da55b1097a894e6ce7a4 100644 --- a/mace/utils/BUILD +++ b/mace/utils/BUILD @@ -47,6 +47,27 @@ cc_library( ], ) +cc_library( + name = "tuner_dev", + srcs = [ + "tuner_development.cc", + ], + deps = [ + ":tuner", + ], +) + +cc_library( + name = "tuner_prod", + srcs = [ + "tuner_production.cc", + ], + deps = [ + ":tuner", + "//mace/codegen:generated_tuning_params", + ], +) + cc_test( name = "tuner_test", testonly = 1, @@ -55,11 +76,12 @@ cc_test( ], linkopts = if_android([ "-pie", - "-lm", + "-lm", # Required by unordered_map ]), linkstatic = 1, deps = [ ":tuner", + ":tuner_dev", "@gtest//:gtest", "@gtest//:gtest_main", ], diff --git a/mace/utils/tuner.h b/mace/utils/tuner.h index b11affd324aa46f78e460547bbc60a24e7d96c82..536e0a04dfdbb205ec21eb558fc494da5a56e287 100644 --- a/mace/utils/tuner.h +++ b/mace/utils/tuner.h @@ -62,7 +62,9 @@ class Tuner { << internal::MakeString(param_table_[obfucated_param_key]); return func(param_table_[obfucated_param_key]); } else { - LOG(WARNING) << "Fallback to default parameter: " << param_key << ", table size: " << param_table_.size(); +#ifndef MACE_DISABLE_NO_TUNING_WARNING + LOG(WARNING) << "Fallback to default parameter: " << param_key; +#endif return func(default_param); } } diff --git a/mace/utils/tuner_development.cc b/mace/utils/tuner_development.cc new file mode 100644 index 0000000000000000000000000000000000000000..ccbe3b64fc5249e1de6e5885b169bb2af8f5be67 --- /dev/null +++ b/mace/utils/tuner_development.cc @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +namespace mace { + +bool GetTuningParams( + const char *path, + std::unordered_map> *param_table) { + if (path != nullptr) { + std::ifstream ifs(path, std::ios::binary | std::ios::in); + if (ifs.is_open()) { + int64_t num_params = 0; + ifs.read(reinterpret_cast(&num_params), sizeof(num_params)); + while (num_params--) { + int32_t key_size = 0; + ifs.read(reinterpret_cast(&key_size), sizeof(key_size)); + std::string key(key_size, ' '); + ifs.read(&key[0], key_size); + + int32_t params_size = 0; + ifs.read(reinterpret_cast(¶ms_size), sizeof(params_size)); + int32_t params_count = params_size / sizeof(unsigned int); + std::vector params(params_count); + for (int i = 0; i < params_count; ++i) { + ifs.read(reinterpret_cast(¶ms[i]), sizeof(unsigned int)); + } + param_table->emplace(key, params); + } + ifs.close(); + } else { + return false; + } + } + return true; +} + +} // namespace mace diff --git a/mace/utils/tuner_production.cc b/mace/utils/tuner_production.cc new file mode 100644 index 0000000000000000000000000000000000000000..f008d8dc52213d644f32d31a6efb68e37deef3a7 --- /dev/null +++ b/mace/utils/tuner_production.cc @@ -0,0 +1,21 @@ +#include +#include +#include +#include + +namespace mace { + +bool GetTuningParams( + const char *path, + std::unordered_map> *param_table) { + extern const std::map> + kTuningParamsData; + for (auto it = kTuningParamsData.begin(); it != kTuningParamsData.end(); + ++it) { + param_table->emplace(it->first, std::vector( + it->second.begin(), it->second.end())); + } + return true; +} + +} // namespace mace diff --git a/tools/bazel-adb-run.sh b/tools/bazel-adb-run.sh index b3457c1a93a9880baa947408378c2eef3867b6af..6865fd194c59a0b967bf30f456067fc1310245b9 100755 --- a/tools/bazel-adb-run.sh +++ b/tools/bazel-adb-run.sh @@ -32,12 +32,15 @@ echo "Step 2: Generate version source" bash mace/tools/git/gen_version_source.sh ${CODEGEN_DIR}/version/version.cc echo "Step 3: Build target" +# -D_GLIBCXX_USE_C99_MATH_TR1 is used to solve include error instead +# of linking error which solved by -lm bazel build -c opt $STRIP --verbose_failures $BAZEL_TARGET \ --crosstool_top=//external:android/crosstool \ --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \ --cpu=$ANDROID_ABI \ --copt="-std=c++11" \ --copt="-D_GLIBCXX_USE_C99_MATH_TR1" \ + --copt="-DMACE_DISABLE_NO_TUNING_WARNING" \ --copt="-Werror=return-type" \ --define neon=false