This readme file for the Multithread Vector Operation OpenCL Design Example contains information about the design example package. For more examples, please visit the Intel FPGA OpenCL Design Examples page.
This example design runs two instances of a class in two separate threads. Each instance uses a different kernel: First instance executes a vector addition kernel to perform: C = A + B where A, B and C are N-element vectors. Second instance executes a memberwise vector multiplication kernel to perform: C = A * B (memberwise). The kernels are intentionally kept simple and not optimized.
Since the device cannot be programmed to use two separate programs simultaneously, both of the problem instances share the same opencl program (hence running in the same context). However, as is the case in this example, the two threads can have separate command queues. For simplicity, the two threads run on two instances of the same code, with different arguments, but they can generally run two separate classses.
In addition to demonstrating the basic OpenCL API, this example supports partitioning the problem across multiple OpenCL devices, if available. If there are M available devices, the problem is divided so that each device operates on N/M points. The host program assumes that all devices are of the same type (that is, the same binary can be used, but the code can be generalized to support different device types easily.
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 | ✓ | ✓ |
Path | Description |
---|---|
multithread_vector_operation/ | |
Makefile | Makefile for host program |
bin/ | Host program, AOCX files |
device/ | OpenCL kernel files |
vector_op.cl | Top-level OpenCL kernel file |
host/ | |
src/ | Host source files |
The top-level OpenCL kernel file is device/vector_op.cl.
To compile the OpenCL kernel, run:
where <board> matches the board you want to target. The -o bin/vector_op.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:
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:
The output will include a wall-clock time of the OpenCL execution time and the kernel time as reported by the OpenCL event profiling API for both of the threads. The host program includes verification against the host CPU, printing out "PASS" when the results match.
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 |
---|---|---|---|
-n1=<integer> | Optional | 100000 | Number of values to add. |
-n2=<integer> | Optional | 200000 | Number of values to multiply. |
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.0 | 16.0 | June 2016 |
|
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.
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).