Joseph Redmon
2014-08-08 d9f1b0b16edeb59281355a855e18a8be343fc33c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
__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) 
{
    int b = get_global_id(0);
    int c = get_global_id(1);
 
    int h = get_local_id(0);
    int w = get_local_id(1);
 
    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 w_offset = c % ksize;
    int h_offset = (c / ksize) % ksize;
    int c_im = c / ksize / ksize;
 
    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];
}