Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
2b5771c4
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
2b5771c4
编写于
6月 15, 2022
作者:
H
huzhiqiang
提交者:
GitHub
6月 15, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
op cache supports un-persistable attributes (#43221)
上级
9b7126d0
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
3 deletion
+18
-3
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+18
-3
未找到文件。
paddle/fluid/framework/operator.cc
浏览文件 @
2b5771c4
...
@@ -1529,8 +1529,20 @@ void OperatorWithKernel::RunImpl(const Scope& scope,
...
@@ -1529,8 +1529,20 @@ void OperatorWithKernel::RunImpl(const Scope& scope,
// Do data transform before building KernelContext
// Do data transform before building KernelContext
// TODO(zhiqiu): support TransferInplaceVarsBack
// TODO(zhiqiu): support TransferInplaceVarsBack
PreparePhiData
(
exec_scope
,
*
pt_kernel_
,
*
kernel_signature_
,
runtime_ctx
);
PreparePhiData
(
exec_scope
,
*
pt_kernel_
,
*
kernel_signature_
,
runtime_ctx
);
BuildPhiKernelContext
(
*
runtime_ctx
,
dev_ctx
,
&
pt_kernel_context
);
if
(
enable_cache_runtime_context_
&&
!
need_prepare_phi_data_
&&
(
*
pt_kernel_
)(
&
pt_kernel_context
);
!
need_prepare_data_
)
{
impl_
=
new
CacheImpl
(
new
phi
::
KernelContext
(),
new
RuntimeInferShapeContext
(
*
this
,
*
runtime_ctx
));
BuildPhiKernelContext
(
*
runtime_ctx
,
dev_ctx
,
impl_
->
getKernelContext
());
(
*
pt_kernel_
)(
impl_
->
getKernelContext
());
}
else
{
phi
::
KernelContext
pt_kernel_context
;
// Do data transform before building KernelContext
// TODO(zhiqiu): support TransferInplaceVarsBack
BuildPhiKernelContext
(
*
runtime_ctx
,
dev_ctx
,
&
pt_kernel_context
);
(
*
pt_kernel_
)(
&
pt_kernel_context
);
}
}
else
{
}
else
{
(
*
kernel_func_
)(
(
*
kernel_func_
)(
ExecutionContext
(
*
this
,
exec_scope
,
*
dev_ctx
,
*
runtime_ctx
));
ExecutionContext
(
*
this
,
exec_scope
,
*
dev_ctx
,
*
runtime_ctx
));
...
@@ -2386,7 +2398,6 @@ void OperatorWithKernel::BuildPhiKernelContext(
...
@@ -2386,7 +2398,6 @@ void OperatorWithKernel::BuildPhiKernelContext(
// calcute the start and end index of the input tensors
// calcute the start and end index of the input tensors
size_t
start_idx
=
size_t
start_idx
=
(
i
==
0
?
0
:
pt_kernel_context
->
InputRangeAt
(
i
-
1
).
second
);
(
i
==
0
?
0
:
pt_kernel_context
->
InputRangeAt
(
i
-
1
).
second
);
// deal with optional here
// deal with optional here
if
((
it
==
ctx
.
inputs
.
end
()
||
it
->
second
.
size
()
==
0
)
&&
if
((
it
==
ctx
.
inputs
.
end
()
||
it
->
second
.
size
()
==
0
)
&&
(
input_defs
[
i
].
type_index
==
(
input_defs
[
i
].
type_index
==
...
@@ -2400,6 +2411,7 @@ void OperatorWithKernel::BuildPhiKernelContext(
...
@@ -2400,6 +2411,7 @@ void OperatorWithKernel::BuildPhiKernelContext(
auto
end_idx
=
start_idx
+
1
;
auto
end_idx
=
start_idx
+
1
;
pt_kernel_context
->
AssignInputRange
(
std
::
make_pair
(
start_idx
,
end_idx
),
pt_kernel_context
->
AssignInputRange
(
std
::
make_pair
(
start_idx
,
end_idx
),
i
);
i
);
continue
;
continue
;
}
}
auto
ins_vector
=
it
->
second
;
auto
ins_vector
=
it
->
second
;
...
@@ -2414,6 +2426,7 @@ void OperatorWithKernel::BuildPhiKernelContext(
...
@@ -2414,6 +2426,7 @@ void OperatorWithKernel::BuildPhiKernelContext(
tensor_in
=
&
(
var
->
Get
<
phi
::
SelectedRows
>
());
tensor_in
=
&
(
var
->
Get
<
phi
::
SelectedRows
>
());
pt_kernel_context
->
EmplaceBackInputWithoutSetRange
(
tensor_in
);
pt_kernel_context
->
EmplaceBackInputWithoutSetRange
(
tensor_in
);
}
else
if
(
var
->
IsType
<
framework
::
LoDTensorArray
>
())
{
}
else
if
(
var
->
IsType
<
framework
::
LoDTensorArray
>
())
{
need_prepare_phi_data_
=
true
;
paddle
::
small_vector
<
const
phi
::
TensorBase
*>
tensor_vector
;
paddle
::
small_vector
<
const
phi
::
TensorBase
*>
tensor_vector
;
auto
&
tensor_array
=
var
->
Get
<
framework
::
LoDTensorArray
>
();
auto
&
tensor_array
=
var
->
Get
<
framework
::
LoDTensorArray
>
();
for
(
auto
&
t
:
tensor_array
)
{
for
(
auto
&
t
:
tensor_array
)
{
...
@@ -2514,6 +2527,7 @@ void OperatorWithKernel::BuildPhiKernelContext(
...
@@ -2514,6 +2527,7 @@ void OperatorWithKernel::BuildPhiKernelContext(
attr_names
[
i
]));
attr_names
[
i
]));
}
}
}
else
{
// scalar is in the input
}
else
{
// scalar is in the input
need_prepare_phi_data_
=
true
;
auto
&
ins_vector
=
ctx
.
inputs
.
at
(
attr_names
[
i
]);
auto
&
ins_vector
=
ctx
.
inputs
.
at
(
attr_names
[
i
]);
pt_kernel_context
->
EmplaceBackAttr
(
std
::
move
(
pt_kernel_context
->
EmplaceBackAttr
(
std
::
move
(
experimental
::
MakePhiScalarFromVar
(
*
ins_vector
.
front
())));
experimental
::
MakePhiScalarFromVar
(
*
ins_vector
.
front
())));
...
@@ -2545,6 +2559,7 @@ void OperatorWithKernel::BuildPhiKernelContext(
...
@@ -2545,6 +2559,7 @@ void OperatorWithKernel::BuildPhiKernelContext(
attr_names
[
i
]));
attr_names
[
i
]));
}
}
}
else
{
// shape is in the input
}
else
{
// shape is in the input
need_prepare_phi_data_
=
true
;
auto
&
ins_vector
=
ctx
.
inputs
.
at
(
attr_names
[
i
]);
auto
&
ins_vector
=
ctx
.
inputs
.
at
(
attr_names
[
i
]);
if
(
ins_vector
.
size
()
==
1
)
{
// ShapeTensor
if
(
ins_vector
.
size
()
==
1
)
{
// ShapeTensor
pt_kernel_context
->
EmplaceBackAttr
(
std
::
move
(
pt_kernel_context
->
EmplaceBackAttr
(
std
::
move
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录