Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夏有凉风,冬有雪
Paddle
提交
e28157d7
P
Paddle
项目概览
夏有凉风,冬有雪
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e28157d7
编写于
11月 22, 2017
作者:
T
tensor-tang
提交者:
QI JUN
11月 22, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix v2 init issue on Mac (#5808)
* fix v2 init issue on Mac * refine the v2 init
上级
67bd4cd6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
55 addition
and
24 deletion
+55
-24
python/paddle/v2/__init__.py
python/paddle/v2/__init__.py
+55
-24
未找到文件。
python/paddle/v2/__init__.py
浏览文件 @
e28157d7
...
...
@@ -62,21 +62,15 @@ __all__ = [
cp
.
begin_parse
()
def
init
(
**
kwargs
):
import
py_paddle.swig_paddle
as
api
args
=
[]
args_dict
=
{}
# NOTE: append arguments if they are in ENV
for
ek
,
ev
in
os
.
environ
.
iteritems
():
if
ek
.
startswith
(
"PADDLE_INIT_"
)
:
args_dict
[
ek
.
replace
(
"PADDLE_INIT_"
,
""
).
lower
()]
=
str
(
ev
)
def
set_omp_mkl_env_vars
(
trainer_count
):
'''Auto set CPU environment if have not set before.
export KMP_AFFINITY, OMP_DYNAMIC according to the Hyper Threading status.
export OMP_NUM_THREADS, MKL_NUM_THREADS according to trainer_count.
'''
import
platform
if
not
platform
.
system
()
in
[
'Linux'
,
'Darwin'
]
:
return
args_dict
.
update
(
kwargs
)
# NOTE: overwrite arguments from ENV if it is in kwargs
for
key
in
args_dict
.
keys
():
args
.
append
(
'--%s=%s'
%
(
key
,
str
(
args_dict
[
key
])))
# auto set cpu environment
def
set_env
(
key
,
value
):
'''If the key has not been set in the environment, set it with value.'''
assert
isinstance
(
key
,
str
)
...
...
@@ -85,22 +79,59 @@ def init(**kwargs):
if
envset
is
None
:
os
.
environ
[
key
]
=
value
ht
=
os
.
popen
(
"lscpu |grep
\"
per core
\"
|awk -F':' '{print $2}'|xargs"
)
ht
=
int
(
ht
.
read
())
if
ht
==
1
:
# ht is off
set_env
(
"OMP_DYNAMIC"
,
"false"
)
set_env
(
"KMP_AFFINITY"
,
"granularity=fine,compact,0,0"
)
else
:
def
num_physical_cores
():
'''Get the number of physical cores'''
if
platform
.
system
()
==
"Linux"
:
num_sockets
=
int
(
os
.
popen
(
"lscpu |grep
\"
Socket
\"
|awk -F':' '{print $2}'|xargs"
)
.
read
())
num_cores_per_socket
=
int
(
os
.
popen
(
"lscpu |grep
\"
per socket
\"
|awk -F':' '{print $2}'|xargs"
)
.
read
())
return
num_sockets
*
num_cores_per_socket
else
:
cmds
=
{
"Darwin"
:
"sysctl hw.physicalcpu"
}
return
int
(
os
.
popen
(
cmds
.
get
(
platform
.
system
(),
"expr 1"
)).
read
())
def
num_logical_processors
():
'''Get the number of logical processors'''
cmds
=
{
"Linux"
:
"grep
\"
processor
\"
/proc/cpuinfo|sort -u|wc -l"
,
"Darwin"
:
"sysctl hw.logicalcpu"
}
return
int
(
os
.
popen
(
cmds
.
get
(
platform
.
system
(),
"expr 1"
)).
read
())
num_cores
=
num_physical_cores
()
num_processors
=
num_logical_processors
()
if
num_processors
>
num_cores
:
# Hyper Threading is enabled
set_env
(
"OMP_DYNAMIC"
,
"true"
)
set_env
(
"KMP_AFFINITY"
,
"granularity=fine,compact,1,0"
)
processors
=
os
.
popen
(
"grep
\"
processor
\"
/proc/cpuinfo|sort -u|wc -l"
)
processors
=
int
(
processors
.
read
()
)
trainers
=
kwargs
.
get
(
'trainer_count'
,
1
)
threads
=
processors
/
trainers
else
:
set_env
(
"OMP_DYNAMIC"
,
"false"
)
set_env
(
"KMP_AFFINITY"
,
"granularity=fine,compact,0,0"
)
threads
=
num_processors
/
trainer_count
threads
=
'1'
if
threads
<
1
else
str
(
threads
)
set_env
(
"OMP_NUM_THREADS"
,
threads
)
set_env
(
"MKL_NUM_THREADS"
,
threads
)
def
init
(
**
kwargs
):
import
py_paddle.swig_paddle
as
api
args
=
[]
args_dict
=
{}
# NOTE: append arguments if they are in ENV
for
ek
,
ev
in
os
.
environ
.
iteritems
():
if
ek
.
startswith
(
"PADDLE_INIT_"
):
args_dict
[
ek
.
replace
(
"PADDLE_INIT_"
,
""
).
lower
()]
=
str
(
ev
)
args_dict
.
update
(
kwargs
)
# NOTE: overwrite arguments from ENV if it is in kwargs
for
key
in
args_dict
.
keys
():
args
.
append
(
'--%s=%s'
%
(
key
,
str
(
args_dict
[
key
])))
set_omp_mkl_env_vars
(
kwargs
.
get
(
'trainer_count'
,
1
))
if
'use_gpu'
in
kwargs
:
cp
.
g_command_config_args
[
'use_gpu'
]
=
kwargs
[
'use_gpu'
]
if
'use_mkldnn'
in
kwargs
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录