[4/4] Add a benchmark which test do 3*3 median filter in image.

Submitted by Meng, Mengmeng on Nov. 18, 2015, 3:43 a.m.

Details

Message ID 1447818196-12337-1-git-send-email-mengmeng.meng@intel.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Beignet

Not browsing as part of any series.

Commit Message

Meng, Mengmeng Nov. 18, 2015, 3:43 a.m.
It's basic image test for uchar, ushort and uint.

Signed-off-by: Meng Mengmeng <mengmeng.meng@intel.com>
---
 benchmark/benchmark_copy_image.cpp | 17 ++++++++++-------
 kernels/bench_copy_image.cl        | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/benchmark/benchmark_copy_image.cpp b/benchmark/benchmark_copy_image.cpp
index a74ed88..22fa78e 100644
--- a/benchmark/benchmark_copy_image.cpp
+++ b/benchmark/benchmark_copy_image.cpp
@@ -2,8 +2,8 @@ 
 #include "utests/utest_helper.hpp"
 #include <sys/time.h>
 
-#define BENCH_COPY_IMAGE(T, M, Q) \
-double benchmark_copy_image_ ##T(void) \
+#define BENCH_COPY_IMAGE(J, T, K, M, Q) \
+double benchmark_ ##J ##_image_ ##T(void) \
 { \
   struct timeval start,stop; \
 \
@@ -16,7 +16,7 @@  double benchmark_copy_image_ ##T(void) \
   memset(&desc, 0x0, sizeof(cl_image_desc)); \
   memset(&format, 0x0, sizeof(cl_image_format)); \
 \
-  OCL_CREATE_KERNEL("bench_copy_image"); \
+  OCL_CREATE_KERNEL_FROM_FILE("bench_copy_image",K); \
   buf_data[0] = (uint32_t*) malloc(sizeof(M) * sz); \
   for (uint32_t i = 0; i < sz; ++i) { \
     ((M*)buf_data[0])[i] = rand(); \
@@ -63,8 +63,11 @@  double benchmark_copy_image_ ##T(void) \
   return (double)(100 / (elapsed * 1e-3)); \
 } \
 \
-MAKE_BENCHMARK_FROM_FUNCTION_KEEP_PROGRAM(benchmark_copy_image_ ##T, true, "FPS");
+MAKE_BENCHMARK_FROM_FUNCTION_KEEP_PROGRAM(benchmark_ ##J ##_image_ ##T, true, "FPS");
 
-BENCH_COPY_IMAGE(uchar,unsigned char,CL_UNSIGNED_INT8)
-BENCH_COPY_IMAGE(ushort,unsigned short,CL_UNSIGNED_INT16)
-BENCH_COPY_IMAGE(uint,unsigned int,CL_UNSIGNED_INT32)
+BENCH_COPY_IMAGE(copy,uchar,"bench_copy_image",unsigned char,CL_UNSIGNED_INT8)
+BENCH_COPY_IMAGE(copy,ushort,"bench_copy_image",unsigned short,CL_UNSIGNED_INT16)
+BENCH_COPY_IMAGE(copy,uint,"bench_copy_image",unsigned int,CL_UNSIGNED_INT32)
+BENCH_COPY_IMAGE(filter,uchar,"bench_filter_image",unsigned char,CL_UNSIGNED_INT8)
+BENCH_COPY_IMAGE(filter,ushort,"bench_filter_image",unsigned short,CL_UNSIGNED_INT16)
+BENCH_COPY_IMAGE(filter,uint,"bench_filter_image",unsigned int,CL_UNSIGNED_INT32)
diff --git a/kernels/bench_copy_image.cl b/kernels/bench_copy_image.cl
index fb6d4f3..0111c39 100644
--- a/kernels/bench_copy_image.cl
+++ b/kernels/bench_copy_image.cl
@@ -13,3 +13,39 @@  bench_copy_image(__read_only image2d_t src, __write_only image2d_t dst)
   color=read_imageui(src, sampler, coord);
   write_imageui(dst, coord, color);
 }
+
+__kernel void
+bench_filter_image(__read_only image2d_t src, __write_only image2d_t dst)
+ {
+  uint4 color = 0;
+  int2 coord_00, coord_01, coord_02, coord_10, coord_11, coord_12, coord_20, coord_21, coord_22;
+  int x = (int)get_global_id(0);
+  int y = (int)get_global_id(1);
+  int x_sz = (int)get_global_size(0);
+  int y_sz = (int)get_global_size(1);
+
+  const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE| CLK_ADDRESS_CLAMP| CLK_FILTER_NEAREST;
+
+  int x0 = x - 1; int x1 = x + 1;
+  int y0 = y - 1; int y1 = y + 1 ;
+  int x_left = (x > 0)?(x-1):x; int x_right = (x > x_sz - 2)?x:(x+1);
+  int y_top = (y > 0)?(y-1):y; int y_bottom = (y > y_sz - 2)?y:(y+1);
+
+  coord_00.x = x_left;  coord_00.y = y_top;
+  coord_01.x = x; coord_01.y = y_top;
+  coord_02.x = x_right; coord_02.y = y_top;
+
+  coord_10.x = x_left; coord_10.y = y;
+  coord_11.x = x; coord_11.y = y;
+  coord_12.x = x_right; coord_12.y = y;
+
+  coord_20.x = x_left; coord_20.y = y_bottom;
+  coord_21.x = x; coord_21.y = y_bottom;
+  coord_22.x = x_right; coord_22.y = y_bottom;
+
+  color = read_imageui(src, sampler, coord_00) + read_imageui(src, sampler, coord_01) + read_imageui(src, sampler, coord_02)
+        + read_imageui(src, sampler, coord_10) + read_imageui(src, sampler, coord_11) + read_imageui(src, sampler, coord_12)
+        + read_imageui(src, sampler, coord_20) + read_imageui(src, sampler, coord_21) + read_imageui(src, sampler, coord_22);
+
+  write_imageui(dst, coord_11, color/9);
+}