Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
900b3e97
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
900b3e97
编写于
4月 03, 2018
作者:
T
tangwei12
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
send mpi and rpc framework
上级
9d256dd1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
120 addition
and
94 deletion
+120
-94
paddle/fluid/operators/detail/mpi_utils.cpp
paddle/fluid/operators/detail/mpi_utils.cpp
+56
-58
paddle/fluid/operators/detail/mpi_utils.h
paddle/fluid/operators/detail/mpi_utils.h
+64
-36
未找到文件。
paddle/fluid/operators/detail/mpi_utils.cpp
浏览文件 @
900b3e97
...
@@ -12,81 +12,79 @@
...
@@ -12,81 +12,79 @@
#define mpi_tag = 2008
#define mpi_tag = 2008
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
namespace
detail
{
namespace
detail
{
MPIUtils
::
MPIUtils
(
const
std
::
string
&
worker_name
)
{
MPIUtils
::
MPIUtils
(
const
std
::
string
&
worker_name
)
{
InitMPI
();
InitMPI
();
int
rank
=
0
,
size
=
1
;
int
rank
=
0
,
size
=
1
;
char
my_name
[
max_work_group_size
];
char
my_name
[
max_work_group_size
];
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
snprintf
(
my_name
,
max_worker_name_length
,
worker_name
.
c_str
());
snprintf
(
my_name
,
max_worker_name_length
,
worker_name
.
c_str
());
std
::
vector
<
char
>
worker_names
(
size
*
max_worker_name_length
);
std
::
vector
<
char
>
worker_names
(
size
*
max_worker_name_length
);
MPI_Allgather
(
my_name
,
max_worker_name_length
,
MPI_CHAR
,
&
worker_names
[
0
],
MPI_Allgather
(
my_name
,
max_worker_name_length
,
MPI_CHAR
,
&
worker_names
[
0
],
max_worker_name_length
,
MPI_CHAR
,
MPI_COMM_WORLD
);
max_worker_name_length
,
MPI_CHAR
,
MPI_COMM_WORLD
);
for
(
int
i
=
0
;
i
<
number_of_procs
;
i
++
)
{
for
(
int
i
=
0
;
i
<
number_of_procs
;
i
++
)
{
name_to_id_
[
std
::
string
(
&
worker_names
[
i
*
128
])]
=
i
;
name_to_id_
[
std
::
string
(
&
worker_names
[
i
*
128
])]
=
i
;
}
}
}
}
void
MPIUtils
::
InitMPI
()
{
void
MPIUtils
::
InitMPI
()
{
int
flag
=
0
;
int
flag
=
0
;
MPI_CHECK
(
MPI_Initialized
(
&
flag
));
MPI_CHECK
(
MPI_Initialized
(
&
flag
));
if
(
!
flag
)
{
if
(
!
flag
)
{
int
rank
=
0
,
size
=
1
,
len
=
-
1
;
int
rank
=
0
,
size
=
1
,
len
=
-
1
;
char
host_name
[
max_worker_name_length
];
char
host_name
[
max_worker_name_length
];
MPI_Init
(
0
,
0
);
MPI_Init
(
0
,
0
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
MPI_Comm_rank
(
MPI_COMM_WORLD
,
&
rank
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
MPI_Comm_size
(
MPI_COMM_WORLD
,
&
size
);
MPI_Get_processor_name
(
host_name
,
&
len
)
MPI_Get_processor_name
(
host_name
,
&
len
);
}
}
};
};
MPIIsend
::
MPIIsend
(
int
dst
,
const
char
*
req
)
{
done1
=
0
;
done2
=
0
;
length
=
strlen
(
req
);
req
=
req
;
}
MPIIsend
::
Send
(
)
{
MPISend
::
MPISend
(
const
Meta
&
meta
)
{
MPI_Isend
(
&
req
,
length
,
MPI_CHAR
,
dst
,
mpi_tag
,
MPI_COMM_WORLD
,
done1_
=
1
;
&
msg1_
)
;
done2_
=
0
;
MPI_Test
(
&
msg1_
,
&
done1_
,
MPI_STATUS_IGNORE
)
this
->
meta
=
meta
;
}
}
bool
MPIIsend
::
IsFinishe
d
()
{
MPISend
::
Sen
d
()
{
MPI_Status
status
;
MPI_Send
(
&
meta
.
request
,
meta
.
count
,
meta
.
datatype
,
meta
.
dst
,
meta
.
tag
,
if
(
!
done1_
)
MPI_Test
(
&
msg1_
,
&
done1_
,
&
status
);
MPI_COMM_WORLD
);
return
done
1
;
done2_
=
1
;
}
}
MPIIsend
::~
MPIIsend
(){
bool
MPISend
::
IsReady
()
{
MPI_Wait
(
&
msg1_
,
MPI_STATUS_IGNORE
);
return
true
;
MPI_Free_mem
(
req
);
}
}
MPIIrecv
::
MPIIrecv
(){
bool
MPISend
::
IsFinished
()
{
return
done1_
&&
done2_
;
}
}
MPISend
::~
MPISend
()
{
MPI_Free_mem
(
meta
);
}
MPIIrecv
::
Recv
(){
}
MPIRecv
::
MPIRecv
(
const
Meta
&
meta
)
{
this
->
meta
=
meta
;
}
MPIIrecv
::
IsFinished
(){
MPIRecv
::
Recv
()
{}
}
bool
MPIRecv
::
IsReady
()
{
return
true
;
}
MPIIrecv
::~
MPIIrecv
(){
MPIRecv
::
IsFinished
()
{}
}
MPIRecv
::~
MPIRecv
()
{
MPI_Free_mem
(
meta
);
}
}
// namespace detail
}
// namespace detail
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
\ No newline at end of file
paddle/fluid/operators/detail/mpi_utils.h
浏览文件 @
900b3e97
...
@@ -10,46 +10,74 @@ See the License for the specific language governing permissions and
...
@@ -10,46 +10,74 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#pragma once
#pragma once
#include <mpi.h>
#include <mpi.h>
#include <map>
#include <map>
#include <string>
#include <string>
#include <vector>
#include <vector>
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
namespace
detail
{
namespace
detail
{
class
MPIUtils
{
class
MPIUtils
{
public:
public:
MPIUtils
(
const
std
::
string
&
worker_name
);
MPIUtils
(
const
std
::
string
&
worker_name
);
const
int
GetRankID
(
const
std
::
string
&
task_id
);
const
int
GetRankID
(
const
std
::
string
&
task_id
);
private:
void
InitMPI
();
private:
std
::
map
<
std
::
string
,
int
>
name_id_map
;
void
InitMPI
();
};
std
::
map
<
std
::
string
,
int
>
name_id_map
;
class
MPIIsend
{
};
public:
MPIIsend
(
int
dst
,
const
char
*
buf
);
class
Meta
{
bool
IsFinished
();
public:
void
Send
();
int
src
;
~
MPIIsend
();
int
dst
;
MPI_Datatype
datatype
;
private:
char
*
request
;
int
done1
;
int
count
;
int
length
;
int
tag
;
char
*
req
;
int
device
;
MPI_Request
msg1_
;
};
};
class
MPISend
{
class
MPIIrecv
{
public:
public:
MPISend
(
const
Meta
&
meta
);
MPIIrecv
();
bool
IsFinished
();
bool
IsFinished
();
void
Recv
();
~
MPIIrecv
();
bool
IsReady
();
};
void
Send
();
}
// namespace detail
}
// namespace operators
~
MPISend
();
private:
int
done1_
;
int
done2_
;
Meta
*
meta
;
};
class
MPIRecv
{
public:
MPIRecv
(
const
Meta
&
meta
);
bool
IsReady
();
bool
IsFinished
();
void
Recv
();
~
MPIRecv
();
private:
int
done1_
;
int
done2_
;
Meta
*
meta
;
};
}
// namespace detail
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录