From 75b995b52b72f986badc23fc31976e7a79038fd4 Mon Sep 17 00:00:00 2001 From: yejianwu Date: Thu, 12 Jul 2018 20:59:24 +0800 Subject: [PATCH] fix benchmark, avoid alwayslink for mace:core --- mace/benchmark/BUILD | 2 +- mace/core/BUILD | 2 - mace/core/mace_runtime.cc | 33 ----------- mace/core/runtime/cpu/cpu_runtime.cc | 17 ------ mace/core/runtime/opencl/opencl_runtime.cc | 16 ++---- mace/core/testing/test_benchmark_main.cc | 6 +- mace/libmace/mace_runtime.cc | 64 ++++++++++++++++++++++ 7 files changed, 73 insertions(+), 67 deletions(-) delete mode 100644 mace/core/mace_runtime.cc create mode 100644 mace/libmace/mace_runtime.cc diff --git a/mace/benchmark/BUILD b/mace/benchmark/BUILD index 201c46dc..020850f2 100644 --- a/mace/benchmark/BUILD +++ b/mace/benchmark/BUILD @@ -36,7 +36,7 @@ cc_binary( "//external:gflags_nothreads", "//mace/codegen:generated_models", "//mace/codegen:generated_mace_engine_factory", - "//mace/ops:ops", + "//mace/libmace:libmace", ], ) diff --git a/mace/core/BUILD b/mace/core/BUILD index 8e3fb50f..7c12cd03 100644 --- a/mace/core/BUILD +++ b/mace/core/BUILD @@ -70,7 +70,6 @@ cc_library( ]) + if_hexagon_enabled([ "//third_party/nnlib:libhexagon", ]), - alwayslink = 1, ) cc_library( @@ -109,5 +108,4 @@ cc_library( "//external:gflags_nothreads", "//mace/utils", ], - alwayslink = 1, ) diff --git a/mace/core/mace_runtime.cc b/mace/core/mace_runtime.cc deleted file mode 100644 index dd7469a8..00000000 --- a/mace/core/mace_runtime.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2018 Xiaomi, Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "mace/public/mace_runtime.h" -#include "mace/utils/logging.h" - -namespace mace { - -std::shared_ptr kStorageFactory = nullptr; - -void SetKVStorageFactory(std::shared_ptr storage_factory) { - VLOG(1) << "Set internal KV Storage Engine"; - kStorageFactory = storage_factory; -} - -std::string kOpenCLParameterPath; // NOLINT(runtime/string) - -void SetOpenCLParameterPath(const std::string &path) { - kOpenCLParameterPath = path; -} - -}; // namespace mace diff --git a/mace/core/runtime/cpu/cpu_runtime.cc b/mace/core/runtime/cpu/cpu_runtime.cc index ec1ed80e..a3fe5959 100644 --- a/mace/core/runtime/cpu/cpu_runtime.cc +++ b/mace/core/runtime/cpu/cpu_runtime.cc @@ -206,22 +206,5 @@ MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint, return SetOpenMPThreadsAndAffinityCPUs(omp_num_threads_hint, use_cpu_ids); } -MaceStatus SetOpenMPThreadPolicy(int num_threads_hint, - CPUAffinityPolicy policy) { - VLOG(1) << "Set OpenMP threads number hint: " << num_threads_hint - << ", affinity policy: " << policy; - return SetOpenMPThreadsAndAffinityPolicy(num_threads_hint, policy); -} - -MaceStatus SetOpenMPThreadAffinity(int num_threads, - const std::vector &cpu_ids) { - return SetOpenMPThreadsAndAffinityCPUs(num_threads, cpu_ids); -} - -MaceStatus GetBigLittleCoreIDs(std::vector *big_core_ids, - std::vector *little_core_ids) { - return GetCPUBigLittleCoreIDs(big_core_ids, little_core_ids); -} - } // namespace mace diff --git a/mace/core/runtime/opencl/opencl_runtime.cc b/mace/core/runtime/opencl/opencl_runtime.cc index ae2f6939..1748a6c1 100644 --- a/mace/core/runtime/opencl/opencl_runtime.cc +++ b/mace/core/runtime/opencl/opencl_runtime.cc @@ -33,20 +33,12 @@ namespace mace { -extern const std::map> - kEncryptedProgramMap; +std::shared_ptr kStorageFactory = nullptr; -void SetGPUHints(GPUPerfHint gpu_perf_hint, GPUPriorityHint gpu_priority_hint) { - VLOG(1) << "Set GPU configurations, gpu_perf_hint: " << gpu_perf_hint - << ", gpu_priority_hint: " << gpu_priority_hint; - OpenCLRuntime::Configure(gpu_perf_hint, gpu_priority_hint); -} - -// Set OpenCL Compiled Binary paths, just call once. (Not thread-safe) -void SetOpenCLBinaryPaths(const std::vector &paths) { - OpenCLRuntime::ConfigureOpenCLBinaryPath(paths); -} +std::string kOpenCLParameterPath; // NOLINT(runtime/string) +extern const std::map> + kEncryptedProgramMap; const std::string OpenCLErrorToString(cl_int error) { switch (error) { diff --git a/mace/core/testing/test_benchmark_main.cc b/mace/core/testing/test_benchmark_main.cc index 4f68d706..7af19d1c 100644 --- a/mace/core/testing/test_benchmark_main.cc +++ b/mace/core/testing/test_benchmark_main.cc @@ -15,6 +15,8 @@ #include #include "gflags/gflags.h" +#include "mace/core/runtime/cpu/cpu_runtime.h" +#include "mace/core/runtime/opencl/opencl_runtime.h" #include "mace/core/testing/test_benchmark.h" #include "mace/public/mace.h" #include "mace/public/mace_runtime.h" @@ -34,13 +36,13 @@ int main(int argc, char **argv) { gflags::ParseCommandLineFlags(&argc, &argv, true); // config runtime - mace::MaceStatus status = mace::SetOpenMPThreadPolicy( + mace::MaceStatus status = mace::SetOpenMPThreadsAndAffinityPolicy( FLAGS_omp_num_threads, static_cast(FLAGS_cpu_affinity_policy)); if (status != mace::MACE_SUCCESS) { LOG(WARNING) << "Set openmp or cpu affinity failed."; } - mace::SetGPUHints( + mace::OpenCLRuntime::Configure( static_cast(FLAGS_gpu_perf_hint), static_cast(FLAGS_gpu_priority_hint)); diff --git a/mace/libmace/mace_runtime.cc b/mace/libmace/mace_runtime.cc new file mode 100644 index 00000000..720b8299 --- /dev/null +++ b/mace/libmace/mace_runtime.cc @@ -0,0 +1,64 @@ +// Copyright 2018 Xiaomi, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "mace/core/runtime/cpu/cpu_runtime.h" +#include "mace/core/runtime/opencl/opencl_runtime.h" +#include "mace/public/mace_runtime.h" +#include "mace/utils/logging.h" + +namespace mace { + +extern std::shared_ptr kStorageFactory; + +void SetKVStorageFactory(std::shared_ptr storage_factory) { + VLOG(1) << "Set internal KV Storage Engine"; + kStorageFactory = storage_factory; +} + +// Set OpenCL Compiled Binary paths, just call once. (Not thread-safe) +void SetOpenCLBinaryPaths(const std::vector &paths) { + OpenCLRuntime::ConfigureOpenCLBinaryPath(paths); +} + +extern std::string kOpenCLParameterPath; + +void SetOpenCLParameterPath(const std::string &path) { + kOpenCLParameterPath = path; +} + +void SetGPUHints(GPUPerfHint gpu_perf_hint, GPUPriorityHint gpu_priority_hint) { + VLOG(1) << "Set GPU configurations, gpu_perf_hint: " << gpu_perf_hint + << ", gpu_priority_hint: " << gpu_priority_hint; + OpenCLRuntime::Configure(gpu_perf_hint, gpu_priority_hint); +} + +MaceStatus SetOpenMPThreadPolicy(int num_threads_hint, + CPUAffinityPolicy policy) { + VLOG(1) << "Set OpenMP threads number hint: " << num_threads_hint + << ", affinity policy: " << policy; + return SetOpenMPThreadsAndAffinityPolicy(num_threads_hint, policy); +} + +MaceStatus SetOpenMPThreadAffinity(int num_threads, + const std::vector &cpu_ids) { + return SetOpenMPThreadsAndAffinityCPUs(num_threads, cpu_ids); +} + +MaceStatus GetBigLittleCoreIDs(std::vector *big_core_ids, + std::vector *little_core_ids) { + return GetCPUBigLittleCoreIDs(big_core_ids, little_core_ids); +} + + +}; // namespace mace -- GitLab