summaryrefslogtreecommitdiff
path: root/utests/compiler_displacement_map_element.cpp
diff options
context:
space:
mode:
authorHomer Hsing <homer.xing@intel.com>2013-06-04 15:52:13 +0800
committerZhigang Gong <zhigang.gong@linux.intel.com>2013-06-04 16:06:16 +0800
commit0ef8b93495d5f75ef86e7e232d58d7e9768b8ede (patch)
tree428acb3a02918992ab3134786c5b49bb777ddd1a /utests/compiler_displacement_map_element.cpp
parentdc17e964a09419036b9e05f37ccd2de2a15ac984 (diff)
downloadbeignet-0ef8b93495d5f75ef86e7e232d58d7e9768b8ede.tar.gz
test case for DW multiplication
This case tests whether a predication bug of DW multiplication had been fixed. Signed-off-by: Homer Hsing <homer.xing@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'utests/compiler_displacement_map_element.cpp')
-rw-r--r--utests/compiler_displacement_map_element.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/utests/compiler_displacement_map_element.cpp b/utests/compiler_displacement_map_element.cpp
new file mode 100644
index 00000000..98041ec4
--- /dev/null
+++ b/utests/compiler_displacement_map_element.cpp
@@ -0,0 +1,64 @@
+#include "utest_helper.hpp"
+
+typedef unsigned int uint;
+constexpr int W = 16, H = 16;
+constexpr int SIZE = W * H;
+uint in_1[SIZE];
+uint disp_map[SIZE];
+uint out_1[SIZE];
+
+uint cpu(const int cx, const int cy, const uint *in, const uint *disp_map, int w, int h) {
+ uint c = disp_map[cy * w + cx];
+ int x_pos = cx + c;
+ int y_pos = cy + c;
+ if(0 <= x_pos && x_pos < w && 0 <= y_pos && y_pos < h)
+ return in[y_pos * w + x_pos];
+ else
+ return 0;
+}
+
+void test() {
+ OCL_MAP_BUFFER(2);
+ for(int y=0; y<H; y++)
+ for(int x=0; x<W; x++) {
+ uint out = ((uint*)buf_data[2]) [y * W + x];
+ uint wish = cpu(x, y, in_1, disp_map, W, H);
+ if(out != wish)
+ printf("XXX %d %d %x %x\n", x, y, out, wish);
+ OCL_ASSERT(out == wish);
+ }
+ OCL_UNMAP_BUFFER(2);
+}
+
+void displacement_map_element(void) {
+ int i, pass;
+
+ OCL_CREATE_KERNEL("compiler_displacement_map_element");
+ OCL_CREATE_BUFFER(buf[0], 0, SIZE * sizeof(uint), NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, SIZE * sizeof(uint), NULL);
+ OCL_CREATE_BUFFER(buf[2], 0, SIZE * sizeof(uint), NULL);
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(cl_mem), &buf[1]);
+ OCL_SET_ARG(2, sizeof(W), &W);
+ OCL_SET_ARG(3, sizeof(H), &H);
+ OCL_SET_ARG(4, sizeof(cl_mem), &buf[2]);
+ globals[0] = W;
+ globals[1] = H;
+ locals[0] = 16;
+ locals[1] = 16;
+
+ for (pass = 0; pass < 8; pass ++) {
+ OCL_MAP_BUFFER(0);
+ OCL_MAP_BUFFER(1);
+ for (i = 0; i < SIZE; i ++) {
+ in_1[i] = ((uint*)buf_data[0])[i] = ((rand() & 0xFFFF) << 16) | (rand() & 0xFFFF);
+ disp_map[i] = ((uint*)buf_data[1])[i] = rand() & 3;
+ }
+ OCL_UNMAP_BUFFER(0);
+ OCL_UNMAP_BUFFER(1);
+ OCL_NDRANGE(2);
+ test();
+ }
+}
+
+MAKE_UTEST_FROM_FUNCTION(displacement_map_element);