[Beignet] [PATCH] add test of cl_mem_use_host_ptr into benchmark

Guo, Yejun yejun.guo at intel.com
Thu Nov 27 17:47:33 PST 2014


Ping for review, thanks.

-----Original Message-----
From: Guo, Yejun 
Sent: Friday, November 21, 2014 3:54 PM
To: beignet at lists.freedesktop.org
Cc: Guo, Yejun
Subject: [PATCH] add test of cl_mem_use_host_ptr into benchmark

and also refine the code to move time_subtract into utest_helper.hpp/cpp

Signed-off-by: Guo Yejun <yejun.guo at intel.com>
---
 benchmark/CMakeLists.txt                    |  3 ++-
 benchmark/benchmark_use_host_ptr_buffer.cpp | 38 +++++++++++++++++++++++++++++
 benchmark/enqueue_copy_buf.cpp              | 24 +-----------------
 utests/utest_helper.cpp                     | 22 +++++++++++++++++
 utests/utest_helper.hpp                     |  3 +++
 5 files changed, 66 insertions(+), 24 deletions(-)
 create mode 100644 benchmark/benchmark_use_host_ptr_buffer.cpp

diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt
index 0a959c8..ac2d8aa 100644
--- a/benchmark/CMakeLists.txt
+++ b/benchmark/CMakeLists.txt
@@ -11,7 +11,8 @@ set (benchmark_sources
   ../utests/utest_file_map.cpp
   ../utests/utest_helper.cpp
   ../utests/vload_bench.cpp
-  enqueue_copy_buf.cpp)
+  enqueue_copy_buf.cpp
+  benchmark_use_host_ptr_buffer.cpp)
 
 
 SET(CMAKE_CXX_FLAGS "-DBUILD_BENCHMARK ${CMAKE_CXX_FLAGS}")
diff --git a/benchmark/benchmark_use_host_ptr_buffer.cpp b/benchmark/benchmark_use_host_ptr_buffer.cpp
new file mode 100644
index 0000000..7ede576
--- /dev/null
+++ b/benchmark/benchmark_use_host_ptr_buffer.cpp
@@ -0,0 +1,38 @@
+#include "utests/utest_helper.hpp"
+#include <sys/time.h>
+
+int benchmark_use_host_ptr_buffer(void)
+{
+  struct timeval start,stop;
+
+  const size_t n = 4096*4096;
+
+  // 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);
+
+  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]);
+
+  OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+  globals[0] = n;
+  locals[0] = 256;
+
+  gettimeofday(&start,0);
+  for (size_t i=0; i<100; i++) {
+    OCL_NDRANGE(1);
+    void* mapptr = (int*)clEnqueueMapBuffer(queue, buf[0], CL_TRUE, CL_MAP_READ, 0, n*sizeof(uint32_t), 0, NULL, NULL, NULL);
+    clEnqueueUnmapMemObject(queue, buf[0], mapptr, 0, NULL, NULL);
+  }
+  gettimeofday(&stop,0);
+
+  clReleaseMemObject(buf[0]);
+  free(buf_data[0]);
+  buf_data[0] = NULL;
+
+  return time_subtract(&stop, &start, 0);
+}
+
+MAKE_BENCHMARK_FROM_FUNCTION(benchmark_use_host_ptr_buffer);
diff --git a/benchmark/enqueue_copy_buf.cpp b/benchmark/enqueue_copy_buf.cpp
index 0d0d4df..f012cf7 100644
--- a/benchmark/enqueue_copy_buf.cpp
+++ b/benchmark/enqueue_copy_buf.cpp
@@ -28,28 +28,6 @@ void test_copy_buf(size_t sz, size_t src_off, size_t dst_off, size_t cb)
     src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
 }
 
-int tim_subtract(struct timeval *y, struct timeval *x, struct timeval *result){
-  if ( x->tv_sec > y->tv_sec )
-    return   -1;
-
-  if ((x->tv_sec == y->tv_sec) && (x->tv_usec > y->tv_usec))
-    return   -1;
-
-  if ( result != NULL){
-    result->tv_sec = ( y->tv_sec - x->tv_sec );
-    result->tv_usec = ( y->tv_usec - x->tv_usec );
-
-    if (result->tv_usec < 0){
-      result->tv_sec --;
-      result->tv_usec += 1000000;
-    }
-  }
-
-  int msec = 1000.0*(y->tv_sec - x->tv_sec) + (y->tv_usec - x->tv_usec)/1000.0;
-  return msec;
-}
-
-
 int enqueue_copy_buf(void)
 {
   size_t i;
@@ -63,7 +41,7 @@ int enqueue_copy_buf(void)
   }
 
   gettimeofday(&stop,0);
-  return tim_subtract(&stop, &start, 0);
+  return time_subtract(&stop, &start, 0);
 }
 
 MAKE_BENCHMARK_FROM_FUNCTION(enqueue_copy_buf);
diff --git a/utests/utest_helper.cpp b/utests/utest_helper.cpp
index df0e508..606c1bf 100644
--- a/utests/utest_helper.cpp
+++ b/utests/utest_helper.cpp
@@ -680,3 +680,25 @@ int cl_INT_ULP(int int_number)
 {
   return 0;
 }
+
+int time_subtract(struct timeval *y, struct timeval *x, struct timeval *result)
+{
+  if ( x->tv_sec > y->tv_sec )
+    return   -1;
+
+  if ((x->tv_sec == y->tv_sec) && (x->tv_usec > y->tv_usec))
+    return   -1;
+
+  if ( result != NULL){
+    result->tv_sec = ( y->tv_sec - x->tv_sec );
+    result->tv_usec = ( y->tv_usec - x->tv_usec );
+
+    if (result->tv_usec < 0){
+      result->tv_sec --;
+      result->tv_usec += 1000000;
+    }
+  }
+
+  int msec = 1000.0*(y->tv_sec - x->tv_sec) + (y->tv_usec - x->tv_usec)/1000.0;
+  return msec;
+}
\ No newline at end of file
diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp
index 026eb1c..5d8e835 100644
--- a/utests/utest_helper.hpp
+++ b/utests/utest_helper.hpp
@@ -230,5 +230,8 @@ extern float cl_FLT_ULP(float float_number);
 /* Calculator ULP of each INT value */
 extern int cl_INT_ULP(int int_number);
 
+/* subtract the time */
+int time_subtract(struct timeval *y, struct timeval *x, struct timeval *result);
+
 #endif /* __UTEST_HELPER_HPP__ */
 
-- 
1.9.1



More information about the Beignet mailing list