In image processing, applying filter function is very common and Gaussian Blur is one such method. In this blog post I’ll share a C++ AMP implementation.
In main(), create an instance of the gaussian_blur class, apply the filter (execute) and validate results (verify). The constructor generates random input data for calculation.
In the gaussian_blur function, kernel input data are stored in a concurrency::array. Then it invokes a parallel_for_each computation (kernel) that uses the simple model. The kernel is implemented in the gaussian_blur::gaussian_blur_simple_amp_kernel function. At the end result is copied out of GPU to host memory.
This function implements a C++ AMP kernel. For each input data point, a GPU thread is used to apply the filter. Each GPU thread for a given data point reads in neighboring data points along both x-axis and y-axis and apply the filter to the point. The filter is applied in the nested “for” loop which is traversing neighbors and the “if” statement inside bounds access to the array dimension. The result is then stored in the output array.
This function validates results computed on the GPU. Here the same input data is used to calculate results on CPU again. Finally results of CPU and GPU are compared to determine correctness.