Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
9dd34e41
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
9dd34e41
编写于
3月 09, 2018
作者:
武
武毅
提交者:
gongweibao
3月 09, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update unpushed commits for zerocopy grpc (#8900)
上级
b825c792
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
43 deletion
+19
-43
paddle/fluid/operators/detail/sendrecvop_utils.cc
paddle/fluid/operators/detail/sendrecvop_utils.cc
+5
-14
paddle/fluid/operators/detail/sendrecvop_utils.h
paddle/fluid/operators/detail/sendrecvop_utils.h
+0
-6
paddle/fluid/operators/detail/test_serde.cc
paddle/fluid/operators/detail/test_serde.cc
+14
-23
未找到文件。
paddle/fluid/operators/detail/sendrecvop_utils.cc
浏览文件 @
9dd34e41
...
@@ -127,8 +127,8 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
...
@@ -127,8 +127,8 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
boost
::
get
<
platform
::
CUDAPlace
>
(
tensor
.
place
()),
boost
::
get
<
platform
::
CUDAPlace
>
(
tensor
.
place
()),
reinterpret_cast
<
const
void
*>
(
tensor
.
data
<
void
>
()),
reinterpret_cast
<
const
void
*>
(
tensor
.
data
<
void
>
()),
copy_size
,
gpu_dev_ctx
.
stream
());
copy_size
,
gpu_dev_ctx
.
stream
());
ctx
.
Wait
();
destroy_callback
=
[](
void
*
backing
)
{
destroy_callback
=
[](
void
*
backing
)
{
std
::
cout
<<
"destroy payload"
<<
std
::
endl
;
platform
::
CPUPlace
cpu
;
platform
::
CPUPlace
cpu
;
memory
::
Free
(
cpu
,
backing
);
memory
::
Free
(
cpu
,
backing
);
};
};
...
@@ -137,12 +137,6 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
...
@@ -137,12 +137,6 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
payload
=
tensor
.
data
<
void
>
();
payload
=
tensor
.
data
<
void
>
();
}
}
payload_size
=
tensor
.
memory_size
();
payload_size
=
tensor
.
memory_size
();
std
::
string
tmp
(
reinterpret_cast
<
char
*>
(
payload
),
payload_size
);
for
(
int
i
=
0
;
i
<
tmp
.
size
();
++
i
)
{
printf
(
"%02X "
,
tmp
.
data
()[
i
]);
}
printf
(
"
\n
"
);
e
.
WriteVarlengthBeginning
(
VarMsg
::
kSerializedFieldNumber
,
payload_size
);
e
.
WriteVarlengthBeginning
(
VarMsg
::
kSerializedFieldNumber
,
payload_size
);
}
break
;
}
break
;
case
framework
::
proto
::
VarType_Type_SELECTED_ROWS
:
{
case
framework
::
proto
::
VarType_Type_SELECTED_ROWS
:
{
...
@@ -167,14 +161,9 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
...
@@ -167,14 +161,9 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
reinterpret_cast
<
const
void
*>
(
tensor
->
data
<
void
>
()),
reinterpret_cast
<
const
void
*>
(
tensor
->
data
<
void
>
()),
copy_size
,
gpu_dev_ctx
.
stream
());
copy_size
,
gpu_dev_ctx
.
stream
());
ctx
.
Wait
();
ctx
.
Wait
();
float
*
ttt
=
reinterpret_cast
<
float
*>
(
payload
);
for
(
int
i
=
0
;
i
<
copy_size
/
4
;
i
++
)
{
std
::
cout
<<
"copied to cpu: "
<<
ttt
[
i
]
<<
std
::
endl
;
}
destroy_callback
=
[](
void
*
backing
)
{
destroy_callback
=
[](
void
*
backing
)
{
std
::
cout
<<
"destroy..."
<<
std
::
endl
;
platform
::
CPUPlace
cpu
;
// platform::CPUPlace cpu;
memory
::
Free
(
cpu
,
backing
);
// memory::Free(cpu, backing);
};
};
#endif
#endif
}
else
{
}
else
{
...
@@ -270,6 +259,7 @@ void DeserializeFromByteBuffer(const ::grpc::ByteBuffer& msg,
...
@@ -270,6 +259,7 @@ void DeserializeFromByteBuffer(const ::grpc::ByteBuffer& msg,
tensor_data
,
cpu
,
tensor_data
,
cpu
,
reinterpret_cast
<
const
void
*>
(
meta
.
serialized
().
data
()),
reinterpret_cast
<
const
void
*>
(
meta
.
serialized
().
data
()),
meta
.
serialized
().
size
(),
gpu_dev_ctx
.
stream
());
meta
.
serialized
().
size
(),
gpu_dev_ctx
.
stream
());
ctx
.
Wait
();
#endif
#endif
}
else
{
}
else
{
memcpy
(
tensor_data
,
memcpy
(
tensor_data
,
...
@@ -292,6 +282,7 @@ void DeserializeFromByteBuffer(const ::grpc::ByteBuffer& msg,
...
@@ -292,6 +282,7 @@ void DeserializeFromByteBuffer(const ::grpc::ByteBuffer& msg,
tensor_data
,
cpu
,
tensor_data
,
cpu
,
reinterpret_cast
<
const
void
*>
(
meta
.
serialized
().
data
()),
reinterpret_cast
<
const
void
*>
(
meta
.
serialized
().
data
()),
meta
.
serialized
().
size
(),
gpu_dev_ctx
.
stream
());
meta
.
serialized
().
size
(),
gpu_dev_ctx
.
stream
());
ctx
.
Wait
();
#endif
#endif
}
else
{
}
else
{
memcpy
(
tensor_data
,
memcpy
(
tensor_data
,
...
...
paddle/fluid/operators/detail/sendrecvop_utils.h
浏览文件 @
9dd34e41
...
@@ -35,12 +35,6 @@ namespace detail {
...
@@ -35,12 +35,6 @@ namespace detail {
typedef
void
(
*
DestroyCallback
)(
void
*
);
typedef
void
(
*
DestroyCallback
)(
void
*
);
inline
int64_t
GetTimestamp
()
{
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
system_clock
::
now
().
time_since_epoch
())
.
count
();
}
void
SerializeToMessage
(
const
std
::
string
&
name
,
const
framework
::
Variable
*
var
,
void
SerializeToMessage
(
const
std
::
string
&
name
,
const
framework
::
Variable
*
var
,
const
platform
::
DeviceContext
&
ctx
,
const
platform
::
DeviceContext
&
ctx
,
sendrecv
::
VariableMessage
*
msg
);
sendrecv
::
VariableMessage
*
msg
);
...
...
paddle/fluid/operators/detail/test_serde.cc
浏览文件 @
9dd34e41
...
@@ -42,7 +42,7 @@ void RunSerdeTestTensor(platform::Place place) {
...
@@ -42,7 +42,7 @@ void RunSerdeTestTensor(platform::Place place) {
int
tensor_numel
=
4
*
8
*
4
*
2
;
int
tensor_numel
=
4
*
8
*
4
*
2
;
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
auto
&
ctx
=
*
pool
.
Get
(
place
);
auto
&
ctx
=
*
pool
.
Get
(
place
);
float
*
orig_tensor_data
=
tensor
->
mutable_data
<
float
>
(
place
);
tensor
->
mutable_data
<
float
>
(
place
);
math
::
set_constant
(
ctx
,
tensor
,
31.9
);
math
::
set_constant
(
ctx
,
tensor
,
31.9
);
::
grpc
::
ByteBuffer
msg
;
::
grpc
::
ByteBuffer
msg
;
...
@@ -71,16 +71,9 @@ void RunSerdeTestTensor(platform::Place place) {
...
@@ -71,16 +71,9 @@ void RunSerdeTestTensor(platform::Place place) {
const
float
*
tensor_data
=
const
float
*
tensor_data
=
reinterpret_cast
<
const
float
*>
(
varmsg
.
serialized
().
data
());
reinterpret_cast
<
const
float
*>
(
varmsg
.
serialized
().
data
());
for
(
int
i
=
0
;
i
<
varmsg
.
serialized
().
size
();
++
i
)
{
printf
(
"%02X "
,
varmsg
.
serialized
().
data
()[
i
]);
}
printf
(
"
\n
"
);
for
(
int
i
=
0
;
i
<
tensor_numel
;
++
i
)
{
for
(
int
i
=
0
;
i
<
tensor_numel
;
++
i
)
{
std
::
cout
<<
"#####tensor data: "
<<
tensor_data
[
i
]
<<
std
::
endl
;
EXPECT_FLOAT_EQ
(
tensor_data
[
i
],
31.9
);
EXPECT_EQ
(
tensor_data
[
i
],
orig_tensor_data
[
i
]);
std
::
cout
<<
"test end 1 "
<<
std
::
endl
;
}
}
std
::
cout
<<
"tensor data end "
<<
std
::
endl
;
// deserialize zero-copy
// deserialize zero-copy
framework
::
Variable
var2
;
framework
::
Variable
var2
;
...
@@ -101,8 +94,7 @@ void RunSerdeTestTensor(platform::Place place) {
...
@@ -101,8 +94,7 @@ void RunSerdeTestTensor(platform::Place place) {
EXPECT_EQ
(
varmsg
.
lod
(
0
).
lod_data
(
0
),
1
);
EXPECT_EQ
(
varmsg
.
lod
(
0
).
lod_data
(
0
),
1
);
EXPECT_EQ
(
varmsg
.
lod
(
0
).
lod_data
(
1
),
3
);
EXPECT_EQ
(
varmsg
.
lod
(
0
).
lod_data
(
1
),
3
);
EXPECT_EQ
(
varmsg
.
lod
(
0
).
lod_data
(
2
),
8
);
EXPECT_EQ
(
varmsg
.
lod
(
0
).
lod_data
(
2
),
8
);
for
(
int
i
=
0
;
i
<
tensor_numel
;
++
i
)
for
(
int
i
=
0
;
i
<
tensor_numel
;
++
i
)
EXPECT_FLOAT_EQ
(
tensor_data2
[
i
],
31.9
);
EXPECT_EQ
(
tensor_data2
[
i
],
orig_tensor_data
[
i
]);
}
}
void
RunSerdeTestSelectedRows
(
platform
::
Place
place
)
{
void
RunSerdeTestSelectedRows
(
platform
::
Place
place
)
{
...
@@ -114,10 +106,9 @@ void RunSerdeTestSelectedRows(platform::Place place) {
...
@@ -114,10 +106,9 @@ void RunSerdeTestSelectedRows(platform::Place place) {
auto
*
slr
=
var
.
GetMutable
<
framework
::
SelectedRows
>
();
auto
*
slr
=
var
.
GetMutable
<
framework
::
SelectedRows
>
();
auto
*
tensor
=
slr
->
mutable_value
();
auto
*
tensor
=
slr
->
mutable_value
();
auto
*
rows
=
slr
->
mutable_rows
();
auto
*
rows
=
slr
->
mutable_rows
();
tensor
->
Resize
(
framework
::
make_ddim
({
2
,
10
}));
tensor
->
Resize
(
framework
::
make_ddim
({
2
,
10
}));
tensor
->
mutable_data
<
float
>
(
place
);
int
tensor_numel
=
2
*
10
;
int
tensor_numel
=
2
*
10
;
float
*
orig_tensor_data
=
tensor
->
mutable_data
<
float
>
(
place
);
math
::
set_constant
(
ctx
,
tensor
,
32.7
);
math
::
set_constant
(
ctx
,
tensor
,
32.7
);
rows
->
push_back
(
3
);
rows
->
push_back
(
3
);
rows
->
push_back
(
10
);
rows
->
push_back
(
10
);
...
@@ -144,7 +135,7 @@ void RunSerdeTestSelectedRows(platform::Place place) {
...
@@ -144,7 +135,7 @@ void RunSerdeTestSelectedRows(platform::Place place) {
const
int64_t
*
rows_data
=
const
int64_t
*
rows_data
=
reinterpret_cast
<
const
int64_t
*>
(
varmsg
.
rows
().
data
());
reinterpret_cast
<
const
int64_t
*>
(
varmsg
.
rows
().
data
());
for
(
int
i
=
0
;
i
<
tensor_numel
;
++
i
)
{
for
(
int
i
=
0
;
i
<
tensor_numel
;
++
i
)
{
EXPECT_
EQ
(
tensor_data
[
i
],
orig_tensor_data
[
i
]
);
EXPECT_
FLOAT_EQ
(
tensor_data
[
i
],
32.7
);
}
}
EXPECT_EQ
(
rows_data
[
0
],
3
);
EXPECT_EQ
(
rows_data
[
0
],
3
);
EXPECT_EQ
(
rows_data
[
1
],
10
);
EXPECT_EQ
(
rows_data
[
1
],
10
);
...
@@ -168,21 +159,21 @@ void RunSerdeTestSelectedRows(platform::Place place) {
...
@@ -168,21 +159,21 @@ void RunSerdeTestSelectedRows(platform::Place place) {
const
int64_t
*
rows_data2
=
rows2
->
data
();
const
int64_t
*
rows_data2
=
rows2
->
data
();
for
(
int
i
=
0
;
i
<
tensor_numel
;
++
i
)
{
for
(
int
i
=
0
;
i
<
tensor_numel
;
++
i
)
{
EXPECT_
EQ
(
tensor_data2
[
i
],
orig_tensor_data
[
i
]
);
EXPECT_
FLOAT_EQ
(
tensor_data2
[
i
],
32.7
);
}
}
EXPECT_EQ
(
rows_data2
[
0
],
3
);
EXPECT_EQ
(
rows_data2
[
0
],
3
);
EXPECT_EQ
(
rows_data2
[
1
],
10
);
EXPECT_EQ
(
rows_data2
[
1
],
10
);
}
}
//
TEST(SelectedRows, CPU) {
TEST
(
SelectedRows
,
CPU
)
{
//
platform::CPUPlace place;
platform
::
CPUPlace
place
;
//
RunSerdeTestSelectedRows(place);
RunSerdeTestSelectedRows
(
place
);
//
}
}
//
TEST(SelectedRows, GPU) {
TEST
(
SelectedRows
,
GPU
)
{
//
platform::CUDAPlace place;
platform
::
CUDAPlace
place
;
//
RunSerdeTestSelectedRows(place);
RunSerdeTestSelectedRows
(
place
);
//
}
}
TEST
(
Tensor
,
CPU
)
{
TEST
(
Tensor
,
CPU
)
{
platform
::
CPUPlace
place
;
platform
::
CPUPlace
place
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录