Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c79d1186
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c79d1186
编写于
4月 22, 2022
作者:
Z
zyfncg
提交者:
GitHub
4月 22, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Dygraph performance optimization (v2) (#42103)
* optimiaze performance of PreparePhiData * dygraph performance optimization
上级
f0ec580e
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
49 addition
and
35 deletion
+49
-35
paddle/fluid/framework/infershape_utils.cc
paddle/fluid/framework/infershape_utils.cc
+3
-3
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+14
-8
paddle/fluid/imperative/prepared_operator.h
paddle/fluid/imperative/prepared_operator.h
+4
-4
paddle/fluid/pybind/imperative.cc
paddle/fluid/pybind/imperative.cc
+3
-3
paddle/fluid/pybind/kernel_signature_generator.cc
paddle/fluid/pybind/kernel_signature_generator.cc
+4
-4
paddle/infrt/dialect/phi/pass/phi_op_convert_pass.cc
paddle/infrt/dialect/phi/pass/phi_op_convert_pass.cc
+2
-2
paddle/phi/core/compat/arg_map_context.cc
paddle/phi/core/compat/arg_map_context.cc
+3
-3
paddle/phi/core/compat/arg_map_context.h
paddle/phi/core/compat/arg_map_context.h
+14
-4
paddle/phi/tests/ops/test_op_signature.cc
paddle/phi/tests/ops/test_op_signature.cc
+2
-4
未找到文件。
paddle/fluid/framework/infershape_utils.cc
浏览文件 @
c79d1186
...
...
@@ -414,9 +414,9 @@ CompatInferMetaContext BuildInferMetaContext(InferShapeContext* ctx,
CompatInferMetaContext
infer_meta_context
(
{
ctx
->
IsRuntime
(),
ctx
->
IsRunMKLDNNKernel
()});
auto
&
input_names
=
std
::
get
<
0
>
(
signature
.
args
)
;
auto
&
attr_names
=
std
::
get
<
1
>
(
signature
.
args
)
;
auto
&
output_names
=
std
::
get
<
2
>
(
signature
.
args
)
;
const
auto
&
input_names
=
signature
.
input_names
;
const
auto
&
attr_names
=
signature
.
attr_names
;
const
auto
&
output_names
=
signature
.
output_names
;
const
auto
&
args_def
=
phi
::
KernelFactory
::
Instance
().
GetFirstKernelArgsDef
(
signature
.
name
);
...
...
paddle/fluid/framework/operator.cc
浏览文件 @
c79d1186
...
...
@@ -1198,8 +1198,10 @@ bool OperatorWithKernel::SupportsMKLDNN(
bool
OperatorWithKernel
::
CanMKLDNNBeUsed
(
const
framework
::
ExecutionContext
&
ctx
,
proto
::
VarType
::
Type
data_type
)
const
{
bool
use_mkldnn_ctx
=
ctx
.
HasAttr
(
"use_mkldnn"
)
&&
ctx
.
Attr
<
bool
>
(
"use_mkldnn"
)
&&
const
auto
&
attrs_map
=
ctx
.
Attrs
();
auto
iter
=
attrs_map
.
find
(
"use_mkldnn"
);
bool
use_mkldnn_ctx
=
iter
!=
attrs_map
.
end
()
&&
BOOST_GET_CONST
(
bool
,
iter
->
second
)
&&
platform
::
is_cpu_place
(
ctx
.
GetPlace
());
return
use_mkldnn_ctx
&&
this
->
SupportsMKLDNN
(
data_type
);
}
...
...
@@ -2124,7 +2126,7 @@ KernelSignature OperatorWithKernel::GetExpectedPhiKernelArgs(
Scope
*
OperatorWithKernel
::
PreparePhiData
(
const
Scope
&
scope
,
const
phi
::
Kernel
&
pt_kernel
,
const
KernelSignature
&
pt_kernel_signature
,
RuntimeContext
*
ctx
)
const
{
auto
&
input_names
=
std
::
get
<
0
>
(
pt_kernel_signature
.
args
)
;
const
auto
&
input_names
=
pt_kernel_signature
.
input_names
;
auto
input_defs
=
pt_kernel
.
args_def
().
input_defs
();
PADDLE_ENFORCE_EQ
(
input_names
.
size
(),
input_defs
.
size
(),
platform
::
errors
::
InvalidArgument
(
...
...
@@ -2176,11 +2178,15 @@ Scope* OperatorWithKernel::PreparePhiData(
if
(
in_def
.
backend
==
phi
::
Backend
::
ALL_BACKEND
)
{
continue
;
}
auto
expected_place
=
phi
::
TransToPhiPlace
(
in_def
.
backend
);
if
(
platform
::
is_same_place
(
tensor_in
->
place
(),
expected_place
))
{
auto
tensor_backend
=
phi
::
TransToPhiBackend
(
tensor_in
->
place
());
if
(
in_def
.
backend
==
tensor_backend
||
(
in_def
.
backend
==
phi
::
Backend
::
GPUDNN
&&
tensor_backend
==
phi
::
Backend
::
GPU
))
{
continue
;
}
auto
expected_place
=
phi
::
TransToPhiPlace
(
in_def
.
backend
);
VLOG
(
3
)
<<
"phi Transform Variable "
<<
input_names
[
i
]
<<
" from "
<<
tensor_in
->
place
()
<<
" to "
<<
expected_place
;
...
...
@@ -2217,9 +2223,9 @@ void OperatorWithKernel::BuildPhiKernelContext(
phi
::
KernelContext
*
pt_kernel_context
)
const
{
pt_kernel_context
->
SetDeviceContext
(
dev_ctx
);
auto
&
input_names
=
std
::
get
<
0
>
(
pt_kernel_signature_
->
args
)
;
auto
&
attr_names
=
std
::
get
<
1
>
(
pt_kernel_signature_
->
args
)
;
auto
&
output_names
=
std
::
get
<
2
>
(
pt_kernel_signature_
->
args
)
;
auto
&
input_names
=
pt_kernel_signature_
->
input_names
;
auto
&
attr_names
=
pt_kernel_signature_
->
attr_names
;
auto
&
output_names
=
pt_kernel_signature_
->
output_names
;
auto
input_defs
=
pt_kernel_
->
args_def
().
input_defs
();
auto
attr_defs
=
pt_kernel_
->
args_def
().
attribute_defs
();
...
...
paddle/fluid/imperative/prepared_operator.h
浏览文件 @
c79d1186
...
...
@@ -233,9 +233,9 @@ void BuildDygraphPhiKernelContext(
platform
::
DeviceContext
*
dev_ctx
,
phi
::
KernelContext
*
kernel_ctx
)
{
kernel_ctx
->
SetDeviceContext
(
dev_ctx
);
auto
&
input_names
=
std
::
get
<
0
>
(
pt_kernel_signature
.
args
)
;
auto
&
attr_names
=
std
::
get
<
1
>
(
pt_kernel_signature
.
args
)
;
auto
&
output_names
=
std
::
get
<
2
>
(
pt_kernel_signature
.
args
)
;
const
auto
&
input_names
=
pt_kernel_signature
.
input_names
;
const
auto
&
attr_names
=
pt_kernel_signature
.
attr_names
;
const
auto
&
output_names
=
pt_kernel_signature
.
output_names
;
auto
&
input_defs
=
pt_kernel
.
args_def
().
input_defs
();
auto
&
output_defs
=
pt_kernel
.
args_def
().
output_defs
();
...
...
@@ -570,7 +570,7 @@ template <typename VarType>
void
PreparePhiData
(
const
phi
::
Kernel
&
pt_kernel
,
const
framework
::
KernelSignature
&
pt_kernel_signature
,
const
NameVarMap
<
VarType
>&
ins
)
{
auto
&
input_names
=
std
::
get
<
0
>
(
pt_kernel_signature
.
args
)
;
const
auto
&
input_names
=
pt_kernel_signature
.
input_names
;
auto
&
input_defs
=
pt_kernel
.
args_def
().
input_defs
();
PADDLE_ENFORCE_EQ
(
input_names
.
size
(),
input_defs
.
size
(),
...
...
paddle/fluid/pybind/imperative.cc
浏览文件 @
c79d1186
...
...
@@ -2050,9 +2050,9 @@ void BindImperative(py::module *m_ptr) {
};
auto
ret
=
self
.
GetExpectedKernelSignature
(
type
,
ins_map
,
outs_map
,
attrs
);
auto
kernelsig_ins
=
input_to_vector
(
std
::
get
<
0
>
(
ret
.
args
)
);
auto
kernelsig_attrs
=
attr_to_vector
(
std
::
get
<
1
>
(
ret
.
args
)
);
auto
kernelsig_outs
=
output_to_vector
(
std
::
get
<
2
>
(
ret
.
args
)
);
auto
kernelsig_ins
=
input_to_vector
(
ret
.
input_names
);
auto
kernelsig_attrs
=
attr_to_vector
(
ret
.
attr_names
);
auto
kernelsig_outs
=
output_to_vector
(
ret
.
output_names
);
return
std
::
make_tuple
(
kernelsig_ins
,
kernelsig_attrs
,
kernelsig_outs
);
}
...
...
paddle/fluid/pybind/kernel_signature_generator.cc
浏览文件 @
c79d1186
...
...
@@ -58,10 +58,10 @@ int main(int argc, char **argv) {
if
(
kernel_signature_map
.
Has
(
op_name
))
{
kernel_signature_map_str
=
kernel_signature_map_str
+
"
\"
"
+
op_kernel_pair
.
first
+
"
\"
:{"
;
auto
&
args
=
kernel_signature_map
.
Get
(
op_name
).
args
;
const
auto
&
args
=
kernel_signature_map
.
Get
(
op_name
)
;
kernel_signature_map_str
+=
"
\"
inputs
\"
:["
;
auto
inputs_
=
std
::
get
<
0
>
(
args
)
;
auto
inputs_
=
args
.
input_names
;
for
(
size_t
i
=
0
;
i
<
inputs_
.
size
();
i
++
)
{
kernel_signature_map_str
=
kernel_signature_map_str
+
"
\"
"
+
inputs_
[
i
]
+
"
\"
,"
;
...
...
@@ -69,14 +69,14 @@ int main(int argc, char **argv) {
if
(
inputs_
.
size
())
kernel_signature_map_str
.
pop_back
();
kernel_signature_map_str
+=
"],
\"
attrs
\"
:["
;
auto
attrs_
=
std
::
get
<
1
>
(
args
)
;
auto
attrs_
=
args
.
attr_names
;
for
(
size_t
i
=
0
;
i
<
attrs_
.
size
();
i
++
)
{
kernel_signature_map_str
=
kernel_signature_map_str
+
"
\"
"
+
attrs_
[
i
]
+
"
\"
,"
;
}
if
(
attrs_
.
size
())
kernel_signature_map_str
.
pop_back
();
kernel_signature_map_str
+=
"],
\"
outputs
\"
:["
;
auto
outputs_
=
std
::
get
<
2
>
(
args
)
;
auto
outputs_
=
args
.
output_names
;
for
(
size_t
i
=
0
;
i
<
outputs_
.
size
();
i
++
)
{
kernel_signature_map_str
=
kernel_signature_map_str
+
"
\"
"
+
outputs_
[
i
]
+
"
\"
,"
;
...
...
paddle/infrt/dialect/phi/pass/phi_op_convert_pass.cc
浏览文件 @
c79d1186
...
...
@@ -200,7 +200,7 @@ void PhiOpConvertPass::convertStage() {
// 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
)
)
{
for
(
const
std
::
string
&
str
:
kernel_sign
.
input_names
)
{
if
(
pd_dialect_inputs_info_map_
.
at
(
op_name
).
count
(
str
)
==
0
)
{
LOG
(
ERROR
)
<<
"No input info for Op "
<<
op_name
<<
" and argument "
<<
str
;
...
...
@@ -210,7 +210,7 @@ void PhiOpConvertPass::convertStage() {
inputs
.
push_back
(
op
->
getOperands
()[
index
]);
}
for
(
const
std
::
string
&
str
:
std
::
get
<
2
>
(
kernel_sign
.
args
)
)
{
for
(
const
std
::
string
&
str
:
kernel_sign
.
output_names
)
{
if
(
pd_dialect_outputs_info_map_
.
at
(
op_name
).
count
(
str
)
==
0
)
{
LOG
(
ERROR
)
<<
"No output info for Op "
<<
op_name
<<
" and argument "
<<
str
;
...
...
paddle/phi/core/compat/arg_map_context.cc
浏览文件 @
c79d1186
...
...
@@ -20,11 +20,11 @@ limitations under the License. */
namespace
phi
{
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
KernelSignature
signature
)
{
os
<<
"Kernel Signature - name: "
<<
signature
.
name
<<
"; inputs: "
<<
paddle
::
string
::
join_strings
(
s
td
::
get
<
0
>
(
signature
.
args
)
,
", "
)
<<
paddle
::
string
::
join_strings
(
s
ignature
.
input_names
,
", "
)
<<
"; attributes: "
<<
paddle
::
string
::
join_strings
(
s
td
::
get
<
1
>
(
signature
.
args
)
,
", "
)
<<
paddle
::
string
::
join_strings
(
s
ignature
.
attr_names
,
", "
)
<<
"; outputs: "
<<
paddle
::
string
::
join_strings
(
s
td
::
get
<
2
>
(
signature
.
args
)
,
", "
);
<<
paddle
::
string
::
join_strings
(
s
ignature
.
output_names
,
", "
);
return
os
;
}
...
...
paddle/phi/core/compat/arg_map_context.h
浏览文件 @
c79d1186
...
...
@@ -33,7 +33,9 @@ using KernelArgsTuple = std::tuple<paddle::SmallVector<const char*>,
struct
KernelSignature
{
const
char
*
name
;
KernelArgsTuple
args
;
paddle
::
SmallVector
<
const
char
*>
input_names
;
paddle
::
SmallVector
<
const
char
*>
attr_names
;
paddle
::
SmallVector
<
const
char
*>
output_names
;
KernelSignature
()
=
default
;
...
...
@@ -41,18 +43,26 @@ struct KernelSignature {
paddle
::
SmallVector
<
const
char
*>&&
inputs
,
paddle
::
SmallVector
<
const
char
*>&&
attrs
,
paddle
::
SmallVector
<
const
char
*>&&
outputs
)
:
name
(
kernel_name
),
args
(
std
::
make_tuple
(
inputs
,
attrs
,
outputs
))
{}
:
name
(
kernel_name
),
input_names
(
std
::
move
(
inputs
)),
attr_names
(
std
::
move
(
attrs
)),
output_names
(
std
::
move
(
outputs
))
{}
KernelSignature
(
const
char
*
kernel_name
,
const
paddle
::
SmallVector
<
const
char
*>&
inputs
,
const
paddle
::
SmallVector
<
const
char
*>&
attrs
,
const
paddle
::
SmallVector
<
const
char
*>&
outputs
)
:
name
(
kernel_name
),
args
(
std
::
make_tuple
(
inputs
,
attrs
,
outputs
))
{}
:
name
(
kernel_name
),
input_names
(
inputs
),
attr_names
(
attrs
),
output_names
(
outputs
)
{}
// TODO(chenweihang): add assign constructor to solve windows compile
// problem, remove it later
KernelSignature
&
operator
=
(
const
KernelSignature
&
other
)
{
name
=
other
.
name
;
args
=
other
.
args
;
input_names
=
other
.
input_names
;
attr_names
=
other
.
attr_names
;
output_names
=
other
.
output_names
;
return
*
this
;
}
};
...
...
paddle/phi/tests/ops/test_op_signature.cc
浏览文件 @
c79d1186
...
...
@@ -560,8 +560,7 @@ TEST(ARG_MAP, allclose) {
auto
signature1
=
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
"allclose"
)(
arg_case1
);
ASSERT_EQ
(
signature1
.
name
,
"allclose"
);
auto
attr_names1
=
std
::
get
<
1
>
(
signature1
.
args
);
ASSERT_EQ
(
attr_names1
[
0
],
"Rtol"
);
ASSERT_EQ
(
signature1
.
attr_names
[
0
],
"Rtol"
);
TestArgumentMappingContext
arg_case2
(
{
"Input"
,
"Other"
,
"Atol"
},
...
...
@@ -573,8 +572,7 @@ TEST(ARG_MAP, allclose) {
auto
signature2
=
OpUtilsMap
::
Instance
().
GetArgumentMappingFn
(
"allclose"
)(
arg_case2
);
ASSERT_EQ
(
signature2
.
name
,
"allclose"
);
auto
attr_names2
=
std
::
get
<
1
>
(
signature2
.
args
);
ASSERT_EQ
(
attr_names2
[
1
],
"Atol"
);
ASSERT_EQ
(
signature2
.
attr_names
[
1
],
"Atol"
);
}
TEST
(
ARG_MAP
,
reshape
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录