Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
5d7c58e4
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看板
提交
5d7c58e4
编写于
5月 29, 2018
作者:
Y
Yancey1989
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code style
上级
8b630ae1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
71 addition
and
70 deletion
+71
-70
paddle/fluid/operators/send_recv_op_test.cc
paddle/fluid/operators/send_recv_op_test.cc
+71
-70
未找到文件。
paddle/fluid/operators/send_recv_op_test.cc
浏览文件 @
5d7c58e4
...
@@ -156,6 +156,7 @@ TEST(SendRecvOp, CPUDense) {
...
@@ -156,6 +156,7 @@ TEST(SendRecvOp, CPUDense) {
std
::
thread
server_thread
(
StartServerNet
,
false
,
&
initialized
);
std
::
thread
server_thread
(
StartServerNet
,
false
,
&
initialized
);
while
(
!
initialized
)
{
while
(
!
initialized
)
{
}
}
static_cast
<
paddle
::
operators
::
ListenAndServOp
*>
(
listen_and_serv_op
.
get
())
static_cast
<
paddle
::
operators
::
ListenAndServOp
*>
(
listen_and_serv_op
.
get
())
->
WaitServerReady
();
->
WaitServerReady
();
...
@@ -175,77 +176,77 @@ TEST(SendRecvOp, CPUDense) {
...
@@ -175,77 +176,77 @@ TEST(SendRecvOp, CPUDense) {
std
::
string
endpoint
=
paddle
::
string
::
Sprintf
(
"127.0.0.1:%d"
,
selected_port
);
std
::
string
endpoint
=
paddle
::
string
::
Sprintf
(
"127.0.0.1:%d"
,
selected_port
);
attrs
.
insert
({
"endpoints"
,
std
::
vector
<
std
::
string
>
({
endpoint
})});
attrs
.
insert
({
"endpoints"
,
std
::
vector
<
std
::
string
>
({
endpoint
})});
attrs
.
insert
({
"epmap"
,
std
::
vector
<
std
::
string
>
({
endpoint
})});
attrs
.
insert
({
"epmap"
,
std
::
vector
<
std
::
string
>
({
endpoint
})});
auto
send_op
=
f
::
OpRegistry
::
CreateOp
(
const
f
::
VariableNameMap
&
inputs
=
{{
"X"
,
{
"x1"
}}};
"send"
,
{{
"X"
,
{
"x1"
}}},
const
f
::
VariableNameMap
&
outputs
=
{{
"Out"
,
{
"Out"
}}};
{{
"Out"
,
{
"Out"
}},
attrs
);
send_op
->
Run
(
scope
,
place
);
auto
send_op
=
f
::
OpRegistry
::
CreateOp
(
"send"
,
inputs
,
outputs
,
attrs
);
send_op
->
Run
(
scope
,
place
);
auto
in_var
=
scope
.
Var
(
"x1"
);
auto
tensor
=
in_var
->
GetMutable
<
f
::
LoDTensor
>
();
auto
in_var
=
scope
.
Var
(
"x1"
);
float
*
expected
=
tensor
->
data
<
float
>
();
auto
tensor
=
in_var
->
GetMutable
<
f
::
LoDTensor
>
();
auto
out_var
=
scope
.
Var
(
"Out"
);
float
*
expected
=
tensor
->
data
<
float
>
();
auto
target
=
out_var
->
GetMutable
<
f
::
LoDTensor
>
();
auto
out_var
=
scope
.
Var
(
"Out"
);
// x1 * 2 == x0
auto
target
=
out_var
->
GetMutable
<
f
::
LoDTensor
>
();
EXPECT_NE
(
target
->
memory_size
(),
size_t
(
0
));
// x1 * 2 == x0
float
*
actual
=
target
->
data
<
float
>
();
EXPECT_NE
(
target
->
memory_size
(),
size_t
(
0
));
for
(
int64_t
i
=
0
;
i
<
target
->
numel
();
++
i
)
{
float
*
actual
=
target
->
data
<
float
>
();
EXPECT_EQ
(
expected
[
i
]
*
2
,
actual
[
i
]);
for
(
int64_t
i
=
0
;
i
<
target
->
numel
();
++
i
)
{
}
EXPECT_EQ
(
expected
[
i
]
*
2
,
actual
[
i
]);
listen_and_serv_op
->
Stop
();
}
server_thread
.
join
();
listen_and_serv_op
->
Stop
();
listen_and_serv_op
.
reset
(
nullptr
);
server_thread
.
join
();
paddle
::
operators
::
ListenAndServOp
::
ResetPort
();
listen_and_serv_op
.
reset
(
nullptr
);
paddle
::
operators
::
ListenAndServOp
::
ResetPort
();
}
}
TEST
(
SendRecvOp
,
CPUSparse
)
{
TEST
(
SendRecvOp
,
CPUSparse
)
{
std
::
atomic
<
bool
>
initialized
;
std
::
atomic
<
bool
>
initialized
;
initialized
=
false
;
initialized
=
false
;
std
::
thread
server_thread
(
StartServerNet
,
true
,
&
initialized
);
std
::
thread
server_thread
(
StartServerNet
,
true
,
&
initialized
);
while
(
!
initialized
)
{
while
(
!
initialized
)
{
}
}
auto
*
listen_and_serv_op_ptr
=
auto
*
listen_and_serv_op_ptr
=
static_cast
<
paddle
::
operators
::
ListenAndServOp
*>
(
static_cast
<
paddle
::
operators
::
ListenAndServOp
*>
(
listen_and_serv_op
.
get
());
listen_and_serv_op
.
get
());
ASSERT_TRUE
(
listen_and_serv_op_ptr
!=
nullptr
);
ASSERT_TRUE
(
listen_and_serv_op_ptr
!=
nullptr
);
listen_and_serv_op_ptr
->
WaitServerReady
();
listen_and_serv_op_ptr
->
WaitServerReady
();
// local net
// local net
f
::
Scope
scope
;
f
::
Scope
scope
;
p
::
CPUPlace
place
;
p
::
CPUPlace
place
;
p
::
CPUDeviceContext
ctx
(
place
);
p
::
CPUDeviceContext
ctx
(
place
);
InitSelectedRowsInScope
(
place
,
&
scope
);
InitSelectedRowsInScope
(
place
,
&
scope
);
scope
.
Var
(
"RPC_CLIENT_VAR"
);
scope
.
Var
(
"RPC_CLIENT_VAR"
);
f
::
AttributeMap
attrs
;
f
::
AttributeMap
attrs
;
selected_port
=
listen_and_serv_op_ptr
->
GetSelectedPort
();
selected_port
=
listen_and_serv_op_ptr
->
GetSelectedPort
();
std
::
string
endpoint
=
std
::
string
endpoint
=
paddle
::
string
::
Sprintf
(
"127.0.0.1:%d"
,
selected_port
);
paddle
::
string
::
Sprintf
(
"127.0.0.1:%d"
,
selected_port
);
attrs
.
insert
({
"endpoints"
,
std
::
vector
<
std
::
string
>
({
endpoint
})});
attrs
.
insert
({
"endpoints"
,
std
::
vector
<
std
::
string
>
({
endpoint
})});
attrs
.
insert
({
"epmap"
,
std
::
vector
<
std
::
string
>
({
endpoint
})});
attrs
.
insert
({
"epmap"
,
std
::
vector
<
std
::
string
>
({
endpoint
})});
auto
send_op
=
f
::
OpRegistry
::
CreateOp
(
"send"
,
{{
"X"
,
{
"x1"
}}},
auto
send_op
=
f
::
OpRegistry
::
CreateOp
(
"send"
,
{{
"X"
,
{
"x1"
}}},
{{
"Out"
,
{
"Out"
}}},
attrs
);
{{
"Out"
,
{
"Out"
}}},
attrs
);
send_op
->
Run
(
scope
,
place
);
send_op
->
Run
(
scope
,
place
);
auto
x0
=
scope
.
Var
(
"x0"
)
->
GetMutable
<
f
::
SelectedRows
>
();
auto
x0
=
scope
.
Var
(
"x0"
)
->
GetMutable
<
f
::
SelectedRows
>
();
auto
x1
=
scope
.
Var
(
"x1"
)
->
GetMutable
<
f
::
SelectedRows
>
();
auto
x1
=
scope
.
Var
(
"x1"
)
->
GetMutable
<
f
::
SelectedRows
>
();
auto
out
=
scope
.
Var
(
"Out"
)
->
GetMutable
<
f
::
SelectedRows
>
();
auto
out
=
scope
.
Var
(
"Out"
)
->
GetMutable
<
f
::
SelectedRows
>
();
auto
actual
=
out
->
mutable_value
();
auto
actual
=
out
->
mutable_value
();
std
::
unique_ptr
<
f
::
SelectedRows
>
expect
{
new
f
::
SelectedRows
()};
std
::
unique_ptr
<
f
::
SelectedRows
>
expect
{
new
f
::
SelectedRows
()};
auto
expect_value
=
expect
->
mutable_value
();
auto
expect_value
=
expect
->
mutable_value
();
expect_value
->
mutable_data
<
float
>
(
f
::
make_ddim
({
5
,
10
}),
place
);
expect_value
->
mutable_data
<
float
>
(
f
::
make_ddim
({
5
,
10
}),
place
);
m
::
SelectedRowsAdd
<
p
::
CPUDeviceContext
,
float
>
add_functor
;
m
::
SelectedRowsAdd
<
p
::
CPUDeviceContext
,
float
>
add_functor
;
add_functor
(
ctx
,
*
x0
,
*
x1
,
expect
.
get
());
add_functor
(
ctx
,
*
x0
,
*
x1
,
expect
.
get
());
EXPECT_EQ
(
actual
->
numel
(),
expect_value
->
numel
());
EXPECT_EQ
(
actual
->
numel
(),
expect_value
->
numel
());
EXPECT_EQ
(
out
->
rows
().
size
(),
x0
->
rows
().
size
()
+
x1
->
rows
().
size
());
EXPECT_EQ
(
out
->
rows
().
size
(),
x0
->
rows
().
size
()
+
x1
->
rows
().
size
());
for
(
int64_t
i
=
0
;
i
<
expect_value
->
numel
();
++
i
)
{
for
(
int64_t
i
=
0
;
i
<
expect_value
->
numel
();
++
i
)
{
EXPECT_EQ
(
expect_value
->
mutable_data
<
float
>
(
place
)[
i
],
EXPECT_EQ
(
expect_value
->
mutable_data
<
float
>
(
place
)[
i
],
actual
->
mutable_data
<
float
>
(
place
)[
i
]);
actual
->
mutable_data
<
float
>
(
place
)[
i
]);
}
}
listen_and_serv_op
->
Stop
();
listen_and_serv_op
->
Stop
();
server_thread
.
join
();
server_thread
.
join
();
listen_and_serv_op
.
reset
();
listen_and_serv_op
.
reset
();
paddle
::
operators
::
ListenAndServOp
::
ResetPort
();
paddle
::
operators
::
ListenAndServOp
::
ResetPort
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录