Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
*.exe
*.out
*.app

# Directories
build/
.vscode/
19 changes: 19 additions & 0 deletions rolling-mean-filter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(CMAKE_CXX_COMPILER "dpcpp")
if(WIN32)
set(CMAKE_C_COMPILER "clang-cl")
endif()

cmake_minimum_required (VERSION 2.8)

project(RollingMeanFilter)

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

# copy image files
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/input/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/input/)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/output/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/output/)

add_subdirectory (src)
add_subdirectory (src/Utils)
23 changes: 23 additions & 0 deletions rolling-mean-filter/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright Intel Corporation

SPDX-License-Identifier: MIT
https://opensource.org/licenses/MIT

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.

111 changes: 111 additions & 0 deletions rolling-mean-filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Rolling Mean Filter
This application details an implementation of a Rolling Mean Filter, and was created by combining the Buffered Host Stream and Zero Copy Data Transfer tutorials from Intels FPGA Code sample github.

***Documentation***: The [DPC++ FPGA Code Samples Guide](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 DPC++ for FPGA. <br>
The [oneAPI DPC++ FPGA Optimization Guide](https://software.intel.com/content/www/us/en/develop/documentation/oneapi-fpga-optimization-guide) is the reference manual for targeting FPGAs through DPC++. <br>
The [oneAPI Programming Guide](https://software.intel.com/en-us/oneapi-programming-guide) is a general resource for target-independent DPC++ programming.

| Optimized for | Description
--- |---
| OS | Linux* Ubuntu* 18.04; Windows* 10
| Hardware | Intel&reg; FPGA Programmable Acceleration Card (PAC) D5005 (with Intel Stratix&reg; 10 SX)
| Software | Intel&reg; oneAPI DPC++ Compiler
| What you will learn | How to optimally stream data between the host and device to maximize throughput
| Time to complete | 3 hours (On target hardware)

_Notice: SYCL USM host allocations (and therefore this tutorial) are only supported for the Intel&reg; FPGA PAC D5005 (with Intel Stratix 10 SX)_
_Notice: This tutorial demonstrates an implementation of host streaming that will be supplanted by better techniques in a future release. See the [Drawbacks and Future Work](#drawbacks-and-future-work)_

## Purpose
This application details an implementation of a Weighted Rolling Mean Filter. The application streams data from the host, to the device where it calculates the mean of an image, and applies the weightes, and back to the host. The techniques employed in this application are not specific to a CPU-FPGA system (like the one used in this tutorial); they apply to GPUs, multi-core CPUs, and other processing units.

### Key Implementation Details
In this application, we will create a design where a *Producer* (running on the CPU) produces data into USM host allocations, a *Kernel* (running on the FPGA) processes this data and produces output into host allocations, and a *Consumer* (running on the CPU) consumes the data. Data is shared between the host and FPGA device via host pointers (pointers to USM host allocations).

![](block_diagram.png)


## License
Code samples are licensed under the MIT license.

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)

## Building the `rolling-mean` Tutorial

### Running Samples in DevCloud
If running a sample in the Intel DevCloud, remember that you must specify the compute node (fpga_compile, fpga_runtime:arria10, or fpga_runtime:stratix10) as well as whether to run in batch or interactive mode. For more information see the Intel&reg; 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.

### On a Linux* System

1. Generate the `Makefile` by running `cmake`.
```
mkdir build
cd build
```
To compile for the Intel&reg; FPGA PAC D5005 (with Intel Stratix&reg; 10 SX), run `cmake` using the command:
```
cmake ..
```

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

* Compile for emulation (fast compile time, targets emulated FPGA device):
```
make fpga_emu
```
* Generate the optimization report:
```
make report
```
* Compile for FPGA hardware (longer compile time, targets FPGA device):
```
make fpga
```

## Examining the Reports
Locate `report.html` in the `rolling-mean.prj/reports/` directory. Open the report in any of Chrome*, Firefox*, Edge*, or Internet Explorer*.

## Running the Sample

1. Run the sample on the FPGA emulator (the kernel executes on the CPU):
```
./rolling-mean.fpga_emu (Linux)
```
2. Run the sample on the FPGA device:
```
./rolling-mean.fpga (Linux)
```

### Example of Output

You should see the following output in the console:

1. When running on the FPGA emulator
```
Iterations: 0

Starting kernel processing.
Kernel processing done.
PASSED
```
NOTE: The FPGA emulator does not accurately represent the performance (throughput or latency) of the kernels.

2. When running on the FPGA device
```
Iterations: 4

Starting kernel processing.
Kernel processing done.
Starting kernel processing.
Kernel processing done.
Starting kernel processing.
Kernel processing done.
Starting kernel processing.
Kernel processing done.

Average latency for the restricted USM kernel: 2830ms

PASSED
```
Binary file added rolling-mean-filter/input/cat.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_0.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_1.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_10.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_100.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_101.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_102.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_103.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_104.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_105.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_106.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_107.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_11.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_12.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_13.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_14.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_15.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_16.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_17.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_18.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_19.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_2.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_20.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_21.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_22.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_23.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_24.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_25.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_26.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_27.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_28.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_29.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_3.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_30.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_31.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_32.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_33.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_34.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_35.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_36.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_37.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_38.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_39.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_4.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_40.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_41.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_42.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_43.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_44.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_45.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_46.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_47.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_48.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_49.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_5.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_50.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_51.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_52.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_53.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_54.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_55.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_56.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_57.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_58.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_59.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_6.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_60.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_61.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_62.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_63.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_64.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_65.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_66.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_67.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_68.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_69.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_7.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_70.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_71.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_72.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_73.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_74.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_75.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_76.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_77.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_78.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_79.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_8.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_80.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_81.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_82.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_83.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_84.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_85.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_86.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_87.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_88.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_89.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_9.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_90.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_91.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_92.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_93.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_94.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_95.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_96.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_97.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_98.bmp
Binary file not shown.
Binary file added rolling-mean-filter/input/cat_99.bmp
Binary file not shown.
1 change: 1 addition & 0 deletions rolling-mean-filter/output/tmp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Empty file to add directory to git repo.
73 changes: 73 additions & 0 deletions rolling-mean-filter/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
set(SOURCE_FILE rolling-mean-filter.cpp)
set(TARGET_NAME rolling-mean-filter)
set(EMULATOR_TARGET ${TARGET_NAME}.fpga_emu)
set(FPGA_TARGET ${TARGET_NAME}.fpga)
set(REPORTS_TARGET ${TARGET_NAME}_report)

# USM is only supported on the PAC S10 board
set(S10_PAC_USM_BOARD_NAME "intel_s10sx_pac:pac_s10_usm")

# Flags
if(WIN32)
set(THREAD_FLAG "")
else()
set(THREAD_FLAG "-lpthread")
endif()

set(EMULATOR_COMPILE_FLAGS "-fintelfpga -Wall -DFPGA_EMULATOR")
set(EMULATOR_LINK_FLAGS "-fintelfpga ${THREAD_FLAG}")
set(HARDWARE_COMPILE_FLAGS "-fintelfpga -c")
set(HARDWARE_LINK_FLAGS "-fintelfpga ${THREAD_FLAG} -Wall -Xshardware -Xsboard=${S10_PAC_USM_BOARD_NAME} -reuse-exe=${CMAKE_BINARY_DIR}/${FPGA_TARGET} ${USER_HARDWARE_FLAGS}")
# use cmake -D USER_HARDWARE_FLAGS=<flags> to set extra flags for FPGA backend compilation


# FPGA emulator
if(WIN32)
set(WIN_EMULATOR_TARGET ${EMULATOR_TARGET}.exe)
add_custom_target(fpga_emu DEPENDS ${WIN_EMULATOR_TARGET})
separate_arguments(WIN_EMULATOR_COMPILE_FLAGS WINDOWS_COMMAND "${EMULATOR_COMPILE_FLAGS}")
add_custom_command(OUTPUT ${WIN_EMULATOR_TARGET}
COMMAND ${CMAKE_CXX_COMPILER} /EHsc ${WIN_EMULATOR_COMPILE_FLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE} -o ${CMAKE_BINARY_DIR}/${WIN_EMULATOR_TARGET}
DEPENDS ${SOURCE_FILE})
else()
add_executable(${EMULATOR_TARGET} ${SOURCE_FILE})
add_custom_target(fpga_emu DEPENDS ${EMULATOR_TARGET})
set_target_properties(${EMULATOR_TARGET} PROPERTIES COMPILE_FLAGS ${EMULATOR_COMPILE_FLAGS})
set_target_properties(${EMULATOR_TARGET} PROPERTIES LINK_FLAGS ${EMULATOR_LINK_FLAGS})
# to link with functions in Utils library (definded in Utils/ folder)
target_link_libraries (${EMULATOR_TARGET} LINK_PUBLIC Utils)
endif()

# FPGA hardware
if(WIN32)
add_custom_target(fpga COMMAND echo "An FPGA hardware target is not provided on Windows. See README for details.")
else()
add_executable(${FPGA_TARGET} EXCLUDE_FROM_ALL ${SOURCE_FILE})
add_custom_target(fpga DEPENDS ${FPGA_TARGET})
set_target_properties(${FPGA_TARGET} PROPERTIES COMPILE_FLAGS ${HARDWARE_COMPILE_FLAGS})
set_target_properties(${FPGA_TARGET} PROPERTIES LINK_FLAGS ${HARDWARE_LINK_FLAGS})
# to link with functions in Utils library (definded in Utils/ folder)
target_link_libraries (${FPGA_TARGET} LINK_PUBLIC Utils)

endif()

# FPGA hardware report
if(WIN32)
set(DEVICE_OBJ_FILE ${TARGET_NAME}_report.a)
add_custom_target(report DEPENDS ${DEVICE_OBJ_FILE})
separate_arguments(HARDWARE_LINK_FLAGS_LIST WINDOWS_COMMAND "${HARDWARE_LINK_FLAGS}")
add_custom_command(OUTPUT ${DEVICE_OBJ_FILE}
COMMAND ${CMAKE_CXX_COMPILER} /EHsc ${HARDWARE_LINK_FLAGS_LIST} -fsycl-link ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE} -o ${CMAKE_BINARY_DIR}/${DEVICE_OBJ_FILE}
DEPENDS ${SOURCE_FILE})
else()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE} ${SOURCE_FILE} COPYONLY)

separate_arguments(HARDWARE_LINK_FLAGS_LIST UNIX_COMMAND "${HARDWARE_LINK_FLAGS}")
separate_arguments(CMAKE_CXX_FLAGS_LIST UNIX_COMMAND "${CMAKE_CXX_FLAGS}")
list(APPEND CMAKE_CXX_FLAGS_LIST -I${CMAKE_CURRENT_SOURCE_DIR}/Utils)
add_custom_command(OUTPUT ${REPORTS_TARGET}
COMMAND ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS_LIST} ${HARDWARE_LINK_FLAGS_LIST} -fsycl-link ${SOURCE_FILE} -o ${CMAKE_BINARY_DIR}/${REPORTS_TARGET}
DEPENDS ${SOURCE_FILE})
add_custom_target(report DEPENDS ${REPORTS_TARGET})
endif()

9 changes: 9 additions & 0 deletions rolling-mean-filter/src/Utils/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Create a library called "Utils" which includes the source file *.c.
# The extension is already found. Any number of sources could be listed here.
file( GLOB UTILS_LIB_SOURCE_FILES *.c)
#message(CHECK_START "Found source files in Utils/ - ${UTILS_LIB_SOURCE_FILES}")
add_library (Utils STATIC ${UTILS_LIB_SOURCE_FILES})

# Make sure the compiler can find include files for our Utils library
# when other libraries or executables link to Hello
target_include_directories (Utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
Loading