提交 21190cad 编写于 作者: Y yejianwu

Merge branch 'master' of github.com:XiaoMi/mace into update_travis_ci

...@@ -99,7 +99,7 @@ python_tools_tests: ...@@ -99,7 +99,7 @@ python_tools_tests:
script: script:
- pwd - pwd
- rm -rf mace-models - rm -rf mace-models
- GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@v9.git.n.xiaomi.com:deep-computing/mace-models.git - GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" git clone git@github.com:XiaoMi/mace-models.git
- CONF_FILE=mace-models/mobilenet-v2/mobilenet-v2.yml - CONF_FILE=mace-models/mobilenet-v2/mobilenet-v2.yml
- sh -c "python tools/converter.py build --config=${CONF_FILE} --disable_tuning && python tools/converter.py run --config=${CONF_FILE} --round=1 --validate && python tools/converter.py run --config=${CONF_FILE} --example --round=1 --validate" || exit 1 - sh -c "python tools/converter.py build --config=${CONF_FILE} --disable_tuning && python tools/converter.py run --config=${CONF_FILE} --round=1 --validate && python tools/converter.py run --config=${CONF_FILE} --example --round=1 --validate" || exit 1
- rm -rf mace-models - rm -rf mace-models
...@@ -253,9 +253,12 @@ int Main(int argc, char **argv) { ...@@ -253,9 +253,12 @@ int Main(int argc, char **argv) {
mace::DeviceType device_type = ParseDeviceType(FLAGS_device); mace::DeviceType device_type = ParseDeviceType(FLAGS_device);
// config runtime // config runtime
mace::SetOpenMPThreadPolicy( MaceStatus ret = mace::SetOpenMPThreadPolicy(
FLAGS_omp_num_threads, FLAGS_omp_num_threads,
static_cast<CPUAffinityPolicy >(FLAGS_cpu_affinity_policy)); static_cast<CPUAffinityPolicy >(FLAGS_cpu_affinity_policy));
if (ret != MACE_SUCCESS) {
LOG(WARNING) << "Set openmp or cpu affinity failed.";
}
#ifdef MACE_ENABLE_OPENCL #ifdef MACE_ENABLE_OPENCL
if (device_type == DeviceType::GPU) { if (device_type == DeviceType::GPU) {
mace::SetGPUHints( mace::SetGPUHints(
......
...@@ -204,9 +204,6 @@ MaceStatus MaceEngine::Impl::Init( ...@@ -204,9 +204,6 @@ MaceStatus MaceEngine::Impl::Init(
MACE_CHECK(hexagon_controller_->Init(), "hexagon init error"); MACE_CHECK(hexagon_controller_->Init(), "hexagon init error");
hexagon_controller_->SetDebugLevel( hexagon_controller_->SetDebugLevel(
static_cast<int>(mace::logging::LogMessage::MinVLogLevel())); static_cast<int>(mace::logging::LogMessage::MinVLogLevel()));
int dsp_mode =
ProtoArgHelper::GetOptionalArg<NetDef, int>(*net_def, "dsp_mode", 0);
hexagon_controller_->SetGraphMode(dsp_mode);
MACE_CHECK(hexagon_controller_->SetupGraph(*net_def, model_data), MACE_CHECK(hexagon_controller_->SetupGraph(*net_def, model_data),
"hexagon setup graph error"); "hexagon setup graph error");
if (VLOG_IS_ON(2)) { if (VLOG_IS_ON(2)) {
......
...@@ -77,14 +77,19 @@ int GetCPUMaxFreq(int cpu_id) { ...@@ -77,14 +77,19 @@ int GetCPUMaxFreq(int cpu_id) {
return freq; return freq;
} }
void SetThreadAffinity(cpu_set_t mask) { MaceStatus SetThreadAffinity(cpu_set_t mask) {
#if defined(__ANDROID__) #if defined(__ANDROID__)
pid_t pid = gettid(); pid_t pid = gettid();
#else #else
pid_t pid = syscall(SYS_gettid); pid_t pid = syscall(SYS_gettid);
#endif #endif
int err = sched_setaffinity(pid, sizeof(mask), &mask); int err = sched_setaffinity(pid, sizeof(mask), &mask);
MACE_CHECK(err == 0, "set affinity error: ", strerror(errno)); if (err) {
LOG(WARNING) << "set affinity error: " << strerror(errno);
return MACE_INVALID_ARGS;
} else {
return MACE_SUCCESS;
}
} }
} // namespace } // namespace
...@@ -129,7 +134,7 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids, ...@@ -129,7 +134,7 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids,
return MACE_SUCCESS; return MACE_SUCCESS;
} }
void SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads, MaceStatus SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads,
const std::vector<int> &cpu_ids) { const std::vector<int> &cpu_ids) {
#ifdef MACE_ENABLE_OPENMP #ifdef MACE_ENABLE_OPENMP
VLOG(1) << "Set OpenMP threads number: " << omp_num_threads VLOG(1) << "Set OpenMP threads number: " << omp_num_threads
...@@ -146,17 +151,23 @@ void SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads, ...@@ -146,17 +151,23 @@ void SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads,
for (auto cpu_id : cpu_ids) { for (auto cpu_id : cpu_ids) {
CPU_SET(cpu_id, &mask); CPU_SET(cpu_id, &mask);
} }
#ifdef MACE_ENABLE_OPENMP #ifdef MACE_ENABLE_OPENMP
std::vector<MaceStatus> status(omp_num_threads);
#pragma omp parallel for #pragma omp parallel for
for (int i = 0; i < omp_num_threads; ++i) { for (int i = 0; i < omp_num_threads; ++i) {
VLOG(1) << "Set affinity for OpenMP thread " << omp_get_thread_num() VLOG(1) << "Set affinity for OpenMP thread " << omp_get_thread_num()
<< "/" << omp_get_num_threads(); << "/" << omp_get_num_threads();
SetThreadAffinity(mask); status[i] = SetThreadAffinity(mask);
}
for (int i = 0; i < omp_num_threads; ++i) {
if (status[i] != MACE_SUCCESS)
return MACE_INVALID_ARGS;
} }
return MACE_SUCCESS;
#else #else
SetThreadAffinity(mask); MaceStatus status = SetThreadAffinity(mask);
VLOG(1) << "Set affinity without OpenMP: " << mask.__bits[0]; VLOG(1) << "Set affinity without OpenMP: " << mask.__bits[0];
return status;
#endif #endif
} }
...@@ -191,8 +202,8 @@ MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint, ...@@ -191,8 +202,8 @@ MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint,
omp_num_threads_hint > static_cast<int>(use_cpu_ids.size())) { omp_num_threads_hint > static_cast<int>(use_cpu_ids.size())) {
omp_num_threads_hint = use_cpu_ids.size(); omp_num_threads_hint = use_cpu_ids.size();
} }
SetOpenMPThreadsAndAffinityCPUs(omp_num_threads_hint, use_cpu_ids);
return MACE_SUCCESS; return SetOpenMPThreadsAndAffinityCPUs(omp_num_threads_hint, use_cpu_ids);
} }
MaceStatus SetOpenMPThreadPolicy(int num_threads_hint, MaceStatus SetOpenMPThreadPolicy(int num_threads_hint,
...@@ -202,7 +213,8 @@ MaceStatus SetOpenMPThreadPolicy(int num_threads_hint, ...@@ -202,7 +213,8 @@ MaceStatus SetOpenMPThreadPolicy(int num_threads_hint,
return SetOpenMPThreadsAndAffinityPolicy(num_threads_hint, policy); return SetOpenMPThreadsAndAffinityPolicy(num_threads_hint, policy);
} }
void SetOpenMPThreadAffinity(int num_threads, const std::vector<int> &cpu_ids) { MaceStatus SetOpenMPThreadAffinity(int num_threads,
const std::vector<int> &cpu_ids) {
return SetOpenMPThreadsAndAffinityCPUs(num_threads, cpu_ids); return SetOpenMPThreadsAndAffinityCPUs(num_threads, cpu_ids);
} }
......
...@@ -25,7 +25,7 @@ namespace mace { ...@@ -25,7 +25,7 @@ namespace mace {
MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids, MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids,
std::vector<int> *little_core_ids); std::vector<int> *little_core_ids);
void SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads, MaceStatus SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads,
const std::vector<int> &cpu_ids); const std::vector<int> &cpu_ids);
MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint, MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint,
......
...@@ -51,7 +51,7 @@ int HexagonControlWrapper::GetVersion() { ...@@ -51,7 +51,7 @@ int HexagonControlWrapper::GetVersion() {
bool HexagonControlWrapper::Config() { bool HexagonControlWrapper::Config() {
LOG(INFO) << "Hexagon config"; LOG(INFO) << "Hexagon config";
if (hexagon_controller_InitHexagonWithMaxAttributes(0, 100) != 0) { if (hexagon_nn_set_powersave_level(0) != 0) {
return false; return false;
} }
return hexagon_nn_config() == 0; return hexagon_nn_config() == 0;
...@@ -66,7 +66,7 @@ bool HexagonControlWrapper::Init() { ...@@ -66,7 +66,7 @@ bool HexagonControlWrapper::Init() {
bool HexagonControlWrapper::Finalize() { bool HexagonControlWrapper::Finalize() {
LOG(INFO) << "Hexagon finalize"; LOG(INFO) << "Hexagon finalize";
return hexagon_controller_DeInitHexagon() == 0; return hexagon_nn_set_powersave_level(1) == 0;
} }
bool HexagonControlWrapper::SetupGraph(const NetDef &net_def, bool HexagonControlWrapper::SetupGraph(const NetDef &net_def,
...@@ -271,11 +271,6 @@ void HexagonControlWrapper::SetDebugLevel(int level) { ...@@ -271,11 +271,6 @@ void HexagonControlWrapper::SetDebugLevel(int level) {
"set debug level error"); "set debug level error");
} }
void HexagonControlWrapper::SetGraphMode(int mode) {
LOG(INFO) << "Set dsp mode: " << mode;
MACE_CHECK(hexagon_nn_set_graph_mode(nn_id_, mode) == 0, "set mode error");
}
void HexagonControlWrapper::GetPerfInfo() { void HexagonControlWrapper::GetPerfInfo() {
LOG(INFO) << "Get perf info"; LOG(INFO) << "Get perf info";
std::vector<hexagon_nn_perfinfo> perf_info(MACE_MAX_NODE); std::vector<hexagon_nn_perfinfo> perf_info(MACE_MAX_NODE);
......
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
#include <vector> #include <vector>
#include "mace/core/runtime/hexagon/hexagon_controller.h"
#include "mace/core/runtime/hexagon/quantize.h" #include "mace/core/runtime/hexagon/quantize.h"
#include "mace/core/tensor.h" #include "mace/core/tensor.h"
#include "mace/public/mace.h" #include "mace/public/mace.h"
#include "third_party/nnlib/hexagon_nn.h"
namespace mace { namespace mace {
...@@ -44,7 +44,6 @@ class HexagonControlWrapper { ...@@ -44,7 +44,6 @@ class HexagonControlWrapper {
void GetPerfInfo(); void GetPerfInfo();
void ResetPerfInfo(); void ResetPerfInfo();
void SetDebugLevel(int level); void SetDebugLevel(int level);
void SetGraphMode(int mode);
private: private:
static constexpr int NODE_ID_OFFSET = 10000; static constexpr int NODE_ID_OFFSET = 10000;
......
// 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.
#ifndef MACE_CORE_RUNTIME_HEXAGON_HEXAGON_CONTROLLER_H_
#define MACE_CORE_RUNTIME_HEXAGON_HEXAGON_CONTROLLER_H_
#include "third_party/nnlib/hexagon_nn.h"
#ifdef __cplusplus
extern "C" {
#else
#include <stdbool.h>
#endif // __cplusplus
int hexagon_controller_InitHexagonWithMaxAttributes(int enable_dcvs,
int bus_usage);
int hexagon_controller_DeInitHexagon();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // MACE_CORE_RUNTIME_HEXAGON_HEXAGON_CONTROLLER_H_
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "mace/core/testing/test_benchmark.h" #include "mace/core/testing/test_benchmark.h"
#include "mace/public/mace.h" #include "mace/public/mace.h"
#include "mace/public/mace_runtime.h" #include "mace/public/mace_runtime.h"
#include "mace/utils/logging.h"
DEFINE_string(filter, "all", "op benchmark regex filter, eg:.*CONV.*"); DEFINE_string(filter, "all", "op benchmark regex filter, eg:.*CONV.*");
DEFINE_int32(gpu_perf_hint, 3, "0:DEFAULT/1:LOW/2:NORMAL/3:HIGH"); DEFINE_int32(gpu_perf_hint, 3, "0:DEFAULT/1:LOW/2:NORMAL/3:HIGH");
...@@ -33,9 +34,12 @@ int main(int argc, char **argv) { ...@@ -33,9 +34,12 @@ int main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true); gflags::ParseCommandLineFlags(&argc, &argv, true);
// config runtime // config runtime
mace::SetOpenMPThreadPolicy( mace::MaceStatus status = mace::SetOpenMPThreadPolicy(
FLAGS_omp_num_threads, FLAGS_omp_num_threads,
static_cast<mace::CPUAffinityPolicy >(FLAGS_cpu_affinity_policy)); static_cast<mace::CPUAffinityPolicy >(FLAGS_cpu_affinity_policy));
if (status != mace::MACE_SUCCESS) {
LOG(WARNING) << "Set openmp or cpu affinity failed.";
}
mace::SetGPUHints( mace::SetGPUHints(
static_cast<mace::GPUPerfHint>(FLAGS_gpu_perf_hint), static_cast<mace::GPUPerfHint>(FLAGS_gpu_perf_hint),
static_cast<mace::GPUPriorityHint>(FLAGS_gpu_priority_hint)); static_cast<mace::GPUPriorityHint>(FLAGS_gpu_priority_hint));
......
...@@ -4,7 +4,7 @@ android { ...@@ -4,7 +4,7 @@ android {
compileSdkVersion 26 compileSdkVersion 26
defaultConfig { defaultConfig {
applicationId "com.xiaomi.mace.demo" applicationId "com.xiaomi.mace.demo"
minSdkVersion 23 minSdkVersion 19
targetSdkVersion 26 targetSdkVersion 26
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
......
...@@ -34,7 +34,7 @@ public class InitData { ...@@ -34,7 +34,7 @@ public class InitData {
public InitData() { public InitData() {
model = MODELS[0]; model = MODELS[0];
ompNumThreads = 2; ompNumThreads = 2;
cpuAffinityPolicy = 1; cpuAffinityPolicy = 0;
gpuPerfHint = 3; gpuPerfHint = 3;
gpuPriorityHint = 3; gpuPriorityHint = 3;
device = DEVICES[0]; device = DEVICES[0];
......
...@@ -5,8 +5,8 @@ set -e -u -o pipefail ...@@ -5,8 +5,8 @@ set -e -u -o pipefail
pushd ../../../ pushd ../../../
python tools/converter.py build --config=docs/getting_started/models/demo_app_models.yaml python tools/converter.py build --config=docs/getting_started/models/demo_app_models.yaml
cp -r builds/mobilenet/include/ mace/examples/android/macelibrary/src/main/cpp/ cp -r builds/mobilenet/include mace/examples/android/macelibrary/src/main/cpp/
cp -r builds/mobilenet/lib/ mace/examples/android/macelibrary/src/main/cpp/ cp -r builds/mobilenet/lib mace/examples/android/macelibrary/src/main/cpp/
popd popd
......
...@@ -9,7 +9,7 @@ android { ...@@ -9,7 +9,7 @@ android {
} }
defaultConfig { defaultConfig {
minSdkVersion 23 minSdkVersion 19
targetSdkVersion 26 targetSdkVersion 26
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
......
...@@ -125,7 +125,8 @@ MaceStatus SetOpenMPThreadPolicy(int num_threads_hint, ...@@ -125,7 +125,8 @@ MaceStatus SetOpenMPThreadPolicy(int num_threads_hint,
// affinity to offline cores may run very slow or unexpectedly. In such cases, // affinity to offline cores may run very slow or unexpectedly. In such cases,
// please use SetOpenMPThreadPolicy with default policy instead. // please use SetOpenMPThreadPolicy with default policy instead.
__attribute__((visibility("default"))) __attribute__((visibility("default")))
void SetOpenMPThreadAffinity(int num_threads, const std::vector<int> &cpu_ids); MaceStatus SetOpenMPThreadAffinity(int num_threads,
const std::vector<int> &cpu_ids);
// Get ARM big.LITTLE configuration. // Get ARM big.LITTLE configuration.
// //
......
...@@ -198,9 +198,12 @@ bool RunModel(const std::string &model_name, ...@@ -198,9 +198,12 @@ bool RunModel(const std::string &model_name,
const std::vector<std::vector<int64_t>> &output_shapes) { const std::vector<std::vector<int64_t>> &output_shapes) {
DeviceType device_type = ParseDeviceType(FLAGS_device); DeviceType device_type = ParseDeviceType(FLAGS_device);
// config runtime // config runtime
mace::SetOpenMPThreadPolicy( MaceStatus status = mace::SetOpenMPThreadPolicy(
FLAGS_omp_num_threads, FLAGS_omp_num_threads,
static_cast<CPUAffinityPolicy >(FLAGS_cpu_affinity_policy)); static_cast<CPUAffinityPolicy >(FLAGS_cpu_affinity_policy));
if (status != MACE_SUCCESS) {
LOG(WARNING) << "Set openmp or cpu affinity failed.";
}
#ifdef MACE_ENABLE_OPENCL #ifdef MACE_ENABLE_OPENCL
if (device_type == DeviceType::GPU) { if (device_type == DeviceType::GPU) {
mace::SetGPUHints( mace::SetGPUHints(
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#define THIRD_PARTY_NNLIB_HEXAGON_NN_H_ #define THIRD_PARTY_NNLIB_HEXAGON_NN_H_
#ifndef __QAIC_HEADER #ifndef __QAIC_HEADER
#define __QAIC_HEADER(ff) ff #define __QAIC_HEADER(ff) ff
#endif // __QAIC_HEADER #endif //__QAIC_HEADER
#ifndef __QAIC_HEADER_EXPORT #ifndef __QAIC_HEADER_EXPORT
#define __QAIC_HEADER_EXPORT #define __QAIC_HEADER_EXPORT
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
#ifndef __QAIC_IMPL #ifndef __QAIC_IMPL
#define __QAIC_IMPL(ff) ff #define __QAIC_IMPL(ff) ff
#endif // __QAIC_IMPL #endif //__QAIC_IMPL
#ifndef __QAIC_IMPL_EXPORT #ifndef __QAIC_IMPL_EXPORT
#define __QAIC_IMPL_EXPORT #define __QAIC_IMPL_EXPORT
...@@ -131,7 +131,7 @@ struct hexagon_nn_const_node { ...@@ -131,7 +131,7 @@ struct hexagon_nn_const_node {
}; };
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_config)(void) __QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_config)(void)
__QAIC_HEADER_ATTRIBUTE; __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_init)(hexagon_nn_nn_id* g) __QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_init)(hexagon_nn_nn_id *g)
__QAIC_HEADER_ATTRIBUTE; __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_debug_level)( __QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_debug_level)(
hexagon_nn_nn_id id, int level) __QAIC_HEADER_ATTRIBUTE; hexagon_nn_nn_id id, int level) __QAIC_HEADER_ATTRIBUTE;
...@@ -221,6 +221,8 @@ __QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_execute_new)( ...@@ -221,6 +221,8 @@ __QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_execute_new)(
int inputsLen, int inputsLen,
hexagon_nn_tensordef *outputs, hexagon_nn_tensordef *outputs,
int outputsLen) __QAIC_HEADER_ATTRIBUTE; int outputsLen) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT unsigned int __QAIC_HEADER(hexagon_nn_get_dsp_offset)(void)
__QAIC_HEADER_ATTRIBUTE;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册