Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1dad4bb2
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看板
未验证
提交
1dad4bb2
编写于
1月 09, 2018
作者:
Y
Yu Yang
提交者:
GitHub
1月 09, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove unused LoDTensor methods (#7247)
* Remove unused LoDTensor methods * Update
上级
274bfcb6
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
0 addition
and
172 deletion
+0
-172
paddle/framework/lod_tensor.cc
paddle/framework/lod_tensor.cc
+0
-49
paddle/framework/lod_tensor.h
paddle/framework/lod_tensor.h
+0
-37
paddle/framework/lod_tensor_test.cc
paddle/framework/lod_tensor_test.cc
+0
-86
未找到文件。
paddle/framework/lod_tensor.cc
浏览文件 @
1dad4bb2
...
...
@@ -59,18 +59,6 @@ std::ostream &operator<<(std::ostream &os, const LoDTensor &t) {
return
os
;
}
LoD
SliceLevels
(
const
LoD
&
in
,
size_t
level_begin
,
size_t
level_end
)
{
LoD
new_lod
;
new_lod
.
reserve
(
level_end
-
level_begin
);
for
(
size_t
i
=
level_begin
;
i
<
level_end
;
i
++
)
{
new_lod
.
emplace_back
(
in
.
at
(
i
));
}
// transform the lowest level to absolute offset.
LoD
abs_offset_lod
=
ToAbsOffset
(
in
);
new_lod
.
back
()
=
abs_offset_lod
[
level_end
-
1
];
return
new_lod
;
}
LoD
SliceInLevel
(
const
LoD
&
in
,
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
)
{
PADDLE_ENFORCE_LT
(
level
,
in
.
size
());
...
...
@@ -131,43 +119,6 @@ bool operator==(const LoD &a, const LoD &b) {
return
true
;
}
size_t
LoDTensor
::
NumElements
(
size_t
level
,
size_t
idx
)
const
{
PADDLE_ENFORCE_LT
(
level
,
NumLevels
());
PADDLE_ENFORCE_LT
(
idx
,
NumElements
(
level
));
return
lod_
[
level
][
idx
+
1
]
-
lod_
[
level
][
idx
];
}
size_t
LoDTensor
::
NumInstancesInElement
(
size_t
level
,
size_t
idx
)
const
{
PADDLE_ENFORCE_LT
(
level
,
NumLevels
());
PADDLE_ENFORCE_LT
(
idx
,
NumElements
(
level
));
auto
abs_lod
=
ToAbsOffset
(
lod
());
size_t
begin
=
abs_lod
[
level
][
idx
];
size_t
end
=
abs_lod
[
level
][
idx
+
1
];
return
end
-
begin
;
}
void
LoDTensor
::
ShrinkLevels
(
size_t
level_begin
,
size_t
level_end
)
{
auto
new_lod
=
framework
::
SliceLevels
(
lod_
,
level_begin
,
level_end
);
lod_
=
new_lod
;
}
void
LoDTensor
::
ShrinkInLevel
(
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
)
{
PADDLE_ENFORCE_LT
(
level
,
NumLevels
());
PADDLE_ENFORCE_LT
(
elem_begin
,
NumElements
(
level
));
PADDLE_ENFORCE_LT
(
elem_end
,
NumElements
(
level
)
+
1
);
auto
abs_lod
=
framework
::
ToAbsOffset
(
lod
());
auto
new_lod
=
framework
::
SliceInLevel
(
lod_
,
level
,
elem_begin
,
elem_end
);
lod_
=
new_lod
;
// slice the underlying tensor
size_t
begin
=
abs_lod
[
level
][
elem_begin
];
size_t
end
=
abs_lod
[
level
][
elem_end
];
PADDLE_ENFORCE_LT
(
begin
,
end
,
"Cannot shrink, the result tensor is empty."
);
ShareDataWith
(
Slice
(
begin
,
end
));
}
using
LoDAndOffset
=
std
::
pair
<
LoD
,
std
::
pair
<
size_t
,
size_t
>>
;
LoDAndOffset
GetSubLoDAndAbsoluteOffset
(
const
LoD
&
lod
,
size_t
start_idx
,
size_t
end_idx
,
size_t
start_level
)
{
...
...
paddle/framework/lod_tensor.h
浏览文件 @
1dad4bb2
...
...
@@ -60,14 +60,6 @@ using LoD = std::vector<Vector<size_t>>;
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
LoD
&
lod
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
LoDTensor
&
t
);
/*
* Slice levels from a LoD.
* NOTE the lowest level should always be the absolute offsets of the underlying
* tensor instances. So if higher layers are sliced without the lowest level,
* the lower level of the sliced LoD will be transformed to the absolute offset.
*/
LoD
SliceLevels
(
const
LoD
&
in
,
size_t
level_begin
,
size_t
level_end
);
LoD
SliceInLevel
(
const
LoD
&
in
,
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
);
/*
...
...
@@ -116,35 +108,6 @@ class LoDTensor : public Tensor {
return
(
lod_
)[
level
].
size
()
-
1
;
}
/*
* Number of lower-level elements.
* For example, a 2-level lod-tensor
*
* 0-th level | |
* 1-th level || |||
*
* NumElements(0, 0) get 2
* NumElements(0, 1) get 3
*/
size_t
NumElements
(
size_t
level
,
size_t
idx
)
const
;
/*
* Get the number of instances in the underlying tensor in the `idx`-th
* element.
*/
size_t
NumInstancesInElement
(
size_t
level
,
size_t
idx
)
const
;
/*
* Shrink levels[level_begin:level_end]
*/
void
ShrinkLevels
(
size_t
level_begin
,
size_t
level_end
);
/*
* Shrink elements of a level, [elem_begin: elem_end]
* @note: low performance in slice lod_.
*/
void
ShrinkInLevel
(
size_t
level
,
size_t
elem_begin
,
size_t
elem_end
);
std
::
vector
<
LoDTensor
>
SplitLoDTensor
(
const
std
::
vector
<
platform
::
Place
>
places
)
const
;
...
...
paddle/framework/lod_tensor_test.cc
浏览文件 @
1dad4bb2
...
...
@@ -54,92 +54,6 @@ class LoDTensorTester : public ::testing::Test {
LoDTensor
lod_tensor_
;
};
TEST_F
(
LoDTensorTester
,
NumLevels
)
{
ASSERT_EQ
(
lod_tensor_
.
NumLevels
(),
3UL
);
}
TEST_F
(
LoDTensorTester
,
NumElements
)
{
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
0
),
2UL
);
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
1
),
3UL
);
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
2
),
8UL
);
}
TEST_F
(
LoDTensorTester
,
NumElements2
)
{
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
0
,
0
),
2UL
);
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
0
,
1
),
1UL
);
ASSERT_EQ
(
lod_tensor_
.
NumElements
(
1
,
1
),
3UL
);
}
TEST_F
(
LoDTensorTester
,
ShrinkLevels
)
{
// slice 1 level
for
(
size_t
level
=
0
;
level
<
3UL
;
++
level
)
{
LoDTensor
new_lod_tensor
=
lod_tensor_
;
new_lod_tensor
.
ShrinkLevels
(
level
,
level
+
1
);
ASSERT_EQ
(
new_lod_tensor
.
NumLevels
(),
1UL
);
ASSERT_EQ
(
new_lod_tensor
.
data
<
float
>
(),
lod_tensor_
.
data
<
float
>
());
}
// shrink 2 level
for
(
size_t
level
=
0
;
level
<
2UL
;
++
level
)
{
LoDTensor
new_lod_tensor
=
lod_tensor_
;
new_lod_tensor
.
ShrinkLevels
(
level
,
level
+
2
);
// the lowest level's last element should be the tensor's batch_size.
ASSERT_EQ
(
new_lod_tensor
.
lod
().
back
().
back
(),
lod_tensor_
.
lod
().
back
().
back
());
ASSERT_EQ
(
new_lod_tensor
.
NumLevels
(),
2UL
);
ASSERT_EQ
(
new_lod_tensor
.
data
<
float
>
(),
lod_tensor_
.
data
<
float
>
());
}
}
TEST_F
(
LoDTensorTester
,
ShrinkInLevel
)
{
size_t
level
=
0
;
LoDTensor
new_lod_tensor
=
lod_tensor_
;
new_lod_tensor
.
ShrinkInLevel
(
level
,
0
,
1
);
ASSERT_EQ
(
new_lod_tensor
.
NumLevels
(),
3UL
);
ASSERT_EQ
(
new_lod_tensor
.
NumElements
(
0
),
1UL
);
ASSERT_EQ
(
new_lod_tensor
.
NumElements
(
1
),
2UL
);
ASSERT_EQ
(
new_lod_tensor
.
NumElements
(
2
),
5UL
);
ASSERT_EQ
(
new_lod_tensor
.
dims
()[
0
],
12
);
for
(
int
i
=
0
;
i
<
12
*
128
;
i
++
)
{
ASSERT_EQ
(
new_lod_tensor
.
data
<
float
>
()[
i
],
i
);
}
level
=
1
;
new_lod_tensor
=
lod_tensor_
;
new_lod_tensor
.
ShrinkInLevel
(
level
,
1
,
2
);
ASSERT_EQ
(
new_lod_tensor
.
NumLevels
(),
2UL
);
ASSERT_EQ
(
new_lod_tensor
.
NumElements
(
0
),
1UL
);
ASSERT_EQ
(
new_lod_tensor
.
NumElements
(
1
),
3UL
);
ASSERT_EQ
(
new_lod_tensor
.
dims
()[
0
],
7
);
for
(
int
i
=
5
*
128
;
i
<
12
*
128
;
i
++
)
{
ASSERT_EQ
(
new_lod_tensor
.
data
<
float
>
()[
i
-
5
*
128
],
i
);
}
LoDTensor
t1
;
t1
.
set_lod
(
lod_tensor_
.
lod
());
t1
.
ShareDataWith
(
lod_tensor_
);
LoDTensor
t2
;
t2
.
set_lod
(
lod_tensor_
.
lod
());
t2
.
ShareDataWith
(
lod_tensor_
);
t1
.
ShrinkInLevel
(
0
,
1
,
2
);
t2
.
ShrinkInLevel
(
0
,
0
,
1
);
EXPECT_NE
(
t1
.
data
<
float
>
(),
t2
.
data
<
float
>
());
EXPECT_NE
(
t1
.
data
<
float
>
(),
lod_tensor_
.
data
<
float
>
());
}
TEST_F
(
LoDTensorTester
,
SerializeAndDeserialize
)
{
LoDTensor
dst_tensor
;
platform
::
CPUDeviceContext
cpu_ctx
((
platform
::
CPUPlace
()));
std
::
ostringstream
oss
;
SerializeToStream
(
oss
,
lod_tensor_
,
cpu_ctx
);
std
::
istringstream
iss
(
oss
.
str
());
DeserializeFromStream
(
iss
,
&
dst_tensor
,
cpu_ctx
);
float
*
dst_ptr
=
dst_tensor
.
mutable_data
<
float
>
(
platform
::
CPUPlace
());
for
(
int
i
=
0
;
i
<
kLodTensorSize
;
++
i
)
{
EXPECT_EQ
(
dst_ptr
[
i
],
i
);
}
EXPECT_EQ
(
dst_tensor
.
lod
(),
lod_tensor_
.
lod
());
}
TEST
(
LodExpand
,
test
)
{
LoD
lod
{{
0
,
2
}};
LoDTensor
tensor
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录