Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
7ffde4bc
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
未验证
提交
7ffde4bc
编写于
12月 19, 2022
作者:
H
HongyuJia
提交者:
GitHub
12月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
simplify FallbackToCpu (#49124)
上级
ff79c144
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
25 addition
and
27 deletion
+25
-27
paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc
...id/framework/new_executor/interpreter/interpreter_util.cc
+2
-2
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+1
-2
paddle/fluid/framework/phi_utils.cc
paddle/fluid/framework/phi_utils.cc
+20
-19
paddle/fluid/framework/phi_utils.h
paddle/fluid/framework/phi_utils.h
+1
-2
paddle/fluid/imperative/prepared_operator.cc
paddle/fluid/imperative/prepared_operator.cc
+1
-2
未找到文件。
paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc
浏览文件 @
7ffde4bc
...
...
@@ -651,8 +651,8 @@ void BuildOpFuncList(const platform::Place& place,
}
else
{
if
(
!
op_with_kernel
->
SupportsKernelType
(
expected_kernel_key
,
exec_ctx
))
{
auto
phi_cpu_kernel_key
=
FallBackToCpu
(
expected_kernel_key
,
phi_kernel_key
,
*
op_with_kernel
);
auto
phi_cpu_kernel_key
=
FallBackToCpu
(
phi_kernel_key
,
*
op_with_kernel
);
op_with_kernel
->
ResetPhiKernel
(
new
phi
::
Kernel
(
phi
::
KernelFactory
::
Instance
().
SelectKernel
(
phi_kernel_name
,
phi_cpu_kernel_key
)));
...
...
paddle/fluid/framework/operator.cc
浏览文件 @
7ffde4bc
...
...
@@ -1808,8 +1808,7 @@ void OperatorWithKernel::RunImpl(const Scope& scope,
#endif
)
{
fallback_to_cpu
=
true
;
auto
phi_cpu_kernel_key
=
FallBackToCpu
(
*
kernel_type_
.
get
(),
phi_kernel_key
,
*
this
);
auto
phi_cpu_kernel_key
=
FallBackToCpu
(
phi_kernel_key
,
*
this
);
phi_kernel_
.
reset
(
new
phi
::
Kernel
(
phi
::
KernelFactory
::
Instance
().
SelectKernel
(
phi_kernel_name
,
phi_cpu_kernel_key
)));
...
...
paddle/fluid/framework/phi_utils.cc
浏览文件 @
7ffde4bc
...
...
@@ -100,58 +100,59 @@ phi::KernelKey TransOpKernelTypeToPhiKernelKey(
framework
::
TransToPhiDataType
(
kernel_type
.
data_type_
));
}
phi
::
KernelKey
FallBackToCpu
(
const
OpKernelType
&
expected_kernel_key
,
const
phi
::
KernelKey
&
kernel_key
,
phi
::
KernelKey
FallBackToCpu
(
const
phi
::
KernelKey
&
kernel_key
,
const
framework
::
OperatorBase
&
op
)
{
#ifdef PADDLE_WITH_XPU
if
(
platform
::
is_xpu_place
(
expected_kernel_key
.
place_
)
||
if
(
kernel_key
.
backend
()
==
phi
::
Backend
::
XPU
||
paddle
::
platform
::
is_in_xpu_black_list
(
op
.
Type
()))
{
VLOG
(
3
)
<<
"phi missing XPU kernel: "
<<
op
.
Type
()
<<
", expected_kernel_key:"
<<
expected_
kernel_key
<<
", fallback
ing
to CPU one!"
;
<<
", expected_kernel_key:"
<<
kernel_key
<<
", fallback to CPU one!"
;
return
phi
::
KernelKey
(
phi
::
Backend
::
CPU
,
kernel_key
.
layout
(),
kernel_key
.
dtype
());
}
#endif
#ifdef PADDLE_WITH_ASCEND_CL
if
(
platform
::
is_npu_place
(
expected_kernel_key
.
place_
)
)
{
if
(
kernel_key
.
backend
()
==
phi
::
Backend
::
NPU
)
{
VLOG
(
3
)
<<
"phi missing NPU kernel: "
<<
op
.
Type
()
<<
", expected_kernel_key:"
<<
expected_
kernel_key
<<
", fallback
ing
to CPU one!"
;
<<
", expected_kernel_key:"
<<
kernel_key
<<
", fallback to CPU one!"
;
return
phi
::
KernelKey
(
phi
::
Backend
::
CPU
,
kernel_key
.
layout
(),
kernel_key
.
dtype
());
}
#endif
#ifdef PADDLE_WITH_MLU
if
(
platform
::
is_mlu_place
(
expected_kernel_key
.
place_
)
)
{
if
(
kernel_key
.
backend
()
==
phi
::
Backend
::
MLU
)
{
VLOG
(
3
)
<<
"phi missing MLU kernel: "
<<
op
.
Type
()
<<
", expected_kernel_key:"
<<
expected_
kernel_key
<<
", fallback
ing
to CPU one!"
;
<<
", expected_kernel_key:"
<<
kernel_key
<<
", fallback to CPU one!"
;
return
phi
::
KernelKey
(
phi
::
Backend
::
CPU
,
kernel_key
.
layout
(),
kernel_key
.
dtype
());
}
#endif
#ifdef PADDLE_WITH_IPU
if
(
platform
::
is_ipu_place
(
expected_kernel_key
.
place_
)
)
{
if
(
kernel_key
.
backend
()
==
phi
::
Backend
::
IPU
)
{
VLOG
(
3
)
<<
"phi missing IPU kernel: "
<<
op
.
Type
()
<<
", expected_kernel_key:"
<<
expected_
kernel_key
<<
", fallback
ing
to CPU one!"
;
<<
", expected_kernel_key:"
<<
kernel_key
<<
", fallback to CPU one!"
;
return
phi
::
KernelKey
(
phi
::
Backend
::
CPU
,
kernel_key
.
layout
(),
kernel_key
.
dtype
());
}
#endif
#ifdef PADDLE_WITH_CUSTOM_DEVICE
if
(
platform
::
is_custom_place
(
expected_kernel_key
.
place_
))
{
VLOG
(
3
)
<<
"phi missing "
<<
expected_kernel_key
.
place_
.
GetDeviceType
()
auto
place
=
phi
::
TransToPhiPlace
(
kernel_key
.
backend
());
if
(
platform
::
is_custom_place
(
place
))
{
VLOG
(
3
)
<<
"phi missing "
<<
place
.
GetDeviceType
()
<<
" kernel: "
<<
op
.
Type
()
<<
", expected_kernel_key:"
<<
expected_
kernel_key
<<
", fallback
ing
to CPU one!"
;
<<
", expected_kernel_key:"
<<
kernel_key
<<
", fallback to CPU one!"
;
return
phi
::
KernelKey
(
phi
::
Backend
::
CPU
,
kernel_key
.
layout
(),
kernel_key
.
dtype
());
}
#endif
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
if
(
platform
::
is_gpu_place
(
expected_kernel_key
.
place_
))
{
if
(
kernel_key
.
backend
()
==
phi
::
Backend
::
GPU
||
kernel_key
.
backend
()
==
phi
::
Backend
::
GPUDNN
)
{
PADDLE_THROW
(
platform
::
errors
::
Unavailable
(
"For GPU kernel, they must not fallback into CPU kernel."
));
}
...
...
paddle/fluid/framework/phi_utils.h
浏览文件 @
7ffde4bc
...
...
@@ -43,8 +43,7 @@ namespace framework {
OpKernelType
TransPhiKernelKeyToOpKernelType
(
const
phi
::
KernelKey
&
kernel_key
);
phi
::
KernelKey
TransOpKernelTypeToPhiKernelKey
(
const
OpKernelType
&
kernel_type
);
phi
::
KernelKey
FallBackToCpu
(
const
OpKernelType
&
expected_kernel_key
,
const
phi
::
KernelKey
&
kernel_key
,
phi
::
KernelKey
FallBackToCpu
(
const
phi
::
KernelKey
&
kernel_key
,
const
framework
::
OperatorBase
&
op
);
/* Kernel Args parse */
...
...
paddle/fluid/imperative/prepared_operator.cc
浏览文件 @
7ffde4bc
...
...
@@ -393,8 +393,7 @@ PreparedOp PrepareImpl(
#endif
)
{
if
(
has_phi_kernel
)
{
auto
phi_cpu_kernel_key
=
FallBackToCpu
(
expected_kernel_key
,
phi_kernel_key
,
op
);
auto
phi_cpu_kernel_key
=
FallBackToCpu
(
phi_kernel_key
,
op
);
auto
&
phi_cpu_kernel
=
phi_kernel_factory
.
SelectKernel
(
phi_kernel_name
,
phi_cpu_kernel_key
);
if
(
phi_cpu_kernel
.
IsValid
())
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录