1 #include "cuda_runtime.h" 14 const int height,
const int width,
const int ksize,
17 const int height_col,
const int width_col,
19 int index = blockIdx.x*blockDim.x+threadIdx.x;
20 for(; index < n; index += blockDim.x*gridDim.x){
22 int w = index % width + pad;
23 int h = (index / width) % height + pad;
24 int c = index / (width * height);
26 int w_col_start = (w < ksize) ? 0 : (w - ksize) / stride + 1;
27 int w_col_end = min(w / stride + 1, width_col);
28 int h_col_start = (h < ksize) ? 0 : (h - ksize) / stride + 1;
29 int h_col_end = min(h / stride + 1, height_col);
32 (c * ksize * ksize + h * ksize + w) * height_col * width_col;
33 int coeff_h_col = (1 - stride * ksize * height_col) * width_col;
34 int coeff_w_col = (1 - stride * height_col * width_col);
35 for (
int h_col = h_col_start; h_col < h_col_end; ++h_col) {
36 for (
int w_col = w_col_start; w_col < w_col_end; ++w_col) {
37 val += data_col[offset + h_col * coeff_h_col + w_col * coeff_w_col];
40 data_im[index] += val;
45 int channels,
int height,
int width,
46 int ksize,
int stride,
int pad,
float *data_im){
49 int height_col = (height + 2 * pad - ksize) / stride + 1;
50 int width_col = (width + 2 * pad - ksize) / stride + 1;
51 int num_kernels = channels * height * width;
54 num_kernels, data_col, height, width, ksize, pad,
void col2im_gpu(float *data_col, int channels, int height, int width, int ksize, int stride, int pad, float *data_im)
__global__ void col2im_gpu_kernel(const int n, const float *data_col, const int height, const int width, const int ksize, const int pad, const int stride, const int height_col, const int width_col, float *data_im)