Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
46abe798
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
46abe798
编写于
3月 17, 2022
作者:
王
王明冬
提交者:
GitHub
3月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[infrt] add default kernel argument remap feature in phi_op_convert_pass. (#40633)
上级
3a256637
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
40 addition
and
32 deletion
+40
-32
paddle/infrt/dialect/phi/pass/phi_op_convert_pass.cc
paddle/infrt/dialect/phi/pass/phi_op_convert_pass.cc
+40
-32
未找到文件。
paddle/infrt/dialect/phi/pass/phi_op_convert_pass.cc
浏览文件 @
46abe798
...
...
@@ -32,6 +32,7 @@
#include "paddle/infrt/dialect/phi/pass/kernel_op_desc.h"
#include "paddle/infrt/dialect/phi/pass/proto_arg_map_context.h"
#include "paddle/phi/core/compat/op_utils.h"
#include "paddle/phi/core/kernel_factory.h"
#include "paddle/phi/ops/compat/signatures.h"
namespace
{
...
...
@@ -94,42 +95,49 @@ void PhiOpConvertPass::convertStage() {
// Todo: print log
continue
;
}
::
phi
::
KernelSignature
kernel_sign
=
::
phi
::
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
op_name
)(
infrt
::
ProtoArgumentMappingContext
(
op
));
// resort input&output according to kernel_sign
::
llvm
::
SmallVector
<
mlir
::
Value
,
4
>
inputs
,
ori_output
;
::
llvm
::
SmallVector
<
mlir
::
Type
,
4
>
output_types
;
for
(
const
std
::
string
&
str
:
std
::
get
<
0
>
(
kernel_sign
.
args
))
{
if
(
pd_dialect_inputs_info_map_
.
at
(
op_name
).
count
(
str
)
==
0
)
{
LOG
(
ERROR
)
<<
"No input info for Op "
<<
op_name
<<
" and argument "
<<
str
;
return
;
auto
loc
=
getFunction
().
getLoc
();
builder
.
setInsertionPoint
(
op
);
if
(
phi
::
KernelFactory
::
Instance
().
HasCompatiblePhiKernel
(
op_name
))
{
std
::
string
kernel_name
=
phi
::
TransToPhiKernelName
(
op_name
);
auto
kernel_op
=
builder
.
create
<
infrt
::
KernelOp
>
(
loc
,
op
->
getResultTypes
(),
op
->
getOperands
(),
kernel_name
,
op
->
getAttrDictionary
());
op
->
replaceAllUsesWith
(
kernel_op
.
getResults
());
}
else
{
::
phi
::
KernelSignature
kernel_sign
=
::
phi
::
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
op_name
)(
infrt
::
ProtoArgumentMappingContext
(
op
));
// resort input&output according to kernel_sign
::
llvm
::
SmallVector
<
mlir
::
Value
,
4
>
inputs
,
ori_output
;
::
llvm
::
SmallVector
<
mlir
::
Type
,
4
>
output_types
;
for
(
const
std
::
string
&
str
:
std
::
get
<
0
>
(
kernel_sign
.
args
))
{
if
(
pd_dialect_inputs_info_map_
.
at
(
op_name
).
count
(
str
)
==
0
)
{
LOG
(
ERROR
)
<<
"No input info for Op "
<<
op_name
<<
" and argument "
<<
str
;
return
;
}
uint8_t
index
=
pd_dialect_inputs_info_map_
.
at
(
op_name
).
at
(
str
);
inputs
.
push_back
(
op
->
getOperands
()[
index
]);
}
uint8_t
index
=
pd_dialect_inputs_info_map_
.
at
(
op_name
).
at
(
str
);
inputs
.
push_back
(
op
->
getOperands
()[
index
]);
}
for
(
const
std
::
string
&
str
:
std
::
get
<
2
>
(
kernel_sign
.
args
))
{
if
(
pd_dialect_outputs_info_map_
.
at
(
op_name
).
count
(
str
)
==
0
)
{
LOG
(
ERROR
)
<<
"No output info for Op "
<<
op_name
<<
" and argument "
<<
str
;
return
;
for
(
const
std
::
string
&
str
:
std
::
get
<
2
>
(
kernel_sign
.
args
))
{
if
(
pd_dialect_outputs_info_map_
.
at
(
op_name
).
count
(
str
)
==
0
)
{
LOG
(
ERROR
)
<<
"No output info for Op "
<<
op_name
<<
" and argument "
<<
str
;
return
;
}
uint8_t
index
=
pd_dialect_outputs_info_map_
.
at
(
op_name
).
at
(
str
);
output_types
.
push_back
(
op
->
getResultTypes
()[
index
]);
ori_output
.
push_back
(
op
->
getResult
(
index
));
}
auto
kernel_op
=
builder
.
create
<
infrt
::
KernelOp
>
(
loc
,
output_types
,
inputs
,
kernel_sign
.
name
,
op
->
getAttrDictionary
());
for
(
size_t
index
=
0
;
index
<
ori_output
.
size
();
++
index
)
{
ori_output
[
index
].
replaceAllUsesWith
(
kernel_op
.
getResult
(
index
));
}
uint8_t
index
=
pd_dialect_outputs_info_map_
.
at
(
op_name
).
at
(
str
);
output_types
.
push_back
(
op
->
getResultTypes
()[
index
]);
ori_output
.
push_back
(
op
->
getResult
(
index
));
}
auto
loc
=
getFunction
().
getLoc
();
builder
.
setInsertionPoint
(
op
);
auto
kernel_op
=
builder
.
create
<
infrt
::
KernelOp
>
(
loc
,
output_types
,
inputs
,
kernel_sign
.
name
,
op
->
getAttrDictionary
());
for
(
size_t
index
=
0
;
index
<
ori_output
.
size
();
++
index
)
{
ori_output
[
index
].
replaceAllUsesWith
(
kernel_op
.
getResult
(
index
));
}
CHECK
(
op
->
use_empty
());
op
->
erase
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录