diff options
author | Guo Yejun <yejun.guo@intel.com> | 2014-11-21 15:53:42 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2014-12-02 17:16:44 +0800 |
commit | 9174fec835760941cd13c49c9d161bd13bb7b0e6 (patch) | |
tree | b6d71a4bf00de009c840dbb6d5a42684aa166c74 /benchmark | |
parent | 3db0329853f97d6cd06a82d3277b6294065c6c51 (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>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/CMakeLists.txt | 3 | ||||
-rw-r--r-- | benchmark/benchmark_use_host_ptr_buffer.cpp | 38 | ||||
-rw-r--r-- | benchmark/enqueue_copy_buf.cpp | 24 |
3 files changed, 41 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); |