diff --git a/mace/benchmark/BUILD b/mace/benchmark/BUILD index 201c46dcb1148df6c45bdc14b2672feda427232a..020850f21a17c426d3db4469c97a10f32c7ee3fb 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 8e3fb50ffd91106348808ce05bf63330e60ee2b1..7c12cd036aae49c65b2e74ba4de796261aed3ce0 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 dd7469a8b18e48d31ae6c0c6185ca1b297a8105c..0000000000000000000000000000000000000000 --- 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 ec1ed80eed340f63ac30d053c2becb3418c43e25..a3fe5959cd058b0ac754361653fcc0429d1b2938 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 ae2f69390968841a4f7410ccec3b16be2bc15971..1748a6c10c6ec5feec48934e9dc65744aa8957a9 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 4f68d7063af63a2bfd0c124d347a4c527b84dd44..7af19d1caabdacb9dace84f01633a1dd0e97d5b5 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 0000000000000000000000000000000000000000..720b82994425905258d0c042b6d5f750004fc7a9 --- /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