[Beignet] [PATCH 2/2] add utest of CL_MEM_ALLOC_HOST_PTR

Guo Yejun yejun.guo at intel.com
Mon Dec 1 17:31:08 PST 2014


Signed-off-by: Guo Yejun <yejun.guo at intel.com>
---
 kernels/runtime_alloc_host_ptr_buffer.cl |  6 ++++++
 utests/CMakeLists.txt                    |  1 +
 utests/runtime_alloc_host_ptr_buffer.cpp | 25 +++++++++++++++++++++++++
 3 files changed, 32 insertions(+)
 create mode 100644 kernels/runtime_alloc_host_ptr_buffer.cl
 create mode 100644 utests/runtime_alloc_host_ptr_buffer.cpp

diff --git a/kernels/runtime_alloc_host_ptr_buffer.cl b/kernels/runtime_alloc_host_ptr_buffer.cl
new file mode 100644
index 0000000..290241d
--- /dev/null
+++ b/kernels/runtime_alloc_host_ptr_buffer.cl
@@ -0,0 +1,6 @@
+__kernel void
+runtime_alloc_host_ptr_buffer(__global int* buf)
+{
+  int id = (int)get_global_id(0);
+  buf[id] = id / 2;
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index 4ad80f0..41d4a7f 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -195,6 +195,7 @@ set (utests_sources
   compiler_assignment_operation_in_if.cpp
   vload_bench.cpp
   runtime_use_host_ptr_buffer.cpp
+  runtime_alloc_host_ptr_buffer.cpp
   utest_assert.cpp
   utest.cpp
   utest_file_map.cpp
diff --git a/utests/runtime_alloc_host_ptr_buffer.cpp b/utests/runtime_alloc_host_ptr_buffer.cpp
new file mode 100644
index 0000000..793682b
--- /dev/null
+++ b/utests/runtime_alloc_host_ptr_buffer.cpp
@@ -0,0 +1,25 @@
+#include "utest_helper.hpp"
+
+static void runtime_alloc_host_ptr_buffer(void)
+{
+  const size_t n = 4096*100;
+
+  // Setup kernel and buffers
+  OCL_CREATE_KERNEL("runtime_alloc_host_ptr_buffer");
+
+  OCL_CREATE_BUFFER(buf[0], CL_MEM_ALLOC_HOST_PTR, n * sizeof(uint32_t), NULL);
+
+  // Run the kernel
+  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+  globals[0] = n;
+  locals[0] = 256;
+  OCL_NDRANGE(1);
+
+  // Check result
+  uint32_t* mapptr = (uint32_t*)clEnqueueMapBuffer(queue, buf[0], CL_TRUE, CL_MAP_READ, 0, n*sizeof(uint32_t), 0, NULL, NULL, NULL);
+  for (uint32_t i = 0; i < n; ++i)
+    OCL_ASSERT(mapptr[i] == i / 2);
+  clEnqueueUnmapMemObject(queue, buf[0], mapptr, 0, NULL, NULL);
+}
+
+MAKE_UTEST_FROM_FUNCTION(runtime_alloc_host_ptr_buffer);
-- 
1.9.1



More information about the Beignet mailing list