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){
21 int w_out = index % width_col;
22 int h_index = index / width_col;
23 int h_out = h_index % height_col;
24 int channel_in = h_index / height_col;
25 int channel_out = channel_in * ksize * ksize;
26 int h_in = h_out * stride - pad;
27 int w_in = w_out * stride - pad;
28 float* data_col_ptr = data_col;
29 data_col_ptr += (channel_out * height_col + h_out) * width_col + w_out;
30 const float* data_im_ptr = data_im;
31 data_im_ptr += (channel_in * height + h_in) * width + w_in;
32 for (
int i = 0; i < ksize; ++i) {
33 for (
int j = 0; j < ksize; ++j) {
37 *data_col_ptr = (h >= 0 && w >= 0 && h < height && w < width) ?
38 data_im_ptr[i * width + j] : 0;
42 data_col_ptr += height_col * width_col;
49 int channels,
int height,
int width,
50 int ksize,
int stride,
int pad,
float *data_col){
53 int height_col = (height + 2 * pad - ksize) / stride + 1;
54 int width_col = (width + 2 * pad - ksize) / stride + 1;
55 int num_kernels = channels * height_col * width_col;
58 num_kernels, im, height, width, ksize, pad,
__global__ void im2col_gpu_kernel(const int n, const float *data_im, 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_col)
void im2col_gpu(float *im, int channels, int height, int width, int ksize, int stride, int pad, float *data_col)