Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
50152b80
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看板
提交
50152b80
编写于
3月 25, 2020
作者:
X
xiaogang
提交者:
GitHub
3月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix infershape profile (#3240)
test=develop
上级
1ff03aec
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
130 addition
and
3 deletion
+130
-3
lite/core/op_lite.h
lite/core/op_lite.h
+5
-0
lite/core/program.cc
lite/core/program.cc
+2
-1
lite/operators/conv_op.cc
lite/operators/conv_op.cc
+30
-2
lite/operators/conv_op.h
lite/operators/conv_op.h
+1
-0
lite/operators/elementwise_ops.cc
lite/operators/elementwise_ops.cc
+32
-0
lite/operators/elementwise_ops.h
lite/operators/elementwise_ops.h
+1
-0
lite/operators/fc_op.cc
lite/operators/fc_op.cc
+28
-0
lite/operators/fc_op.h
lite/operators/fc_op.h
+1
-0
lite/operators/softmax_op.cc
lite/operators/softmax_op.cc
+29
-0
lite/operators/softmax_op.h
lite/operators/softmax_op.h
+1
-0
未找到文件。
lite/core/op_lite.h
浏览文件 @
50152b80
...
...
@@ -65,6 +65,7 @@ class OpLite : public Registry {
virtual
bool
CheckShape
()
const
{
return
true
;
}
// Inference the outputs' shape.
virtual
bool
InferShape
()
const
{
return
true
;
}
virtual
bool
SmartInferShape
()
{
return
this
->
InferShape
();
}
// Run this operator.
virtual
bool
Run
();
// Indicate whether the Op runs only once or not
...
...
@@ -150,6 +151,10 @@ class OpLite : public Registry {
std
::
vector
<
Place
>
valid_places_
;
Place
kernel_place_
{
TARGET
(
kHost
),
PRECISION
(
kFloat
)};
std
::
unique_ptr
<
OpInfo
>
op_info_
;
std
::
vector
<
DDimLite
>
last_input_shapes
;
std
::
vector
<
DDimLite
>
last_output_shapes
;
std
::
vector
<
std
::
vector
<
std
::
vector
<
uint64_t
>>>
last_output_lods
;
std
::
vector
<
std
::
vector
<
std
::
vector
<
uint64_t
>>>
last_input_lods
;
};
/*
...
...
lite/core/program.cc
浏览文件 @
50152b80
...
...
@@ -286,7 +286,8 @@ void Instruction::Run() {
return
;
}
op_
->
InferShape
();
// op_->InferShape();
op_
->
SmartInferShape
();
kernel_
->
Launch
();
has_run_
=
true
;
}
...
...
lite/operators/conv_op.cc
浏览文件 @
50152b80
...
...
@@ -80,6 +80,34 @@ void UpdatePaddingAndDilation(std::vector<int>* paddings,
}
}
bool
ConvOpLite
::
SmartInferShape
()
{
if
(
!
last_input_shapes
.
empty
())
{
if
(
last_input_shapes
[
0
]
==
param_
.
x
->
dims
()
&&
last_input_lods
[
0
]
==
param_
.
x
->
lod
())
{
param_
.
output
->
Resize
(
last_output_shapes
[
0
]);
param_
.
output
->
set_lod
(
last_output_lods
[
0
]);
return
true
;
}
}
this
->
InferShape
();
if
(
!
last_input_shapes
.
empty
())
{
last_input_shapes
.
clear
();
last_input_lods
.
clear
();
}
last_input_shapes
.
push_back
(
param_
.
x
->
dims
());
last_input_lods
.
push_back
(
param_
.
x
->
lod
());
if
(
!
last_output_shapes
.
empty
())
{
last_output_shapes
.
clear
();
last_output_lods
.
clear
();
}
last_output_shapes
.
push_back
(
param_
.
output
->
dims
());
last_output_lods
.
push_back
(
param_
.
output
->
lod
());
return
true
;
}
bool
ConvOpLite
::
InferShape
()
const
{
const
auto
in_dims
=
param_
.
x
->
dims
();
const
auto
filter_dims
=
param_
.
filter
->
dims
();
...
...
@@ -104,9 +132,9 @@ bool ConvOpLite::InferShape() const {
// Set output dims
param_
.
output
->
Resize
(
lite
::
DDim
(
output_shape
));
// share LoD
// param_.output->set_lod(param_.x->lod());
param_
.
output
->
set_lod
(
param_
.
x
->
lod
());
return
true
;
}
...
...
lite/operators/conv_op.h
浏览文件 @
50152b80
...
...
@@ -36,6 +36,7 @@ class ConvOpLite : public OpLite {
bool
CheckShape
()
const
override
;
bool
InferShape
()
const
override
;
bool
SmartInferShape
()
override
;
// TODO(Superjomn) replace framework::OpDesc with a lite one.
bool
AttachImpl
(
const
cpp
::
OpDesc
&
op_desc
,
lite
::
Scope
*
scope
)
override
{
...
...
lite/operators/elementwise_ops.cc
浏览文件 @
50152b80
...
...
@@ -26,7 +26,38 @@ bool ElementwiseOp::CheckShape() const {
CHECK_OR_FALSE
(
param_
.
Out
);
return
true
;
}
bool
ElementwiseOp
::
SmartInferShape
()
{
if
(
!
last_input_shapes
.
empty
())
{
if
(
last_input_shapes
[
0
]
==
param_
.
X
->
dims
()
&&
last_input_shapes
[
1
]
==
param_
.
Y
->
dims
()
&&
last_input_lods
[
0
]
==
param_
.
X
->
lod
()
&&
last_input_lods
[
1
]
==
param_
.
Y
->
lod
())
{
param_
.
Out
->
Resize
(
last_output_shapes
[
0
]);
param_
.
Out
->
set_lod
(
last_output_lods
[
0
]);
return
true
;
}
}
this
->
InferShape
();
if
(
!
last_input_shapes
.
empty
())
{
last_input_shapes
.
clear
();
last_input_lods
.
clear
();
}
last_input_shapes
.
push_back
(
param_
.
X
->
dims
());
last_input_lods
.
push_back
(
param_
.
X
->
lod
());
last_input_shapes
.
push_back
(
param_
.
Y
->
dims
());
last_input_lods
.
push_back
(
param_
.
Y
->
lod
());
if
(
!
last_output_shapes
.
empty
())
{
last_output_shapes
.
clear
();
last_output_lods
.
clear
();
}
last_output_shapes
.
push_back
(
param_
.
Out
->
dims
());
last_output_lods
.
push_back
(
param_
.
Out
->
lod
());
return
true
;
}
bool
ElementwiseOp
::
InferShape
()
const
{
auto
x_dim
=
param_
.
X
->
dims
();
auto
y_dim
=
param_
.
Y
->
dims
();
...
...
@@ -81,6 +112,7 @@ bool ElementwiseOp::InferShape() const {
auto
out_lod
=
param_
.
Out
->
mutable_lod
();
*
out_lod
=
param_
.
X
->
lod
();
}
return
true
;
}
...
...
lite/operators/elementwise_ops.h
浏览文件 @
50152b80
...
...
@@ -28,6 +28,7 @@ class ElementwiseOp : public OpLite {
bool
CheckShape
()
const
override
;
bool
InferShape
()
const
override
;
bool
SmartInferShape
()
override
;
bool
AttachImpl
(
const
cpp
::
OpDesc
&
opdesc
,
lite
::
Scope
*
scope
)
override
;
...
...
lite/operators/fc_op.cc
浏览文件 @
50152b80
...
...
@@ -48,6 +48,33 @@ bool FcOpLite::CheckShape() const {
return
true
;
}
bool
FcOpLite
::
SmartInferShape
()
{
if
(
!
last_input_shapes
.
empty
()
&&
!
last_output_shapes
.
empty
())
{
if
(
last_input_shapes
[
0
]
==
param_
.
input
->
dims
()
&&
last_input_lods
[
0
]
==
param_
.
input
->
lod
())
{
param_
.
output
->
Resize
(
last_output_shapes
[
0
]);
param_
.
output
->
set_lod
(
last_output_lods
[
0
]);
return
true
;
}
}
this
->
InferShape
();
if
(
!
last_input_shapes
.
empty
())
{
last_input_shapes
.
clear
();
last_input_lods
.
clear
();
}
last_input_shapes
.
push_back
(
param_
.
input
->
dims
());
last_input_lods
.
push_back
(
param_
.
input
->
lod
());
if
(
!
last_output_shapes
.
empty
())
{
last_output_shapes
.
clear
();
last_output_lods
.
clear
();
}
last_output_shapes
.
push_back
(
param_
.
output
->
dims
());
last_output_lods
.
push_back
(
param_
.
output
->
lod
());
return
true
;
}
bool
FcOpLite
::
InferShape
()
const
{
const
auto
&
input_dims
=
param_
.
input
->
dims
();
const
auto
&
w_dims
=
param_
.
w
->
dims
();
...
...
@@ -64,6 +91,7 @@ bool FcOpLite::InferShape() const {
// share LoD
param_
.
output
->
set_lod
(
param_
.
input
->
lod
());
return
true
;
}
...
...
lite/operators/fc_op.h
浏览文件 @
50152b80
...
...
@@ -36,6 +36,7 @@ class FcOpLite : public OpLite {
bool
CheckShape
()
const
override
;
bool
InferShape
()
const
override
;
bool
SmartInferShape
()
override
;
bool
AttachImpl
(
const
cpp
::
OpDesc
&
op_desc
,
lite
::
Scope
*
scope
)
override
;
...
...
lite/operators/softmax_op.cc
浏览文件 @
50152b80
...
...
@@ -29,10 +29,39 @@ bool SoftmaxOp::CheckShape() const {
return
true
;
}
bool
SoftmaxOp
::
SmartInferShape
()
{
if
(
!
last_input_shapes
.
empty
()
&&
!
last_output_shapes
.
empty
())
{
if
(
param_
.
x
->
dims
()
==
last_input_shapes
[
0
]
&&
param_
.
x
->
lod
()
==
last_input_lods
[
0
])
{
param_
.
output
->
Resize
(
last_output_shapes
[
0
]);
param_
.
output
->
set_lod
(
last_output_lods
[
0
]);
return
true
;
}
}
this
->
InferShape
();
if
(
!
last_input_shapes
.
empty
())
{
last_input_shapes
.
clear
();
last_input_lods
.
clear
();
}
last_input_shapes
.
push_back
(
param_
.
x
->
dims
());
last_input_lods
.
push_back
(
param_
.
x
->
lod
());
if
(
!
last_output_shapes
.
empty
())
{
last_output_shapes
.
clear
();
last_output_lods
.
clear
();
}
last_output_shapes
.
push_back
(
param_
.
output
->
dims
());
last_output_lods
.
push_back
(
param_
.
output
->
lod
());
return
true
;
}
bool
SoftmaxOp
::
InferShape
()
const
{
param_
.
output
->
Resize
(
param_
.
x
->
dims
());
auto
out_lod
=
param_
.
output
->
mutable_lod
();
*
out_lod
=
param_
.
x
->
lod
();
return
true
;
}
...
...
lite/operators/softmax_op.h
浏览文件 @
50152b80
...
...
@@ -31,6 +31,7 @@ class SoftmaxOp : public OpLite {
bool
CheckShape
()
const
override
;
bool
InferShape
()
const
override
;
bool
SmartInferShape
()
override
;
bool
AttachImpl
(
const
cpp
::
OpDesc
&
opdesc
,
lite
::
Scope
*
scope
)
override
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录