From cd5d97e34b3b79dbd12ba9baf4523934589137ba Mon Sep 17 00:00:00 2001 From: liu zhengxi <380185688@qq.com> Date: Fri, 15 Nov 2019 10:49:17 +0800 Subject: [PATCH] fix the cuda bilinear and nearest precision, test=develop (#2426) fix the cuda bilinear and nearest precision caused by data type conversion. --- lite/kernels/cuda/bilinear_interp_compute.cu | 4 ++-- lite/kernels/cuda/nearest_interp_compute.cu | 4 ++-- lite/kernels/cuda/nearest_interp_compute_test.cc | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lite/kernels/cuda/bilinear_interp_compute.cu b/lite/kernels/cuda/bilinear_interp_compute.cu index 4f8b5dc8f8..00b1457938 100644 --- a/lite/kernels/cuda/bilinear_interp_compute.cu +++ b/lite/kernels/cuda/bilinear_interp_compute.cu @@ -28,8 +28,8 @@ inline std::vector get_new_shape( for (size_t i = 0; i < list_new_shape_tensor.size(); ++i) { auto tensor = list_new_shape_tensor[i]; lite::Tensor temp; - auto temp_data = temp.mutable_data(); - auto tensor_data = tensor->data(); + auto temp_data = temp.mutable_data(); + auto tensor_data = tensor->data(); cudaMemcpy(temp_data, tensor_data, tensor->dims().production() * sizeof(float), diff --git a/lite/kernels/cuda/nearest_interp_compute.cu b/lite/kernels/cuda/nearest_interp_compute.cu index 89d9c66ccd..adae034a1d 100644 --- a/lite/kernels/cuda/nearest_interp_compute.cu +++ b/lite/kernels/cuda/nearest_interp_compute.cu @@ -28,8 +28,8 @@ inline std::vector get_new_shape( for (size_t i = 0; i < list_new_shape_tensor.size(); ++i) { auto tensor = list_new_shape_tensor[i]; lite::Tensor temp; - auto temp_data = temp.mutable_data(); - auto tensor_data = tensor->data(); + auto temp_data = temp.mutable_data(); + auto tensor_data = tensor->data(); cudaMemcpy(temp_data, tensor_data, tensor->dims().production() * sizeof(float), diff --git a/lite/kernels/cuda/nearest_interp_compute_test.cc b/lite/kernels/cuda/nearest_interp_compute_test.cc index 60e30e55de..ad2ef9294e 100644 --- a/lite/kernels/cuda/nearest_interp_compute_test.cc +++ b/lite/kernels/cuda/nearest_interp_compute_test.cc @@ -202,6 +202,7 @@ TEST(nearest_interp, update) { float* size_tensor1_ref_data = size_tensor_ref[1].mutable_data(); float* input_scale_ref_data = input_scale_ref.mutable_data(); float* osz_ref_data = osz_ref.mutable_data(); + float* out_ref_data = out_ref.mutable_data(); for (int i = 0; i < x_cpu.numel(); ++i) { x_cpu_data[i] = i + 5.0; @@ -247,8 +248,9 @@ TEST(nearest_interp, update) { CopySync( out_cpu_data, out_data, sizeof(float) * out.numel(), IoDirection::DtoH); + NearestInterpRef(&x_ref, &out_ref, false); for (int i = 0; i < out.numel(); i++) { - LOG(INFO) << out_cpu_data[i]; + EXPECT_NEAR(out_cpu_data[i], out_ref_data[i], 1e-5); } } -- GitLab