Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
942ff89f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
942ff89f
编写于
8月 02, 2022
作者:
W
Weilong Wu
提交者:
GitHub
8月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Phi] polish and rename, pt* -> phi* (#44697)
* polish and rename, pt* -> phi* * fix code format
上级
d985b4b1
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
844 addition
and
840 deletion
+844
-840
paddle/fluid/framework/new_executor/interpretercore.cc
paddle/fluid/framework/new_executor/interpretercore.cc
+3
-3
paddle/fluid/framework/new_executor/interpretercore_util.cc
paddle/fluid/framework/new_executor/interpretercore_util.cc
+12
-12
paddle/fluid/framework/new_executor/new_executor_defs.cc
paddle/fluid/framework/new_executor/new_executor_defs.cc
+3
-1
paddle/fluid/framework/new_executor/new_executor_defs.h
paddle/fluid/framework/new_executor/new_executor_defs.h
+1
-1
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+101
-100
paddle/fluid/framework/operator.h
paddle/fluid/framework/operator.h
+4
-4
paddle/fluid/imperative/op_base.h
paddle/fluid/imperative/op_base.h
+1
-1
paddle/fluid/imperative/prepared_operator.cc
paddle/fluid/imperative/prepared_operator.cc
+27
-26
paddle/phi/capi/include/kernel_utils.h
paddle/phi/capi/include/kernel_utils.h
+249
-249
paddle/phi/core/kernel_registry.h
paddle/phi/core/kernel_registry.h
+443
-443
未找到文件。
paddle/fluid/framework/new_executor/interpretercore.cc
浏览文件 @
942ff89f
...
...
@@ -621,13 +621,13 @@ void InterpreterCore::RunInstruction(const Instruction& instr_node) {
VLOG
(
4
)
<<
"Run phi kernel: "
<<
op
->
Type
();
VLOG
(
4
)
<<
instr_node
.
InnerRuntimeContext
().
get
()
<<
" "
<<
&
instr_node
.
DeviceContext
();
phi
::
KernelContext
p
t
_kernel_context
;
phi
::
KernelContext
p
hi
_kernel_context
;
op_with_kernel
->
BuildPhiKernelContext
(
*
instr_node
.
InnerRuntimeContext
().
get
(),
const_cast
<
platform
::
DeviceContext
*>
(
&
instr_node
.
DeviceContext
()),
&
p
t
_kernel_context
);
&
p
hi
_kernel_context
);
(
*
instr_node
.
PhiKernel
())(
&
p
t
_kernel_context
);
(
*
instr_node
.
PhiKernel
())(
&
p
hi
_kernel_context
);
}
else
{
instr_node
.
KernelFunc
()(
*
instr_node
.
InnerExecutionContext
().
get
());
...
...
paddle/fluid/framework/new_executor/interpretercore_util.cc
浏览文件 @
942ff89f
...
...
@@ -513,25 +513,25 @@ void build_op_func_list(const platform::Place& place,
auto
run_phi_kernel
=
false
;
if
(
phi
::
KernelFactory
::
Instance
().
HasCompatiblePhiKernel
(
op_with_kernel
->
Type
()))
{
auto
p
t
_kernel_key
=
op_with_kernel
->
ChoosePhiKernel
(
exec_ctx
);
auto
p
t
_kernel_name
=
op_with_kernel
->
PhiKernelSignature
()
->
name
;
auto
p
hi
_kernel_key
=
op_with_kernel
->
ChoosePhiKernel
(
exec_ctx
);
auto
p
hi
_kernel_name
=
op_with_kernel
->
PhiKernelSignature
()
->
name
;
if
(
op_with_kernel
->
PhiKernel
()
->
IsValid
())
{
run_phi_kernel
=
true
;
}
else
{
if
(
!
op_with_kernel
->
SupportsKernelType
(
expected_kernel_key
))
{
auto
p
t
_cpu_kernel_key
=
FallBackToCpu
(
expected_kernel_key
,
p
t
_kernel_key
,
*
op_with_kernel
);
auto
p
hi
_cpu_kernel_key
=
FallBackToCpu
(
expected_kernel_key
,
p
hi
_kernel_key
,
*
op_with_kernel
);
op_with_kernel
->
ResetPhiKernel
(
new
phi
::
Kernel
(
phi
::
KernelFactory
::
Instance
().
SelectKernel
(
p
t_kernel_name
,
pt
_cpu_kernel_key
)));
p
hi_kernel_name
,
phi
_cpu_kernel_key
)));
if
(
op_with_kernel
->
PhiKernel
()
->
IsValid
())
{
VLOG
(
6
)
<<
"Static mode PrepareImpl - kernel name: "
<<
p
t
_kernel_name
<<
" | kernel key: "
<<
p
t
_cpu_kernel_key
<<
p
hi
_kernel_name
<<
" | kernel key: "
<<
p
hi
_cpu_kernel_key
<<
" | kernel: "
<<
*
(
op_with_kernel
->
PhiKernel
());
op_with_kernel
->
ResetKernelType
(
new
OpKernelType
(
TransPhiKernelKeyToOpKernelType
(
p
t
_cpu_kernel_key
)));
TransPhiKernelKeyToOpKernelType
(
p
hi
_cpu_kernel_key
)));
run_phi_kernel
=
true
;
}
}
...
...
@@ -541,7 +541,7 @@ void build_op_func_list(const platform::Place& place,
op_with_kernel
->
ChooseKernel
(
exec_ctx
);
op_func_node
.
kernel_func_
=
*
op_with_kernel
->
kernel_func
();
}
else
{
op_func_node
.
p
t
_kernel_
=
op_with_kernel
->
PhiKernel
();
op_func_node
.
p
hi
_kernel_
=
op_with_kernel
->
PhiKernel
();
}
auto
kernel_type
=
*
(
op_with_kernel
->
kernel_type
());
if
(
kernel_type
.
place_
!=
dev_ctx
->
GetPlace
())
{
...
...
@@ -583,10 +583,10 @@ void build_op_func_list(const platform::Place& place,
// step 5. run kernel
if
(
run_phi_kernel
)
{
phi
::
KernelContext
p
t
_kernel_context
;
phi
::
KernelContext
p
hi
_kernel_context
;
op_with_kernel
->
BuildPhiKernelContext
(
runtime_context
,
dev_ctx
,
&
p
t
_kernel_context
);
(
*
op_func_node
.
p
t_kernel_
)(
&
pt
_kernel_context
);
runtime_context
,
dev_ctx
,
&
p
hi
_kernel_context
);
(
*
op_func_node
.
p
hi_kernel_
)(
&
phi
_kernel_context
);
}
else
{
// the place of exec_ctx maybe has changed.
op_func_node
.
kernel_func_
(
ExecutionContext
(
...
...
paddle/fluid/framework/new_executor/new_executor_defs.cc
浏览文件 @
942ff89f
...
...
@@ -705,7 +705,9 @@ OpKernelComputeFunc Instruction::KernelFunc() const {
return
op_func_node_
.
kernel_func_
;
}
phi
::
Kernel
*
Instruction
::
PhiKernel
()
const
{
return
op_func_node_
.
pt_kernel_
;
}
phi
::
Kernel
*
Instruction
::
PhiKernel
()
const
{
return
op_func_node_
.
phi_kernel_
;
}
OpFuncType
Instruction
::
KernelType
()
const
{
return
op_func_node_
.
type_
;
}
...
...
paddle/fluid/framework/new_executor/new_executor_defs.h
浏览文件 @
942ff89f
...
...
@@ -283,7 +283,7 @@ struct OpFuncNode {
platform
::
DeviceContext
*
dev_ctx_
;
// not owned
// fit for phi kernel
phi
::
Kernel
*
p
t
_kernel_
{
nullptr
};
// not owned
phi
::
Kernel
*
p
hi
_kernel_
{
nullptr
};
// not owned
OpFuncType
type_
;
};
...
...
paddle/fluid/framework/operator.cc
浏览文件 @
942ff89f
此差异已折叠。
点击以展开。
paddle/fluid/framework/operator.h
浏览文件 @
942ff89f
...
...
@@ -652,16 +652,16 @@ class OperatorWithKernel : public OperatorBase {
void
BuildPhiKernelContext
(
const
RuntimeContext
&
ctx
,
platform
::
DeviceContext
*
dev_ctx
,
phi
::
KernelContext
*
p
t
_kernel_context
)
const
;
phi
::
KernelContext
*
p
hi
_kernel_context
)
const
;
phi
::
KernelSignature
*
PhiKernelSignature
()
const
{
return
kernel_signature_
.
get
();
}
phi
::
Kernel
*
PhiKernel
()
const
{
return
p
t
_kernel_
.
get
();
}
phi
::
Kernel
*
PhiKernel
()
const
{
return
p
hi
_kernel_
.
get
();
}
void
ResetPhiKernel
(
phi
::
Kernel
*
kernel
)
const
{
return
p
t
_kernel_
.
reset
(
kernel
);
return
p
hi
_kernel_
.
reset
(
kernel
);
}
const
OpKernelType
*
kernel_type
()
const
{
return
kernel_type_
.
get
();
}
...
...
@@ -730,7 +730,7 @@ class OperatorWithKernel : public OperatorBase {
mutable
bool
run_phi_kernel_
=
false
;
mutable
bool
run_kp_kernel
=
false
;
mutable
std
::
unique_ptr
<
phi
::
KernelSignature
>
kernel_signature_
;
mutable
std
::
unique_ptr
<
phi
::
Kernel
>
p
t
_kernel_
;
mutable
std
::
unique_ptr
<
phi
::
Kernel
>
p
hi
_kernel_
;
mutable
std
::
unique_ptr
<
phi
::
ArgumentMappingFn
>
arg_map_fn_
;
struct
CacheImpl
;
...
...
paddle/fluid/imperative/op_base.h
浏览文件 @
942ff89f
...
...
@@ -227,7 +227,7 @@ class OpBase {
size_t
id_
{
-
1UL
};
// In order to reduce the compatibility phase
// performance overhead, temporarily cache KernelContext
static
phi
::
KernelContext
p
t
_kernel_context_
;
static
phi
::
KernelContext
p
hi
_kernel_context_
;
std
::
vector
<
std
::
shared_ptr
<
std
::
function
<
void
()
>>>
void_function_post_hooks_
;
};
...
...
paddle/fluid/imperative/prepared_operator.cc
浏览文件 @
942ff89f
...
...
@@ -183,8 +183,8 @@ PreparedOp PrepareImpl(
const
phi
::
KernelSignature
*
default_kernel_signature
=
nullptr
;
phi
::
KernelSignature
kernel_signature
;
phi
::
KernelKey
p
t
_kernel_key
;
std
::
string
p
t
_kernel_name
;
phi
::
KernelKey
p
hi
_kernel_key
;
std
::
string
p
hi
_kernel_name
;
#if defined(PADDLE_WITH_XPU)
bool
is_xpu_unsupport
=
paddle
::
platform
::
is_xpu_place
(
expected_kernel_key
.
place_
)
&&
...
...
@@ -213,7 +213,7 @@ PreparedOp PrepareImpl(
if
(
has_phi_kernel
)
{
VLOG
(
6
)
<<
kernel_signature
;
p
t
_kernel_name
=
kernel_signature
.
name
;
p
hi
_kernel_name
=
kernel_signature
.
name
;
// 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
// library_type here, otherwise it can't work.
...
...
@@ -236,34 +236,35 @@ PreparedOp PrepareImpl(
auto
expected_kernel_key_library_type
=
expected_kernel_key
.
library_type_
;
expected_kernel_key
.
library_type_
=
paddle
::
framework
::
LibraryType
::
kKP
;
VLOG
(
3
)
<<
"modifing XPU KP kernel: "
<<
p
t
_kernel_name
VLOG
(
3
)
<<
"modifing XPU KP kernel: "
<<
p
hi
_kernel_name
<<
", using_kernel_key:"
<<
expected_kernel_key
;
phi
::
KernelKey
try_p
t
_kernel_key
=
phi
::
KernelKey
try_p
hi
_kernel_key
=
TransOpKernelTypeToPhiKernelKey
(
expected_kernel_key
);
if
(
!
phi_kernel_factory
.
HasKernel
(
pt_kernel_name
,
try_pt_kernel_key
))
{
if
(
!
phi_kernel_factory
.
HasKernel
(
phi_kernel_name
,
try_phi_kernel_key
))
{
expected_kernel_key
.
library_type_
=
expected_kernel_key_library_type
;
VLOG
(
3
)
<<
"modify XPU KP kernel: "
<<
p
t
_kernel_name
VLOG
(
3
)
<<
"modify XPU KP kernel: "
<<
p
hi
_kernel_name
<<
" in dynamic graph is failed "
<<
expected_kernel_key
;
}
else
{
VLOG
(
3
)
<<
"modify XPU KP kernel: "
<<
p
t
_kernel_name
VLOG
(
3
)
<<
"modify XPU KP kernel: "
<<
p
hi
_kernel_name
<<
" in dynamic graph is succeed "
<<
expected_kernel_key
;
}
}
}
#endif
p
t
_kernel_key
=
TransOpKernelTypeToPhiKernelKey
(
expected_kernel_key
);
p
hi
_kernel_key
=
TransOpKernelTypeToPhiKernelKey
(
expected_kernel_key
);
auto
&
phi_kernel
=
phi_kernel_factory
.
SelectKernel
(
p
t_kernel_name
,
pt
_kernel_key
);
phi_kernel_factory
.
SelectKernel
(
p
hi_kernel_name
,
phi
_kernel_key
);
if
(
phi_kernel
.
IsValid
()
#if defined(PADDLE_WITH_XPU) && !defined(PADDLE_WITH_XPU_KP)
&&
!
is_xpu_unsupport
#endif
)
{
VLOG
(
6
)
<<
"Dynamic mode PrepareImpl - kernel name: "
<<
p
t
_kernel_name
<<
" | kernel key: "
<<
p
t
_kernel_key
VLOG
(
6
)
<<
"Dynamic mode PrepareImpl - kernel name: "
<<
p
hi
_kernel_name
<<
" | kernel key: "
<<
p
hi
_kernel_key
<<
" | kernel: "
<<
phi_kernel
;
if
(
expected_kernel_key
.
place_
!=
place
)
{
...
...
@@ -279,7 +280,7 @@ PreparedOp PrepareImpl(
phi_kernel
,
dev_ctx
);
}
else
{
VLOG
(
6
)
<<
"Dynamic mode ChoosePhiKernel - kernel `"
<<
p
t
_kernel_name
VLOG
(
6
)
<<
"Dynamic mode ChoosePhiKernel - kernel `"
<<
p
hi
_kernel_name
<<
"` not found."
;
}
}
...
...
@@ -316,23 +317,23 @@ PreparedOp PrepareImpl(
#endif
)
{
if
(
has_phi_kernel
)
{
auto
p
t
_cpu_kernel_key
=
FallBackToCpu
(
expected_kernel_key
,
p
t
_kernel_key
,
op
);
auto
&
p
t
_cpu_kernel
=
phi_kernel_factory
.
SelectKernel
(
p
t_kernel_name
,
pt
_cpu_kernel_key
);
if
(
p
t
_cpu_kernel
.
IsValid
())
{
VLOG
(
6
)
<<
"Dynamic mode PrepareImpl - kernel name: "
<<
p
t
_kernel_name
<<
" | kernel key: "
<<
p
t
_cpu_kernel_key
<<
" | kernel: "
<<
p
t
_cpu_kernel
;
auto
p
hi
_cpu_kernel_key
=
FallBackToCpu
(
expected_kernel_key
,
p
hi
_kernel_key
,
op
);
auto
&
p
hi
_cpu_kernel
=
phi_kernel_factory
.
SelectKernel
(
p
hi_kernel_name
,
phi
_cpu_kernel_key
);
if
(
p
hi
_cpu_kernel
.
IsValid
())
{
VLOG
(
6
)
<<
"Dynamic mode PrepareImpl - kernel name: "
<<
p
hi
_kernel_name
<<
" | kernel key: "
<<
p
hi
_cpu_kernel_key
<<
" | kernel: "
<<
p
hi
_cpu_kernel
;
auto
*
cpu_ctx
=
pool
.
Get
(
paddle
::
platform
::
CPUPlace
());
return
PreparedOp
(
op
,
empty_ctx
,
framework
::
TransPhiKernelKeyToOpKernelType
(
p
t
_cpu_kernel_key
),
framework
::
TransPhiKernelKeyToOpKernelType
(
p
hi
_cpu_kernel_key
),
arg_map_fn
,
default_kernel_signature
,
std
::
move
(
kernel_signature
),
p
t
_cpu_kernel
,
p
hi
_cpu_kernel
,
cpu_ctx
);
}
}
...
...
@@ -610,7 +611,7 @@ static void PreparedOpRunPtImpl(
PreparePhiData
<
VarType
>
(
phi_kernel
,
kernel_signature
,
ins
);
phi
::
KernelContext
p
t
_kernel_context
;
phi
::
KernelContext
p
hi
_kernel_context
;
BuildDygraphPhiKernelContext
<
VarType
>
(
kernel_signature
,
phi_kernel
,
ins
,
...
...
@@ -618,9 +619,9 @@ static void PreparedOpRunPtImpl(
attrs
,
default_attrs
,
dev_ctx
,
&
p
t
_kernel_context
);
&
p
hi
_kernel_context
);
phi_kernel
(
&
p
t
_kernel_context
);
phi_kernel
(
&
p
hi
_kernel_context
);
}
if
(
FLAGS_check_nan_inf
)
{
...
...
paddle/phi/capi/include/kernel_utils.h
浏览文件 @
942ff89f
此差异已折叠。
点击以展开。
paddle/phi/core/kernel_registry.h
浏览文件 @
942ff89f
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录