From 508ca98ba91b9bf7f60ae659294b3908e068a072 Mon Sep 17 00:00:00 2001 From: Jiaying Zhao Date: Sat, 12 Oct 2019 16:18:58 +0800 Subject: [PATCH] fix clang compile error. test=develop (#2180) --- mobile/src/framework/cl/cl_helper.h | 12 ++++++------ mobile/src/framework/cl/cl_image.cpp | 4 ++-- mobile/src/framework/cl/cl_image.h | 5 +++-- .../operators/kernel/cl/elementwise_add_kernel.cpp | 8 ++++---- mobile/src/operators/kernel/cl/prior_box_kernel.cpp | 6 +++--- mobile/test/net/test_net.cpp | 4 ++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/mobile/src/framework/cl/cl_helper.h b/mobile/src/framework/cl/cl_helper.h index 09beb7c72f..893456211d 100644 --- a/mobile/src/framework/cl/cl_helper.h +++ b/mobile/src/framework/cl/cl_helper.h @@ -66,9 +66,9 @@ class CLHelper { auto h = image_dim[2]; auto w = image_dim[3]; auto image_width = image.ImageWidth(); - auto work_size_0 = image_width / w; - auto work_size_1 = w; - auto work_size_2 = n * h; + size_t work_size_0 = image_width / w; + size_t work_size_1 = w; + size_t work_size_2 = n * h; return {work_size_0, work_size_1, work_size_2}; } else if (image_dim.size() == 2) { auto h = image_dim[0]; @@ -77,9 +77,9 @@ class CLHelper { } else if (image_dim.size() == 1) { return {1, image.ImageWidth(), 1}; } else if (image_dim.size() == 3) { - int c = image_dim[0]; - int h = image_dim[1]; - int w = image_dim[2]; + size_t c = image_dim[0]; + size_t h = image_dim[1]; + size_t w = image_dim[2]; return {(c + 3) / 4, w, h}; } PADDLE_MOBILE_THROW_EXCEPTION(" not support this dim, need imp "); diff --git a/mobile/src/framework/cl/cl_image.cpp b/mobile/src/framework/cl/cl_image.cpp index 4f4b0d8883..0d4cf87db0 100644 --- a/mobile/src/framework/cl/cl_image.cpp +++ b/mobile/src/framework/cl/cl_image.cpp @@ -119,8 +119,8 @@ void TensorToCLImage(Tensor *tensor, CLImage *cl_image, cl_context context, #ifdef PADDLE_MOBILE_DEBUG Print &operator<<(Print &printer, const CLImage &cl_image) { - int width = cl_image.ImageDims()[0]; - int height = cl_image.ImageDims()[1]; + size_t width = cl_image.ImageDims()[0]; + size_t height = cl_image.ImageDims()[1]; half_t *image_data = new half_t[height * width * 4]; cl_int err; diff --git a/mobile/src/framework/cl/cl_image.h b/mobile/src/framework/cl/cl_image.h index f648ca0443..3a09436a1f 100644 --- a/mobile/src/framework/cl/cl_image.h +++ b/mobile/src/framework/cl/cl_image.h @@ -177,7 +177,7 @@ class CLImage { * init cl mem with a exist cl mem */ void InitWithExistMem(cl_context context, cl_command_queue command_queue, - DDim need_dims, CLImage &src) { + DDim need_dims, const CLImage &src) { CLImageConverterNormal *normal_converter = new CLImageConverterNormal(); real_image_dims_ = src.real_image_dims_; @@ -271,7 +271,8 @@ class CLImage { CLImageConverterBase *Converter() const { return image_converter_; } private: - void InitCLImage(cl_context context, int width, int height, void *data) { + void InitCLImage(cl_context context, size_t width, size_t height, + void *data) { cl_image_format cf = {.image_channel_order = CL_RGBA, .image_channel_data_type = CL_HALF_FLOAT}; cl_image_desc cid = { diff --git a/mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp b/mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp index 1506956280..06d718601c 100644 --- a/mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp +++ b/mobile/src/operators/kernel/cl/elementwise_add_kernel.cpp @@ -77,8 +77,8 @@ void ElementwiseAddKernel::Compute( status = clSetKernelArg(kernel, 2, sizeof(cl_mem), reinterpret_cast(&output_image)); CL_CHECK_ERRORS(status); - int width = input->ImageWidth(); - int height = input->ImageHeight(); + auto width = input->ImageWidth(); + auto height = input->ImageHeight(); size_t global_work_size[2] = {width, height}; status = clEnqueueNDRangeKernel(this->cl_helper_.CLCommandQueue(), kernel, 2, @@ -103,8 +103,8 @@ void ElementwiseAddKernel::Compute( status = clSetKernelArg(kernel, 3, sizeof(cl_int), reinterpret_cast(&tensor_w)); CL_CHECK_ERRORS(status); - int width = input->ImageWidth(); - int height = input->ImageHeight(); + auto width = input->ImageWidth(); + auto height = input->ImageHeight(); DLOG << "dede:" << width << "," << height; size_t global_work_size[2] = {width, height}; cl_event out_event = param.Out()->GetClEvent(); diff --git a/mobile/src/operators/kernel/cl/prior_box_kernel.cpp b/mobile/src/operators/kernel/cl/prior_box_kernel.cpp index 92764b379e..c10bfed8d1 100644 --- a/mobile/src/operators/kernel/cl/prior_box_kernel.cpp +++ b/mobile/src/operators/kernel/cl/prior_box_kernel.cpp @@ -121,9 +121,9 @@ void PriorBoxKernel::Compute( auto kernel = this->cl_helper_.KernelAt(0); auto default_work_size = this->cl_helper_.DefaultWorkSize(*param.OutputBoxes()); - int c_block = default_work_size[0]; - int w = default_work_size[1]; - int nh = default_work_size[2]; + auto c_block = default_work_size[0]; + auto w = default_work_size[1]; + auto nh = default_work_size[2]; std::vector box_shape({num_priors}); framework::DDim ddim = framework::make_ddim(box_shape); diff --git a/mobile/test/net/test_net.cpp b/mobile/test/net/test_net.cpp index 74a124e46c..0251d774dd 100644 --- a/mobile/test/net/test_net.cpp +++ b/mobile/test/net/test_net.cpp @@ -185,8 +185,8 @@ void test(int argc, char *argv[]) { if (len == 0) { continue; } - int width = cl_image->ImageDims()[0]; - int height = cl_image->ImageDims()[1]; + size_t width = cl_image->ImageDims()[0]; + size_t height = cl_image->ImageDims()[1]; paddle_mobile::framework::half_t *image_data = new paddle_mobile::framework::half_t[height * width * 4]; cl_int err; -- GitLab