Parallel Programming in Native Code

Parallel programming using C++ AMP, PPL and Agents libraries.

Gaussian Blur using C++ AMP

Gaussian Blur using C++ AMP

  • Comments 2

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.

main – Program entry point

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.

Download the sample

Please download the attached sample of the Gaussian Blur that we discussed here and run it on your hardware, and try to understand what the code does and to learn from it. You will need, as always, Visual Studio 11.
Blog - Comment List MSDN TechNet
  • Loading...
Leave a Comment
  • Please add 3 and 7 and type the answer here:
  • Post