summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuo Yejun <yejun.guo@intel.com>2014-11-21 15:53:42 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-12-02 17:16:44 +0800
commit9174fec835760941cd13c49c9d161bd13bb7b0e6 (patch)
treeb6d71a4bf00de009c840dbb6d5a42684aa166c74
parent3db0329853f97d6cd06a82d3277b6294065c6c51 (diff)
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@intel.com> Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
-rw-r--r--benchmark/CMakeLists.txt3
-rw-r--r--benchmark/benchmark_use_host_ptr_buffer.cpp38
-rw-r--r--benchmark/enqueue_copy_buf.cpp24
-rw-r--r--utests/utest_helper.cpp22
-rw-r--r--utests/utest_helper.hpp3
5 files changed, 66 insertions, 24 deletions
diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt
index 0a959c88..ac2d8aad 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 00000000..7ede5767
--- /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 0d0d4dfe..f012cf71 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 df0e5087..606c1bfc 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 026eb1cb..5d8e835c 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__ */