2014-12-04 10:20:29 +03:00
|
|
|
__kernel void col2im(__global float *data_col, int offset,
|
2014-10-13 11:29:01 +04:00
|
|
|
int channels, int height, int width,
|
|
|
|
int ksize, int stride, int pad, __global float *data_im)
|
2014-08-28 06:11:46 +04:00
|
|
|
{
|
|
|
|
|
2014-10-13 11:29:01 +04:00
|
|
|
int height_col = (height - ksize) / stride + 1;
|
|
|
|
int width_col = (width - ksize) / stride + 1;
|
|
|
|
if (pad){
|
|
|
|
height_col = 1 + (height-1) / stride;
|
|
|
|
width_col = 1 + (width-1) / stride;
|
|
|
|
pad = ksize/2;
|
|
|
|
}
|
|
|
|
|
2014-08-28 06:11:46 +04:00
|
|
|
int id = get_global_id(0);
|
|
|
|
int index = id;
|
2014-10-13 11:29:01 +04:00
|
|
|
int w = id%width + pad;
|
2014-08-28 06:11:46 +04:00
|
|
|
id /= width;
|
2014-10-13 11:29:01 +04:00
|
|
|
int h = id%height + pad;
|
2014-08-28 06:11:46 +04:00
|
|
|
id /= height;
|
|
|
|
int c = id%channels;
|
|
|
|
|
2014-10-30 21:28:37 +03:00
|
|
|
int w_start = (w-ksize+stride)/stride;
|
2014-10-13 11:29:01 +04:00
|
|
|
int w_end = w/stride + 1;
|
|
|
|
|
2014-10-30 21:28:37 +03:00
|
|
|
int h_start = (h-ksize+stride)/stride;
|
2014-10-13 11:29:01 +04:00
|
|
|
int h_end = h/stride + 1;
|
|
|
|
|
2014-08-28 06:11:46 +04:00
|
|
|
int rows = channels * ksize * ksize;
|
|
|
|
int cols = height_col*width_col;
|
2014-12-04 10:20:29 +03:00
|
|
|
int col_offset = (c*ksize*ksize + h * ksize + w)*height_col*width_col;
|
2014-10-13 11:29:01 +04:00
|
|
|
int h_coeff = (1-stride*ksize*height_col)*width_col;
|
|
|
|
int w_coeff = 1-stride*height_col*width_col;
|
|
|
|
float val = 0;
|
|
|
|
int h_col, w_col;
|
|
|
|
for(h_col = h_start; h_col < h_end; ++h_col){
|
|
|
|
for(w_col = w_start; w_col < w_end; ++w_col){
|
2014-12-04 10:20:29 +03:00
|
|
|
int col_index = col_offset +h_col*h_coeff + w_col*w_coeff;
|
2014-10-30 21:28:37 +03:00
|
|
|
float part = (w_col < 0 || h_col < 0 || h_col >= height_col || w_col >= width_col) ? 0 : data_col[col_index];
|
|
|
|
val += part;
|
2014-08-28 06:11:46 +04:00
|
|
|
}
|
|
|
|
}
|
2014-12-04 10:20:29 +03:00
|
|
|
data_im[index+offset] = val;
|
2014-08-28 06:11:46 +04:00
|
|
|
}
|