Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
c56fffb4
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看板
未验证
提交
c56fffb4
编写于
4月 23, 2022
作者:
Z
zyfncg
提交者:
GitHub
4月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize performance of dygraph (#42137)
上级
79ac8870
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
166 addition
and
100 deletion
+166
-100
paddle/fluid/framework/infershape_utils.cc
paddle/fluid/framework/infershape_utils.cc
+4
-5
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+10
-2
paddle/fluid/imperative/prepared_operator.cc
paddle/fluid/imperative/prepared_operator.cc
+26
-10
paddle/infrt/dialect/phi/pass/phi_op_convert_pass.cc
paddle/infrt/dialect/phi/pass/phi_op_convert_pass.cc
+1
-1
paddle/phi/core/compat/op_utils.h
paddle/phi/core/compat/op_utils.h
+12
-7
paddle/phi/tests/ops/test_op_signature.cc
paddle/phi/tests/ops/test_op_signature.cc
+113
-75
未找到文件。
paddle/fluid/framework/infershape_utils.cc
浏览文件 @
c56fffb4
...
@@ -402,12 +402,11 @@ std::vector<phi::MetaTensor*> CompatInferMetaContext::MutableOutputBetween(
...
@@ -402,12 +402,11 @@ std::vector<phi::MetaTensor*> CompatInferMetaContext::MutableOutputBetween(
CompatInferMetaContext
BuildInferMetaContext
(
InferShapeContext
*
ctx
,
CompatInferMetaContext
BuildInferMetaContext
(
InferShapeContext
*
ctx
,
const
std
::
string
&
op_type
)
{
const
std
::
string
&
op_type
)
{
// 1. get kernel args
// 1. get kernel args
auto
arg_map_fn
=
phi
::
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
op_type
);
auto
*
arg_map_fn
=
phi
::
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
op_type
);
PADDLE_ENFORCE_NOT_NULL
(
arg_map_fn
,
platform
::
errors
::
NotFound
(
"The ArgumentMappingFn of %s op is not found."
,
op_type
));
InferShapeArgumentMappingContext
arg_map_context
(
*
ctx
);
InferShapeArgumentMappingContext
arg_map_context
(
*
ctx
);
auto
signature
=
arg_map_fn
(
arg_map_context
);
KernelSignature
signature
=
arg_map_fn
?
(
*
arg_map_fn
)(
arg_map_context
)
:
phi
::
DefaultKernelSignatureMap
::
Instance
().
Get
(
op_type
);
VLOG
(
3
)
<<
"BuildInferMetaContext: op kernel signature - "
<<
signature
;
VLOG
(
3
)
<<
"BuildInferMetaContext: op kernel signature - "
<<
signature
;
// 2. build infermeta context
// 2. build infermeta context
...
...
paddle/fluid/framework/operator.cc
浏览文件 @
c56fffb4
...
@@ -2117,8 +2117,16 @@ KernelSignature OperatorWithKernel::GetExpectedPhiKernelArgs(
...
@@ -2117,8 +2117,16 @@ KernelSignature OperatorWithKernel::GetExpectedPhiKernelArgs(
const
ExecutionContext
&
ctx
)
const
{
const
ExecutionContext
&
ctx
)
const
{
ExecutionArgumentMappingContext
arg_mapping_ctx
(
ctx
);
ExecutionArgumentMappingContext
arg_mapping_ctx
(
ctx
);
if
(
arg_map_fn_
==
nullptr
)
{
if
(
arg_map_fn_
==
nullptr
)
{
arg_map_fn_
.
reset
(
new
phi
::
ArgumentMappingFn
(
auto
*
arg_map_fn
=
phi
::
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
type_
);
phi
::
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
Type
())));
if
(
arg_map_fn
)
{
arg_map_fn_
.
reset
(
new
phi
::
ArgumentMappingFn
(
*
arg_map_fn
));
}
else
{
auto
func
=
[
this
](
const
phi
::
ArgumentMappingContext
&
ctx
)
->
KernelSignature
{
return
phi
::
DefaultKernelSignatureMap
::
Instance
().
Get
(
type_
);
};
arg_map_fn_
.
reset
(
new
phi
::
ArgumentMappingFn
(
func
));
}
}
}
return
(
*
arg_map_fn_
)(
arg_mapping_ctx
);
return
(
*
arg_map_fn_
)(
arg_mapping_ctx
);
}
}
...
...
paddle/fluid/imperative/prepared_operator.cc
浏览文件 @
c56fffb4
...
@@ -37,6 +37,8 @@ namespace paddle {
...
@@ -37,6 +37,8 @@ namespace paddle {
namespace
imperative
{
namespace
imperative
{
static
const
phi
::
Kernel
empty_kernel
;
static
const
phi
::
Kernel
empty_kernel
;
static
const
framework
::
RuntimeContext
empty_ctx
({},
{});
static
const
framework
::
Scope
empty_scope
;
const
std
::
shared_ptr
<
VariableWrapper
>&
GetVariableWrapper
(
const
std
::
shared_ptr
<
VariableWrapper
>&
GetVariableWrapper
(
const
std
::
shared_ptr
<
paddle
::
imperative
::
VarBase
>&
var
)
{
const
std
::
shared_ptr
<
paddle
::
imperative
::
VarBase
>&
var
)
{
...
@@ -138,8 +140,6 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
...
@@ -138,8 +140,6 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
auto
*
dev_ctx
=
pool
.
Get
(
place
);
auto
*
dev_ctx
=
pool
.
Get
(
place
);
framework
::
RuntimeContext
ctx
({},
{});
#ifdef PADDLE_WITH_MKLDNN
#ifdef PADDLE_WITH_MKLDNN
// MKLDNN variant of code reads attributes in some of GetKernelTypeForVar and
// MKLDNN variant of code reads attributes in some of GetKernelTypeForVar and
// GetKernelType functions, so we need to copy the attributes there.
// GetKernelType functions, so we need to copy the attributes there.
...
@@ -158,7 +158,7 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
...
@@ -158,7 +158,7 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
// 1. get expected kernel key
// 1. get expected kernel key
auto
dygraph_exe_ctx
=
DygraphExecutionContext
<
VarType
>
(
auto
dygraph_exe_ctx
=
DygraphExecutionContext
<
VarType
>
(
op
,
framework
::
Scope
(),
*
dev_ctx
,
ctx
,
ins
,
outs
,
attrs
,
default_attrs
);
op
,
empty_scope
,
*
dev_ctx
,
empty_
ctx
,
ins
,
outs
,
attrs
,
default_attrs
);
auto
expected_kernel_key
=
op
.
GetExpectedKernelType
(
dygraph_exe_ctx
);
auto
expected_kernel_key
=
op
.
GetExpectedKernelType
(
dygraph_exe_ctx
);
framework
::
KernelSignature
pt_kernel_signature
;
framework
::
KernelSignature
pt_kernel_signature
;
...
@@ -172,11 +172,26 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
...
@@ -172,11 +172,26 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
paddle
::
platform
::
is_in_xpu_black_list
(
op
.
Type
());
paddle
::
platform
::
is_in_xpu_black_list
(
op
.
Type
());
#endif
#endif
if
(
phi
::
KernelFactory
::
Instance
().
HasCompatiblePhiKernel
(
op
.
Type
()))
{
pt_kernel_signature
=
std
::
move
(
op
.
GetExpectedPhiKernelArgs
(
dygraph_exe_ctx
));
VLOG
(
6
)
<<
pt_kernel_signature
;
bool
has_phi_kernel
=
false
;
const
auto
*
arg_map_fn
=
phi
::
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
op
.
Type
());
if
(
arg_map_fn
)
{
has_phi_kernel
=
true
;
pt_kernel_signature
=
(
*
arg_map_fn
)(
framework
::
ExecutionArgumentMappingContext
(
dygraph_exe_ctx
));
}
else
{
const
auto
*
kernel_sig
=
phi
::
DefaultKernelSignatureMap
::
Instance
().
GetNullable
(
op
.
Type
());
if
(
kernel_sig
)
{
has_phi_kernel
=
true
;
pt_kernel_signature
=
*
kernel_sig
;
}
}
if
(
has_phi_kernel
)
{
VLOG
(
6
)
<<
pt_kernel_signature
;
pt_kernel_name
=
pt_kernel_signature
.
name
;
pt_kernel_name
=
pt_kernel_signature
.
name
;
// NOTE(Liu-xiandong): The register kernel used KP have library_type[KP],
// NOTE(Liu-xiandong): The register kernel used KP have library_type[KP],
// But the default library_type is Plain, so we need to modify the
// But the default library_type is Plain, so we need to modify the
...
@@ -231,7 +246,7 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
...
@@ -231,7 +246,7 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
dev_ctx
=
pool
.
Get
(
expected_kernel_key
.
place_
);
dev_ctx
=
pool
.
Get
(
expected_kernel_key
.
place_
);
}
}
return
PreparedOp
(
op
,
ctx
,
expected_kernel_key
,
return
PreparedOp
(
op
,
empty_
ctx
,
expected_kernel_key
,
std
::
move
(
pt_kernel_signature
),
pt_kernel
,
dev_ctx
);
std
::
move
(
pt_kernel_signature
),
pt_kernel
,
dev_ctx
);
}
else
{
}
else
{
VLOG
(
6
)
<<
"Dynamic mode ChoosePhiKernel - kernel `"
<<
pt_kernel_name
VLOG
(
6
)
<<
"Dynamic mode ChoosePhiKernel - kernel `"
<<
pt_kernel_name
...
@@ -280,7 +295,7 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
...
@@ -280,7 +295,7 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
<<
" | kernel key: "
<<
pt_cpu_kernel_key
<<
" | kernel key: "
<<
pt_cpu_kernel_key
<<
" | kernel: "
<<
pt_cpu_kernel
;
<<
" | kernel: "
<<
pt_cpu_kernel
;
auto
*
cpu_ctx
=
pool
.
Get
(
paddle
::
platform
::
CPUPlace
());
auto
*
cpu_ctx
=
pool
.
Get
(
paddle
::
platform
::
CPUPlace
());
return
PreparedOp
(
op
,
ctx
,
expected_kernel_key
,
return
PreparedOp
(
op
,
empty_
ctx
,
expected_kernel_key
,
std
::
move
(
pt_kernel_signature
),
pt_cpu_kernel
,
std
::
move
(
pt_kernel_signature
),
pt_cpu_kernel
,
cpu_ctx
);
cpu_ctx
);
}
}
...
@@ -373,7 +388,8 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
...
@@ -373,7 +388,8 @@ PreparedOp PrepareImpl(const NameVarMap<VarType>& ins,
dev_ctx
=
pool
.
Get
(
expected_kernel_key
.
place_
);
dev_ctx
=
pool
.
Get
(
expected_kernel_key
.
place_
);
}
}
return
PreparedOp
(
op
,
ctx
,
expected_kernel_key
,
kernel_iter
->
second
,
dev_ctx
);
return
PreparedOp
(
op
,
empty_ctx
,
expected_kernel_key
,
kernel_iter
->
second
,
dev_ctx
);
}
}
PreparedOp
PreparedOp
::
Prepare
(
const
NameVarMap
<
VarBase
>&
ins
,
PreparedOp
PreparedOp
::
Prepare
(
const
NameVarMap
<
VarBase
>&
ins
,
...
...
paddle/infrt/dialect/phi/pass/phi_op_convert_pass.cc
浏览文件 @
c56fffb4
...
@@ -193,7 +193,7 @@ void PhiOpConvertPass::convertStage() {
...
@@ -193,7 +193,7 @@ void PhiOpConvertPass::convertStage() {
op
->
replaceAllUsesWith
(
kernel_op
.
getResults
());
op
->
replaceAllUsesWith
(
kernel_op
.
getResults
());
}
else
{
}
else
{
::
phi
::
KernelSignature
kernel_sign
=
::
phi
::
KernelSignature
kernel_sign
=
::
phi
::
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
op_name
)(
(
*::
phi
::
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
op_name
)
)(
infrt
::
ProtoArgumentMappingContext
(
op
));
infrt
::
ProtoArgumentMappingContext
(
op
));
VLOG
(
3
)
<<
"IncompatiblePhiKernel: op("
<<
op_name
<<
"), kernel("
VLOG
(
3
)
<<
"IncompatiblePhiKernel: op("
<<
op_name
<<
"), kernel("
<<
kernel_sign
.
name
<<
")"
;
<<
kernel_sign
.
name
<<
")"
;
...
...
paddle/phi/core/compat/op_utils.h
浏览文件 @
c56fffb4
...
@@ -86,6 +86,14 @@ class DefaultKernelSignatureMap {
...
@@ -86,6 +86,14 @@ class DefaultKernelSignatureMap {
return
it
->
second
;
return
it
->
second
;
}
}
const
KernelSignature
*
GetNullable
(
const
std
::
string
&
op_type
)
const
{
auto
it
=
map_
.
find
(
op_type
);
if
(
it
!=
map_
.
end
())
{
return
&
it
->
second
;
}
return
nullptr
;
}
void
Insert
(
std
::
string
op_type
,
KernelSignature
signature
)
{
void
Insert
(
std
::
string
op_type
,
KernelSignature
signature
)
{
PADDLE_ENFORCE_NE
(
PADDLE_ENFORCE_NE
(
Has
(
op_type
),
Has
(
op_type
),
...
@@ -148,16 +156,13 @@ class OpUtilsMap {
...
@@ -148,16 +156,13 @@ class OpUtilsMap {
}
}
}
}
ArgumentMappingFn
GetArgumentMappingFn
(
const
std
::
string
&
op_type
)
const
{
const
ArgumentMappingFn
*
GetArgumentMappingFn
(
const
std
::
string
&
op_type
)
const
{
auto
it
=
arg_mapping_fn_map_
.
find
(
op_type
);
auto
it
=
arg_mapping_fn_map_
.
find
(
op_type
);
if
(
it
==
arg_mapping_fn_map_
.
end
())
{
if
(
it
==
arg_mapping_fn_map_
.
end
())
{
auto
func
=
return
nullptr
;
[
&
op_type
](
const
ArgumentMappingContext
&
ctx
)
->
KernelSignature
{
return
DefaultKernelSignatureMap
::
Instance
().
Get
(
op_type
);
};
return
func
;
}
else
{
}
else
{
return
it
->
second
;
return
&
it
->
second
;
}
}
}
}
...
...
paddle/phi/tests/ops/test_op_signature.cc
浏览文件 @
c56fffb4
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录