Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
liming1019
Paddle
提交
17b8335b
P
Paddle
项目概览
liming1019
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
17b8335b
编写于
3月 23, 2022
作者:
J
jiangcheng
提交者:
GitHub
3月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix cinn graph may hasn't input problem (#40814)
上级
db41e39e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
56 addition
and
4 deletion
+56
-4
paddle/fluid/operators/cinn/cinn_instruction_run_op.cc
paddle/fluid/operators/cinn/cinn_instruction_run_op.cc
+50
-1
paddle/fluid/operators/cinn/cinn_launch_op.cc
paddle/fluid/operators/cinn/cinn_launch_op.cc
+6
-3
未找到文件。
paddle/fluid/operators/cinn/cinn_instruction_run_op.cc
浏览文件 @
17b8335b
...
...
@@ -24,7 +24,9 @@ class CinnInstructionRunOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInputs
(
kX
),
"Input"
,
kX
,
"CinnInstructionRun"
);
// The cinn-graph may hasn't input for CINN now support fill_constant,
// and its all inputs may generated by fill_constant instead of by fetch.
// OP_INOUT_CHECK(ctx->HasInputs(kX), "Input", kX, "CinnInstructionRun");
OP_INOUT_CHECK
(
ctx
->
HasOutputs
(
kOutputs
),
"Output"
,
kOutputs
,
"CinnInstructionRun"
);
const
CinnCompiledObject
&
compiled_object
=
...
...
@@ -43,6 +45,53 @@ class CinnInstructionRunOp : public framework::OperatorWithKernel {
});
ctx
->
SetOutputsDim
(
kOutputs
,
output_dims
);
}
protected:
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
// Why we need override GetExpectedKernelType?
// A cinn-graph may has no inpute var, if we use the base function,
// it will check wheter input tensors is initialized. Here we rewrite
// the function so that we can infer kernel type by output date type.
if
(
ctx
.
InputSize
(
kX
))
{
// if the instruction has input, infer kernel type by input date type:
return
OperatorWithKernel
::
GetExpectedKernelType
(
ctx
);
}
// Else infer kernel type by output date type:
// The `OutputVar` will check wheter the kOutputs iff has one output var
const
framework
::
Variable
*
var
=
ctx
.
OutputVar
(
kOutputs
);
PADDLE_ENFORCE_NE
(
var
,
nullptr
,
platform
::
errors
::
InvalidArgument
(
"The cinn_instruction_run Op's Output Variable should not empty."
));
const
framework
::
Tensor
*
tensor
=
nullptr
;
if
(
var
->
IsType
<
framework
::
Tensor
>
())
{
tensor
=
&
var
->
Get
<
framework
::
Tensor
>
();
}
else
if
(
var
->
IsType
<
framework
::
LoDTensor
>
())
{
tensor
=
&
var
->
Get
<
framework
::
LoDTensor
>
();
}
else
if
(
var
->
IsType
<
phi
::
SelectedRows
>
())
{
tensor
=
&
(
var
->
Get
<
phi
::
SelectedRows
>
().
value
());
}
else
if
(
var
->
IsType
<
framework
::
LoDTensorArray
>
())
{
auto
t_arr
=
&
var
->
Get
<
framework
::
LoDTensorArray
>
();
PADDLE_ENFORCE_EQ
(
t_arr
->
size
(),
1UL
,
platform
::
errors
::
InvalidArgument
(
"The cinn_instruction_run Op should just has One "
"Output when Input empty."
));
tensor
=
&
(
t_arr
->
front
());
}
PADDLE_ENFORCE_NE
(
tensor
,
nullptr
,
platform
::
errors
::
InvalidArgument
(
"The cinn_instruction_run Op's Output Tensor should not empty."
));
VLOG
(
4
)
<<
"The tensor ["
<<
ctx
.
OutputName
(
kOutputs
)
<<
"]'s dtype is "
<<
paddle
::
framework
::
DataType2String
(
tensor
->
dtype
());
auto
output_type
=
paddle
::
framework
::
TransToProtoVarType
(
tensor
->
dtype
());
return
framework
::
OpKernelType
(
output_type
,
ctx
.
device_context
());
}
};
class
CinnInstructionRunOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
...
...
paddle/fluid/operators/cinn/cinn_launch_op.cc
浏览文件 @
17b8335b
...
...
@@ -87,9 +87,12 @@ class CinnLaunchOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInputs
(
kX
)
||
ctx
->
HasInputs
(
kNoNeedBufferX
),
"Input"
,
string
::
format_string
(
"%s|%s"
,
kX
,
kNoNeedBufferX
),
"CinnLaunchOp"
);
// The cinn-graph may hasn't input for CINN now support fill_constant,
// and its all inputs may generated by fill_constant instead of by fetch.
// OP_INOUT_CHECK(ctx->HasInputs(kX) || ctx->HasInputs(kNoNeedBufferX),
// "Input", string::format_string("%s|%s", kX,
// kNoNeedBufferX),
// "CinnLaunchOp");
OP_INOUT_CHECK
(
ctx
->
HasOutputs
(
kOutputs
),
"Output"
,
kOutputs
,
"CinnLaunchOp"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录