Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
c096096f
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
338
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看板
提交
c096096f
编写于
5月 13, 2020
作者:
D
dingminghui
提交者:
jackzhang235
5月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mlu): fix error while LITE_MLU_CAST is on
上级
9553fab2
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
21 addition
and
13 deletion
+21
-13
lite/core/mir/mlu_postprocess_pass.cc
lite/core/mir/mlu_postprocess_pass.cc
+21
-13
未找到文件。
lite/core/mir/mlu_postprocess_pass.cc
浏览文件 @
c096096f
...
@@ -610,16 +610,19 @@ void MLUPostprocessPass::ModifyLayout(SSAGraph* graph) {
...
@@ -610,16 +610,19 @@ void MLUPostprocessPass::ModifyLayout(SSAGraph* graph) {
}
}
}
}
std
::
string
CheckInputAndInsert
(
cpp
::
BlockDesc
*
block_desc
,
std
::
string
CheckInputAndInsert
(
Scope
*
scope
,
cpp
::
BlockDesc
*
block_desc
,
const
std
::
string
&
input_name
,
const
std
::
string
&
input_name
,
const
Type
*
tensor_type
,
const
Type
*
tensor_type
,
const
Type
*
subgraph_type
)
{
const
Type
*
subgraph_type
)
{
auto
cur_node
=
input_name
;
auto
cur_node
=
input_name
;
if
(
DataLayoutCompatible
(
*
tensor_type
,
*
subgraph_type
))
{
if
(
DataLayoutCompatible
(
*
tensor_type
,
*
subgraph_type
))
{
auto
layout_op
=
block_desc
->
AddOp
<
cpp
::
OpDesc
>
();
auto
layout_op
=
block_desc
->
AddOp
<
cpp
::
OpDesc
>
();
auto
layout_arg_name
=
string_format
(
"%s/layout"
,
cur_node
);
auto
layout_arg_name
=
string_format
(
"%s/layout"
,
cur_node
.
c_str
());
scope
->
Var
(
layout_arg_name
);
VLOG
(
5
)
<<
"insert layout in subgraph, arg tensor name: "
<<
layout_arg_name
;
layout_op
->
SetType
(
"layout"
);
layout_op
->
SetType
(
"layout"
);
layout_op
->
SetInput
(
"
X
"
,
{
cur_node
});
layout_op
->
SetInput
(
"
Input
"
,
{
cur_node
});
layout_op
->
SetOutput
(
"Out"
,
{
layout_arg_name
});
layout_op
->
SetOutput
(
"Out"
,
{
layout_arg_name
});
cur_node
=
layout_arg_name
;
cur_node
=
layout_arg_name
;
}
}
...
@@ -627,7 +630,9 @@ std::string CheckInputAndInsert(cpp::BlockDesc* block_desc,
...
@@ -627,7 +630,9 @@ std::string CheckInputAndInsert(cpp::BlockDesc* block_desc,
if
(
PrecisionCompatible
(
*
tensor_type
,
*
subgraph_type
)
&&
if
(
PrecisionCompatible
(
*
tensor_type
,
*
subgraph_type
)
&&
tensor_type
->
precision
()
!=
PRECISION
(
kInt8
))
{
tensor_type
->
precision
()
!=
PRECISION
(
kInt8
))
{
auto
cast_op
=
block_desc
->
AddOp
<
cpp
::
OpDesc
>
();
auto
cast_op
=
block_desc
->
AddOp
<
cpp
::
OpDesc
>
();
auto
cast_arg_name
=
string_format
(
"%s/cast"
,
cur_node
);
auto
cast_arg_name
=
string_format
(
"%s/cast"
,
cur_node
.
c_str
());
scope
->
Var
(
cast_arg_name
);
VLOG
(
5
)
<<
"insert cast in subgraph, arg tensor name: "
<<
cast_arg_name
;
cast_op
->
SetType
(
"cast"
);
cast_op
->
SetType
(
"cast"
);
cast_op
->
SetAttr
<
int
>
(
"in_dtype"
,
4
);
// FP32
cast_op
->
SetAttr
<
int
>
(
"in_dtype"
,
4
);
// FP32
cast_op
->
SetAttr
<
int
>
(
"out_dtype"
,
5
);
// FP16
cast_op
->
SetAttr
<
int
>
(
"out_dtype"
,
5
);
// FP16
...
@@ -639,7 +644,8 @@ std::string CheckInputAndInsert(cpp::BlockDesc* block_desc,
...
@@ -639,7 +644,8 @@ std::string CheckInputAndInsert(cpp::BlockDesc* block_desc,
return
cur_node
;
return
cur_node
;
}
}
std
::
string
CheckOutputAndInsert
(
cpp
::
BlockDesc
*
block_desc
,
std
::
string
CheckOutputAndInsert
(
Scope
*
scope
,
cpp
::
BlockDesc
*
block_desc
,
const
std
::
string
&
output_name
,
const
std
::
string
&
output_name
,
const
Type
*
tensor_type
,
const
Type
*
tensor_type
,
const
Type
*
subgraph_type
)
{
const
Type
*
subgraph_type
)
{
...
@@ -655,16 +661,20 @@ std::string CheckOutputAndInsert(cpp::BlockDesc* block_desc,
...
@@ -655,16 +661,20 @@ std::string CheckOutputAndInsert(cpp::BlockDesc* block_desc,
}
}
if
(
DataLayoutCompatible
(
*
tensor_type
,
*
subgraph_type
))
{
if
(
DataLayoutCompatible
(
*
tensor_type
,
*
subgraph_type
))
{
auto
layout_arg_name
=
string_format
(
"%s/layout"
,
cur_node
);
auto
layout_arg_name
=
string_format
(
"%s/layout"
,
cur_node
.
c_str
());
scope
->
Var
(
layout_arg_name
);
VLOG
(
5
)
<<
"insert layout in subgraph, arg tensor name: "
<<
layout_arg_name
;
layout_op
=
block_desc
->
AddOp
<
cpp
::
OpDesc
>
();
layout_op
=
block_desc
->
AddOp
<
cpp
::
OpDesc
>
();
layout_op
->
SetType
(
"layout"
);
layout_op
->
SetType
(
"layout"
);
layout_op
->
SetInput
(
"
X
"
,
{
layout_arg_name
});
layout_op
->
SetInput
(
"
Input
"
,
{
layout_arg_name
});
layout_op
->
SetOutput
(
"Out"
,
{
cur_node
});
layout_op
->
SetOutput
(
"Out"
,
{
cur_node
});
cur_node
=
layout_arg_name
;
cur_node
=
layout_arg_name
;
}
}
if
(
cast_op
)
{
if
(
cast_op
)
{
auto
cast_arg_name
=
string_format
(
"%s/cast"
,
cur_node
);
auto
cast_arg_name
=
string_format
(
"%s/cast"
,
cur_node
.
c_str
());
scope
->
Var
(
cast_arg_name
);
VLOG
(
5
)
<<
"insert cast in subgraph, arg tensor name: "
<<
cast_arg_name
;
cast_op
->
SetInput
(
"X"
,
{
cast_arg_name
});
cast_op
->
SetInput
(
"X"
,
{
cast_arg_name
});
cast_op
->
SetOutput
(
"Out"
,
{
cur_node
});
cast_op
->
SetOutput
(
"Out"
,
{
cur_node
});
cur_node
=
cast_arg_name
;
cur_node
=
cast_arg_name
;
...
@@ -675,7 +685,7 @@ std::string CheckOutputAndInsert(cpp::BlockDesc* block_desc,
...
@@ -675,7 +685,7 @@ std::string CheckOutputAndInsert(cpp::BlockDesc* block_desc,
// insert cast op on mlu, to avoid cast on cpu, invoke before first run
// insert cast op on mlu, to avoid cast on cpu, invoke before first run
void
MLUPostprocessPass
::
AdjustSubgraph
(
Node
*
subgraph_node
,
void
MLUPostprocessPass
::
AdjustSubgraph
(
Node
*
subgraph_node
,
const
Type
*
op
_type
)
{
const
Type
*
subgraph
_type
)
{
auto
subgraph_op
=
subgraph_node
->
AsStmt
().
op
();
auto
subgraph_op
=
subgraph_node
->
AsStmt
().
op
();
CHECK_EQ
(
subgraph_op
->
Type
(),
"subgraph"
);
CHECK_EQ
(
subgraph_op
->
Type
(),
"subgraph"
);
auto
op
=
dynamic_cast
<
operators
::
SubgraphOp
*>
(
subgraph_op
.
get
());
auto
op
=
dynamic_cast
<
operators
::
SubgraphOp
*>
(
subgraph_op
.
get
());
...
@@ -700,7 +710,7 @@ void MLUPostprocessPass::AdjustSubgraph(Node* subgraph_node,
...
@@ -700,7 +710,7 @@ void MLUPostprocessPass::AdjustSubgraph(Node* subgraph_node,
if
(
!
(
input
->
AsArg
().
is_weight
||
input
->
AsArg
().
is_persist
))
{
if
(
!
(
input
->
AsArg
().
is_weight
||
input
->
AsArg
().
is_persist
))
{
i_names
.
emplace_back
(
input_name
);
i_names
.
emplace_back
(
input_name
);
node_replace
[
input_name
]
=
CheckInputAndInsert
(
node_replace
[
input_name
]
=
CheckInputAndInsert
(
new_block_desc
,
input_name
,
input
->
AsArg
().
type
,
op
_type
);
op
->
scope
(),
new_block_desc
,
input_name
,
input
->
AsArg
().
type
,
subgraph
_type
);
}
}
}
}
for
(
auto
&
output
:
subgraph_node
->
outlinks
)
{
for
(
auto
&
output
:
subgraph_node
->
outlinks
)
{
...
@@ -708,7 +718,7 @@ void MLUPostprocessPass::AdjustSubgraph(Node* subgraph_node,
...
@@ -708,7 +718,7 @@ void MLUPostprocessPass::AdjustSubgraph(Node* subgraph_node,
if
(
!
(
output
->
AsArg
().
is_weight
||
output
->
AsArg
().
is_persist
))
{
if
(
!
(
output
->
AsArg
().
is_weight
||
output
->
AsArg
().
is_persist
))
{
o_names
.
emplace_back
(
output_name
);
o_names
.
emplace_back
(
output_name
);
node_replace
[
output_name
]
=
CheckOutputAndInsert
(
node_replace
[
output_name
]
=
CheckOutputAndInsert
(
block_desc
,
output_name
,
output
->
AsArg
().
type
,
op
_type
);
op
->
scope
(),
block_desc
,
output_name
,
output
->
AsArg
().
type
,
subgraph
_type
);
}
}
}
}
...
@@ -749,8 +759,6 @@ void MLUPostprocessPass::AdjustSubgraph(Node* subgraph_node,
...
@@ -749,8 +759,6 @@ void MLUPostprocessPass::AdjustSubgraph(Node* subgraph_node,
}
}
}
}
op
->
SetSubBlock
(
new_block_desc
);
op
->
SetSubBlock
(
new_block_desc
);
// set param to kernel
op
->
AttachKernel
(
op
->
GetKernel
());
}
}
void
MLUPostprocessPass
::
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
{
void
MLUPostprocessPass
::
Apply
(
const
std
::
unique_ptr
<
SSAGraph
>&
graph
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录