summaryrefslogtreecommitdiff
path: root/utests/compare_image_2d_and_1d_array.cpp
diff options
context:
space:
mode:
authorJunyan He <junyan.he@linux.intel.com>2014-06-20 18:07:40 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-06-23 11:00:55 +0800
commit0a346a52fc9f8fcb35461bd5dadb024358df6ab9 (patch)
treedc407c7b52a358146b149cd08d5e9d22342aab2b /utests/compare_image_2d_and_1d_array.cpp
parentfcb3b6f12dbd28c97b2dbed0610cbe44650cb082 (diff)
downloadbeignet-0a346a52fc9f8fcb35461bd5dadb024358df6ab9.tar.gz
Add the test cases for 1D Image Array
Signed-off-by: Junyan He <junyan.he@linux.intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'utests/compare_image_2d_and_1d_array.cpp')
-rw-r--r--utests/compare_image_2d_and_1d_array.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/utests/compare_image_2d_and_1d_array.cpp b/utests/compare_image_2d_and_1d_array.cpp
new file mode 100644
index 00000000..f2c828ea
--- /dev/null
+++ b/utests/compare_image_2d_and_1d_array.cpp
@@ -0,0 +1,79 @@
+#include <string.h>
+#include "utest_helper.hpp"
+
+static void compare_image_2d_and_1d_array(void)
+{
+ const int w = 64;
+ const int h = 32;
+ cl_image_format format;
+ cl_image_desc desc;
+ cl_sampler sampler;
+
+ // Create the 1D array buffer.
+ memset(&desc, 0x0, sizeof(cl_image_desc));
+ memset(&format, 0x0, sizeof(cl_image_format));
+
+ uint32_t* image_data1 = (uint32_t *)malloc(w * h * sizeof(uint32_t));
+ uint32_t* image_data2 = (uint32_t *)malloc(w * h * sizeof(uint32_t));
+ for (int j = 0; j < h; j++) {
+ for (int i = 0; i < w; i++) {
+ char a = 0;
+ if (j % 2 == 0)
+ a = (j + 3) & 0x3f;
+
+ image_data2[w * j + i] = image_data1[w * j + i] = a << 24 | a << 16 | a << 8 | a;
+ }
+ }
+
+ 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, image_data1);
+
+ // Create the 2D array buffer.
+ memset(&desc, 0x0, sizeof(cl_image_desc));
+ memset(&format, 0x0, sizeof(cl_image_format));
+
+ format.image_channel_order = CL_RGBA;
+ format.image_channel_data_type = CL_UNSIGNED_INT8;
+ desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
+ desc.image_width = w;
+ desc.image_array_size = h;
+ desc.image_row_pitch = w * sizeof(uint32_t);
+ OCL_CREATE_IMAGE(buf[1], CL_MEM_COPY_HOST_PTR, &format, &desc, image_data2);
+
+ OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_LINEAR);
+
+ // Setup kernel and images
+ OCL_CREATE_KERNEL("compare_image_2d_and_1d_array");
+
+ // Run the kernel
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+ OCL_SET_ARG(2, sizeof(cl_sampler), &sampler);
+ globals[0] = 32;
+ globals[1] = 16;
+ locals[0] = 32;
+ locals[1] = 16;
+ OCL_NDRANGE(2);
+
+ OCL_MAP_BUFFER_GTT(0);
+ OCL_MAP_BUFFER_GTT(1);
+ for (int j = 0; j < h; ++j) {
+ for (int i = 0; i < w; i++) {
+ // Because the array index will not join the sample caculation, the result should
+ // be different between the 2D and 1D_array.
+ if (j % 2 == 0)
+ OCL_ASSERT(((uint32_t*)buf_data[0])[j * w + i] == ((uint32_t*)buf_data[1])[j * w + i]);
+ }
+ }
+ OCL_UNMAP_BUFFER_GTT(0);
+ OCL_UNMAP_BUFFER_GTT(1);
+
+ OCL_CALL(clReleaseSampler, sampler);
+}
+
+MAKE_UTEST_FROM_FUNCTION(compare_image_2d_and_1d_array);