Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
e2e67b04
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e2e67b04
编写于
7月 19, 2019
作者:
J
Jiaying Zhao
提交者:
GitHub
7月 19, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reduce memery when input change small in lod_mode (#1756)
上级
c1f540ca
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
16 deletion
+49
-16
src/framework/executor.cpp
src/framework/executor.cpp
+16
-15
src/framework/tensor.h
src/framework/tensor.h
+31
-1
src/framework/tensor_base.h
src/framework/tensor_base.h
+2
-0
未找到文件。
src/framework/executor.cpp
浏览文件 @
e2e67b04
...
...
@@ -299,31 +299,26 @@ void Executor<Device, T>::InitNoPersistableMemory(const Tensor &input_tensor) {
for
(
const
auto
&
block
:
program_desc_
->
Blocks
())
{
for
(
const
auto
&
var_desc
:
block
->
Vars
())
{
auto
var
=
program_
.
scope
->
Var
(
var_desc
->
Name
());
auto
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
if
(
var_desc
->
Persistable
())
{
if
(
var_desc
->
Name
()
==
"feed"
||
var_desc
->
Name
()
==
"fetch"
)
{
var
->
template
GetMutable
<
framework
::
LoDTensorArray
>();
continue
;
}
}
else
{
if
(
var_desc
->
Type
()
==
VARTYPE_TYPE_LOD_TENSOR
)
{
if
(
!
var_desc
->
Persistable
()
&&
var_desc
->
Type
()
==
VARTYPE_TYPE_LOD_TENSOR
)
{
DLOG
<<
"InitNoPersistableMemory var "
<<
var_desc
->
Name
();
auto
tensor
=
var
->
template
GetMutable
<
LoDTensor
>();
if
(
tensor
->
IsInitialized
())
{
DLOG
<<
"var's tensor is Initialized"
;
DDim
tensor_dim
=
tensor
->
dims
();
DDim
new_dim
=
make_ddim
({
tensor_dim
[
0
],
tensor_dim
[
1
],
input_tensor
.
dims
()[
2
],
input_tensor
.
dims
()[
3
]});
tensor
->
Resize
(
new_dim
);
tensor
->
template
mutable_data
<
T
>();
tensor
->
template
mutable_data_new
<
T
>();
DLOG
<<
"var's tensor dims "
<<
tensor_dim
;
DLOG
<<
"var's tensor new dims "
<<
new_dim
;
}
else
{
PADDLE_MOBILE_THROW_EXCEPTION
(
"Unsupported var type `%d`"
,
var_desc
->
Type
());
DLOG
<<
"var's tensor is not Initialized ???"
;
}
}
}
}
std
::
shared_ptr
<
LoDTensor
>
output
=
GetOutput
(
"fetch"
);
output
->
Resize
(
input_tensor
.
dims
());
output
->
mutable_data
<
T
>
();
}
template
<
typename
Device
,
typename
T
>
...
...
@@ -411,6 +406,9 @@ void Executor<Device, T>::SetInput(const Tensor &input,
target
.
ShareDataWith
(
input
);
if
(
feed_indices_
.
size
()
==
1
)
{
auto
&
dim
=
input
.
dims
();
if
(
lod_mode_
&&
product
(
dim
)
<
0.9
*
product
(
input_dim_last_
))
{
InitNoPersistableMemory
(
target
);
}
input_dim_has_changed_
=
input_dim_last_
!=
dim
;
input_dim_last_
=
static_cast
<
DDim
>
(
dim
);
}
...
...
@@ -432,6 +430,9 @@ void Executor<Device, T>::SetInput(const LoDTensor &input,
target
.
set_lod
(
input
.
lod
());
if
(
feed_indices_
.
size
()
==
1
)
{
auto
&
dim
=
input
.
dims
();
if
(
lod_mode_
&&
product
(
dim
)
<
0.9
*
product
(
input_dim_last_
))
{
InitNoPersistableMemory
(
target
);
}
input_dim_has_changed_
=
input_dim_last_
!=
dim
;
input_dim_last_
=
static_cast
<
DDim
>
(
dim
);
}
...
...
src/framework/tensor.h
浏览文件 @
e2e67b04
...
...
@@ -68,7 +68,8 @@ class Tensor : public TensorBase {
Resize
(
ddim
);
auto
type
=
type_id
<
T
>
().
hash_code
();
int64_t
size
=
numel
()
*
SizeOfType
(
type
);
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
type
,
(
uint8_t
*
)
input
));
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
type
,
reinterpret_cast
<
uint8_t
*>
(
input
)));
holder_
->
set_type
(
type
);
offset_
=
0
;
}
...
...
@@ -103,6 +104,29 @@ class Tensor : public TensorBase {
return
*
this
;
}
template
<
typename
T
>
inline
T
*
mutable_data_new
()
{
static_assert
(
std
::
is_pod
<
T
>::
value
,
"T must be POD"
);
const
kTypeId_t
type
=
type_id
<
T
>
().
hash_code
();
if
(
holder_
!=
nullptr
)
{
holder_
->
set_type
(
type
);
}
PADDLE_MOBILE_ENFORCE
(
numel
()
>=
0
,
"the Tensor's numel must >=0."
)
int64_t
size
=
numel
()
*
SizeOfType
(
type
);
if
(
holder_
==
nullptr
||
holder_
->
size
()
!=
size
+
offset_
)
{
if
(
holder_
==
nullptr
)
{
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
type
));
}
else
{
holder_
->
realloc
(
size
);
}
offset_
=
0
;
}
return
reinterpret_cast
<
T
*>
(
reinterpret_cast
<
uintptr_t
>
(
holder_
->
ptr
())
+
offset_
);
}
inline
void
*
mutable_data
(
const
kTypeId_t
type
)
{
if
(
holder_
!=
nullptr
)
{
holder_
->
set_type
(
type
);
...
...
@@ -244,6 +268,12 @@ class Tensor : public TensorBase {
size_
=
size
;
}
virtual
void
realloc
(
size_t
size
)
{
capatity_
=
size
;
ptr_
.
reset
(
static_cast
<
uint8_t
*>
(
memory
::
Alloc
(
capatity_
)));
size_
=
size
;
}
std
::
unique_ptr
<
uint8_t
,
std
::
function
<
void
(
uint8_t
*
)
>>
ptr_
;
/*! the size of memory block. */
...
...
src/framework/tensor_base.h
浏览文件 @
e2e67b04
...
...
@@ -117,6 +117,8 @@ class TensorBase {
virtual
void
set_type
(
kTypeId_t
type
)
=
0
;
virtual
void
resize
(
size_t
size
)
=
0
;
virtual
void
realloc
(
size_t
size
)
=
0
;
};
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录