Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
8c1025d6
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8c1025d6
编写于
1月 11, 2018
作者:
Y
Yang Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
first commit
上级
377424bf
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
53 addition
and
7 deletion
+53
-7
paddle/framework/lod_tensor.cc
paddle/framework/lod_tensor.cc
+25
-7
paddle/framework/lod_tensor_test.cc
paddle/framework/lod_tensor_test.cc
+28
-0
未找到文件。
paddle/framework/lod_tensor.cc
浏览文件 @
8c1025d6
...
@@ -225,20 +225,38 @@ void DeserializeFromStream(std::istream &is, LoDTensor *tensor,
...
@@ -225,20 +225,38 @@ void DeserializeFromStream(std::istream &is, LoDTensor *tensor,
std
::
vector
<
LoDTensor
>
LoDTensor
::
SplitLoDTensor
(
std
::
vector
<
LoDTensor
>
LoDTensor
::
SplitLoDTensor
(
const
std
::
vector
<
platform
::
Place
>
places
)
const
{
const
std
::
vector
<
platform
::
Place
>
places
)
const
{
check_memory_size
();
check_memory_size
();
PADDLE_ENFORCE
(
lod
().
empty
(),
"Disable parallel lod for now"
);
PADDLE_ENFORCE
(
dims
()[
0
]
%
places
.
size
()
==
0
,
PADDLE_ENFORCE
(
dims
()[
0
]
%
places
.
size
()
==
0
,
"Batch size should be divided by places size"
);
"Batch size should be divided by places size"
);
std
::
vector
<
LoDTensor
>
lods
;
std
::
vector
<
LoDTensor
>
lods
;
for
(
size_t
place_idx
=
0
;
place_idx
<
places
.
size
();
++
place_idx
)
{
for
(
size_t
place_idx
=
0
;
place_idx
<
places
.
size
();
++
place_idx
)
{
int
begin
=
place_idx
*
dims
()[
0
]
/
places
.
size
();
size_t
batch_size
=
lod
().
empty
()
?
dims
()[
0
]
:
NumElements
(
0
);
int
end
=
(
place_idx
+
1
)
*
dims
()[
0
]
/
places
.
size
();
size_t
begin
=
place_idx
*
batch_size
/
places
.
size
();
size_t
end
=
(
place_idx
+
1
)
*
batch_size
/
places
.
size
();
LoDTensor
dst
;
if
(
lod
().
empty
())
{
auto
src
=
Slice
(
begin
,
end
);
auto
src
=
Slice
(
begin
,
end
);
auto
&
dst_place
=
places
[
place_idx
];
auto
&
dst_place
=
places
[
place_idx
];
LoDTensor
dst
;
framework
::
Copy
(
src
,
dst_place
,
&
dst
);
}
else
{
auto
lod_and_offset
=
GetSubLoDAndAbsoluteOffset
(
lod
(),
begin
,
end
,
0
);
auto
&
offset
=
lod_and_offset
.
second
;
auto
src
=
Slice
(
offset
.
first
,
offset
.
second
);
auto
&
dst_place
=
places
[
place_idx
];
framework
::
Copy
(
src
,
dst_place
,
&
dst
);
framework
::
Copy
(
src
,
dst_place
,
&
dst
);
LoD
my_lod
;
for
(
auto
&
l
:
lod_and_offset
.
first
)
{
std
::
vector
<
size_t
>
v
{
0
};
for
(
auto
&
ll
:
l
)
{
v
.
push_back
(
ll
+
v
.
back
());
}
my_lod
.
emplace_back
(
v
);
}
dst
.
set_lod
(
my_lod
);
}
lods
.
emplace_back
(
dst
);
lods
.
emplace_back
(
dst
);
}
}
...
...
paddle/framework/lod_tensor_test.cc
浏览文件 @
8c1025d6
...
@@ -131,5 +131,33 @@ TEST(LoD, ToAbsOffset) {
...
@@ -131,5 +131,33 @@ TEST(LoD, ToAbsOffset) {
EXPECT_EQ
(
abs_lod
,
expected
);
EXPECT_EQ
(
abs_lod
,
expected
);
}
}
TEST
(
LoD
,
SplitLoDTensor
)
{
LoD
lod
;
lod
.
push_back
(
std
::
vector
<
size_t
>
({
0
,
2
,
4
,
5
,
6
}));
lod
.
push_back
(
std
::
vector
<
size_t
>
({
0
,
1
,
6
,
8
,
13
,
15
,
20
}));
platform
::
CPUPlace
place
;
LoDTensor
lod_tensor
;
lod_tensor
.
Resize
({
20
,
1
});
float
*
dst_ptr
=
lod_tensor
.
mutable_data
<
float
>
(
place
);
for
(
int
i
=
0
;
i
<
lod_tensor
.
numel
();
++
i
)
{
dst_ptr
[
i
]
=
i
;
}
lod_tensor
.
set_lod
(
lod
);
std
::
vector
<
platform
::
Place
>
places
{
platform
::
CPUPlace
(),
platform
::
CPUPlace
()};
LoD
lod0
;
lod0
.
push_back
(
std
::
vector
<
size_t
>
({
0
,
2
,
4
}));
lod0
.
push_back
(
std
::
vector
<
size_t
>
({
0
,
1
,
6
,
8
,
13
}));
LoD
lod1
;
lod1
.
push_back
(
std
::
vector
<
size_t
>
({
0
,
1
,
2
}));
lod1
.
push_back
(
std
::
vector
<
size_t
>
({
0
,
2
,
7
}));
auto
lods
=
lod_tensor
.
SplitLoDTensor
(
places
);
EXPECT_EQ
(
lods
[
0
].
lod
(),
lod0
);
EXPECT_EQ
(
lods
[
1
].
lod
(),
lod1
);
}
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录