summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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__ */