forked from oneapi-src/oneAPI-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Cmake rework #19
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
Open
yuguen
wants to merge
22
commits into
master
Choose a base branch
from
cmake-rework
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Cmake rework #19
Changes from 10 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2eeafc2
remove src/CMakeLists.txt
yuguen 9679e50
target compile rework
yuguen 22ad09c
common include
yuguen 2b0e099
include to all targets
yuguen cf3d6ef
add include cmake
yuguen 2b32e94
force compiler on Windows
yuguen 5cd5fda
adding clang on windows
yuguen 2f244df
fix report target
yuguen 5174e56
integrating Paul's comments
yuguen 024ec20
add the qactypes flag
yuguen f6d4ca6
validated on Linux only
yuguen ca75f68
fix windows commands
yuguen ea8047e
support for multiple input files
yuguen e8e3b93
fix absolute includes
yuguen 2732ac4
Apply suggestions from code review
yuguen a379d58
support link libraries
yuguen 2aed6e5
fix multi-file support
yuguen c59a06d
add printing of user flags
yuguen aca2b3e
remove unnecessary comments
yuguen abcc914
rename USER flags etc.
yuguen 3c44a64
fix hardcoded EMULATOR_TARGET path
yuguen eb1a7cd
fix fpga messages
yuguen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
171 changes: 166 additions & 5 deletions
171
DirectProgramming/DPC++FPGA/Tutorials/Features/loop_unroll/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,20 +1,181 @@ | ||||||||||||||||||||||
| # Direct CMake to use icpx rather than the default C++ compiler/linker on Linux | ||||||||||||||||||||||
| # and icx-cl on Windows | ||||||||||||||||||||||
| 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 icx-cl 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) | ||||||||||||||||||||||
| cmake_minimum_required (VERSION 3.7.2) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| project(LoopUnroll 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) | ||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| ### Customize these build variables | ||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| set(SOURCE_FILE src/loop_unroll.cpp) | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| set(TARGET_NAME loop_unroll) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # 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}") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Use cmake -DUSER_INCLUDE_PATHS=<paths> to set extra paths for general | ||||||||||||||||||||||
| # compilation. | ||||||||||||||||||||||
| set(USER_INCLUDE_PATHS "${USER_INCLUDE_PATHS}") | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Specify the location of the FPGA include directory | ||||||||||||||||||||||
| set(FPGA_INCLUDE_PATHS ../../../include) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| ### no changes after here | ||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Make cmake export the compile_commands.json file that contains the | ||||||||||||||||||||||
| # compile commands of each target | ||||||||||||||||||||||
| set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Print the device being used for the compiles | ||||||||||||||||||||||
| message(STATUS "Configuring the design to run on FPGA board ${FPGA_DEVICE}") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Set the names of the makefile targets to be generated by cmake | ||||||||||||||||||||||
| set(EMULATOR_TARGET fpga_emu) | ||||||||||||||||||||||
| set(SIMULATOR_TARGET fpga_sim) | ||||||||||||||||||||||
| set(REPORT_TARGET report) | ||||||||||||||||||||||
| set(FPGA_TARGET fpga) | ||||||||||||||||||||||
| set(IP_EXPORT_TARGET fpga_ip_export) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Set the names of the generated files per makefile target | ||||||||||||||||||||||
| set(EMULATOR_OUTPUT_NAME ${TARGET_NAME}.${EMULATOR_TARGET}) | ||||||||||||||||||||||
| set(SIMULATOR_OUTPUT_NAME ${TARGET_NAME}.${SIMULATOR_TARGET}) | ||||||||||||||||||||||
| set(REPORT_OUTPUT_NAME ${TARGET_NAME}.${REPORT_TARGET}) | ||||||||||||||||||||||
| set(FPGA_OUTPUT_NAME ${TARGET_NAME}.${FPGA_TARGET}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
|
||||||||||||||||||||||
| # Get the user include path | ||||||||||||||||||||||
| set(INCLUDEPATHS_LIST ${USER_INCLUDE_PATHS}) | ||||||||||||||||||||||
| # Add the FPGA include directory location | ||||||||||||||||||||||
| list(APPEND INCLUDEPATHS_LIST ${FPGA_INCLUDE_PATHS}) | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| # Sanitize the include path | ||||||||||||||||||||||
| separate_arguments(INCLUDEPATHS_LIST) | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the point of this |
||||||||||||||||||||||
| include_directories(${INCLUDEPATHS_LIST}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
|
||||||||||||||||||||||
| # This is a Windows-specific flag that enables exception handling in host code | ||||||||||||||||||||||
| if(WIN32) | ||||||||||||||||||||||
| # add qactypes to link command on Windows only | ||||||||||||||||||||||
| set(QACTYPES "/Qactypes") | ||||||||||||||||||||||
| set(WIN_FLAG "/EHsc") | ||||||||||||||||||||||
| else() | ||||||||||||||||||||||
| # add qactypes for Linux | ||||||||||||||||||||||
| set(QACTYPES "-qactypes") | ||||||||||||||||||||||
| endif() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| set(COMMON_COMPILE_FLAGS -fsycl -fintelfpga -Wall ${WIN_FLAG} ${QACTYPES}) | ||||||||||||||||||||||
| set(COMMON_LINK_FLAGS -fsycl -fintelfpga ${QACTYPES}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # A SYCL ahead-of-time (AoT) compile processes the device code in two stages. | ||||||||||||||||||||||
| # 1. The "compile" stage compiles the device code to an intermediate representation (SPIR-V). | ||||||||||||||||||||||
| # 2. The "link" stage invokes the compiler's FPGA backend before linking. | ||||||||||||||||||||||
| # For this reason, FPGA backend flags must be passed as link flags in CMake. | ||||||||||||||||||||||
| set(EMULATOR_COMPILE_FLAGS -DFPGA_EMULATOR) | ||||||||||||||||||||||
| set(EMULATOR_LINK_FLAGS ) | ||||||||||||||||||||||
| set(REPORT_COMPILE_FLAGS -DFPGA_HARDWARE) | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
|
||||||||||||||||||||||
| set(REPORT_LINK_FLAGS -Xshardware -Xstarget=${FPGA_DEVICE} ${USER_HARDWARE_FLAGS} -fsycl-link=early) | ||||||||||||||||||||||
| set(SIMULATOR_COMPILE_FLAGS -Xssimulation -DFPGA_SIMULATOR) | ||||||||||||||||||||||
| set(SIMULATOR_LINK_FLAGS -Xssimulation -Xsghdl -Xstarget=${FPGA_DEVICE} ${USER_HARDWARE_FLAGS}) | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| set(HARDWARE_COMPILE_FLAGS -DFPGA_HARDWARE) | ||||||||||||||||||||||
| set(HARDWARE_LINK_FLAGS -Xshardware -Xstarget=${FPGA_DEVICE} ${USER_HARDWARE_FLAGS} -reuse-exe=${CMAKE_BINARY_DIR}/${FPGA_OUTPUT_NAME}) | ||||||||||||||||||||||
| # use cmake -D USER_HARDWARE_FLAGS=<flags> to set extra flags for FPGA simulator compilation and backend compilation | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
|
||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| ### FPGA Emulator | ||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| add_executable(${EMULATOR_TARGET} ${SOURCE_FILE}) | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| target_compile_options(${EMULATOR_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS}) | ||||||||||||||||||||||
| target_compile_options(${EMULATOR_TARGET} PRIVATE ${EMULATOR_COMPILE_FLAGS}) | ||||||||||||||||||||||
| target_link_libraries(${EMULATOR_TARGET} ${COMMON_LINK_FLAGS}) | ||||||||||||||||||||||
| target_link_libraries(${EMULATOR_TARGET} ${EMULATOR_LINK_FLAGS}) | ||||||||||||||||||||||
| set_target_properties(${EMULATOR_TARGET} PROPERTIES OUTPUT_NAME ${EMULATOR_OUTPUT_NAME}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Make cmake print the locations of the command before building | ||||||||||||||||||||||
| add_custom_target( displayEmulationCommands ALL | ||||||||||||||||||||||
| ${CMAKE_COMMAND} -E cmake_echo_color --cyan "" | ||||||||||||||||||||||
| COMMENT "Find the compile command in ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json (the one using FPGA_EMULATOR) and the link command in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${EMULATOR_TARGET}.dir/link.txt") | ||||||||||||||||||||||
| add_dependencies(${EMULATOR_TARGET} displayEmulationCommands) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| ### FPGA Simulator | ||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| add_executable(${SIMULATOR_TARGET} ${SOURCE_FILE}) | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| target_compile_options(${SIMULATOR_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS}) | ||||||||||||||||||||||
| target_compile_options(${SIMULATOR_TARGET} PRIVATE ${SIMULATOR_COMPILE_FLAGS}) | ||||||||||||||||||||||
| target_link_libraries(${SIMULATOR_TARGET} ${COMMON_LINK_FLAGS}) | ||||||||||||||||||||||
| target_link_libraries(${SIMULATOR_TARGET} ${SIMULATOR_LINK_FLAGS}) | ||||||||||||||||||||||
| set_target_properties(${SIMULATOR_TARGET} PROPERTIES OUTPUT_NAME ${SIMULATOR_OUTPUT_NAME}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Make cmake print the locations of the command before building | ||||||||||||||||||||||
| add_custom_target( displaySimulationCommands ALL | ||||||||||||||||||||||
| ${CMAKE_COMMAND} -E cmake_echo_color --cyan "" | ||||||||||||||||||||||
| COMMENT "Find the compile command in ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json (the one using FPGA_SIMULATOR) and the link command in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${SIMULATOR_TARGET}.dir/link.txt") | ||||||||||||||||||||||
| add_dependencies(${SIMULATOR_TARGET} displaySimulationCommands) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| ### Generate Report | ||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| add_executable(${REPORT_TARGET} ${SOURCE_FILE}) | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| target_compile_options(${REPORT_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS}) | ||||||||||||||||||||||
| target_compile_options(${REPORT_TARGET} PRIVATE ${REPORT_COMPILE_FLAGS}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # The report target does not need the QACTYPES flag at link stage | ||||||||||||||||||||||
| set(MODIFIED_COMMON_LINK_FLAGS_REPORT ${COMMON_LINK_FLAGS}) | ||||||||||||||||||||||
| list(REMOVE_ITEM MODIFIED_COMMON_LINK_FLAGS_REPORT ${QACTYPES}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| target_link_libraries(${REPORT_TARGET} ${MODIFIED_COMMON_LINK_FLAGS_REPORT}) | ||||||||||||||||||||||
| target_link_libraries(${REPORT_TARGET} ${REPORT_LINK_FLAGS}) | ||||||||||||||||||||||
| set_target_properties(${REPORT_TARGET} PROPERTIES OUTPUT_NAME ${REPORT_OUTPUT_NAME}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Make cmake print the locations of the command before building | ||||||||||||||||||||||
| add_custom_target( displayReportCommands ALL | ||||||||||||||||||||||
| ${CMAKE_COMMAND} -E cmake_echo_color --cyan "" | ||||||||||||||||||||||
| COMMENT "Find the compile command in ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json (the one using FPGA_HARDWARE with fsycl-link=early) and the link command in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${REPORT_TARGET}.dir/link.txt") | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| add_dependencies(${REPORT_TARGET} displayReportCommands) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| ### FPGA Hardware | ||||||||||||||||||||||
| ############################################################################### | ||||||||||||||||||||||
| add_executable(${FPGA_TARGET} EXCLUDE_FROM_ALL ${SOURCE_FILE}) | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
| target_compile_options(${FPGA_TARGET} PRIVATE ${COMMON_COMPILE_FLAGS}) | ||||||||||||||||||||||
| target_compile_options(${FPGA_TARGET} PRIVATE ${HARDWARE_COMPILE_FLAGS}) | ||||||||||||||||||||||
| target_link_libraries(${FPGA_TARGET} ${COMMON_LINK_FLAGS}) | ||||||||||||||||||||||
| target_link_libraries(${FPGA_TARGET} ${HARDWARE_LINK_FLAGS}) | ||||||||||||||||||||||
| set_target_properties(${FPGA_TARGET} PROPERTIES OUTPUT_NAME ${FPGA_OUTPUT_NAME}) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Make cmake print the locations of the command before building | ||||||||||||||||||||||
| add_custom_target( displayFPGACommands ALL | ||||||||||||||||||||||
| ${CMAKE_COMMAND} -E cmake_echo_color --cyan "" | ||||||||||||||||||||||
| COMMENT "Find the compile command in ${CMAKE_CURRENT_BINARY_DIR}/compile_commands.json (the one using FPGA_HARDWARE without fsycl-link=early) and the link command in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${FPGA_TARGET}.dir/link.txt") | ||||||||||||||||||||||
| add_dependencies(${FPGA_TARGET} displayFPGACommands) | ||||||||||||||||||||||
|
yuguen marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.