This readme file for the Finite Difference (3D) Computation OpenCL Design Example contains information about the design example package. For more examples, please visit the Altera OpenCL Design Examples page.
This benchmark demonstrates an OpenCL implementation of a 3D finite difference stencil-only computation. In an order-k stencil computation, each output point is a function of 3k + 1 points (k adjacent points on each direction). Because the input volume is large, only a subset of the input points may be present in on-chip memory at any given time. Traditional OpenCL implementations load tiles of the input volume. The border points of each tile will be reloaded by multiple tiles to process all the associated outputs. This leads to a large number of redundant memory accesses. Due to the high memory bandwidth requirements, the overall performance of the computation is dependent on the number of redundant memory accesses.
Altera's compiler leverages a sliding window computation pattern to avoid most redundant accesses. A volume much larger than the tile size is streamed through an on-chip memory window with fewer redundant accesses. This computation pattern can be described using a single work-item kernel.
The benchmark code is configured to compute an order-8 stencil on a volume of 504x504x504 points. The volume geometry can be changed at run time.
For more implementation details, see device/fd3d.cl.
Requirement | Version | OpenCL Kernel | Host Program | ||||
---|---|---|---|---|---|---|---|
Hardware Compile | Emulation Compile | Hardware | Emulation | ||||
Compile | Run | Compile | Run | ||||
Altera Complete Design Suite (Quartus II) | 16.0 or later | ✓ | ✓ | ||||
Altera SDK for OpenCL | 16.0 or later | ✓ | ✓ | ✓ (either) | ✓ (either) | ✓ (either) | ✓ (either) |
Altera Runtime Environment for OpenCL | 16.0 or later | ||||||
Board Support Package | 16.0-compatible | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Board Hardware | - | ✓ | |||||
gcc | 4.4.7 or later | ✓ | ✓ | ✓ | ✓ | ||
GNU Make | 3.8.1 or later | ✓ | ✓ |
Path | Description |
---|---|
fd3d/ | |
Makefile | Makefile for host program |
bin/ | Host program, AOCX files |
device/ | OpenCL kernel files |
fd3d.cl | Top-level OpenCL kernel file |
host/ | |
inc/ | Host include files |
src/ | Host source files |
The top-level OpenCL kernel file is device/fd3d.cl.
To compile the OpenCL kernel, run:
where <board> matches the board you want to target. The -o bin/fd3d.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:
When running this kernel in emulation mode, set dimensions to be much lower than the defaults. Otherwise, the emulated code may crash due to running out of stack space.
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:
Example output of running this benchmark is shown below:
Volume size: 504 x 504 x 504 Launching an order-8 stencil computation for 5 time steps Processing time = 244.6780ms Throughput = 2.6162 Gpoints / sec Verifying data --> PASSEDOutput
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:
The general command-line for the host program is:
where the parameters are:
Parameter | Type | Default | Description |
---|---|---|---|
-t=<#> | Optional | 5 | Number of time steps |
-x=<#> | Optional | 504 | Size of x dimension of volume |
-y=<#> | Optional | 504 | Size of y dimension of volume |
-z=<#> | Optional | 504 | Size of z dimension of volume |
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 |
---|---|---|---|
1.4 | 16.0 | June 2016 |
|
1.3 | 14.1 | December 2014 |
|
1.2 | 14.0 | July 2014 |
|
1.1 | 13.1 | January 2014 |
|
1.0 | 13.1 | December 2013 |
|
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.
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 Altera support (myAltera).