Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
46989663
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
46989663
编写于
4月 04, 2018
作者:
Y
Yancey1989
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
prefetch selected rows
上级
abfd9fe7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
33 deletion
+32
-33
paddle/fluid/operators/detail/grpc_server_test.cc
paddle/fluid/operators/detail/grpc_server_test.cc
+32
-33
未找到文件。
paddle/fluid/operators/detail/grpc_server_test.cc
浏览文件 @
46989663
...
...
@@ -45,7 +45,7 @@ framework::BlockDesc* AppendPrefetchBlcok(framework::ProgramDesc* program) {
op
->
SetOutput
(
"Out"
,
{
"out"
});
auto
&
out
=
*
root_block
->
Var
(
"out"
);
out
.
SetType
(
framework
::
proto
::
VarType
::
LOD_TENSOR
);
out
.
SetType
(
framework
::
proto
::
VarType
::
SELECTED_ROWS
);
out
.
SetShape
({
10
,
10
});
return
block
;
...
...
@@ -53,35 +53,37 @@ framework::BlockDesc* AppendPrefetchBlcok(framework::ProgramDesc* program) {
void
CreateVarsOnScope
(
framework
::
Scope
*
scope
,
platform
::
CPUPlace
*
place
)
{
auto
w_var
=
scope
->
Var
(
"w"
);
auto
w
=
w_var
->
GetMutable
<
framework
::
LoDTensor
>
();
w
->
Resize
({
10
,
10
});
w
->
mutable_data
<
float
>
(
*
place
);
w_var
->
GetMutable
<
framework
::
SelectedRows
>
();
auto
out_var
=
scope
->
Var
(
"out"
);
auto
out
=
out_var
->
GetMutable
<
framework
::
LoDTensor
>
();
out
->
Resize
({
5
,
10
});
out
->
mutable_data
<
float
>
(
*
place
);
out_var
->
GetMutable
<
framework
::
SelectedRows
>
();
auto
ids_var
=
scope
->
Var
(
"ids"
);
auto
ids
=
ids_var
->
GetMutable
<
framework
::
LoDTensor
>
();
ids
->
Resize
({
5
,
1
});
ids_var
->
GetMutable
<
framework
::
SelectedRows
>
();
}
void
InitTensorsOnClient
(
framework
::
Scope
*
scope
,
platform
::
CPUPlace
*
place
)
{
void
InitTensorsOnClient
(
framework
::
Scope
*
scope
,
platform
::
CPUPlace
*
place
,
int64_t
rows_numel
)
{
CreateVarsOnScope
(
scope
,
place
);
auto
ids
=
scope
->
Var
(
"ids"
)
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
ptr
=
ids
->
mutable_data
<
int64_t
>
(
*
place
);
for
(
int64_t
i
=
0
;
i
<
ids
->
numel
();
++
i
)
{
ptr
[
i
]
=
i
*
2
;
}
auto
ids
_var
=
scope
->
Var
(
"ids"
)
->
GetMutable
<
framework
::
SelectedRows
>
();
auto
rows
=
ids_var
->
mutable_rows
(
);
for
(
int64_t
i
=
0
;
i
<
rows_numel
;
++
i
)
rows
->
push_back
(
i
*
2
);
ids_var
->
mutable_value
()
->
Resize
({
rows_numel
,
1
})
;
ids_var
->
mutable_value
()
->
mutable_data
<
float
>
(
*
place
);
}
void
InitTensorsOnServer
(
framework
::
Scope
*
scope
,
platform
::
CPUPlace
*
place
)
{
void
InitTensorsOnServer
(
framework
::
Scope
*
scope
,
platform
::
CPUPlace
*
place
,
int64_t
rows_numel
)
{
CreateVarsOnScope
(
scope
,
place
);
auto
w_var
=
scope
->
Var
(
"w"
);
auto
w
=
w_var
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
ptr
=
w
->
mutable_data
<
float
>
(
*
place
);
for
(
int64_t
i
=
0
;
i
<
w
->
numel
();
++
i
)
{
auto
w
=
scope
->
Var
(
"w"
)
->
GetMutable
<
framework
::
SelectedRows
>
();
auto
rows
=
w
->
mutable_rows
();
for
(
int64_t
i
=
0
;
i
<
rows_numel
;
++
i
)
rows
->
push_back
(
i
);
auto
w_value
=
w
->
mutable_value
();
w_value
->
Resize
({
rows_numel
,
10
});
auto
ptr
=
w_value
->
mutable_data
<
float
>
(
*
place
);
for
(
int64_t
i
=
0
;
i
<
w_value
->
numel
();
++
i
)
{
ptr
[
i
]
=
static_cast
<
float
>
(
i
/
10
);
}
}
...
...
@@ -94,7 +96,7 @@ void StartServer(const std::string& endpoint) {
framework
::
Executor
exe
(
place
);
platform
::
CPUDeviceContext
ctx
(
place
);
auto
*
block
=
AppendPrefetchBlcok
(
&
program
);
InitTensorsOnServer
(
&
scope
,
&
place
);
InitTensorsOnServer
(
&
scope
,
&
place
,
10
);
rpc_service_
->
SetProgram
(
&
program
);
rpc_service_
->
SetPrefetchBlkdId
(
block
->
ID
());
...
...
@@ -107,15 +109,14 @@ void StartServer(const std::string& endpoint) {
TEST
(
PREFETCH
,
CPU
)
{
// start up a server instance backend
// TODO(Yancey1989): Need to start a server with optimize blocks and
// prefetch blocks.
std
::
thread
server_thread
(
StartServer
,
"127.0.0.1:8889"
);
sleep
(
2
);
framework
::
Scope
scope
;
platform
::
CPUPlace
place
;
platform
::
CPUDeviceContext
ctx
(
place
);
// create var on local scope
InitTensorsOnClient
(
&
scope
,
&
place
);
int64_t
rows_numel
=
5
;
InitTensorsOnClient
(
&
scope
,
&
place
,
rows_numel
);
std
::
string
in_var_name
(
"ids"
);
std
::
string
out_var_name
(
"out"
);
...
...
@@ -124,18 +125,16 @@ TEST(PREFETCH, CPU) {
out_var_name
);
client
.
Wait
();
auto
out_var
=
scope
.
Var
(
out_var_name
);
auto
out
=
out_var
->
Get
<
framework
::
LoDTensor
>
();
// auto out_var = scope.Var(out_var_name);
auto
var
=
scope
.
Var
(
out_var_name
);
auto
value
=
var
->
GetMutable
<
framework
::
SelectedRows
>
()
->
value
();
auto
ptr
=
value
.
mutable_data
<
float
>
(
place
);
auto
out_ptr
=
out
.
data
<
float
>
();
rpc_service_
->
ShutDown
();
server_thread
.
join
();
rpc_service_
.
reset
(
nullptr
);
EXPECT_EQ
(
out
.
dims
().
size
(),
2
);
EXPECT_EQ
(
out_ptr
[
0
],
static_cast
<
float
>
(
0
));
EXPECT_EQ
(
out_ptr
[
0
+
1
*
out
.
dims
()[
1
]],
static_cast
<
float
>
(
2
));
EXPECT_EQ
(
out_ptr
[
0
+
2
*
out
.
dims
()[
1
]],
static_cast
<
float
>
(
4
));
EXPECT_EQ
(
out_ptr
[
0
+
3
*
out
.
dims
()[
1
]],
static_cast
<
float
>
(
6
));
EXPECT_EQ
(
out_ptr
[
0
+
4
*
out
.
dims
()[
1
]],
static_cast
<
float
>
(
8
));
for
(
int64_t
i
=
0
;
i
<
rows_numel
;
++
i
)
{
EXPECT_EQ
(
ptr
[
0
+
i
*
value
.
dims
()[
1
]],
static_cast
<
float
>
(
i
*
2
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录