Convert a color image to grayscale on the GPU with a 2D grid of 2D blocks, one thread per pixel.
The input rgb holds height rows of width pixels, row-major, with the three channels interleaved: pixel occupies bytes 3 * (r * width + c), +1 and +2 for red, green and blue. The output gray holds one byte per pixel at index r * width + c. Use the integer luminance formula
a fixed-point version of rounded to the nearest integer (the weights sum to 256).
Complete:
__global__ kernel that computes its pixel's column from the x dimension and its row from the y dimension, and skips threads that fall outside the image.void rgb_to_gray(const unsigned char* rgb, unsigned char* gray, int width, int height) with host pointers. Allocate, copy in, launch a 2D grid (for example 16 x 16 blocks), copy back and free. width, height . Do not write a main() in your solution.