Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
86e1044a
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
86e1044a
编写于
12月 10, 2018
作者:
H
heqiaozhi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine interface & add ps_instance
上级
6bc0efb4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
108 addition
and
0 deletion
+108
-0
python/paddle/fluid/distributed/ps_instance.py
python/paddle/fluid/distributed/ps_instance.py
+108
-0
未找到文件。
python/paddle/fluid/distributed/ps_instance.py
0 → 100644
浏览文件 @
86e1044a
#import paddle.fluid.distributed.helper as dist_helper
import
helper
as
dist_helper
import
sys
#from mpi4py import MPI
class
PaddlePSInstance
(
object
):
def
__init__
(
self
,
init_param
,
server_worker_mode
,
proc_per_node
):
self
.
dh
=
dist_helper
.
MPIHelper
()
self
.
_config
=
init_param
self
.
_rankid
=
self
.
dh
.
get_rank
()
self
.
_server_worker_mode
=
server_worker_mode
self
.
_proc_per_node
=
proc_per_node
self
.
_nodes
=
self
.
dh
.
get_size
()
self
.
_ip
=
0
self
.
_worker_num
=
self
.
_nodes
*
self
.
_proc_per_node
/
2
self
.
_server_num
=
self
.
_nodes
*
self
.
_proc_per_node
/
2
self
.
_total_server_worker
=
self
.
_worker_num
+
self
.
_server_num
self
.
_node_type
=
None
#IDLE=-1, WORKER=1, SERVER=0
self
.
_set_nodetype
()
self
.
_comm
=
None
self
.
_split_comm
()
def
_set_nodetype
(
self
):
if
self
.
_server_worker_mode
==
0
:
if
self
.
_rankid
<
self
.
_server_num
:
self
.
_node_type
=
1
elif
self
.
_rankid
<
self
.
_total_server_worker
:
self
.
_node_type
=
0
else
:
self
.
_node_type
=
-
1
elif
self
.
_server_worker_mode
==
1
:
if
self
.
_rankid
<
self
.
_total_server_worker
:
if
0
==
self
.
_rankid
%
self
.
_proc_per_node
%
2
:
self
.
_node_type
=
0
else
:
self
.
_node_type
=
1
else
:
self
.
_node_type
=
-
1
;
else
:
self
.
_node_type
=
-
1
#if self._rankid == 0:
#print "node type: ", self._node_type
def
_split_comm
(
self
):
if
self
.
is_server
():
self
.
_comm
=
self
.
dh
.
comm
.
Split
(
self
.
_node_type
)
elif
self
.
is_worker
():
self
.
_comm
=
self
.
dh
.
comm
.
Split
(
self
.
_node_type
)
pass
def
get_worker_index
(
self
):
if
self
.
_server_worker_mode
==
0
:
return
self
.
_rankid
==
self
.
server_num
else
:
return
self
.
_rankid
/
self
.
_proc_per_node
def
get_server_index
(
self
):
if
self
.
_server_worker_mode
==
0
:
return
self
.
rank_id
else
:
return
self
.
rank_id
/
self
.
_proc_per_node
def
is_worker
(
self
):
return
self
.
_node_type
==
1
def
is_server
(
self
):
return
self
.
_node_type
==
0
def
is_first_worker
(
self
):
return
self
.
is_worker
()
and
0
==
self
.
get_worker_index
()
def
set_ip
(
self
,
ip
):
self
.
_ip
=
ip
def
gather_ips
(
self
):
self
.
_ips
=
self
.
dh
.
comm
.
allgather
(
self
.
_ip
)
return
self
.
_ips
def
get_node_cnt
(
self
):
return
self
.
_nodes
def
barrier_all
(
self
):
#print self._rankid, "begin"
#sys.stdout.flush()
self
.
dh
.
comm
.
barrier
()
#print self._rankid, "end"
def
barrier_worker
(
self
):
if
self
.
is_worker
():
#print "worker: ", self._rankid, "begin"
#sys.stdout.flush()
self
.
_comm
.
barrier
()
#print "worker: ", self._rankid, "end"
pass
def
finalize
(
self
):
pass
if
__name__
==
"__main__"
:
instance
=
PaddlePSInstance
(
1
,
1
,
2
,
50
)
instance
.
barrier_all
()
#print "-----"
#instance.barrier_worker()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录