Hi Xionghu,
        First of all, I think you should merge [PATCH 2/3] and [PATCH 3/3] into 
one patch, because
it's your programming error during your development.
        For other comments, please see my comments below.
        
-----Original Message-----
From: Luo, Xionghu 
Sent: Wednesday, April 01, 2015 8:52
To: Weng, Chuanbo
Cc: [email protected]
Subject: RE: [PATCH 1/3] add benckmark for copy data from buffer to image.

Hi Chuanbo,
Please review this patchset for me.
It adds aligned copy data from buffer to image 2d (only image 2d to buffer 
before).

Luo Xionghu
Best Regards

-----Original Message-----
From: Luo, Xionghu
Sent: Wednesday, April 1, 2015 8:48 AM
To: [email protected]
Cc: Luo, Xionghu
Subject: [PATCH 1/3] add benckmark for copy data from buffer to image.

From: Luo Xionghu <[email protected]>

Signed-off-by: Luo Xionghu <[email protected]>
---
 benchmark/CMakeLists.txt                     |  1 +
 benchmark/benchmark_copy_buffer_to_image.cpp | 67 ++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)
 create mode 100644 benchmark/benchmark_copy_buffer_to_image.cpp

diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 
7bd61ee..3e43a21 100644
--- a/benchmark/CMakeLists.txt
+++ b/benchmark/CMakeLists.txt
@@ -15,6 +15,7 @@ set (benchmark_sources
   benchmark_use_host_ptr_buffer.cpp
   benchmark_read_buffer.cpp
   benchmark_read_image.cpp
+  benchmark_copy_buffer_to_image.cpp
   benchmark_copy_image_to_buffer.cpp)
 
 
diff --git a/benchmark/benchmark_copy_buffer_to_image.cpp 
b/benchmark/benchmark_copy_buffer_to_image.cpp
new file mode 100644
index 0000000..c3eee13
--- /dev/null
+++ b/benchmark/benchmark_copy_buffer_to_image.cpp
@@ -0,0 +1,67 @@
+#include <string.h>
+#include "utests/utest_helper.hpp"
+#include <sys/time.h>
+
+#define IMAGE_BPP 2
+
+double benchmark_copy_buffer_to_image(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] = i;//(rand() & 0xffff);  }
You should use random value instead.

+
+  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 = 0;  OCL_CREATE_BUFFER(buf[0], 
+ CL_MEM_COPY_HOST_PTR, sz, buf_data[0]);  OCL_CREATE_IMAGE(buf[1], 0, 
+ &format, &desc, NULL);
+
+  /*copy image to buffer*/
Modify your comment here.

+  size_t origin[3] = {0, 0, 0};
+  size_t region[3] = {w, h, 1};
+
+  OCL_CALL (clEnqueueCopyBufferToImage, queue, buf[0], buf[1], 0, origin, 
region,
+            0, NULL, NULL);
+  OCL_FINISH();
+  OCL_MAP_BUFFER_GTT(1);
+  /*check result*/
+  for (uint32_t j = 0; j < h; ++j)
+    for (uint32_t i = 0; i < w; i++)
+    {
+      OCL_ASSERT(((unsigned short*)buf_data[0])[j * w + i] == ((unsigned 
short*)buf_data[1])[j * w + i]);
+    }
+  OCL_UNMAP_BUFFER_GTT(1);
+  gettimeofday(&start,0);
+
+  for (uint32_t i=0; i<100; i++) {
+    OCL_CALL (clEnqueueCopyBufferToImage, queue, buf[0], buf[1], 0, origin, 
region,
+            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_buffer_to_image);
+
--
1.9.1

_______________________________________________
Beignet mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/beignet

Reply via email to