Skip to content

FPGA: Add fpga_template sample #1262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
935ba83
add fpga_template source code from add-empty-design branch
whitepau Dec 7, 2022
6167e7b
add support for 2023.1 and 2023.0
whitepau Dec 7, 2022
9fa0534
fix for errant clang-format
whitepau Dec 7, 2022
4736d41
add note about CL... environment variable
whitepau Dec 8, 2022
98a0dfc
improve verbosity of CMake file. open issue: doesn't print object file
whitepau Dec 9, 2022
259be82
Revert "improve verbosity of CMake file. open issue: doesn't print ob…
whitepau Dec 9, 2022
539bba7
clean up CMakeLists environment variables
whitepau Dec 9, 2022
9e78584
fix bug in CMakeLists (missing Xstarget)
whitepau Dec 9, 2022
1242e91
Merge branch 'oneapi-src:master' into add-fpga_template
whitepau Dec 12, 2022
fabe2ee
update readme per Yohann's requests
whitepau Dec 15, 2022
3ab9516
Merge branch 'add-fpga_template' of https://github.com/whitepau/oneAP…
whitepau Dec 15, 2022
19b52dd
add support for additional include paths
whitepau Dec 16, 2022
5fcf38b
Merge branch 'master' into add-fpga_template
whitepau Jan 16, 2023
3497ef4
use One True CMake file
whitepau Jan 16, 2023
96ea182
remove lib paths and lib because it doesn't work on windows
whitepau Jan 17, 2023
593508d
minor readme tweaks
whitepau Jan 18, 2023
b04e525
Yohann's changes
whitepau Jan 19, 2023
9dc212e
move out of experimental dir
whitepau Jan 20, 2023
f242ce9
minor edits from yohann's code review
whitepau Jan 23, 2023
dd174e3
Update DirectProgramming/C++SYCL_FPGA/Tutorials/GettingStarted/fpga_t…
whitepau Jan 23, 2023
0fb00aa
fix flag outputs for `fpga` target
whitepau Jan 24, 2023
5bbf85d
code style improvements
whitepau Jan 30, 2023
f19a571
update readme to be compliant with IPA/Intel® Agilex® defaults
whitepau Feb 1, 2023
cdcf2f1
simplify as per Paul Pedersen's feedback
whitepau Feb 3, 2023
bd67843
remove redundant 'public'
whitepau Feb 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DirectProgramming/DPC++FPGA/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ flowchart LR
|:--- |:--- |:---
| [fpga_compile](Tutorials/GettingStarted/fpga_compile) | [Tutorials/GettingStarted](Tutorials/GettingStarted) | How and why compiling SYCL* code for FPGA differs from CPU or GPU <br> FPGA device image types and when to use them. <br> The compile options used to target FPGA
| [fast_recompile](Tutorials/GettingStarted/fast_recompile) | [Tutorials/GettingStarted](Tutorials/GettingStarted) | Why to separate host and device code compilation in your FPGA project <br> How to use the `-reuse-exe` and device link. <br> Which method to choose for your project
| [fpga_template](Tutorials/GettingStarted/fpga_template) | [Tutorials/GettingStarted](Tutorials/GettingStarted) | Showcases the CMake build system that is used in other code samples, and serves as a template that you can re-use in your own designs.

#### Tier 2: Explore the Fundamentals

Expand Down Expand Up @@ -92,7 +93,7 @@ flowchart LR
| [pipes](Tutorials/Features/pipes) | [Tutorials/Features](Tutorials/Features) | The basics of using SYCL*-compliant pipes extension for FPGA <br> How to declare and use pipes
| [printf](Tutorials/Features/printf) | [Tutorials/DesignPatterns](Tutorials/DesignPatterns) | How to declare and use `printf` in program

#### Tier 3: Explore the Advances Techniques
#### Tier 3: Explore the Advanced Techniques

```mermaid
flowchart LR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
if(UNIX)
# Direct CMake to use icpx rather than the default C++ compiler/linker
set(CMAKE_CXX_COMPILER icpx)
else() # Windows
# Force CMake to use icpx rather than the default C++ compiler/linker
# (needed on Windows only)
include (CMakeForceCompiler)
CMAKE_FORCE_CXX_COMPILER (icx-cl IntelDPCPP)
include (Platform/Windows-Clang)
endif()

cmake_minimum_required (VERSION 3.4)

project(FPGATemplate CXX)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

add_subdirectory (src)
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
# FPGA Template

This project serves as a template for Intel® oneAPI FPGA designs.

| Optimized for | Description
|:--- |:---
| OS | Linux* Ubuntu* 18.04/20.04 <br> RHEL*/CentOS* 8 <br> SUSE* 15 <br> Windows* 10
| Hardware | Intel® FPGA Programmable Acceleration Card (PAC) D5005 (with Intel Stratix® 10 SX) <br> Intel® FPGA 3rd party / custom platforms with oneAPI support (and SYCL USM support) Note: Intel® FPGA PAC hardware is only compatible with Ubuntu 18.04*
| Software | Intel® oneAPI DPC++ Compiler <br> Intel® Quartus Prime Pro Edition
| What you will learn | Best practices for creating and managing a oneAPI FPGA project
| Time to complete | 10 minutes

***Notice**: SYCL Unified Shared Memory (USM) host allocations (and therefore the code in this tutorial) are only supported by Board Support Packages (BSPs) with USM support (e.g. the Intel® FPGA PAC D5005 (with Intel Stratix® 10 SX) `intel_s10sx_pac:pac_s10_usm`)*

## Purpose

Use this project as a starting point when you build designs for the Intel® oneAPI FPGA compiler. It includes a CMake build system to automate selecting the various command-line flags for the oneAPI FPGA compiler, and a simple single-source design to serve as an example. You can customize the build flags by modifying the top part of `src/CMakeLists.txt`: if you want to pass additional flags to the Intel® oneAPI FPGA compiler, you can change the `USER_FLAGS` and `USER_HARDWARE_FLAGS` variables defined in `src/CMakeLists.txt`.

> **Note**: The code sample in this design only uses USM for improved code simplicity as compared with buffers/accessors. The included CMake build system can also be used for designs that do not use USM.

| Variable | Description |
|:--- |:---
| `USER_HARDWARE_FLAGS` | These flags apply only to flows that generate FPGA hardware (i.e. report, simulation, hardware). You can specify flags such as `-Xsclock` or `-Xshyper-optimized-handshaking=off` |
| `USER_FLAGS` | These flags apply to all flows, including emulation. You can specify flags such as `-v` or define macros such as `-DYOUR_OWN_MACRO=3` |

```bash
###############################################################################
### Customize these build variables
###############################################################################
set(SOURCE_FILE fpga_template.cpp)
set(TARGET_NAME fpga_template)

# Use cmake -DFPGA_DEVICE=<board-support-package>:<board-variant> to choose a
# different device. Here are a few device examples (this list is not
# exhaustive):
# intel_s10sx_pac:pac_s10
# intel_s10sx_pac:pac_s10_usm
# intel_a10gx_pac:pac_a10
# Note that depending on your installation, you may need to specify the full
# path to the board support package (BSP), this usually is in your install
# folder.
#
# You can also specify a device family (E.g. "Arria10" or "Stratix10") or a
# specific part number (E.g. "10AS066N3F40E2SG") to generate a standalone IP.
if(NOT DEFINED FPGA_DEVICE)
set(FPGA_DEVICE "intel_s10sx_pac:pac_s10_usm")
endif()

# Use cmake -DUSER_FPGA_FLAGS=<flags> to set extra flags for FPGA backend
# compilation.
set(USER_FPGA_FLAGS "${USER_FPGA_FLAGS}")

# Use cmake -DUSER_FLAGS=<flags> to set extra flags for general compilation.
set(USER_FLAGS "${USER_FLAGS}")
```

Everything below this in the `src/CMakeLists.txt` is necessary for selecting the compiler flags that are necessary to support the build targets specified below, and should not need to be modified.

## Building the `fpga_template` Tutorial

> **Note**: If you have not already done so, set up your CLI
> environment by sourcing the `setvars` script located in
> the root of your oneAPI installation.
>
> Linux*:
> - For system wide installations: `/opt/intel/oneapi/setvars.sh`
> - For private installations: `~/intel/oneapi/setvars.sh`
>
> Windows*:
> - `C:\Program Files(x86)\Intel\oneAPI\setvars.bat`
> - For PowerShell*, use the following command: `cmd.exe "/K" '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell'`
>
>For more information on environment variables, see **Use the setvars Script** for [Linux or macOS](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-linux-or-macos.html), or [Windows](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup/use-the-setvars-script-with-windows.html).

### Running Samples in Intel® DevCloud
If running a sample in the Intel® DevCloud, remember that you must specify the type of compute node and whether to run in batch or interactive mode. Compiles to FPGA are only supported on fpga_compile nodes. Executing programs on FPGA hardware is only supported on fpga_runtime nodes of the appropriate type, such as fpga_runtime:arria10 or fpga_runtime:stratix10. Neither compiling nor executing programs on FPGA hardware are supported on the login nodes. For more information, see the Intel® oneAPI Base Toolkit Get Started Guide ([https://devcloud.intel.com/oneapi/documentation/base-toolkit/](https://devcloud.intel.com/oneapi/documentation/base-toolkit/)).
When compiling for FPGA hardware, it is recommended to increase the job timeout to 12h.
### Using Visual Studio Code* (Optional)
You can use Visual Studio Code (VS Code) extensions to set your environment, create launch configurations,
and browse and download samples.
The basic steps to build and run a sample using VS Code include:
- Download a sample using the extension **Code Sample Browser for Intel® oneAPI Toolkits**.
- Configure the oneAPI environment with the extension **Environment Configurator for Intel® oneAPI Toolkits**.
- Open a Terminal in VS Code (**Terminal>New Terminal**).
- Run the sample in the VS Code terminal using the instructions below.
- (Linux only) Debug your GPU application with GDB for Intel® oneAPI toolkits using the **Generate Launch Configurations** extension.
To learn more about the extensions, see the
[Using Visual Studio Code with Intel® oneAPI Toolkits User Guide](https://www.intel.com/content/www/us/en/develop/documentation/using-vs-code-with-intel-oneapi/top.html).

Use these commands to run the design, depending on your OS.

### On a Linux* System
This design uses CMake to generate a build script for GNU/make.

1. Generate the `Makefile` by running `cmake`.

```bash
mkdir build
cd build
```

To compile for the Intel® FPGA PAC D5005 (with Intel Stratix® 10 SX), run `cmake` using the command:

```bash
cmake ..
```

You can also compile for a custom FPGA platform. Ensure that the board support package is installed on your system. Then run `cmake` using the command:

```
cmake .. -DFPGA_DEVICE=<board-support-package>:<board-variant>
```

> **NOTE**: This design will **not** work on the Intel® PAC with Intel Arria® 10 GX FPGA, because the design depends on USM.

2. Compile the design through the generated `Makefile`. The following build targets are provided, matching the recommended development flow:

| Target | Expected Time | Output | Description
|:--- |:--- |:--- |:---
| `make fpga_emu` | Seconds | x86-64 binary | Compiles the FPGA device code to the CPU. Use the Intel® FPGA Emulation Platform for OpenCL™ software to verify your SYCL code’s functional correctness.
| `make report` | Minutes | RTL + FPGA reports | Compiles the FPGA device code to RTL and generates an optimization report that describes the structures generated on the FPGA, identifies performance bottlenecks, and estimates resource utilization. This report will include the interfaces defined in your selected Board Support Package.
| `make fpga_sim` | Minutes | RTL + FPGA reports + x86-64 binary | Compiles the FPGA device code to RTL and generates a simulation testbench. Use the Questa*-Intel® FPGA Edition simulator to verify your design.
| `make fpga` | Multiple Hours | Quartus Place & Route (Full accelerator) + FPGA reports + x86-64 host binary | Compiles the FPGA device code to RTL and generate an FPGA image that you can run on a supported accelerator board.

The `fpga_emu`, `fpga_sim` and `fpga` targets produce binaries that you can run. The executables will be called `TARGET_NAME.fpga_emu`, `TARGET_NAME.fpga_sim`, and `TARGET_NAME.fpga`, where `TARGET_NAME` is the value you specify in `src/CMakeLists.txt`.

### On a Windows* System
This design uses CMake to generate a build script for `nmake`.

1. Generate the `Makefile` by running `cmake`.

```bash
mkdir build
cd build
```

To compile for the Intel® FPGA PAC D5005 (with Intel Stratix® 10 SX), run `cmake` using the command:

```bash
cmake -G "NMake Makefiles" ..
```

You can also compile for a custom FPGA platform. Ensure that the board support package is installed on your system. Then run `cmake` using the command:

```
cmake -G "NMake Makefiles" .. -DFPGA_DEVICE=<board-support-package>:<board-variant>
```

> **NOTE**: This design will **not** work on the Intel® PAC with Intel Arria® 10 GX FPGA, because the design depends on USM.


2. Compile the design through the generated `Makefile`. The following build targets are provided, matching the recommended development flow:

| Target | Expected Time | Output | Description
|:--- |:--- |:--- |:---
| `nmake fpga_emu` | Seconds | x86-64 binary | Compiles the FPGA device code to the CPU. Use the Intel® FPGA Emulation Platform for OpenCL™ software to verify your SYCL code’s functional correctness.
| `nmake report` | Minutes | RTL + FPGA reports | Compiles the FPGA device code to RTL and generates an optimization report that describes the structures generated on the FPGA, identifies performance bottlenecks, and estimates resource utilization. This report will include the interfaces defined in your selected Board Support Package.
| `nmake fpga_sim` | Minutes | RTL + FPGA reports + x86-64 binary | Compiles the FPGA device code to RTL and generates a simulation testbench. Use the Questa*-Intel® FPGA Edition simulator to verify your design.
| `nmake fpga` | Multiple Hours | Quartus Place & Route (Full accelerator) + FPGA reports + x86-64 host binary | Compiles the FPGA device code to RTL and generate an FPGA image that you can run on a supported accelerator board.

The `fpga_emu`, `fpga_sim`, and `fpga` targets also produce binaries that you can run. The executables will be called `TARGET_NAME.fpga_emu.exe`, `TARGET_NAME.fpga_sim.exe`, and `TARGET_NAME.fpga.exe`, where `TARGET_NAME` is the value you specify in `src/CMakeLists.txt`.

> **Note**: The Intel® PAC with Intel Arria® 10 GX FPGA and Intel® FPGA PAC D5005 (with Intel Stratix® 10 SX) do not support Windows*. Compiling to FPGA hardware on Windows* requires a third-party or custom Board Support Package (BSP) with Windows* support.

> **Note**: If you encounter any issues with long paths when compiling under Windows*, you may have to create your ‘build’ directory in a shorter path, for example c:\samples\build. You can then run cmake from that directory, and provide cmake with the full path to your sample directory.

### Additional Documentation
- [Explore SYCL* Through Intel® FPGA Code Samples](https://software.intel.com/content/www/us/en/develop/articles/explore-dpcpp-through-intel-fpga-code-samples.html) helps you to navigate the samples and build your knowledge of FPGAs and SYCL.
- [FPGA Optimization Guide for Intel® oneAPI Toolkits](https://software.intel.com/content/www/us/en/develop/documentation/oneapi-fpga-optimization-guide) helps you understand how to target FPGAs using SYCL and Intel® oneAPI Toolkits.
- [Intel® oneAPI Programming Guide](https://software.intel.com/en-us/oneapi-programming-guide) helps you understand target-independent, SYCL-compliant programming using Intel® oneAPI Toolkits.

### Troubleshooting
If an error occurs, you can get more details by running `make` with the `VERBOSE=1` argument (on Windows use `nmake` instead):

```
make VERBOSE=1
```

```
nmake VERBOSE=1
```

For more comprehensive troubleshooting, use the Diagnostics Utility for Intel® oneAPI Toolkits, which provides system checks to find missing dependencies and permissions errors. [Learn more](https://www.intel.com/content/www/us/en/develop/documentation/diagnostic-utility-user-guide/top.html).

### In Third-Party Integrated Development Environments (IDEs)

You can compile and run this tutorial in the Eclipse* IDE (in Linux*) and the Visual Studio* IDE (in Windows*). For instructions, refer to the following link: [FPGA Workflows on Third-Party IDEs for Intel® oneAPI Toolkits](https://www.intel.com/content/www/us/en/developer/articles/technical/intel-oneapi-dpcpp-fpga-workflow-on-ide.html).

## Running the Sample

1. Run the sample on the FPGA emulator (the kernel executes on the CPU):

```
./fpga_template.fpga_emu (Linux)
fpga_template.fpga_emu.exe (Windows)
```

2. Run the sample on the FPGA simulator device:

> **NOTE**: you need to define the `CL_CONTEXT_MPSIM_DEVICE_INTELFPGA=1 environment variable in oneAPI 2023.1

```
CL_CONTEXT_MPSIM_DEVICE_INTELFPGA=1 ./fpga_template.fpga_sim (Linux)
cmd /V /C "set CL_CONTEXT_MPSIM_DEVICE_INTELFPGA=1&& fpga_template.fpga_sim.exe" (Windows)
```

3. Run the sample on the FPGA device:
```
./fpga_template.fpga (Linux)
fpga_template.fpga.exe (Windows)
```

## License
Code samples are licensed under the MIT license. See
[License.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/License.txt) for details.

Third party program Licenses can be found here: [third-party-programs.txt](https://github.com/oneapi-src/oneAPI-samples/blob/master/third-party-programs.txt).
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"guid": "418AA4D8-0A61-4FDB-845A-CDA4DA0655E7",
"name": "FPGA Template",
"categories": ["Toolkit/oneAPI Direct Programming/DPC++ FPGA/Getting Started Tutorials"],
"description": "This project serves as a template for Intel® oneAPI FPGA designs. ",
"toolchain": ["dpcpp"],
"os": ["linux", "windows"],
"targetDevice": ["FPGA"],
"builder": ["cmake"],
"languages": [{"cpp":{}}],
"commonFolder": {
"base": "../../..",
"include": [
"README.md",
"Tutorials/GettingStarted/experimental/fpga_template",
"include"
],
"exclude": []
},
"ciTests": {
"linux": [
{
"id": "fpga_emu",
"steps": [
"dpcpp --version",
"mkdir build",
"cd build",
"cmake ..",
"make fpga_emu",
"./fpga_template.fpga_emu"
]
},
{
"id": "report",
"steps": [
"dpcpp --version",
"mkdir build",
"cd build",
"cmake ..",
"make report"
]
},
{
"id": "fpga_sim",
"steps": [
"dpcpp --version",
"mkdir build",
"cd build",
"cmake ..",
"make fpga_sim",
"./fpga_template.fpga_sim"
]
}
],
"windows": [
{
"id": "fpga_emu",
"steps": [
"dpcpp --version",
"cd ../../../..",
"mkdir build",
"cd build",
"cmake -G \"NMake Makefiles\" ../Tutorials/GettingStarted/experimental/fpga_template",
"nmake fpga_emu",
"fpga_template.fpga_emu.exe"
]
},
{
"id": "report",
"steps": [
"dpcpp --version",
"cd ../../../..",
"mkdir build",
"cd build",
"cmake -G \"NMake Makefiles\" ../Tutorials/GettingStarted/experimental/fpga_template",
"nmake report"
]
},
{
"id": "fpga_sim",
"steps": [
"dpcpp --version",
"cd ../../../..",
"mkdir build",
"cd build",
"cmake -G \"NMake Makefiles\" ../Tutorials/GettingStarted/experimental/fpga_template",
"nmake fpga_sim",
"fpga_template.fpga_sim.exe"
]
}
]
},
"expertise": "Getting Started"
}
Loading