未验证 提交 15c0c9d2 编写于 作者: Z zyfncg 提交者: GitHub

support auto fallback to cpu kernel for cusom device (#44639)

上级 42d58ddd
......@@ -110,6 +110,7 @@ const Kernel& KernelFactory::SelectKernelOrThrowError(
<< "] is not registered.";
}
#endif
auto kernel_iter = iter->second.find(kernel_key);
// TODO(chenweihang): polish refind impl here
if (kernel_iter == iter->second.end() &&
......@@ -118,6 +119,22 @@ const Kernel& KernelFactory::SelectKernelOrThrowError(
kernel_key.backend(), phi::DataLayout::ALL_LAYOUT, kernel_key.dtype());
kernel_iter = iter->second.find(any_layout_kernel_key);
}
#ifdef PADDLE_WITH_CUSTOM_DEVICE
if (kernel_iter == iter->second.end()) {
// Fallback CPU backend
phi::KernelKey cpu_kernel_key(
phi::Backend::CPU, kernel_key.layout(), kernel_key.dtype());
kernel_iter = iter->second.find(cpu_kernel_key);
if (kernel_iter == iter->second.end() &&
kernel_key.layout() != phi::DataLayout::ALL_LAYOUT) {
phi::KernelKey any_layout_kernel_key(
phi::Backend::CPU, phi::DataLayout::ALL_LAYOUT, kernel_key.dtype());
kernel_iter = iter->second.find(any_layout_kernel_key);
}
}
#endif
PADDLE_ENFORCE_NE(
kernel_iter,
iter->second.end(),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册