[Beignet] [PATCH 2/2] Refine copy_buf benchmark and rename the file.

Zhigang Gong zhigang.gong at linux.intel.com
Thu Jan 29 18:03:19 PST 2015


This patch LGTM. Thanks.

On Tue, Jan 27, 2015 at 02:18:54PM +0800, Chuanbo Weng wrote:
> Some refinement for copy_buf benchmark:
> 1. We should measure execution time of clEnqueueCopyBuffer(buffer
>    creation and initialization time should not be included).
> 2. Add clFinish before gettimeofday.
> 3. Rename the file in order to keep the name format the same as
>    other benchmarks.
> 
> Signed-off-by: Chuanbo Weng <chuanbo.weng at intel.com>
> ---
>  benchmark/CMakeLists.txt         |  2 +-
>  benchmark/benchmark_copy_buf.cpp | 50 ++++++++++++++++++++++++++++++++++++++++
>  benchmark/enqueue_copy_buf.cpp   | 47 -------------------------------------
>  3 files changed, 51 insertions(+), 48 deletions(-)
>  create mode 100644 benchmark/benchmark_copy_buf.cpp
>  delete mode 100644 benchmark/enqueue_copy_buf.cpp
> 
> diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt
> index 9a2bd77..73dbe85 100644
> --- a/benchmark/CMakeLists.txt
> +++ b/benchmark/CMakeLists.txt
> @@ -11,7 +11,7 @@ set (benchmark_sources
>    ../utests/utest_file_map.cpp
>    ../utests/utest_helper.cpp
>    ../utests/vload_bench.cpp
> -  enqueue_copy_buf.cpp
> +  benchmark_copy_buf.cpp
>    benchmark_use_host_ptr_buffer.cpp
>    benchmark_read_buffer.cpp
>    benchmark_read_image.cpp)
> diff --git a/benchmark/benchmark_copy_buf.cpp b/benchmark/benchmark_copy_buf.cpp
> new file mode 100644
> index 0000000..ff070c6
> --- /dev/null
> +++ b/benchmark/benchmark_copy_buf.cpp
> @@ -0,0 +1,50 @@
> +#include "utests/utest_helper.hpp"
> +#include <sys/time.h>
> +
> +double benchmark_copy_buf(void)
> +{
> +  size_t i;
> +  const size_t sz = 127 *1023 * 1023;
> +  const size_t cb = sz;
> +  size_t src_off =0, dst_off = 0;
> +  struct timeval start,stop;
> +
> +  cl_char* buf0;
> +
> +  OCL_CREATE_BUFFER(buf[0], 0, sz * sizeof(char), NULL);
> +  OCL_CREATE_BUFFER(buf[1], 0, sz * sizeof(char), NULL);
> +
> +  buf0 = (cl_char *)clEnqueueMapBuffer(queue, buf[0], CL_TRUE, CL_MAP_WRITE, 0, sizeof(char), 0, NULL, NULL, NULL);
> +
> +  for (i=0; i < sz; i++) {
> +    buf0[i]=(rand() & 0xFF);
> +  }
> +
> +  clEnqueueUnmapMemObject(queue, buf[0], buf0, 0, NULL, NULL);
> +
> +  if (src_off + cb > sz || dst_off + cb > sz) {
> +    /* Expect Error. */
> +    OCL_ASSERT(clEnqueueCopyBuffer(queue, buf[0], buf[1],
> +          src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
> +  }
> +
> +  /*Internal kernel will be built for the first time of calling
> +  clEnqueueCopyBuffer, so the first execution time of clEnqueueCopyBuffer
> +  will be much longer. It should not be added to benchmark time.*/
> +  OCL_ASSERT(CL_SUCCESS == clEnqueueCopyBuffer(queue, buf[0], buf[1],
> +        src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
> +  OCL_FINISH();
> +  gettimeofday(&start,0);
> +
> +  for (i=0; i<100; i++) {
> +    OCL_ASSERT(CL_SUCCESS == clEnqueueCopyBuffer(queue, buf[0], buf[1],
> +          src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
> +  }
> +  OCL_FINISH();
> +
> +  gettimeofday(&stop,0);
> +
> +  return time_subtract(&stop, &start, 0) / 100;
> +}
> +
> +MAKE_EXECTIME_BENCHMARK_FROM_FUNCTION(benchmark_copy_buf);
> diff --git a/benchmark/enqueue_copy_buf.cpp b/benchmark/enqueue_copy_buf.cpp
> deleted file mode 100644
> index 78dbe75..0000000
> --- a/benchmark/enqueue_copy_buf.cpp
> +++ /dev/null
> @@ -1,47 +0,0 @@
> -#include "utests/utest_helper.hpp"
> -#include <sys/time.h>
> -
> -void test_copy_buf(size_t sz, size_t src_off, size_t dst_off, size_t cb)
> -{
> -  unsigned int i;
> -  cl_char* buf0;
> -
> -  OCL_CREATE_BUFFER(buf[0], 0, sz * sizeof(char), NULL);
> -  OCL_CREATE_BUFFER(buf[1], 0, sz * sizeof(char), NULL);
> -
> -  buf0 = (cl_char *)clEnqueueMapBuffer(queue, buf[0], CL_TRUE, CL_MAP_WRITE, 0, sizeof(char), 0, NULL, NULL, NULL);
> -
> -  for (i=0; i < sz; i++) {
> -    buf0[i]=(rand() & 0xFF);
> -  }
> -
> -  clEnqueueUnmapMemObject(queue, buf[0], buf0, 0, NULL, NULL);
> -
> -  if (src_off + cb > sz || dst_off + cb > sz) {
> -  /* Expect Error. */
> -    OCL_ASSERT(clEnqueueCopyBuffer(queue, buf[0], buf[1],
> -                 src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
> -    return;
> -  }
> -
> -  OCL_ASSERT(CL_SUCCESS == clEnqueueCopyBuffer(queue, buf[0], buf[1],
> -    src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
> -}
> -
> -double enqueue_copy_buf(void)
> -{
> -  size_t i;
> -  const size_t sz = 127 *1023 * 1023;
> -  struct timeval start,stop;
> -
> -  gettimeofday(&start,0);
> -
> -  for (i=0; i<10; i++) {
> -    test_copy_buf(sz, 0, 0, sz);
> -  }
> -
> -  gettimeofday(&stop,0);
> -  return time_subtract(&stop, &start, 0) / 10;
> -}
> -
> -MAKE_EXECTIME_BENCHMARK_FROM_FUNCTION(enqueue_copy_buf);
> -- 
> 1.9.1
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list