This readme file for the Mandelbrot OpenCL Design Example contains information about the design example package. For more examples, please visit the Intel FPGA OpenCL Design Examples page.
This example provides a OpenCL kernel implementing the Mandelbrot fractal algorithm and an interactive host application that allows the user to explore the fractal by moving and zooming. The kernel is responsible for determining whether or not a point in the region to be shown is part of the Mandelbrot set or not.
This example supports partitioning the problem across multiple OpenCL devices, if available. In this example, if there are M available devices, the problem is divided such each device computes the fractal for N / M rows, where N is the number of rows in the rendered region.
Requirement | Version | OpenCL Kernel | Host Program | ||||
---|---|---|---|---|---|---|---|
Hardware Compile | Emulation Compile | Hardware | Emulation | ||||
Compile | Run | Compile | Run | ||||
Quartus Prime Design Software (Quartus II) | 16.1 or later | ✓ | ✓ | ||||
Intel(R) FPGA SDK for OpenCL(TM) | 16.1 or later | ✓ | ✓ | ✓ (either) | ✓ (either) | ✓ (either) | ✓ (either) |
Intel(R) FPGA Runtime Environment for OpenCL(TM) | 16.1 or later | ||||||
Board Support Package | 16.1-compatible | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Board Hardware | - | ✓ | |||||
gcc | 4.4.7 or later | ✓ | ✓ | ✓ | ✓ | ||
GNU Make | 3.8.1 or later | ✓ | ✓ | ||||
SDL (Simple DirectMedia Layer) library(1) | 2.0.3 | ✓ | ✓ | ✓ | ✓ |
Path | Description |
---|---|
mandelbrot/ | |
Makefile | Makefile for host program |
bin/ | Host program, AOCX files |
device/ | OpenCL kernel files |
mandelbrot_kernel.cl | Top-level OpenCL kernel file |
host/ | |
inc/ | Host include files |
src/ | Host source files |
The top-level OpenCL kernel file is device/mandelbrot_kernel.cl.
To compile the OpenCL kernel, run:
where <board> matches the board you want to target. The -o bin/mandelbrot_kernel.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:
To use the emulation flow, the compilation command just needs to be modified slightly:
The kernel has the following preprocessor definitions:
Define | Type | Default | Description |
---|---|---|---|
-DUNROLL=<#> | Optional | 20 | Number of times to unroll the main computation loop. More unrolled loop iterations lead to higher performance but with higher resource usage. |
To compile the host program, run:
The compiled host program will be located at bin/host.
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:
Please note that the command includes directives to modify the environment to point to external libraries needed by the host program.
In program controls:
Input | Action |
---|---|
q | Quit |
h | Toggle between CPU and OpenCL (hardware) modes |
d | Toggle auto-location selection mode (ignores mouse input while on) |
r | Reset view |
Left click | Move to location |
Right click | Zoom in to location |
Middle click | Zoom out from location |
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 Intel(R) FPGA SDK for OpenCL(TM) Programming Guide for more information.
For this example design, the suggested emulation command is:
The general command-line for the host program is:
where the parameters are:
Parameter | Type | Default | Description |
---|---|---|---|
-w=<#> | Optional | 800 | Width of the window |
-h=<#> | Optional | 640 | Height of the window |
-c=<#> | Optional | 1000 | Number of colors, which corresponds to the maximum number of iterations to compute for each point |
-nosmooth | Optional | Disable smoothing of large movements, where large movements are divded into multiple smaller movements | |
-display=<0|1> | Optional | 1 | Controls whether or not the output is displayed via SDL |
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):
Example Version | SDK Version | Date | Changes |
---|---|---|---|
2.4 | 16.0 | June 2016 |
|
2.3 | 14.1 | December 2014 |
|
2.2 | 14.0 | July 2014 |
|
2.1 | 13.1 | January 2014 |
|
2.0 | 13.1 | December 2013 |
|
1.0 | 13.0 | June 2013 |
|
Copyright (C) 2013-2018 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.
Simple DirectMedia Layer Copyright (C) 1997-2014 Sam LantingaThis software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.
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.
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 Intel support (myAltera).