Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Xiaomi
Mace
提交
f69b8695
Mace
项目概览
Xiaomi
/
Mace
通知
106
Star
40
Fork
27
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f69b8695
编写于
5月 16, 2018
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update OpenMP logging
上级
1f9b2ee2
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
11 addition
and
9 deletion
+11
-9
mace/core/runtime/cpu/cpu_runtime.cc
mace/core/runtime/cpu/cpu_runtime.cc
+11
-9
未找到文件。
mace/core/runtime/cpu/cpu_runtime.cc
浏览文件 @
f69b8695
...
...
@@ -21,6 +21,7 @@
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
...
...
@@ -44,7 +45,7 @@ int GetCPUCount() {
result
=
access
(
path
,
F_OK
);
if
(
result
!=
0
)
{
if
(
errno
!=
ENOENT
)
{
LOG
(
ERROR
)
<<
"Access "
<<
path
<<
" failed
, errno: "
<<
errno
;
LOG
(
ERROR
)
<<
"Access "
<<
path
<<
" failed
: "
<<
strerror
(
errno
)
;
}
return
cpu_count
;
}
...
...
@@ -81,7 +82,7 @@ void SetThreadAffinity(cpu_set_t mask) {
pid_t
pid
=
syscall
(
SYS_gettid
);
#endif
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
...
...
@@ -101,7 +102,7 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids,
for
(
int
i
=
0
;
i
<
cpu_count
;
++
i
)
{
cpu_max_freq
[
i
]
=
GetCPUMaxFreq
(
i
);
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."
;
return
MACE_INVALID_ARGS
;
}
...
...
@@ -128,13 +129,12 @@ MaceStatus GetCPUBigLittleCoreIDs(std::vector<int> *big_core_ids,
void
SetOpenMPThreadsAndAffinityCPUs
(
int
omp_num_threads
,
const
std
::
vector
<
int
>
&
cpu_ids
)
{
#ifdef MACE_ENABLE_OPENMP
VLOG
(
1
)
<<
"Set OpenMP threads number: "
<<
omp_num_threads
<<
", CPU core IDs: "
<<
MakeString
(
cpu_ids
);
#ifdef MACE_ENABLE_OPENMP
omp_set_num_threads
(
omp_num_threads
);
#else
LOG
(
WARNING
)
<<
"
OpenMP not enabled. Set OpenMP threads number fai
led."
;
LOG
(
WARNING
)
<<
"
Set OpenMP threads number failed: OpenMP not enab
led."
;
#endif
// compute mask
...
...
@@ -147,11 +147,13 @@ void SetOpenMPThreadsAndAffinityCPUs(int omp_num_threads,
#ifdef MACE_ENABLE_OPENMP
#pragma omp parallel for
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
);
}
#else
SetThreadAffinity
(
mask
);
LOG
(
INFO
)
<<
"SetThreadAffinity
: "
<<
mask
.
__bits
[
0
];
VLOG
(
1
)
<<
"Set affinity without OpenMP
: "
<<
mask
.
__bits
[
0
];
#endif
}
...
...
@@ -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
()));
}
#else
LOG
(
WARNING
)
<<
"
OpenMP not enabled. Set OpenMP threads number fai
led."
;
LOG
(
WARNING
)
<<
"
Set OpenMP threads number failed: OpenMP not enab
led."
;
#endif
return
MACE_SUCCESS
;
}
...
...
@@ -192,7 +194,7 @@ MaceStatus SetOpenMPThreadsAndAffinityPolicy(int omp_num_threads_hint,
MaceStatus
SetOpenMPThreadPolicy
(
int
num_threads_hint
,
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
;
return
SetOpenMPThreadsAndAffinityPolicy
(
num_threads_hint
,
policy
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录