Compute a same-size 2-D convolution with zero padding on the GPU. Given an input image of height and width and a square kernel of radius (so the kernel is ), produce an output of the same where
and whenever falls outside the image.
Your kernel must restage each output tile plus its 2-D halo through shared memory so interior pixels are fetched once per block. Both the image and the kernel are stored row-major: is at index i * W + j, and is at index (u+R) * (2R+1) + (v+R).
Complete:
__global__ kernel that performs the tiled convolution.void solve(const float* input, const float* kernel, float* output, int H, int W, int radius) where every pointer is a host pointer. input and output have H * W elements; kernel has (2*radius+1)^2 elements. Allocate, copy in, launch, copy out, and free.Constraints: 1 <= H, W <= 32, 1 <= radius <= 2. Do not write a main() in your solution.