The AMD FFT IP block can be
called within a C++ design using the library hls_fft.h
. This section explains how the FFT can be configured in your
C++ code. An example FFT application can be found in Vitis-HLS-Introductory-Examples/Misc on
GitHub.
To use the FFT in your C++ code:
- Include the hls_fft.h library in the code
- Set the default parameters using the predefined struct
hls::ip_fft::params_t
- Define the runtime configuration
- Call the FFT functionTip: Because it uses the DATAFLOW pragma or directive, the pipelined execution of an FFT must be in a dataflow loop and not a pipelined loop.
- Optionally, check the runtime status
The following code examples provide a summary of how each of these steps is performed. Each step is discussed in more detail below.
First, include the FFT library in the source code. This header file resides in the include directory in the Vitis HLS installation area which is automatically searched when Vitis HLS executes.
#include "hls_fft.h"
Define the static parameters of the FFT. This includes such things as
input width, number of channels, type of architecture. which do not change
dynamically. The FFT library includes a parameterization struct hls::ip_fft::params_t
, which can be used to initialize
all static parameters with default values.
In this example, the default values for output ordering and the
widths of the configuration and status ports are over-ridden using a user-defined
struct param1
based on the predefined struct.
struct param1 : hls::ip_fft::params_t {
static const unsigned ordering_opt = hls::ip_fft::natural_order;
static const unsigned config_width = FFT_CONFIG_WIDTH;
static const unsigned status_width = FFT_STATUS_WIDTH;
};
Define types and variables for both the runtime configuration and runtime status. These values can be dynamic and are therefore defined as variables in the C code which can change and are accessed through APIs.
typedef hls::ip_fft::config_t<param1> config_t;
typedef hls::ip_fft::status_t<param1> status_t;
config_t fft_config1;
status_t fft_status1;
Next, set the runtime configuration. This example sets the direction of the FFT (Forward or Inverse) based on the value of variable “direction” and also set the value of the scaling schedule.
fft_config1.setDir(direction);
fft_config1.setSch(0x2AB);
Call the FFT function using the HLS namespace with the defined static
configuration (param1
in this example). The
function parameters are, in order, input data, output data, output status and input
configuration.
hls::fft<param1> (xn1, xk1, &fft_status1, &fft_config1);
Finally, check the output status. This example checks the overflow flag and stores the results in variable “ovflo”
*ovflo = fft_status1->getOvflo();
hls::stream
for arguments. Refer to Using FFT Function with Streaming Interface for more information.