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

Update OpenMP logging

上级 1f9b2ee2
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <sys/types.h> #include <sys/types.h>
#include <string.h>
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -44,7 +45,7 @@ int GetCPUCount() { ...@@ -44,7 +45,7 @@ int GetCPUCount() {
result = access(path, F_OK); result = access(path, F_OK);
if (result != 0) { if (result != 0) {
if (errno != ENOENT) { if (errno != ENOENT) {
LOG(ERROR) << "Access " << path << " failed, errno: " << errno; LOG(ERROR) << "Access " << path << " failed: " << strerror(errno);
} }
return cpu_count; return cpu_count;
} }
...@@ -81,7 +82,7 @@ void SetThreadAffinity(cpu_set_t mask) { ...@@ -81,7 +82,7 @@ void SetThreadAffinity(cpu_set_t mask) {
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: ", errno); MACE_CHECK(err == 0, "set affinity error: ", strerror(errno));
} }
} // namespace } // namespace
...@@ -101,7 +102,7 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids, ...@@ -101,7 +102,7 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids,
for (int i = 0; i < cpu_count; ++i) { for (int i = 0; i < cpu_count; ++i) {
cpu_max_freq[i] = GetCPUMaxFreq(i); cpu_max_freq[i] = GetCPUMaxFreq(i);
if (cpu_max_freq[i] == 0) { if (cpu_max_freq[i] == 0) {
LOG(WARNING) << "Cannot get cpu" << i LOG(WARNING) << "Cannot get CPU" << i
<< "'s max frequency info, maybe it is offline."; << "'s max frequency info, maybe it is offline.";
return MACE_INVALID_ARGS; return MACE_INVALID_ARGS;
} }
...@@ -128,13 +129,12 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids, ...@@ -128,13 +129,12 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids,
void SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads, void SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads,
const std::vector<int> &cpu_ids) { const std::vector<int> &cpu_ids) {
#ifdef MACE_ENABLE_OPENMP
VLOG(1) << "Set OpenMP threads number: " << omp_num_threads VLOG(1) << "Set OpenMP threads number: " << omp_num_threads
<< ", CPU core IDs: " << MakeString(cpu_ids); << ", CPU core IDs: " << MakeString(cpu_ids);
#ifdef MACE_ENABLE_OPENMP
omp_set_num_threads(omp_num_threads); omp_set_num_threads(omp_num_threads);
#else #else
LOG(WARNING) << "OpenMP not enabled. Set OpenMP threads number failed."; LOG(WARNING) << "Set OpenMP threads number failed: OpenMP not enabled.";
#endif #endif
// compute mask // compute mask
...@@ -147,11 +147,13 @@ void SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads, ...@@ -147,11 +147,13 @@ void SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads,
#ifdef MACE_ENABLE_OPENMP #ifdef MACE_ENABLE_OPENMP
#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()
<< "/" << omp_get_num_threads();
SetThreadAffinity(mask); SetThreadAffinity(mask);
} }
#else #else
SetThreadAffinity(mask); SetThreadAffinity(mask);
LOG(INFO) << "SetThreadAffinity: " << mask.__bits[0]; VLOG(1) << "Set affinity without OpenMP: " << mask.__bits[0];
#endif #endif
} }
...@@ -163,7 +165,7 @@ MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint, ...@@ -163,7 +165,7 @@ MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint,
omp_set_num_threads(std::min(omp_num_threads_hint, omp_get_num_procs())); omp_set_num_threads(std::min(omp_num_threads_hint, omp_get_num_procs()));
} }
#else #else
LOG(WARNING) << "OpenMP not enabled. Set OpenMP threads number failed."; LOG(WARNING) << "Set OpenMP threads number failed: OpenMP not enabled.";
#endif #endif
return MACE_SUCCESS; return MACE_SUCCESS;
} }
...@@ -192,7 +194,7 @@ MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint, ...@@ -192,7 +194,7 @@ MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint,
MaceStatus SetOpenMPThreadPolicy(int num_threads_hint, MaceStatus SetOpenMPThreadPolicy(int num_threads_hint,
CPUAffinityPolicy policy) { CPUAffinityPolicy policy) {
VLOG(1) << "Set CPU openmp num_threads_hint: " << num_threads_hint VLOG(1) << "Set OpenMP threads number hint: " << num_threads_hint
<< ", affinity policy: " << policy; << ", affinity policy: " << policy;
return SetOpenMPThreadsAndAffinityPolicy(num_threads_hint, policy); return SetOpenMPThreadsAndAffinityPolicy(num_threads_hint, policy);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册