Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
e28157d7
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
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__ = [
...
@@ -62,21 +62,15 @@ __all__ = [
cp
.
begin_parse
()
cp
.
begin_parse
()
def
init
(
**
kwargs
):
def
set_omp_mkl_env_vars
(
trainer_count
):
import
py_paddle.swig_paddle
as
api
'''Auto set CPU environment if have not set before.
args
=
[]
export KMP_AFFINITY, OMP_DYNAMIC according to the Hyper Threading status.
args_dict
=
{}
export OMP_NUM_THREADS, MKL_NUM_THREADS according to trainer_count.
# NOTE: append arguments if they are in ENV
'''
for
ek
,
ev
in
os
.
environ
.
iteritems
():
import
platform
if
ek
.
startswith
(
"PADDLE_INIT_"
):
if
not
platform
.
system
()
in
[
'Linux'
,
'Darwin'
]:
args_dict
[
ek
.
replace
(
"PADDLE_INIT_"
,
""
).
lower
()]
=
str
(
ev
)
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
):
def
set_env
(
key
,
value
):
'''If the key has not been set in the environment, set it with value.'''
'''If the key has not been set in the environment, set it with value.'''
assert
isinstance
(
key
,
str
)
assert
isinstance
(
key
,
str
)
...
@@ -85,22 +79,59 @@ def init(**kwargs):
...
@@ -85,22 +79,59 @@ def init(**kwargs):
if
envset
is
None
:
if
envset
is
None
:
os
.
environ
[
key
]
=
value
os
.
environ
[
key
]
=
value
ht
=
os
.
popen
(
"lscpu |grep
\"
per core
\"
|awk -F':' '{print $2}'|xargs"
)
def
num_physical_cores
():
ht
=
int
(
ht
.
read
())
'''Get the number of physical cores'''
if
ht
==
1
:
# ht is off
if
platform
.
system
()
==
"Linux"
:
set_env
(
"OMP_DYNAMIC"
,
"false"
)
num_sockets
=
int
(
set_env
(
"KMP_AFFINITY"
,
"granularity=fine,compact,0,0"
)
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
:
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
(
"OMP_DYNAMIC"
,
"true"
)
set_env
(
"KMP_AFFINITY"
,
"granularity=fine,compact,1,0"
)
set_env
(
"KMP_AFFINITY"
,
"granularity=fine,compact,1,0"
)
processors
=
os
.
popen
(
"grep
\"
processor
\"
/proc/cpuinfo|sort -u|wc -l"
)
else
:
processors
=
int
(
processors
.
read
()
)
set_env
(
"OMP_DYNAMIC"
,
"false"
)
trainers
=
kwargs
.
get
(
'trainer_count'
,
1
)
set_env
(
"KMP_AFFINITY"
,
"granularity=fine,compact,0,0"
)
threads
=
processors
/
trainers
threads
=
num_processors
/
trainer_count
threads
=
'1'
if
threads
<
1
else
str
(
threads
)
threads
=
'1'
if
threads
<
1
else
str
(
threads
)
set_env
(
"OMP_NUM_THREADS"
,
threads
)
set_env
(
"OMP_NUM_THREADS"
,
threads
)
set_env
(
"MKL_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
:
if
'use_gpu'
in
kwargs
:
cp
.
g_command_config_args
[
'use_gpu'
]
=
kwargs
[
'use_gpu'
]
cp
.
g_command_config_args
[
'use_gpu'
]
=
kwargs
[
'use_gpu'
]
if
'use_mkldnn'
in
kwargs
:
if
'use_mkldnn'
in
kwargs
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录