From 1edcf73a73d2007afc61289245763f5cf0c29e10 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Thu, 04 Dec 2014 07:20:29 +0000
Subject: [PATCH] Detection good, split up col images

---
 src/im2col.cl |   64 +++++++++++++++++++++++++------
 1 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/src/im2col.cl b/src/im2col.cl
index 765a92d..31f7db6 100644
--- a/src/im2col.cl
+++ b/src/im2col.cl
@@ -1,26 +1,64 @@
 
-__kernel void im2col(__global float *data_im, const int im_offset,
-    const int channels, const int height, const int width,
-    const int ksize, const int stride, __global float *data_col, const int col_offset) 
+__kernel void im2col_pad(__global float *im,  int offset,
+     int channels,  int height,  int width,
+     int ksize,  int stride, __global float *data_col)
 {
-    int b = get_global_id(0);
-    int c = get_global_id(1);
+    int c,h,w;
+    int height_col = 1 + (height-1) / stride;
+    int width_col = 1 + (width-1) / stride;
+    int channels_col = channels * ksize * ksize;
 
-    int h = get_local_id(0);
-    int w = get_local_id(1);
+    int pad = ksize/2;
 
+    int id = get_global_id(0);
+    int col_index = id;
+    w = id % width_col;
+    id /= width_col;
+    h = id % height_col;
+    id /= height_col;
+    c = id % channels_col;
+    id /= channels_col;
+
+    int col_size = height_col*width_col*channels_col;
+    int w_offset = c % ksize;
+    int h_offset = (c / ksize) % ksize;
+    int im_channel = c / ksize / ksize;
+    int im_row = h_offset + h * stride - pad;
+    int im_col = w_offset + w * stride - pad;
+
+    int im_index = offset + im_col + width*(im_row + height*im_channel);
+    float val = (im_row < 0 || im_col < 0 || im_row >= height || im_col >= width) ? 0 : im[im_index];
+
+    data_col[col_index] = val;
+}
+
+__kernel void im2col_nopad(__global float *im,  int offset,
+        int channels,  int height,  int width,
+        int ksize,  int stride, __global float *data_col)
+{
+    int c,h,w;
     int height_col = (height - ksize) / stride + 1;
     int width_col = (width - ksize) / stride + 1;
     int channels_col = channels * ksize * ksize;
 
-    int im_offset = height*width*channels*b;
-    int col_offset = height_col*width_col*channels_col*b;
+    int id = get_global_id(0);
+    int col_index = id;
+    w = id % width_col;
+    id /= width_col;
+    h = id % height_col;
+    id /= height_col;
+    c = id % channels_col;
+    id /= channels_col;
 
+    int col_size = height_col*width_col*channels_col;
     int w_offset = c % ksize;
     int h_offset = (c / ksize) % ksize;
-    int c_im = c / ksize / ksize;
+    int im_channel = c / ksize / ksize;
+    int im_row = h_offset + h * stride;
+    int im_col = w_offset + w * stride;
 
-    data_col[(c * height_col + h) * width_col + w + col_offset] =
-        data_im[(c_im * height + h * stride + h_offset) * width
-        + w * stride + w_offset + im_offset];
+    int im_index = offset + im_col + width*(im_row + height*im_channel);
+    float val = (im_row < 0 || im_col < 0 || im_row >= height || im_col >= width) ? 0 : im[im_index];
+
+    data_col[col_index] = val;
 }

--
Gitblit v1.10.0