Skip to content

Commit

Permalink
Fix bug when eigen_device() is nullptr in top_k (PaddlePaddle#40459)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzSean authored Mar 14, 2022
1 parent 88ec08a commit 29453da
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions paddle/phi/kernels/gpu/top_k_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ void TopkKernel(const Context& dev_ctx,
// The conclusion is drawn from the data through multiple sets of
// statistics
if (input_width >= 128 && k >= input_width * 0.75) {
if (ops::SortTopk<T>(
paddle::platform::CUDADeviceContext(dev_ctx.GetPlace()),
input,
input_width,
input_height,
k,
out,
indices,
largest)) {
auto* ctx = reinterpret_cast<const paddle::platform::CUDADeviceContext*>(
&dev_ctx);
if (ops::SortTopk<T>(*ctx,
input,
input_width,
input_height,
k,
out,
indices,
largest)) {
// Successed, return.
return;
} else {
Expand Down Expand Up @@ -181,15 +182,16 @@ void TopkKernel(const Context& dev_ctx,
// The conclusion is drawn from the data through multiple sets of
// statistics
if (input_width >= 128 && k >= input_width * 0.75) {
if (ops::SortTopk<T>(
paddle::platform::CUDADeviceContext(dev_ctx.GetPlace()),
&trans_input,
input_width,
input_height,
k,
&trans_out,
&trans_ind,
largest)) {
auto* ctx = reinterpret_cast<const paddle::platform::CUDADeviceContext*>(
&dev_ctx);
if (ops::SortTopk<T>(*ctx,
&trans_input,
input_width,
input_height,
k,
&trans_out,
&trans_ind,
largest)) {
// last step, tranpose back the indices and output
funcs::TransCompute<phi::GPUContext, int64_t>(
ndims, dev_ctx, trans_ind, indices, trans);
Expand Down

0 comments on commit 29453da

Please sign in to comment.