From daf5aa9b8b4fae099e3536e8ed05837a74796afd Mon Sep 17 00:00:00 2001 From: whs Date: Tue, 29 Sep 2020 07:07:11 +0800 Subject: [PATCH] Fix round in grid sample op (#27657) --- paddle/fluid/operators/grid_sampler_op.cu | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/operators/grid_sampler_op.cu b/paddle/fluid/operators/grid_sampler_op.cu index b250407fdb..e9b0a0108a 100644 --- a/paddle/fluid/operators/grid_sampler_op.cu +++ b/paddle/fluid/operators/grid_sampler_op.cu @@ -238,9 +238,8 @@ __global__ void grid_sample_cuda_kernel(const int nthreads, int n, int out_c, } } } else if (mode == Mode::nearest) { - int ix_nearest = static_cast(round(ix)); - int iy_nearest = static_cast(round(iy)); - + int ix_nearest = static_cast(std::nearbyint(ix)); + int iy_nearest = static_cast(std::nearbyint(iy)); auto inp_offset_NC = n * inp_sN; auto out_ptr_NCHW = output + n * out_sN + h * out_sH + w * out_sW; for (int c = 0; c < out_c; @@ -403,8 +402,8 @@ __global__ void grid_sampler_cuda_backward_kernel( gGrid_ptr_NHW[1] = giy_mult * giy; } } else if (mode == Mode::nearest) { - int ix_nearest = static_cast(::round(ix)); - int iy_nearest = static_cast(::round(iy)); + int ix_nearest = static_cast(std::nearbyint(ix)); + int iy_nearest = static_cast(std::nearbyint(iy)); int gOut_offset = n * gOut_sN + h * gOut_sH + w * gOut_sW; T* gInp_ptr_NC = grad_input + n * inp_sN; -- GitLab