Skip to content

Commit 7e82210

Browse files
authored
FPGA: Add platform designer tutorial (#1348)
1 parent 06fc0f2 commit 7e82210

38 files changed

+10399
-0
lines changed

DirectProgramming/C++SYCL_FPGA/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ flowchart LR
131131
| [n_way_buffering](Tutorials/DesignPatterns/n_way_buffering) | [Tutorials/DesignPatterns](Tutorials/DesignPatterns) | How and when to apply the N-way buffering optimization technique
132132
| [onchip_memory_cache](Tutorials/DesignPatterns/onchip_memory_cache) | [Tutorials/DesignPatterns](Tutorials/DesignPatterns) | How and when to implement the on-chip memory cache optimization
133133
| [optimize_inner_loop](Tutorials/DesignPatterns/optimize_inner_loop) | [Tutorials/DesignPatterns](Tutorials/DesignPatterns) | How to optimize the throughput of an inner loop with a low trip
134+
| [platform_designer](Tutorials/Tools/experimental/platform_designer) | [Tutorials/Tools](Tutorials/Tools) | How to use an IP Component with Intel® Quartus® Prime Pro Edition software suite and Platform Designer
134135
| [pipe_array](Tutorials/DesignPatterns/pipe_array) | [Tutorials/DesignPatterns](Tutorials/DesignPatterns) | A design pattern to generate an array of pipes using SYCL* <br> Static loop unrolling through template metaprogramming
135136
| [private_copies](Tutorials/Features/private_copies) | [Tutorials/Features](Tutorials/Features) | The basic usage of the `private_copies` attribute <br> How the `private_copies` attribute affects the throughput and resource use of your FPGA program <br> How to apply the `private_copies` attribute to variables or arrays in your program <br> How to identify the correct `private_copies` factor for your program
136137
| [read_only_cache](Tutorials/Features/read_only_cache) | [Tutorials/Features](Tutorials/Features) | How and when to use the read-only cache feature

DirectProgramming/C++SYCL_FPGA/Tutorials/Tools/experimental/platform_designer/README.md

+318
Large diffs are not rendered by default.

DirectProgramming/C++SYCL_FPGA/Tutorials/Tools/experimental/platform_designer/README_2023-0.md

+327
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
# Direct CMake to use icpx rather than the default C++ compiler/linker on Linux
2+
# and icx-cl on Windows
3+
if(UNIX)
4+
set(CMAKE_CXX_COMPILER icpx)
5+
else() # Windows
6+
include (CMakeForceCompiler)
7+
CMAKE_FORCE_CXX_COMPILER (icx-cl IntelDPCPP)
8+
include (Platform/Windows-Clang)
9+
endif()
10+
11+
cmake_minimum_required (VERSION 3.7.2)
12+
13+
project(Add_oneAPI CXX)
14+
15+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
16+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
17+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
18+
19+
###############################################################################
20+
### Customize these build variables
21+
###############################################################################
22+
set(SOURCE_FILES src/add.cpp)
23+
set(TARGET_NAME add)
24+
25+
# Use cmake -DFPGA_DEVICE=<board-support-package>:<board-variant> to choose a
26+
# different device. Here are a few device examples (this list is not
27+
# exhaustive):
28+
# intel_s10sx_pac:pac_s10
29+
# intel_s10sx_pac:pac_s10_usm
30+
# intel_a10gx_pac:pac_a10
31+
# Note that depending on your installation, you may need to specify the full
32+
# path to the board support package (BSP), this usually is in your install
33+
# folder.
34+
#
35+
# You can also specify a device family (E.g. "Arria10" or "Stratix10") or a
36+
# specific part number (E.g. "10AS066N3F40E2SG") to generate a standalone IP.
37+
if(NOT DEFINED FPGA_DEVICE)
38+
set(FPGA_DEVICE "10AS066N3F40E2SG")
39+
endif()
40+
41+
# Use cmake -DUSER_FPGA_FLAGS=<flags> to set extra flags for FPGA backend
42+
# compilation.
43+
set(USER_FPGA_FLAGS ${USER_FPGA_FLAGS})
44+
45+
# Use cmake -DUSER_FLAGS=<flags> to set extra flags for general compilation.
46+
set(USER_FLAGS ${USER_FLAGS})
47+
48+
# Use cmake -DUSER_INCLUDE_PATHS=<paths> to set extra paths for general
49+
# compilation.
50+
set(USER_INCLUDE_PATHS ../../../../../include;${USER_INCLUDE_PATHS})
51+
52+
###############################################################################
53+
### no changes after here
54+
###############################################################################
55+
56+
# Print the device being used for the compiles
57+
message(STATUS "Configuring the design to run on FPGA board ${FPGA_DEVICE}")
58+
59+
# Set the names of the makefile targets to be generated by cmake
60+
set(EMULATOR_TARGET fpga_emu)
61+
set(SIMULATOR_TARGET fpga_sim)
62+
set(REPORT_TARGET report)
63+
set(FPGA_TARGET fpga)
64+
set(IP_EXPORT_TARGET fpga_ip_export)
65+
66+
# Set the names of the generated files per makefile target
67+
set(EMULATOR_OUTPUT_NAME ${TARGET_NAME}.${EMULATOR_TARGET})
68+
set(SIMULATOR_OUTPUT_NAME ${TARGET_NAME}.${SIMULATOR_TARGET})
69+
set(REPORT_OUTPUT_NAME ${TARGET_NAME}.${REPORT_TARGET})
70+
set(FPGA_OUTPUT_NAME ${TARGET_NAME}.${FPGA_TARGET})
71+
set(IP_EXPORT_OUTPUT_NAME ${TARGET_NAME}.${IP_EXPORT_TARGET})
72+
73+
message(STATUS "Additional USER_FPGA_FLAGS=${USER_FPGA_FLAGS}")
74+
message(STATUS "Additional USER_FLAGS=${USER_FLAGS}")
75+
76+
include_directories(${USER_INCLUDE_PATHS})
77+
message(STATUS "Additional USER_INCLUDE_PATHS=${USER_INCLUDE_PATHS}")
78+
79+
link_directories(${USER_LIB_PATHS})
80+
message(STATUS "Additional USER_LIB_PATHS=${USER_LIB_PATHS}")
81+
82+
link_libraries(${USER_LIBS})
83+
message(STATUS "Additional USER_LIBS=${USER_LIBS}")
84+
85+
if(WIN32)
86+
# add qactypes for Windows
87+
set(QACTYPES "-Qactypes")
88+
# This is a Windows-specific flag that enables exception handling in host code
89+
set(WIN_FLAG "/EHsc")
90+
else()
91+
# add qactypes for Linux
92+
set(QACTYPES "-qactypes")
93+
endif()
94+
95+
set(COMMON_COMPILE_FLAGS -fsycl -fintelfpga -Wall ${WIN_FLAG} ${QACTYPES} ${USER_FLAGS})
96+
set(COMMON_LINK_FLAGS -fsycl -fintelfpga ${QACTYPES} ${USER_FLAGS})
97+
98+
# A SYCL ahead-of-time (AoT) compile processes the device code in two stages.
99+
# 1. The "compile" stage compiles the device code to an intermediate
100+
# representation (SPIR-V).
101+
# 2. The "link" stage invokes the compiler's FPGA backend before linking. For
102+
# this reason, FPGA backend flags must be passed as link flags in CMake.
103+
set(EMULATOR_COMPILE_FLAGS -DFPGA_EMULATOR)
104+
set(EMULATOR_LINK_FLAGS )
105+
set(REPORT_COMPILE_FLAGS -DFPGA_HARDWARE)
106+
set(REPORT_LINK_FLAGS -Xshardware -Xstarget=${FPGA_DEVICE} ${USER_FPGA_FLAGS} -fsycl-link=early)
107+
set(SIMULATOR_COMPILE_FLAGS -Xssimulation -DFPGA_SIMULATOR)
108+
set(SIMULATOR_LINK_FLAGS -Xssimulation -Xsghdl -Xstarget=${FPGA_DEVICE} ${USER_FPGA_FLAGS} -reuse-exe=${CMAKE_BINARY_DIR}/${SIMULATOR_OUTPUT_NAME})
109+
set(FPGA_COMPILE_FLAGS -DFPGA_HARDWARE)
110+
set(FPGA_LINK_FLAGS -Xshardware -Xstarget=${FPGA_DEVICE} ${USER_FPGA_FLAGS} -reuse-exe=${CMAKE_BINARY_DIR}/${FPGA_OUTPUT_NAME})
111+
# get rid of this once host pipes work properly
112+
set(IP_EXPORT_COMPILE_FLAGS -DFPGA_HARDWARE)
113+
set(IP_EXPORT_LINK_FLAGS -Xshardware -Xstarget=${FPGA_DEVICE} ${USER_FPGA_FLAGS} -fsycl-link=early -fsycl-device-code-split=per_kernel)
114+
115+
###############################################################################
116+
### FPGA Emulator
117+
###############################################################################
118+
add_executable(${EMULATOR_TARGET} ${SOURCE_FILES})
119+
target_compile_options(${EMULATOR_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS})
120+
target_compile_options(${EMULATOR_TARGET} PRIVATE ${EMULATOR_COMPILE_FLAGS})
121+
target_link_libraries(${EMULATOR_TARGET} ${COMMON_LINK_FLAGS})
122+
target_link_libraries(${EMULATOR_TARGET} ${EMULATOR_LINK_FLAGS})
123+
set_target_properties(${EMULATOR_TARGET} PROPERTIES OUTPUT_NAME ${EMULATOR_OUTPUT_NAME})
124+
125+
###############################################################################
126+
### FPGA Simulator
127+
###############################################################################
128+
add_executable(${SIMULATOR_TARGET} ${SOURCE_FILES})
129+
target_compile_options(${SIMULATOR_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS})
130+
target_compile_options(${SIMULATOR_TARGET} PRIVATE ${SIMULATOR_COMPILE_FLAGS})
131+
target_link_libraries(${SIMULATOR_TARGET} ${COMMON_LINK_FLAGS})
132+
target_link_libraries(${SIMULATOR_TARGET} ${SIMULATOR_LINK_FLAGS})
133+
set_target_properties(${SIMULATOR_TARGET} PROPERTIES OUTPUT_NAME ${SIMULATOR_OUTPUT_NAME})
134+
135+
###############################################################################
136+
### Generate Report
137+
###############################################################################
138+
add_executable(${REPORT_TARGET} ${SOURCE_FILES})
139+
target_compile_options(${REPORT_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS})
140+
target_compile_options(${REPORT_TARGET} PRIVATE ${REPORT_COMPILE_FLAGS})
141+
142+
# The report target does not need the QACTYPES flag at link stage
143+
set(MODIFIED_COMMON_LINK_FLAGS_REPORT ${COMMON_LINK_FLAGS})
144+
list(REMOVE_ITEM MODIFIED_COMMON_LINK_FLAGS_REPORT ${QACTYPES})
145+
146+
target_link_libraries(${REPORT_TARGET} ${MODIFIED_COMMON_LINK_FLAGS_REPORT})
147+
target_link_libraries(${REPORT_TARGET} ${REPORT_LINK_FLAGS})
148+
set_target_properties(${REPORT_TARGET} PROPERTIES OUTPUT_NAME ${REPORT_OUTPUT_NAME})
149+
150+
###############################################################################
151+
### FPGA Hardware
152+
###############################################################################
153+
add_executable(${FPGA_TARGET} EXCLUDE_FROM_ALL ${SOURCE_FILES})
154+
target_compile_options(${FPGA_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS})
155+
target_compile_options(${FPGA_TARGET} PRIVATE ${FPGA_COMPILE_FLAGS})
156+
target_link_libraries(${FPGA_TARGET} ${COMMON_LINK_FLAGS})
157+
target_link_libraries(${FPGA_TARGET} ${FPGA_LINK_FLAGS})
158+
set_target_properties(${FPGA_TARGET} PROPERTIES OUTPUT_NAME ${FPGA_OUTPUT_NAME})
159+
160+
###############################################################################
161+
### FPGA IP Export (only necessary until native host pipes)
162+
###############################################################################
163+
add_executable(${IP_EXPORT_TARGET} ${SOURCE_FILES})
164+
target_compile_options(${IP_EXPORT_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS})
165+
target_compile_options(${IP_EXPORT_TARGET} PRIVATE ${IP_EXPORT_COMPILE_FLAGS})
166+
167+
# The ip export target does not need the QACTYPES flag at link stage
168+
set(MODIFIED_COMMON_LINK_FLAGS_EXPORT ${COMMON_LINK_FLAGS})
169+
list(REMOVE_ITEM MODIFIED_COMMON_LINK_FLAGS_EXPORT ${QACTYPES})
170+
171+
target_link_libraries(${IP_EXPORT_TARGET} ${MODIFIED_COMMON_LINK_FLAGS_EXPORT})
172+
target_link_libraries(${IP_EXPORT_TARGET} ${IP_EXPORT_LINK_FLAGS})
173+
set_target_properties(${IP_EXPORT_TARGET} PROPERTIES OUTPUT_NAME ${IP_EXPORT_OUTPUT_NAME})
174+
175+
###############################################################################
176+
### This part only manipulates cmake variables to print the commands to the user
177+
###############################################################################
178+
179+
# set the correct object file extension depending on the target platform
180+
if(WIN32)
181+
set(OBJ_EXTENSION "obj")
182+
else()
183+
set(OBJ_EXTENSION "o")
184+
endif()
185+
186+
# Set the source file names in a string
187+
set(SOURCE_FILE_NAME "${SOURCE_FILES}")
188+
189+
function(getCompileCommands common_compile_flags special_compile_flags common_link_flags special_link_flags target output_name)
190+
191+
set(file_names ${SOURCE_FILE_NAME})
192+
set(COMPILE_COMMAND )
193+
set(LINK_COMMAND )
194+
195+
foreach(source ${file_names})
196+
# Get the relative path to the source and object files
197+
file(RELATIVE_PATH CURRENT_SOURCE_FILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/${source})
198+
file(RELATIVE_PATH OBJ_FILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir/${source}.${OBJ_EXTENSION})
199+
200+
# Creating a string that contains the compile command
201+
# Start by the compiler invocation
202+
set(COMPILE_COMMAND "${COMPILE_COMMAND}${CMAKE_CXX_COMPILER}")
203+
204+
# Add all the potential includes
205+
foreach(INCLUDE ${USER_INCLUDE_PATHS})
206+
if(NOT IS_ABSOLUTE ${INCLUDE})
207+
file(RELATIVE_PATH INCLUDE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/${INCLUDE})
208+
endif()
209+
set(COMPILE_COMMAND "${COMPILE_COMMAND} -I${INCLUDE}")
210+
endforeach()
211+
212+
# Add all the common compile flags
213+
foreach(FLAG ${common_compile_flags})
214+
set(COMPILE_COMMAND "${COMPILE_COMMAND} ${FLAG}")
215+
endforeach()
216+
217+
# Add all the specific compile flags
218+
foreach(FLAG ${special_compile_flags})
219+
set(COMPILE_COMMAND "${COMPILE_COMMAND} ${FLAG}")
220+
endforeach()
221+
222+
# Get the location of the object file
223+
file(RELATIVE_PATH OBJ_FILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir/${source}.${OBJ_EXTENSION})
224+
225+
# Add the source file and the output file
226+
set(COMPILE_COMMAND "${COMPILE_COMMAND} -c ${CURRENT_SOURCE_FILE} -o ${OBJ_FILE}\n")
227+
endforeach()
228+
229+
set(COMPILE_COMMAND "${COMPILE_COMMAND}" PARENT_SCOPE)
230+
231+
# Creating a string that contains the link command
232+
# Start by the compiler invocation
233+
set(LINK_COMMAND "${LINK_COMMAND}${CMAKE_CXX_COMPILER}")
234+
235+
# Add all the common link flags
236+
foreach(FLAG ${common_link_flags})
237+
set(LINK_COMMAND "${LINK_COMMAND} ${FLAG}")
238+
endforeach()
239+
240+
# Add all the specific link flags
241+
foreach(FLAG ${special_link_flags})
242+
set(LINK_COMMAND "${LINK_COMMAND} ${FLAG}")
243+
endforeach()
244+
245+
# Add the output file
246+
set(LINK_COMMAND "${LINK_COMMAND} -o ${output_name}")
247+
248+
foreach(source ${file_names})
249+
# Get the relative path to the source and object files
250+
file(RELATIVE_PATH OBJ_FILE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${target}.dir/${source}.${OBJ_EXTENSION})
251+
252+
# Add the source file and the output file
253+
set(LINK_COMMAND "${LINK_COMMAND} ${OBJ_FILE}")
254+
endforeach()
255+
256+
# Add all the potential library paths
257+
foreach(LIB_PATH ${USER_LIB_PATHS})
258+
if(NOT IS_ABSOLUTE ${LIB_PATH})
259+
file(RELATIVE_PATH LIB_PATH ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/${LIB_PATH})
260+
endif()
261+
if(NOT WIN32)
262+
set(LINK_COMMAND "${LINK_COMMAND} -L${LIB_PATH}")
263+
else()
264+
set(LINK_COMMAND "${LINK_COMMAND} -L${LIB_PATH} -Wl,-rpath,${LIB_PATH}")
265+
endif()
266+
endforeach()
267+
268+
# Add all the potential includes
269+
foreach(LIB ${USER_LIBS})
270+
set(LINK_COMMAND "${LINK_COMMAND} -l${LIB}")
271+
endforeach()
272+
273+
set(LINK_COMMAND "${LINK_COMMAND}" PARENT_SCOPE)
274+
275+
endfunction()
276+
277+
# Windows executable is going to have the .exe extension
278+
if(WIN32)
279+
set(EXECUTABLE_EXTENSION ".exe")
280+
endif()
281+
282+
# Display the compile instructions in the emulation flow
283+
getCompileCommands("${COMMON_COMPILE_FLAGS}" "${EMULATOR_COMPILE_FLAGS}" "${COMMON_LINK_FLAGS}" "${EMULATOR_LINK_FLAGS}" "${EMULATOR_TARGET}" "${EMULATOR_OUTPUT_NAME}${EXECUTABLE_EXTENSION}")
284+
285+
add_custom_target( displayEmulationCompileCommands ALL
286+
${CMAKE_COMMAND} -E cmake_echo_color --cyan ""
287+
COMMENT "To compile manually:\n${COMPILE_COMMAND}\nTo link manually:\n${LINK_COMMAND}")
288+
add_dependencies(${EMULATOR_TARGET} displayEmulationCompileCommands)
289+
290+
# Display the compile instructions in the simulation flow
291+
getCompileCommands("${COMMON_COMPILE_FLAGS}" "${SIMULATOR_COMPILE_FLAGS}" "${COMMON_LINK_FLAGS}" "${SIMULATOR_LINK_FLAGS}" "${SIMULATOR_TARGET}" "${SIMULATOR_OUTPUT_NAME}${EXECUTABLE_EXTENSION}")
292+
293+
add_custom_target( displaySimulationCompileCommands ALL
294+
${CMAKE_COMMAND} -E cmake_echo_color --cyan ""
295+
COMMENT "To compile manually:\n${COMPILE_COMMAND}\nTo link manually:\n${LINK_COMMAND}")
296+
add_dependencies(${SIMULATOR_TARGET} displaySimulationCompileCommands)
297+
298+
# Display the compile instructions in the report flow
299+
getCompileCommands("${COMMON_COMPILE_FLAGS}" "${REPORT_COMPILE_FLAGS}" "${MODIFIED_COMMON_LINK_FLAGS_REPORT}" "${REPORT_LINK_FLAGS}" "${REPORT_TARGET}" "${REPORT_OUTPUT_NAME}${EXECUTABLE_EXTENSION}")
300+
301+
add_custom_target( displayReportCompileCommands ALL
302+
${CMAKE_COMMAND} -E cmake_echo_color --cyan ""
303+
COMMENT "To compile manually:\n${COMPILE_COMMAND}\nTo link manually:\n${LINK_COMMAND}")
304+
add_dependencies(${REPORT_TARGET} displayReportCompileCommands)
305+
306+
# Display the compile instructions in the IP export flow (Remove after native host pipes work properly)
307+
getCompileCommands("${COMMON_COMPILE_FLAGS}" "${IP_EXPORT_COMPILE_FLAGS}" "${MODIFIED_COMMON_LINK_FLAGS_EXPORT}" "${IP_EXPORT_LINK_FLAGS}" "${IP_EXPORT_TARGET}" "${IP_EXPORT_OUTPUT_NAME}${EXECUTABLE_EXTENSION}")
308+
309+
add_custom_target( displayExportCompileCommands ALL
310+
${CMAKE_COMMAND} -E cmake_echo_color --cyan ""
311+
COMMENT "To compile manually:\n${COMPILE_COMMAND}\nTo link manually:\n${LINK_COMMAND}")
312+
add_dependencies(${IP_EXPORT_TARGET} displayExportCompileCommands)
313+
314+
# Display the compile instructions in the fpga flow
315+
getCompileCommands("${COMMON_COMPILE_FLAGS}" "${FPGA_COMPILE_FLAGS}" "${COMMON_LINK_FLAGS}" "${FPGA_LINK_FLAGS}" "${FPGA_TARGET}" "${FPGA_OUTPUT_NAME}${EXECUTABLE_EXTENSION}")
316+
317+
add_custom_target( displayFPGACompileCommands ALL
318+
${CMAKE_COMMAND} -E cmake_echo_color --cyan ""
319+
COMMENT "To compile manually:\n${COMPILE_COMMAND}\nTo link manually:\n${LINK_COMMAND}")
320+
add_dependencies(${FPGA_TARGET} displayFPGACompileCommands)

0 commit comments

Comments
 (0)