Following up on the previous post in which I introduced Fast Fourier transforms (FFT) on the GPU, in this post I will talk about the C++ AMP FFT Library and explain how to use it in your application.
As was noted in the previous post, DirectX already contains an FFT API. So what was left for us to do is provide a simple C++ AMP wrapper on top of it which is available as the C++ AMP FFT Library on CodePlex. To use it follow these steps:
If you download the library sources, the sample directory has an example Visual Studio project showing how to use C++ AMP FFT library to perform forward and inverse transforms.
Let’s go over a very simple use of the fft class in the C++ AMP FFT Library and explain it.
The first line creates the transform object, of type fft<float, 1>. Note that like C++ AMP arrays, the transform type captures the element type of the transformation, andits dimension:
After the fft object is created, you’d typically cache it and reuse it to transform many different inputs, albeit all have to have the same extent.
Lines 2 and 3 define such possible input and output, and line 4 transforms the input into the output. As is typical with C++ AMP, the output is left on the accelerator, and you have the choice if and when to copy it back to the CPU. You could, for example, use the output of an FFT transform in a subsequent parallel_for_each call, without ever bringing the results back to main memory.
Because the FFT library is implemented using DirectCompute and not using C++ AMP, it has some disadvantages when used from C++ AMP.
In my next post on the topic of FFT I will share a test program which illustrates higher dimensional transforms and inverse transforms.
Part I: Fast Fourier Transforms (FFT) on The GPU
Part II: C++ AMP FFT Library
Part III: C++ AMP FFT Test Application