diff options
author | Chuanbo Weng <chuanbo.weng@intel.com> | 2015-02-13 00:36:52 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2015-02-13 11:56:23 +0800 |
commit | 4f711f957791a2724272b2c88ee496d8e5412b17 (patch) | |
tree | 4078329f59df2505f251a1a9588bdf88c276d7ae | |
parent | 727519ae1be8d3b5edabf104feb1c05507f8babb (diff) |
Add benchmark of clEnqueueCopyImageToBuffer(copy 2d image to buffer).
v2:
Change test image size from (width, height) = (960, 540)
to (960 * 4, 540 * 4), becaue larger workload get more stable
benchmark result.
Signed-off-by: Chuanbo Weng <chuanbo.weng@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
-rw-r--r-- | benchmark/CMakeLists.txt | 3 | ||||
-rw-r--r-- | benchmark/benchmark_copy_image_to_buffer.cpp | 64 |
2 files changed, 66 insertions, 1 deletions
diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 73dbe853..7bd61ee1 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -14,7 +14,8 @@ set (benchmark_sources benchmark_copy_buf.cpp benchmark_use_host_ptr_buffer.cpp benchmark_read_buffer.cpp - benchmark_read_image.cpp) + benchmark_read_image.cpp + benchmark_copy_image_to_buffer.cpp) SET(CMAKE_CXX_FLAGS "-DBUILD_BENCHMARK ${CMAKE_CXX_FLAGS}") diff --git a/benchmark/benchmark_copy_image_to_buffer.cpp b/benchmark/benchmark_copy_image_to_buffer.cpp new file mode 100644 index 00000000..debed093 --- /dev/null +++ b/benchmark/benchmark_copy_image_to_buffer.cpp @@ -0,0 +1,64 @@ +#include <string.h> +#include "utests/utest_helper.hpp" +#include <sys/time.h> + +#define IMAGE_BPP 2 + +double benchmark_copy_image_to_buffer(void) +{ + struct timeval start,stop; + const size_t w = 960 * 4; + const size_t h = 540 * 4; + const size_t sz = IMAGE_BPP * w * h; + cl_image_format format; + cl_image_desc desc; + + memset(&desc, 0x0, sizeof(cl_image_desc)); + memset(&format, 0x0, sizeof(cl_image_format)); + + // Setup image and buffer + buf_data[0] = (unsigned short*) malloc(sz); + for (uint32_t i = 0; i < w*h; ++i) { + ((unsigned short*)buf_data[0])[i] = (rand() & 0xffff); + } + + format.image_channel_order = CL_R; + format.image_channel_data_type = CL_UNSIGNED_INT16; + desc.image_type = CL_MEM_OBJECT_IMAGE2D; + desc.image_width = w; + desc.image_height = h; + desc.image_row_pitch = desc.image_width * IMAGE_BPP; + OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, &desc, buf_data[0]); + OCL_CREATE_BUFFER(buf[1], 0, sz, NULL); + + /*copy image to buffer*/ + size_t origin[3] = {0, 0, 0}; + size_t region[3] = {w, h, 1}; + + OCL_CALL (clEnqueueCopyImageToBuffer, queue, buf[0], buf[1], origin, region, + 0, 0, NULL, NULL); + OCL_FINISH(); + OCL_MAP_BUFFER(1); + /*check result*/ + for (uint32_t i = 0; i < w*h; ++i) { + OCL_ASSERT(((unsigned short *)buf_data[0])[i] == ((unsigned short *)buf_data[1])[i]); + } + OCL_UNMAP_BUFFER(1); + gettimeofday(&start,0); + + for (uint32_t i=0; i<100; i++) { + OCL_CALL (clEnqueueCopyImageToBuffer, queue, buf[0], buf[1], origin, region, + 0, 0, NULL, NULL); + } + OCL_FINISH(); + + gettimeofday(&stop,0); + free(buf_data[0]); + buf_data[0] = NULL; + + double elapsed = time_subtract(&stop, &start, 0); + + return BANDWIDTH(sz * 100, elapsed); +} + +MAKE_BENCHMARK_FROM_FUNCTION(benchmark_copy_image_to_buffer); |