Skip to content

Fix the bug where the device memory address appears in abs_grad kernel fallback to CPU. test=kunlun #47186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion paddle/phi/api/lib/api_custom_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,15 @@ Tensor add_n_impl(const std::vector<Tensor>& x) {
(*kernel_fn)(*dev_ctx, input_x, kernel_out);
} else {
std::vector<const phi::TensorBase*> input_x(x.size());
std::vector<std::shared_ptr<phi::DenseTensor>> temp_dense_tensots;
temp_dense_tensots.reserve(x.size());
for (size_t i = 0; i < input_x.size(); ++i) {
input_x[i] = x[i].impl().get();
if (phi::DenseTensor::classof(x[i].impl().get())) {
temp_dense_tensots.push_back(PrepareData(x[i], kernel.InputAt(0), {}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个Dense判断是?

input_x[i] = temp_dense_tensots.back().get();
} else {
input_x[i] = x[i].impl().get();
}
}
auto x_meta_vec = MakeMetaTensor(input_x);
std::vector<const phi::MetaTensor*> x_metas(x_meta_vec.size());
Expand All @@ -118,6 +125,9 @@ Tensor add_n_impl(const std::vector<Tensor>& x) {
auto* kernel_fn = kernel.GetVariadicKernelFn<kernel_signature>();

(*kernel_fn)(*dev_ctx, input_x, kernel_out);
if (kernel_result.has_fallback_cpu) {
TransDataBackend(kernel_out, kernel_backend, kernel_out);
}
}

return api_output;
Expand Down
8 changes: 5 additions & 3 deletions paddle/phi/core/kernel_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ KernelResult KernelFactory::SelectKernelOrThrowError(
kernel_key,
kernel_name));

if ((FLAGS_enable_api_kernel_fallback && kernel_iter == iter->second.end())
#if defined(PADDLE_WITH_XPU) && !defined(PADDLE_WITH_XPU_KP)
|| paddle::platform::is_in_xpu_black_list(TransToFluidOpName(kernel_name))

VLOG(6) << "fluid_op_name: " << TransToFluidOpName(kernel_name);
if ((FLAGS_enable_api_kernel_fallback && kernel_iter == iter->second.end()) ||
paddle::platform::is_in_xpu_black_list(TransToFluidOpName(kernel_name))
#else
if ((FLAGS_enable_api_kernel_fallback && kernel_iter == iter->second.end())
#endif
) {
// Fallback CPU backend
Expand Down