Altera® OpenCL™ Design Example
Fast Fourier Transform (2D)

This readme file for the Fast Fourier Transform (2D) OpenCL Design Example contains information about the design example package. For more examples, please visit the Altera OpenCL Design Examples page.

Description

This benchmark demonstrates an OpenCL implementation of a 2D Fast Fourier Transform (2D FFT) on Altera FPGAs. The benchmark processes a 2D matrix of 1k × 1k complex single-precision floating-point data. The 2D transform is decomposed as a 1D FFT applied to each row followed by a 1D FFT applied to each column.

The device portion of the code applies a 1D transform to each row and transposes the matrix. This computation is enqueued twice from the host code. The second iteration applies a 1D transform to each transposed row, producing the column-wise FFT. The second transposition restores the original matrix layout.

The 1D FFT engine is written as a single work-item kernel. To achieve efficient memory access two additional ND range kernels are used to read / write data from / to global memory. All three kernels run concurrently and exchange data through channels, an Altera specific extension. See device/fft2d.cl for more implementation details.

Software & Hardware Requirements

Requirement Version OpenCL KernelHost Program
Hardware
Compile
Emulation
Compile
HardwareEmulation
CompileRunCompileRun
Altera Complete Design Suite (Quartus II)16.0 or later
Altera SDK for OpenCL16.0 or later
(either)
(either)
(either)
(either)
Altera Runtime Environment for OpenCL16.0 or later
Board Support Package16.0-compatible
Board Hardware-
gcc4.4.7 or later
GNU Make3.8.1 or later

Package Contents

Path Description
fft2d/
Makefile Makefile for host program
bin/ Host program, AOCX files
device/ OpenCL kernel files
fft2d.cl Top-level OpenCL kernel file
host/
inc/ Host include files
src/ Host source files

Compiling the OpenCL Kernel

The top-level OpenCL kernel file is device/fft2d.cl.

To compile the OpenCL kernel, run:

aoc device/fft2d.cl -o bin/fft2d.aocx --fpc --no-interleaving default --board <board>

where <board> matches the board you want to target. The -o bin/fft2d.aocx argument is used to place the compiled binary in the location that the host program expects.

If you are unsure of the boards available, use the following command to list available boards:

aoc --list-boards

Compiling for Emulator

To use the emulation flow, the compilation command just needs to be modified slightly:

aoc -march=emulator device/fft2d.cl -o bin/fft2d.aocx --fpc --no-interleaving default --board <board>

Kernel Preprocessor Definitions

The kernel has the following preprocessor definitions:

Define Type Default Description
-DLOGN=<#> Optional 10 log(total number of points) / 2. The same value must be used for host and kernel compilation.

Compiling the Host Program

To compile the host program, run:

make

The compiled host program will be located at bin/host.

Host Preprocessor Definitions

The host program has the following preprocessor definitions:

Define Type Default Description
-DLOGN=<#> Optional 10 log(total number of points) / 2. The same value must be used for host and kernel compilation.

On Linux, custom values for preprocessor defines can be specified by setting the value of CPPFLAGS when invoking the Makefile.

Running the Host Program

Before running the host program, you should have compiled the OpenCL kernel and the host program. Refer to the above sections if you have not completed those steps.

To run the host program on hardware, execute:

bin/host

Example output of running this benchmark is shown below:

Launching FFT transform (ordered data layout)
Kernel initialization is complete.
        Processing time = 3.4020ms
        Throughput = 0.3082 Gpoints / sec (30.8224 Gflops)
        Signal to noise ratio on output sample: 124.236435 --> PASSED

Launching inverse FFT transform (ordered data layout)
Kernel initialization is complete.
        Processing time = 3.3848ms
        Throughput = 0.3098 Gpoints / sec (30.9787 Gflops)
        Signal to noise ratio on output sample: 124.227971 --> PASSED

Launching FFT transform (alternative data layout)
Kernel initialization is complete.
        Processing time = 2.1122ms
        Throughput = 0.4964 Gpoints / sec (49.6450 Gflops)
        Signal to noise ratio on output sample: 124.236876 --> PASSED

Launching inverse FFT transform (alternative data layout)
Kernel initialization is complete.
        Processing time = 2.1369ms
        Throughput = 0.4907 Gpoints / sec (49.0689 Gflops)
        Signal to noise ratio on output sample: 124.231472 --> PASSED
Output

Running with the Emulator

Prior to running the emulation flow, ensure that you have compiled the kernel for emulation. Refer to the above sections if you have not done so. Also, please set up your environment for emulation. Please see the Altera SDK for OpenCL Programming Guide for more information.

For this example design, the suggested emulation command is:

CL_CONTEXT_EMULATOR_DEVICE_ALTERA=1 bin/host

OpenCL Binary Selection

The host program requires a OpenCL binary (AOCX) file to run. For this example design, OpenCL binary files should be placed in the bin directory.

By default, the host program will look for a binary file in the following order (earlier pattern matches take priority):

  1. A file named fft2d.aocx.
  2. A file named fft2d_<board>_160.aocx, where <board> is the name of the board (as passed as the --board argument to aoc).

Release History

Example Version SDK Version Date Changes
1.5 16.0 June 2016
  • Fixed makefile.
1.4 14.1 December 2014
  • New readme documentation.
  • Remove __attribute((task))__ from kernels (no longer necessary).
1.3 14.0 July 2014
  • Clean up casts in device code.
1.2 14.0 July 2014
  • Add optional host argument to control number of time steps and volume dimensions.
1.1 13.1 January 2014
  • On Linux, fix possible compilation issues (missing include files).
1.0 13.1 December 2013
  • First release of example.

Legal

Copyright (C) 2013-2016 Altera Corporation, San Jose, California, USA. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to
whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

This agreement shall be governed in all respects by the laws of the State of California and
by the laws of the United States of America.

Trademarks

OpenCL and the OpenCL logo are trademarks of Apple Inc. used by permission by Khronos.

Product is based on a published Khronos Specification, and has passed the Khronos Conformance Testing Process. Current conformance status can be found at www.khronos.org/conformance.

Contacting Altera

Although we have made every effort to ensure that this design example works correctly, there might be problems that we have not encountered. If you have a question or problem that is not answered by the information provided in this readme file or the example's documentation, please contact Altera support (myAltera).