[Beignet] [PATCH 2/2] test the case that user ptr is not page aligned

Guo Yejun yejun.guo at intel.com
Mon Dec 22 00:56:00 PST 2014


the previous code only test user ptr that is page aligned, remove
this limitation together with the driver.

Signed-off-by: Guo Yejun <yejun.guo at intel.com>
---
 benchmark/benchmark_use_host_ptr_buffer.cpp | 12 +++++++++---
 utests/runtime_use_host_ptr_buffer.cpp      | 14 ++++++++++----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/benchmark/benchmark_use_host_ptr_buffer.cpp b/benchmark/benchmark_use_host_ptr_buffer.cpp
index 7ede576..ecc0f8b 100644
--- a/benchmark/benchmark_use_host_ptr_buffer.cpp
+++ b/benchmark/benchmark_use_host_ptr_buffer.cpp
@@ -5,13 +5,19 @@ int benchmark_use_host_ptr_buffer(void)
 {
   struct timeval start,stop;
 
-  const size_t n = 4096*4096;
+  const size_t n = 4096*4096 + 256;
 
   // Setup kernel and buffers
   OCL_CREATE_KERNEL("runtime_use_host_ptr_buffer");
 
-  int ret = posix_memalign(&buf_data[0], 4096, sizeof(uint32_t) * n);
-  OCL_ASSERT(ret == 0);
+  buf_data[0] = malloc(sizeof(uint32_t) * n);
+
+  //it does not matter if buf_data[0] is page aligned or not,
+  //here, just to test the case that it is not page aligned.
+  while ((unsigned long)buf_data[0] % 4096 == 0) {
+    free(buf_data[0]);
+    buf_data[0] = malloc(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]);
diff --git a/utests/runtime_use_host_ptr_buffer.cpp b/utests/runtime_use_host_ptr_buffer.cpp
index 79273c3..3971533 100644
--- a/utests/runtime_use_host_ptr_buffer.cpp
+++ b/utests/runtime_use_host_ptr_buffer.cpp
@@ -2,13 +2,19 @@
 
 static void runtime_use_host_ptr_buffer(void)
 {
-  const size_t n = 4096*100;
+  const size_t n = 4096*10 + 1111;
 
   // Setup kernel and buffers
   OCL_CREATE_KERNEL("runtime_use_host_ptr_buffer");
 
-  int ret = posix_memalign(&buf_data[0], 4096, sizeof(uint32_t) * n);
-  OCL_ASSERT(ret == 0);
+  buf_data[0] = malloc(sizeof(uint32_t) * n);
+
+  //it does not matter if buf_data[0] is page aligned or not,
+  //here, just to test the case that it is not page aligned.
+  while ((unsigned long)buf_data[0] % 4096 == 0) {
+    free(buf_data[0]);
+    buf_data[0] = malloc(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]);
@@ -16,7 +22,7 @@ static void runtime_use_host_ptr_buffer(void)
   // Run the kernel
   OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
   globals[0] = n;
-  locals[0] = 256;
+  locals[0] = 1;
   OCL_NDRANGE(1);
 
   // Check result
-- 
1.9.1



More information about the Beignet mailing list