summaryrefslogtreecommitdiff
path: root/utests/runtime_use_host_ptr_buffer.cpp
diff options
context:
space:
mode:
authorGuo Yejun <yejun.guo@intel.com>2014-11-07 16:21:05 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-11-07 16:03:51 +0800
commit084a9f301c3ccdc8f278c69e8d5e652d17a1a840 (patch)
tree1b15296d8dc8a6ffff12e20da23cb83ec3a74678 /utests/runtime_use_host_ptr_buffer.cpp
parent99e3b583f0d5837601670ca3486cb5ecfd8bf1a1 (diff)
downloadbeignet-084a9f301c3ccdc8f278c69e8d5e652d17a1a840.tar.gz
add test for cl buffer created with CL_MEM_USE_HOST_PTR
Signed-off-by: Guo Yejun <yejun.guo@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com> Reviewed-by: Zhenyu Wang <zhenyuw@linux.intel.com>
Diffstat (limited to 'utests/runtime_use_host_ptr_buffer.cpp')
-rw-r--r--utests/runtime_use_host_ptr_buffer.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/utests/runtime_use_host_ptr_buffer.cpp b/utests/runtime_use_host_ptr_buffer.cpp
new file mode 100644
index 00000000..ca06f4be
--- /dev/null
+++ b/utests/runtime_use_host_ptr_buffer.cpp
@@ -0,0 +1,36 @@
+#include "utest_helper.hpp"
+
+static void runtime_use_host_ptr_buffer(void)
+{
+ const size_t n = 4096*100;
+
+ // Setup kernel and buffers
+ OCL_CREATE_KERNEL("runtime_use_host_ptr_buffer");
+ buf_data[0] = (uint32_t*) aligned_alloc(4096, sizeof(uint32_t) * n);
+ for (uint32_t i = 0; i < n; ++i) ((uint32_t*)buf_data[0])[i] = i;
+ OCL_CREATE_BUFFER(buf[0], CL_MEM_USE_HOST_PTR, n * sizeof(uint32_t), buf_data[0]);
+
+ // Run the kernel
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ globals[0] = n;
+ locals[0] = 256;
+ OCL_NDRANGE(1);
+
+ // Check result
+
+#ifdef HAS_USERPTR
+ OCL_FINISH();
+#else
+ void* mapptr = (int*)clEnqueueMapBuffer(queue, buf[0], CL_TRUE, CL_MAP_READ, 0, n*sizeof(uint32_t), 0, NULL, NULL, NULL);
+ OCL_ASSERT(mapptr == buf_data[0]);
+ clEnqueueUnmapMemObject(queue, buf[0], mapptr, 0, NULL, NULL);
+#endif
+
+ for (uint32_t i = 0; i < n; ++i)
+ OCL_ASSERT(((uint32_t*)buf_data[0])[i] == i / 2);
+
+ free(buf_data[0]);
+ buf_data[0] = NULL;
+}
+
+MAKE_UTEST_FROM_FUNCTION(runtime_use_host_ptr_buffer);