Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
28b240bb
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看板
提交
28b240bb
编写于
1月 17, 2018
作者:
Y
Yang Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete todo in MergeLoDTensor
上级
208f950c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
59 addition
and
8 deletion
+59
-8
paddle/framework/lod_tensor.cc
paddle/framework/lod_tensor.cc
+22
-8
paddle/framework/lod_tensor_test.cc
paddle/framework/lod_tensor_test.cc
+37
-0
未找到文件。
paddle/framework/lod_tensor.cc
浏览文件 @
28b240bb
...
...
@@ -262,24 +262,38 @@ std::vector<LoDTensor> LoDTensor::SplitLoDTensor(
return
lods
;
}
// TODO(tonyyang-svail): make this function support LoD
void
LoDTensor
::
MergeLoDTensor
(
const
std
::
vector
<
const
LoDTensor
*>
&
lod_tensors
,
platform
::
Place
dst_place
)
{
PADDLE_ENFORCE
(
!
lod_tensors
.
empty
());
framework
::
DDim
new_dim
=
lod_tensors
[
0
]
->
dims
();
std
::
type_index
new_type
=
lod_tensors
[
0
]
->
type
();
auto
new_layout
=
lod_tensors
[
0
]
->
layout
();
for
(
auto
*
lod
:
lod_tensors
)
{
PADDLE_ENFORCE
(
new_dim
==
lod
->
dims
());
PADDLE_ENFORCE
(
new_type
==
lod
->
type
());
PADDLE_ENFORCE
(
new_layout
==
lod
->
layout
());
framework
::
DataLayout
new_layout
=
lod_tensors
[
0
]
->
layout
();
LoD
new_lod
=
lod_tensors
[
0
]
->
lod
();
for
(
size_t
i
=
1
;
i
<
lod_tensors
.
size
();
++
i
)
{
auto
*
t
=
lod_tensors
[
i
];
PADDLE_ENFORCE_EQ
(
new_type
.
hash_code
(),
t
->
type
().
hash_code
());
PADDLE_ENFORCE_EQ
(
new_layout
,
t
->
layout
());
PADDLE_ENFORCE_EQ
(
framework
::
product
(
new_dim
)
/
new_dim
[
0
],
framework
::
product
(
t
->
dims
())
/
t
->
dims
()[
0
]);
new_dim
[
0
]
+=
t
->
dims
()[
0
];
auto
&
lod
=
t
->
lod
();
for
(
size_t
j
=
0
;
j
<
lod
.
size
();
++
j
)
{
auto
&
sub_lod
=
new_lod
[
j
];
auto
&
offset
=
sub_lod
.
back
();
for
(
size_t
k
=
1
;
k
<
lod
[
j
].
size
();
++
k
)
{
sub_lod
.
push_back
(
lod
[
j
][
k
]
+
offset
);
}
}
}
new_dim
[
0
]
*=
lod_tensors
.
size
();
Resize
(
new_dim
);
set_layout
(
new_layout
);
set_lod
(
new_lod
);
mutable_data
(
dst_place
,
new_type
);
int
begin
=
0
;
for
(
auto
*
src
:
lod_tensors
)
{
int
end
=
begin
+
src
->
dims
()[
0
];
...
...
paddle/framework/lod_tensor_test.cc
浏览文件 @
28b240bb
...
...
@@ -159,5 +159,42 @@ TEST(LoD, SplitLoDTensor) {
EXPECT_EQ
(
lods
[
1
].
lod
(),
lod1
);
}
TEST
(
LoD
,
MergeLoDTensor
)
{
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_tensor0
;
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_tensor0
.
set_lod
(
lod0
);
lod_tensor0
.
Resize
({
13
,
1
});
float
*
dst_ptr
=
lod_tensor0
.
mutable_data
<
float
>
(
place
);
for
(
int
i
=
0
;
i
<
lod_tensor0
.
numel
();
++
i
)
{
dst_ptr
[
i
]
=
i
;
}
LoDTensor
lod_tensor1
;
LoD
lod1
;
lod1
.
push_back
(
std
::
vector
<
size_t
>
({
0
,
1
,
2
}));
lod1
.
push_back
(
std
::
vector
<
size_t
>
({
0
,
2
,
7
}));
lod_tensor1
.
set_lod
(
lod1
);
lod_tensor1
.
Resize
({
7
,
1
});
dst_ptr
=
lod_tensor1
.
mutable_data
<
float
>
(
place
);
for
(
int
i
=
0
;
i
<
lod_tensor1
.
numel
();
++
i
)
{
dst_ptr
[
i
]
=
i
;
}
std
::
vector
<
const
LoDTensor
*>
lods
{
&
lod_tensor0
,
&
lod_tensor1
};
LoDTensor
lod_tensor
;
lod_tensor
.
MergeLoDTensor
(
lods
,
place
);
EXPECT_EQ
(
lod_tensor
.
lod
(),
lod
);
}
}
// namespace framework
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录