[Beignet] [PATCH 4/4] utests: add one test case to test get_image_width/height.
Zhigang Gong
zhigang.gong at linux.intel.com
Fri May 17 02:00:00 PDT 2013
Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
---
kernels/test_get_image_size.cl | 9 +++++++++
utests/CMakeLists.txt | 1 +
utests/compiler_get_image_size.cpp | 37 +++++++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+)
create mode 100644 kernels/test_get_image_size.cl
create mode 100644 utests/compiler_get_image_size.cpp
diff --git a/kernels/test_get_image_size.cl b/kernels/test_get_image_size.cl
new file mode 100644
index 0000000..aeb7d66
--- /dev/null
+++ b/kernels/test_get_image_size.cl
@@ -0,0 +1,9 @@
+__kernel void
+test_get_image_size(__write_only image2d_t src, __global int *info)
+{
+ int id = (int)get_global_id(0);
+ int w, h;
+ w = get_image_width(src);
+ h = get_image_height(src);
+ info[id] = (w << 16 | h);
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index 45732c8..2ba01c4 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -75,6 +75,7 @@ set (utests_sources
compiler_movforphi_undef.cpp
compiler_volatile.cpp
compiler_copy_image1.cpp
+ compiler_get_image_size.cpp
runtime_createcontext.cpp
utest_assert.cpp
utest.cpp
diff --git a/utests/compiler_get_image_size.cpp b/utests/compiler_get_image_size.cpp
new file mode 100644
index 0000000..49c08ad
--- /dev/null
+++ b/utests/compiler_get_image_size.cpp
@@ -0,0 +1,37 @@
+#include "utest_helper.hpp"
+
+static void compiler_get_image_size(void)
+{
+ const size_t w = 256;
+ 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 = 0;
+
+ // Setup kernel and images
+ OCL_CREATE_KERNEL("test_get_image_size");
+
+ OCL_CREATE_IMAGE(buf[0], 0, &format, &desc, NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, 32 * sizeof(int), NULL);
+
+ // Run the kernel
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+ globals[0] = 32;
+ locals[0] = 16;
+ OCL_NDRANGE(1);
+
+ // Check result
+ OCL_MAP_BUFFER(1);
+ for (uint32_t i = 0; i < 32; i++)
+ OCL_ASSERT(((uint32_t*)buf_data[1])[i] == ((w << 16) | (h)));
+ OCL_UNMAP_BUFFER(0);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compiler_get_image_size);
--
1.7.11.7
More information about the Beignet
mailing list