summaryrefslogtreecommitdiff
path: root/utests/compiler_subgroup_image_block_read.cpp
diff options
context:
space:
mode:
authorPan Xiuli <xiuli.pan@intel.com>2016-05-26 08:26:37 +0800
committerYang Rong <rong.r.yang@intel.com>2016-06-13 17:02:40 +0800
commitcfb8e5feb42407b4b7bac1cae3e0048783f668c3 (patch)
tree1773d427a3602da2fb54fb5e78eab6b036bbd505 /utests/compiler_subgroup_image_block_read.cpp
parent15dfc20b396210f27c59b5512f256f3628230721 (diff)
downloadbeignet-cfb8e5feb42407b4b7bac1cae3e0048783f668c3.tar.gz
Utest: Add tset case for block read/write image
Signed-off-by: Pan Xiuli <xiuli.pan@intel.com> Reviewed-by: Yang Rong <rong.r.yang@intel.com>
Diffstat (limited to 'utests/compiler_subgroup_image_block_read.cpp')
-rw-r--r--utests/compiler_subgroup_image_block_read.cpp189
1 files changed, 189 insertions, 0 deletions
diff --git a/utests/compiler_subgroup_image_block_read.cpp b/utests/compiler_subgroup_image_block_read.cpp
new file mode 100644
index 00000000..daccaa59
--- /dev/null
+++ b/utests/compiler_subgroup_image_block_read.cpp
@@ -0,0 +1,189 @@
+#include <cstdint>
+#include <cstring>
+#include <iostream>
+#include "utest_helper.hpp"
+
+using namespace std;
+
+/* set to 1 for debug, output of input-expected data */
+#define DEBUG_STDOUT 0
+
+/* NDRANGE */
+#define WG_GLOBAL_SIZE 32
+#define WG_LOCAL_SIZE 32
+/*
+ * Generic compute-expected function for meida block read
+ */
+template<class T>
+static void compute_expected(T* input,
+ T* expected,
+ size_t VEC_SIZE)
+{
+ for(uint32_t i = 0; i < WG_GLOBAL_SIZE; i++)
+ for(uint32_t j = 0; j < VEC_SIZE; j++)
+ expected[i * VEC_SIZE + j] = input[WG_GLOBAL_SIZE * j + i];
+}
+
+/*
+ * Generic input-expected generate function for media block read
+ */
+template<class T>
+static void generate_data(T* &input,
+ T* &expected,
+ size_t VEC_SIZE)
+{
+ /* allocate input and expected arrays */
+ input = new T[WG_GLOBAL_SIZE * VEC_SIZE];
+ expected = new T[WG_GLOBAL_SIZE * VEC_SIZE];
+
+ /* base value for all data types */
+ T base_val = (int)7 << (sizeof(T) * 5 - 3);
+
+ /* seed for random inputs */
+ srand (time(NULL));
+
+#if DEBUG_STDOUT
+ cout << endl << "IN: " << endl;
+#endif
+ /* generate inputs and expected values */
+ for(uint32_t gid = 0; gid < WG_GLOBAL_SIZE * VEC_SIZE; gid++)
+ {
+ /* initially 0, augment after */
+ input[gid] = ((rand() % 2 - 1) * base_val) + (rand() % 112);
+
+#if DEBUG_STDOUT
+ /* output generated input */
+ cout << setw(4) << input[gid] << ", " ;
+ if((gid + 1) % 8 == 0)
+ cout << endl;
+#endif
+
+ }
+ /* expected values */
+ compute_expected(input, expected, VEC_SIZE);
+
+#if DEBUG_STDOUT
+ /* output expected input */
+ cout << endl << "EXP: " << endl;
+ for(uint32_t gid = 0; gid < WG_GLOBAL_SIZE; gid++)
+ {
+ cout << "(";
+ for(uint32_t vsz = 0; vsz < VEC_SIZE; vsz++)
+ cout << setw(4) << expected[gid* VEC_SIZE + vsz] << ", " ;
+ cout << ")";
+ if((gid + 1) % 8 == 0)
+ cout << endl;
+ cout << endl;
+ }
+#endif
+}
+
+/*
+ * Generic subgroup utest function for media block read
+ */
+template<class T>
+static void subgroup_generic(T* input,
+ T* expected,
+ size_t VEC_SIZE)
+{
+ cl_image_format format;
+ cl_image_desc desc;
+
+ memset(&desc, 0x0, sizeof(cl_image_desc));
+ memset(&format, 0x0, sizeof(cl_image_format));
+
+ /* get simd size */
+ globals[0] = WG_GLOBAL_SIZE;
+ locals[0] = WG_LOCAL_SIZE;
+ size_t SIMD_SIZE = 0;
+ OCL_CALL(clGetKernelSubGroupInfoKHR,kernel,device,CL_KERNEL_MAX_SUB_GROUP_SIZE_FOR_NDRANGE_KHR,sizeof(size_t)*1,locals,sizeof(size_t),&SIMD_SIZE,NULL);
+
+ size_t buf_sz = VEC_SIZE * WG_GLOBAL_SIZE;
+ /* input and expected data */
+ generate_data(input, expected, VEC_SIZE);
+
+ /* prepare input for datatype */
+ format.image_channel_order = CL_R;
+ format.image_channel_data_type = CL_UNSIGNED_INT32;
+ desc.image_type = CL_MEM_OBJECT_IMAGE2D;
+ desc.image_width = WG_GLOBAL_SIZE;
+ desc.image_height = VEC_SIZE;
+ desc.image_row_pitch = WG_GLOBAL_SIZE * sizeof(uint32_t);
+
+ OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, &desc, input);
+ OCL_CREATE_BUFFER(buf[1], 0, buf_sz * sizeof(T), NULL);
+
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+
+ /* run the kernel on GPU */
+ OCL_NDRANGE(1);
+
+ /* check if mismatch */
+ OCL_MAP_BUFFER(1);
+ uint32_t mismatches = 0;
+
+ for (uint32_t i = 0; i < buf_sz; i++)
+ if(((T *)buf_data[1])[i] != *(expected + i))
+ {
+ /* found mismatch, increment */
+ mismatches++;
+
+#if DEBUG_STDOUT
+ /* output mismatch */
+ cout << "Err at " << i << ", " <<
+ ((T *)buf_data[1])[i] << " != " << *(expected + i) << endl;
+#endif
+ }
+
+#if DEBUG_STDOUT
+ /* output mismatch count */
+ cout << "mismatches " << mismatches << endl;
+#endif
+
+ OCL_UNMAP_BUFFER(1);
+
+ OCL_ASSERT(mismatches == 0);
+ free(input);
+ free(expected);
+}
+
+/*
+ * sub_group image block read functions
+ */
+void compiler_subgroup_image_block_read1(void)
+{
+ cl_uint *input = NULL;
+ cl_uint *expected = NULL;
+ OCL_CREATE_KERNEL_FROM_FILE("compiler_subgroup_image_block_read",
+ "compiler_subgroup_image_block_read1");
+ subgroup_generic(input, expected, 1);
+}
+MAKE_UTEST_FROM_FUNCTION(compiler_subgroup_image_block_read1);
+void compiler_subgroup_image_block_read2(void)
+{
+ cl_uint *input = NULL;
+ cl_uint *expected = NULL;
+ OCL_CREATE_KERNEL_FROM_FILE("compiler_subgroup_image_block_read",
+ "compiler_subgroup_image_block_read2");
+ subgroup_generic(input, expected, 2);
+}
+MAKE_UTEST_FROM_FUNCTION(compiler_subgroup_image_block_read2);
+void compiler_subgroup_image_block_read4(void)
+{
+ cl_uint *input = NULL;
+ cl_uint *expected = NULL;
+ OCL_CREATE_KERNEL_FROM_FILE("compiler_subgroup_image_block_read",
+ "compiler_subgroup_image_block_read4");
+ subgroup_generic(input, expected, 4);
+}
+MAKE_UTEST_FROM_FUNCTION(compiler_subgroup_image_block_read4);
+void compiler_subgroup_image_block_read8(void)
+{
+ cl_uint *input = NULL;
+ cl_uint *expected = NULL;
+ OCL_CREATE_KERNEL_FROM_FILE("compiler_subgroup_image_block_read",
+ "compiler_subgroup_image_block_read8");
+ subgroup_generic(input, expected, 8);
+}
+MAKE_UTEST_FROM_FUNCTION(compiler_subgroup_image_block_read8);