From 12f08a61b5933baf9ceb24609b95cb1cb85d88c8 Mon Sep 17 00:00:00 2001 From: Zhigang Gong Date: Thu, 21 Feb 2013 17:09:51 +0800 Subject: [PATCH] Use new OCL1.2 API rather than those deprecated API. Use clCreateImage to replace the old API clCreateImage2D. It will silent the compiler warnings. Signed-off-by: Zhigang Gong Reviewed-by: Homer Hsing --- utests/compiler_copy_image.cpp | 15 ++++++++++----- utests/compiler_fill_image.cpp | 9 +++++++-- utests/compiler_fill_image0.cpp | 8 +++++++- utests/compiler_movforphi_undef.cpp | 11 ++++++++--- utests/utest_helper.hpp | 4 ++-- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/utests/compiler_copy_image.cpp b/utests/compiler_copy_image.cpp index ad19cf2..685a189 100644 --- a/utests/compiler_copy_image.cpp +++ b/utests/compiler_copy_image.cpp @@ -5,11 +5,9 @@ static void compiler_copy_image(void) const size_t w = 512; const size_t h = 512; cl_image_format format; + cl_image_desc desc; cl_sampler sampler; - format.image_channel_order = CL_RGBA; - format.image_channel_data_type = CL_UNSIGNED_INT8; - // Setup kernel and images OCL_CREATE_KERNEL("test_copy_image"); buf_data[0] = (uint32_t*) malloc(sizeof(uint32_t) * w * h); @@ -17,8 +15,15 @@ static void compiler_copy_image(void) for (uint32_t i = 0; i < w; i++) ((uint32_t*)buf_data[0])[j * w + i] = j * w + i; - OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, w, h, w * sizeof(uint32_t), buf_data[0]); - OCL_CREATE_IMAGE(buf[1], 0, &format, w, h, w * sizeof(uint32_t), NULL); + format.image_channel_order = CL_RGBA; + format.image_channel_data_type = CL_UNSIGNED_INT8; + desc.image_type = CL_MEM_OBJECT_IMAGE2D; + desc.image_width = w; + desc.image_height = h; + desc.image_row_pitch = w * sizeof(uint32_t); + + OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, &desc, buf_data[0]); + OCL_CREATE_IMAGE(buf[1], 0, &format, &desc, NULL); OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST); free(buf_data[0]); buf_data[0] = NULL; diff --git a/utests/compiler_fill_image.cpp b/utests/compiler_fill_image.cpp index b15cdff..c9744cc 100644 --- a/utests/compiler_fill_image.cpp +++ b/utests/compiler_fill_image.cpp @@ -4,16 +4,21 @@ static void compiler_fill_image(void) { const size_t w = 512; const size_t h = 512; - cl_image_format format; uint32_t color = 0x12345678; + cl_image_format format; + cl_image_desc desc; format.image_channel_order = CL_RGBA; format.image_channel_data_type = CL_UNSIGNED_INT8; + desc.image_type = CL_MEM_OBJECT_IMAGE2D; + desc.image_width = w; + desc.image_height = h; + desc.image_row_pitch = w * sizeof(uint32_t); // Setup kernel and images OCL_CREATE_KERNEL("test_fill_image"); - OCL_CREATE_IMAGE(buf[0], 0, &format, w, h, w * sizeof(uint32_t), NULL); + OCL_CREATE_IMAGE(buf[0], 0, &format, &desc, NULL); // Run the kernel OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]); diff --git a/utests/compiler_fill_image0.cpp b/utests/compiler_fill_image0.cpp index ed92432..2fef90c 100644 --- a/utests/compiler_fill_image0.cpp +++ b/utests/compiler_fill_image0.cpp @@ -5,14 +5,20 @@ static void compiler_fill_image0(void) const size_t w = 512; const size_t h = 512; cl_image_format format; + cl_image_desc desc; format.image_channel_order = CL_RGBA; format.image_channel_data_type = CL_UNSIGNED_INT8; + desc.image_type = CL_MEM_OBJECT_IMAGE2D; + desc.image_width = w; + desc.image_height = h; + desc.image_row_pitch = w * sizeof(uint32_t); + // Setup kernel and images OCL_CREATE_KERNEL("test_fill_image0"); - OCL_CREATE_IMAGE(buf[0], 0, &format, w, h, w * sizeof(uint32_t), NULL); + OCL_CREATE_IMAGE(buf[0], 0, &format, &desc, NULL); // Run the kernel OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]); diff --git a/utests/compiler_movforphi_undef.cpp b/utests/compiler_movforphi_undef.cpp index f2ee009..19e395f 100644 --- a/utests/compiler_movforphi_undef.cpp +++ b/utests/compiler_movforphi_undef.cpp @@ -4,11 +4,16 @@ static void compiler_movforphi_undef(void) { const size_t w = 16; const size_t h = 16; - cl_image_format format; cl_sampler sampler; + cl_image_format format; + cl_image_desc desc; format.image_channel_order = CL_RGBA; format.image_channel_data_type = CL_UNSIGNED_INT8; + desc.image_type = CL_MEM_OBJECT_IMAGE2D; + desc.image_width = w; + desc.image_height = h; + desc.image_row_pitch = w * sizeof(uint32_t); // Setup kernel and images OCL_CREATE_KERNEL("test_movforphi_undef"); @@ -17,8 +22,8 @@ static void compiler_movforphi_undef(void) for (uint32_t i = 0; i < w; i++) ((uint32_t*)buf_data[0])[j * w + i] = j * w + i; - OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, w, h, w * sizeof(uint32_t), buf_data[0]); - OCL_CREATE_IMAGE(buf[1], 0, &format, w, h, w * sizeof(uint32_t), NULL); + OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, &desc, buf_data[0]); + OCL_CREATE_IMAGE(buf[1], 0, &format, &desc, NULL); OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST); free(buf_data[0]); buf_data[0] = NULL; diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp index 7987e75..112c74d 100644 --- a/utests/utest_helper.hpp +++ b/utests/utest_helper.hpp @@ -64,10 +64,10 @@ if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \ } while (0) -#define OCL_CREATE_IMAGE(IMAGE, FLAGS, FORMAT, W, H, PITCH, DATA) \ +#define OCL_CREATE_IMAGE(IMAGE, FLAGS, FORMAT, DESC, DATA) \ do { \ cl_int status; \ - IMAGE = clCreateImage2D(ctx, FLAGS, FORMAT, W, H, PITCH, DATA, &status);\ + IMAGE = clCreateImage(ctx, FLAGS, FORMAT, DESC, DATA, &status);\ if (status != CL_SUCCESS) OCL_THROW_ERROR(FN, status); \ } while (0) -- 2.7.4