Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
779a560c
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
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看板
提交
779a560c
编写于
3月 19, 2019
作者:
H
hjchen2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine memory optimize pass for multiple blocks
上级
72d3cb39
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
24 deletion
+23
-24
src/framework/tensor.h
src/framework/tensor.h
+0
-4
src/pass/memory_optimize.cpp
src/pass/memory_optimize.cpp
+22
-19
src/pass/memory_optimize.h
src/pass/memory_optimize.h
+1
-1
未找到文件。
src/framework/tensor.h
浏览文件 @
779a560c
...
@@ -28,8 +28,6 @@ limitations under the License. */
...
@@ -28,8 +28,6 @@ limitations under the License. */
#include "framework/tensor_base.h"
#include "framework/tensor_base.h"
#include "memory/t_malloc.h"
#include "memory/t_malloc.h"
#include <iostream>
namespace
paddle_mobile
{
namespace
paddle_mobile
{
namespace
framework
{
namespace
framework
{
...
@@ -84,10 +82,8 @@ class Tensor : public TensorBase {
...
@@ -84,10 +82,8 @@ class Tensor : public TensorBase {
int64_t
size
=
numel
()
*
SizeOfType
(
type
);
int64_t
size
=
numel
()
*
SizeOfType
(
type
);
if
(
holder_
==
nullptr
||
holder_
->
size
()
<
size
+
offset_
)
{
if
(
holder_
==
nullptr
||
holder_
->
size
()
<
size
+
offset_
)
{
if
(
holder_
==
nullptr
)
{
if
(
holder_
==
nullptr
)
{
std
::
cout
<<
"reset holder... size "
<<
size
<<
std
::
endl
;
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
type
));
holder_
.
reset
(
new
PlaceholderImpl
(
size
,
type
));
}
else
{
}
else
{
std
::
cout
<<
"resize holder... size "
<<
size
<<
std
::
endl
;
holder_
->
resize
(
size
);
holder_
->
resize
(
size
);
}
}
offset_
=
0
;
offset_
=
0
;
...
...
src/pass/memory_optimize.cpp
浏览文件 @
779a560c
...
@@ -18,8 +18,8 @@ limitations under the License. */
...
@@ -18,8 +18,8 @@ limitations under the License. */
namespace
paddle_mobile
{
namespace
paddle_mobile
{
namespace
pass
{
namespace
pass
{
void
MemoryOptPass
::
Init
BlockVars
(
const
framework
::
BlockDesc
*
block
)
{
void
MemoryOptPass
::
Append
BlockVars
(
const
framework
::
BlockDesc
*
block
)
{
block_vars_
.
clear
();
//
block_vars_.clear();
for
(
const
auto
var
:
block
->
Vars
())
{
for
(
const
auto
var
:
block
->
Vars
())
{
block_vars_
[
var
->
Name
()]
=
var
.
get
();
block_vars_
[
var
->
Name
()]
=
var
.
get
();
}
}
...
@@ -51,8 +51,8 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program,
...
@@ -51,8 +51,8 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program,
framework
::
Scope
*
scope
)
{
framework
::
Scope
*
scope
)
{
const
auto
&
blocks
=
program
->
Blocks
();
const
auto
&
blocks
=
program
->
Blocks
();
for
(
const
auto
&
block
:
blocks
)
{
for
(
const
auto
&
block
:
blocks
)
{
// access all variables in
block, and stored in map
// access all variables in
each block
Init
BlockVars
(
block
.
get
());
Append
BlockVars
(
block
.
get
());
reused_nodes_
.
clear
();
reused_nodes_
.
clear
();
// collect all not persistable variables, and accumulate
// collect all not persistable variables, and accumulate
...
@@ -91,6 +91,8 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program,
...
@@ -91,6 +91,8 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program,
}
}
}
}
DLOG
<<
"analysis_nodes_ size: "
<<
analysis_nodes_
.
size
();
// apply optimize
// apply optimize
while
(
!
analysis_nodes_
.
empty
())
{
while
(
!
analysis_nodes_
.
empty
())
{
auto
*
node
=
analysis_nodes_
.
top
();
auto
*
node
=
analysis_nodes_
.
top
();
...
@@ -117,21 +119,22 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program,
...
@@ -117,21 +119,22 @@ void MemoryOptPass::operator()(const framework::ProgramDesc *program,
node
->
visited
=
true
;
node
->
visited
=
true
;
node
->
count
-=
1
;
node
->
count
-=
1
;
}
}
}
// shared data within all variables in the same reused list
// shared data within all variables in the same reused list
for
(
const
auto
&
list
:
reused_nodes_
)
{
for
(
const
auto
&
list
:
reused_nodes_
)
{
DLOG
<<
"
\n
"
;
DLOG
<<
"
\n
"
;
DLOG
<<
"share memory within these variables"
;
DLOG
<<
"share memory within these variables"
;
std
::
string
name
=
list
[
0
]
->
name
;
std
::
string
name
=
list
[
0
]
->
name
;
auto
*
reused_var
=
scope
->
Var
(
name
);
auto
*
reused_var
=
scope
->
Var
(
name
);
auto
*
reuse_tensor
=
auto
*
reuse_tensor
=
reused_var
->
template
GetMutable
<
framework
::
LoDTensor
>();
reused_var
->
template
GetMutable
<
framework
::
LoDTensor
>();
reuse_tensor
->
mutable_data
<
float
>
();
reuse_tensor
->
mutable_data
<
float
>
();
for
(
const
auto
&
node
:
list
)
{
for
(
const
auto
&
node
:
list
)
{
DLOG
<<
node
->
name
;
DLOG
<<
node
->
name
;
auto
*
var
=
scope
->
Var
(
node
->
name
);
auto
*
var
=
scope
->
Var
(
node
->
name
);
auto
*
tensor
=
var
->
template
GetMutable
<
framework
::
LoDTensor
>();
auto
*
tensor
=
var
->
template
GetMutable
<
framework
::
LoDTensor
>();
tensor
->
ShareDataWith
(
*
reuse_tensor
);
tensor
->
ShareDataWith
(
*
reuse_tensor
);
}
}
}
}
}
}
}
...
...
src/pass/memory_optimize.h
浏览文件 @
779a560c
...
@@ -49,7 +49,7 @@ class MemoryOptPass : public PassBase {
...
@@ -49,7 +49,7 @@ class MemoryOptPass : public PassBase {
void
operator
()(
const
framework
::
ProgramDesc
*
program
,
void
operator
()(
const
framework
::
ProgramDesc
*
program
,
framework
::
Scope
*
scope
);
framework
::
Scope
*
scope
);
void
Init
BlockVars
(
const
framework
::
BlockDesc
*
block
);
void
Append
BlockVars
(
const
framework
::
BlockDesc
*
block
);
bool
IsPersistable
(
const
std
::
string
name
);
bool
IsPersistable
(
const
std
::
string
name
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录