Creating an SDSoC Application
AnSDSoC™application can be created through theSDx™IDE or by using a command line interface. In this chapter, theSDxIDE shows how to create a workspace, generate an application project for a selected platform, and use the available application templates. Working with code, adjusting hardware accelerator settings and targeting either emulation or a board is also covered. Excerpts of how to perform the IDE operations using command line equivalents is interspersed with the GUI illustrations.
Using an SDx Workspace
- Launch theSDx™IDE directly from the desktop icon or from the command line by one of the following methods:
- Using either of the following commands from the command prompt:
sdx
or
sdx -workspace
- Double-clicking theSDxicon to start the program.
- Launching from theStartmenu in the Windows operating system.
- Using either of the following commands from the command prompt:
- TheSDxIDE opens and prompts you to select a workspace, as shown in the following figure.
Figure:Specify the SDx Workspace
TheSDxworkspace is the folder that stores your projects, source files, and results while working in the tool. You can define separate workspaces for each project or have workspaces for different types of projects. The following instructions show you how to define a workspace for anSDSoCproject.
- Click theBrowsebutton to navigate to, and specify, the workspace, or type the appropriate path in theWorkspacefield.
- Select theUse this as the default and do not ask againcheck box to set the specified workspace as your default choice and eliminate this dialog box in subsequent uses ofSDx.
- ClickLaunch.
TIP:You can change the current workspace from within the SDxIDE by selecting .
You have now created anSDxworkspace and can populate the workspace with projects. Platform and application projects are created to describe theSDxtool flow for creating anSDSoCplatform.
- Application Project
- Platform Project
- Library Project
Creating an Application Project
- After launching theSDxIDE you can create a new Project. Select , or if this is the first time theSDxIDE has been launched, you can selectCreate Application Projecton the Welcome screen.
- The Create a NewSDxApplication Project wizard opens.
- In the Create a NewSDxApplication Project page, you can specify the project name as shown. Specify the name of the project in theProject namefield.
Figure:Create a NewSDxApplication Project
- TheUse default locationis selected by default to locate your project in a folder in theSDxworkspace. You can uncheck this check box to specify that the project is created in aLocationof your choice.
- If you specify the location, you can useChoose file systemto select thedefaultfile system, JSch, or enable the Eclipse Remote File System Explorer (RSE).
IMPORTANT:The project location cannot be a parent folder of an SDxworkspace.
- ClickNext.
The Platform dialog box, similar to the one shown in the following figure, displays the available installed platforms. For installing additional platforms, see the "Installing Platform-Specific Packages" section inSDAccel Environment Release Notes, Installation, and Licensing Guide(UG1238).
Figure:SpecifySDSoCPlatform
A platform is composed of a shell, which describes the base hardware design, the meta-data used in attaching accelerators to declared interfaces, and the software environment, which can include operating system images (for example, Linux), as well as boot-up and runtime files.
TheSDSoCdevelopment environment offers base-platforms for specific boards based on the following:
- Zynq®-7000
- zc702
- zc706
- ZynqUltraScale+™MPSoC
- zcu102
- zcu104
- zcu106
- zed
You can add custom defined or third-party platforms into a repository. SeeManaging Platforms and Repositoriesfor more information.
- Select the target platform for your project from the listed platforms. A series of actions are also available in this Platform dialog through the five icons immediately above the platform list. From left-to-right, clicking an icon invokes a platform text string search, adding a custom platform, managing a platform repository, adding new devices or platforms, and listing additional information about a selected platform.
- Select one of the predefined, installed platforms and clickNext.
- The System configuration page opens, as shown in the following figure. SelectSystem configurationandRuntimefrom a list of those defined for the selected platform. The System Configuration defines the software environment that runs on the hardware platform. It specifies the operating system and the available runtime settings for the processors in the hardware platform.
Figure:Specify System Configuration
- When setting the system configuration, you can also check theDomainand specify aLinux Root File Systemif a Linux-based configuration is selected. TheLinux Root File Systemis a sysroot directory structure that provides the necessities for a system to run and locate headers.
- After selecting theSystem Configurationand clickingNext, the Templates page displays, as shown in the following figure. Specify an application template for your new project. Thesamplesdirectory within theSDxtools installation contains multiple source code example templates.
- Initially, you have the option in the Template dialog box of anEmpty Applicationor one of the provided application templates. You can download additionalSDxexamples or update the installed examples by clicking theSDx Examplesbutton, which retrieves content from theXilinxGitHubas discussed inGetting Started with Examples.
Figure:Application Templates
- You can use the template projects as examples to learn about theSDxtool and acceleration kernels or as a foundation for your new project. Note that you must select a template. You can selectEmpty Applicationto create a blank project into which you can import files and build your project from scratch.
- ClickFinishto close the NewSDxProject wizard and open the project.
Importing a Project
- Select
Figure:Select an SDx Project
menu and click , or go directly through the Import Project selection on the Welcome screen.
- Chose the import type as anSDx project exported zip filewhich opens up a dialog for browsing to the exported zip file. ClickNext.
Figure:Import Type
- Select and clickOpenprovides a list of Application projects that can be brought into the workspace.
Note: Xilinxrecommends using SDxexported zip files to move projects between workspaces. Also, this is the last SDxrelease, so use the import sources as opposed to the remote sources.
Working with Code
TheSDxenvironment provides a GUI-based IDE as well as command line control to invoke thesds++
system compiler with user-specified command options from a shell prompt.
Application code generally consists of C/C++ source files, C/C++ header files, and libraries created for shared or static use. TheSDxtools help you identify and convert C/C++ source code functions into hardware accelerators. By analyzing function arguments, argument types, and any applied directives or pragmas, theSDxtools generate data movers and pipelined dataflows to feed data into and out of an accelerator. Typical data sources and data sinks are memories and I/O streams.
TheSDSoC-generated accelerators reside in the PL and need to fit in the PL resources. SeeExecution Model of an SDSoC Application. The interfaces between the PS and PL are user-configurable. For instance,SDxtools automatically generate data movers for crossing the PS-PL boundary with interface direction as set by your C/C++ source code.
Source files to create anSDxapplication with exampleSDxpragmas are provided within the IDE by selecting . Additional examples are available for download from theSDSoC Examples GitHub.
Importing Sources
Importing C/C++ Sources
- To add files in the Project Explorer, right-click thesrcfolder and select theImport Sourcescommand.
IMPORTANT:When you import source files into a workspace, it copies the files into the workspace (by default, you can deselect it). Any changes to the files are lost if you delete the workspace.
- This displays the Import dialog box that enables you to specify the source of the files from which you are importing. The different sources include importing from archives, from existing projects, from the file system, and from a Git repository. Select the source of files to import and clickNext.
- The displayed dialog box depends on the source of files you selected in the prior step. In the following figure, the File system dialog box shows the result of choosing to import sources from the file system.
Figure:Import File System Sources
- The File system dialog box allows you to navigate to a folder in the system and select files to import into your project. You can specify files from multiple folders and specify the folder to import files into.
TIP:Having each hardware accelerator function exist in a separate file enables parallel compilation of the accelerator, thereby speeding up the compilation time in SDx.
- In the Options, select theOverwrite existing resource without warningcheck box to overwrite any existing files, and select theCreate top-level foldercheck box to have the files imported into a directory structure that matches the source file structure.
Note:If this check box is not enabled, which is the default, then the files are imported into the folder listed in the Into folderoption.
- On the Windows operating system, you can add files to your project by dragging and dropping them from the Windows Explorer. Select files or folders in the Explorer and drop them into thesrcfolder, or another appropriate folder in theSDxIDE Project Explorer. When you perform this, the tool prompts you to specify how to add the files to your project, as shown in the following figure.
Figure:File and Folder Operation
- You can copy files and folders into your project, add links to the files, or link to the files in virtual folders to preserve the original file structure. There is also a link to theConfigure Drag and Drop Settingsoption, which allows you to specify how the tool should handle these types of drag and drop operations by default. You can also access these settings through the menu command.
- After adding source files to your project, you are ready to begin configuring, compiling, and running the application.
Note:When you make code changes, including changes to hardware functions, it is valuable to rerun a software-only compile to verify that your changes did not adversely change your program. A software-only compile is much faster than a full-system compile.
Importing C-Callable IP Libraries
- In the Project Explorer, right-click the application name or itsproject.sdxfile and selectProperties.
- Select .
- Add
to the-l
libraries list. - Add the directory that contains the
object file to the -L
Library search path. - ClickApply.
- ClickOK.
- Ensure that a C-Callable IP header (.h/.hpp) file is present in project source tree.
- Build the project.
Selecting Functions for Hardware Acceleration
The first task is to identify portions of application code that are suitable for implementation in hardware, and that significantly improve the overall application performance when run in hardware.
Before marking any functions for acceleration you should profile the software. Self-contained compute intensive functions with limited external control logic are good starting points, especially when its possible to stream data between hardware, the CPU, and memory to overlap the computation with the communication. You can build and run your application on one of the platforms provided in theSDSoCenvironment install to identify compute intensive functions on theArmprocessor.
Every base platform included in theSDSoCenvironment includes a pre-built SD card image from which you can boot and run your application code if you do not have any functions selected for acceleration on the hardware platform. Running the application this way enables you to profile the original application code to identify candidates for acceleration.
SeeProfiling and Optimizationfor more information on profiling your application. Also, theSDSoC Environment Profiling and Optimization Guide(UG1235)provides more extensive detail.
After determining the function or functions to move into hardware, with a project, you can select the function from the Add Hardware Functions portion of the window.
Click theHardware Functionsbuttonof the Project Editor window to display the list of candidate functions within your program. This displays the Add Hardware Functions dialog box, that lets you select one or more functions from a list of functions in the call graph of the
main
function by default.
Figure:Add Hardware Functions Dialog Box
From within the Add Hardware Functions dialog box, select one or more functions for hardware acceleration and clickOK.
The list of functions starts at theRoot functionas defined in theOptionspanel of the Project window and is set tomain
by default. You can change theRoot functionby clicking theBrowse() command and selecting an alternate root.
The functions display in the Hardware Functions panel of theSDxApplication Project Settings window as shown in the following figure.
Figure:Hardware Function Panel
When moving a function optimized for CPU execution into programmable logic, you can usually revise the code to improve the overall performance. See the "Programming Hardware Functions" section in theSDSoC Environment Programmers Guide(UG1278).
For accelerators using the xfOpenCV library, right-click and selectToggle Hardwarefrom the associated header files in the project included in Project Explorer. See theXilinx OpenCV User Guidefor more information.
Selecting Clock Frequencies
After selecting hardware functions, it could be necessary to select the clock frequency for running the function or the data motion network clock.
Every platform supports one or more clock sources, which is defined by the platform developer as described inSDSoC Environment Platform Development Guide. Setting the clock frequency of the hardware function determines the clock setting for the hardware function's logic as well as its associated data mover. Setting the clock frequency of the Data Motion network determines the clock used for theaxi_litecontrol buses. By default, the Data Motion network shares its clock with the hardware accelerator generated during system generation. You can select the Data Motion network clock and the hardware function clock from theSDxIDE or the command line.
You can view the available platform clocks by selecting the Platform link in theGeneraloption of theSDx Application Project Settingswindow. This displays details of the platform, including the available clock frequencies.
Figure:SDxIDE – General
The function clock displays in theSDx Application Project Settingswindow, in theHardware Functionspanel.
Select a function from the list, likemadd
in the figure below, and click in theClock Frequencycolumn to access the pull-down menu to specify the clock frequency for the function.
Figure:Select Function Clock Frequency
To specify the Data Motion clock frequency, select theData motion network clock frequencypull-down menu in theOptionspanel of theSDx Application Project Settingswindow. The Data Motion network clock frequency menu is populated by the available clocks on the platform.
Figure:Data Motion Network Clock Frequency
Command Line Options
You can set clock frequencies for either the Hardware Accelerator or the Data Motion network at the command line, as shown in the following examples.
Set the clock frequency for a function from the command line, by specifying the Clock ID (clkid
).
$ sds++ -c mmult.cpp -o mmult.o -sds-pf zcu102 -sds-hw mmult mmult.cpp -clkid 1 -sds-end
-ac
option.
$ sds++ -lmyIpLib -ac myAc:3 -o main.elf main.o
-dmclkid
option. For example:
$ sds++ -sds-pf zcu102 -dmclkid 1
You can use the following command to see the available clocks for a platform, and determine the clock ID:
$ sds++ -sds-pf-info
As an example for the ZCU102 platform, running thesds++ -sds-pf-info zcu102
command displays the following output. The clock ID and its frequency is shown for each declared system clock. A list of available system configurations and system port interfaces is also provided.
Platform Information ==================== Name: zcu102 Device ------ Architecture: zynquplus Device: xczu9eg Package: ffvb1156 Speed grade: -2 System Clocks ------------- Clock ID Frequency ----------|------------ 1199.880127 0 74.992500 1 99.990000 2 149.985000 3 199.980000 4 299.970000 5 399.960000 6 599.940000 Platform: zcu102 (/platforms/zcu102) Description: A basic platform targeting the ZCU102 evaluation board, which includes 4GB of DDR4 for the Processing System, 512MB of DDR4 for the Programmable Logic, 2x64MB Quad-SPI Flash and an SDIO card interface. More information at https://www.xilinx.com/products/boards-and-kits/ek-u1-zcu102-g.html Available system configurations: a53_linux (a53_linux) a53_standalone (a53_standalone) r5_standalone (r5_standalone) System Ports Use the system port name in a sysport pragma, for example #pragma SDS data sysport(parameter_name:system_port_name) System Port Name (Vivado BD instance name, Vivado BD port name) ps_e_S_AXI_HPC0_FPD (ps_e, S_AXI_HPC0_FPD) ps_e_S_AXI_HPC1_FPD (ps_e, S_AXI_HPC1_FPD) ps_e_S_AXI_HP0_FPD (ps_e, S_AXI_HP0_FPD) ps_e_S_AXI_HP1_FPD (ps_e, S_AXI_HP1_FPD) ps_e_S_AXI_HP2_FPD (ps_e, S_AXI_HP2_FPD) ps_e_S_AXI_HP3_FPD (ps_e, S_AXI_HP3_FPD)
Building the SDSoC Project
After you have added source code, identified the functions to accelerate, and selected the accelerator and data mover clock frequencies, you can build for a Hardware target or an Emulation target.
For Hardware targets, seeTargeting Hardware.
For Emulation targets, seeTargeting System Emulation.
The following section describes theSDxproject to target a Hardware Project build.
Targeting Hardware
- Select theBuildbutton (
) or right-click the project name and selectBuild Projectin the Project Explorer window.
- Initiate a build through the Assistant window by right-clicking either theDebug [Hardware]orRelease [Hardware]selections.
- Right-clickDebug [Hardware]and, from the context menu, selectBuild.
Figure:Assistant Window
This generates a bitstream and bootable SD card image, based on the check-marked project options. The build process also produces aCompilation Logfile and aData Motion Network Reportthat you can access through the Assistant window.
- The results of the build process produce files to populate an SD card for booting and running on a target board. Using the Assistant window, the set of generated files can be viewed by right-clicking and selecting
Figure:Build Results
.
- SDxcreates detailed reports of the compilation process and saves those files in theDebug/_sds/reportsdirectory. Access these files through the Project Explorer or the Assistant window. The following figure shows a Project Explorer expansion of thereportsdirectory and a view into thesds.logcompilation log file.
Figure:Compilation Log
An excerpt of a log file showing the equivalent system compiler commands run by the IDE for creating the accelerators added as part of the matrix multiply and matrix add example, shown in the following code snippet. The-sds-pf
option identifies the platform, and each accelerated function is identified by placing the function name and its defining source file between their own set of-sds-hw
and-sds-end
hardware function options. The accelerator clock ID is also chosen within the hardware function options by setting the-clkid
option.
Compilation of functionmadd()
:
sds++ -Wall -O0 -g -I../src -c -fmessage-length=0 -MTsrc/madd.o\ -MMD -MP -MFsrc/madd.d -MTsrc/madd.o -o src/madd.o ../src/madd.cpp\ -sds-hw mmult mmult.cpp -clkid 1 -sds-end\ -sds-hw madd madd.cpp -clkid 1 -sds-end\ -sds-sys-config a53_linux -sds-proc a53_linux -sds-pf zcu102
Compilation of functionmain()
:
sds++ -Wall -O0 -g -I ../src -c -fmessage-length=0 -MTsrc/main.o\ -MMD -MP -MFsrc/main.d -MTsrc/main.o -o src/main.o ../src/main.cpp\ -sds-hw mmult mmult.cpp -clkid 1 -sds-end\ -sds-hw madd madd.cpp -clkid 1 -sds-end\ -sds-sys-config a53_linux -sds-proc a53_linux -sds-pf zcu102
Compilation of functionmmult()
:
sds++ -Wall -O0 -g -I../src -c -fmessage-length=0 -MTsrc/mmult.o\ -MMD -MP -MFsrc/mmult.d -MTsrc/mmult.o -o src/mmult.o ../src/mmult.cpp\ -sds-hw mmult mmult.cpp -clkid 1 -sds-end\ -sds-hw madd madd.cpp -clkid 1 -sds-end\ -sds-sys-config a53_linux -sds-proc a53_linux -sds-pf zcu102
The compiled object files are then linked by theSDxtools to produce the single executable file for the matrix multiply and matrix add example containing the application code as well as the code to invoke the accelerated functions. This executable is targeted for Linux as specified with the-sds-sys-config
and-sds-proc
options.
Linking object files to produce an executable file (ELF) and boot files for SD card:
sds++ --remote_ip_cache /tmp/sdx_workspace/ip_cache -o project_one.elf\ ./src/madd.o ./src/main.o ./src/mmult.o\ -dmclkid 1 -sds-sys-config a53_linux\ -sds-proc a53_linux -sds-pf zcu102
XP Option: Advanced Feature for Controlling a Vivado Build
While thesds++
system compiler automatically invokes theVivado®design tools to implement the hardware system, users who are familiar withVivadotool options have the ability to further customize the flow by passing arguments on the command line. The-xp
option of thesds++
system compiler can be used to pass aparameter-value
orproperty-value
pair into theVivadotools for guiding accelerator implementation.
The following is an example of specifying aVivadosynthesis option:
sds++ -xp "vivado_prop:run.synth_1.STEPS.SYNTH_DESIGN.TCL.POST="
This example-xp
option specifies a post-synthesis execution of aVivadotool Tcl file. Multiple-xp
options can be specified on a single system compiler invocation.
However, for synthesis and implementation strategies, thesds++
command directly takes the-impl-strategy
and-synth-strategy
options, and does not use the-xp
option.
For example:
sds++ -synth-strategy
sds++ -impl-strategy
sds++ -synth-strategy -impl-strategy
When using the IDE, the-xp
options can be added to a build configuration as described inSDS++ Linker Settings, under the Miscellaneous options.
See the following resources for more information:
- Vivado Design Suite Tcl Command Reference Guide(UG835)
- Vivado Design Suite User Guide: Synthesis(UG901)
- Vivado Design Suite User Guide: Implementation(UG904)
- SDSoC Profiling and Optimization Guide
- SDx Command and Utility Reference Guide
Targeting System Emulation
After the hardware functions are identified, the logic can be compiled, and the entire system (PS and PL) verified using emulation onXilinxbase platforms (such as zc702, zc706, zcu102, zcu104, and zcu106). System emulation allows you to verify and debug the system with the same level of accuracy as a full bitstream compilation, without requiring a bitstream. This can significantly reduce design iteration time, and allow faster iteration through debug cycles more.
To enable system emulation, from the Editor Area, click theTargetfield, and selectEmulation.
Figure:Emulation Target
System emulation offersDebugandOptimizedmodes, which can be specified by clicking in theEmulation Modelfield.
- Debug
- Builds the system through RTL generation, and the VivadoIP integrator block design containing the hardware function, elaborates the hardware design, and runs behavioral simulation on the design, with a waveform viewer to help you analyze the results. If there is a functional issue with the code, use this option.
- Optimized
- Runs the behavioral simulation in batch mode, returning the results without the waveform data. While Optimized can be faster, it returns less information than Debug mode.
To capture waveform data from the PL hardware emulation for viewing and debugging, select the Debug pull-down menu option. For faster emulation without capturing this hardware debug information, selectOptimized.
After specifying the emulation options, click theBuild() command to compile the active build configuration. The Build command invokes the system compilers to build your application project. There are two build configurations available:
- Debug
- This compiles the project use in software debug. The compiler produces extra information for use by a debugger to facilitate debug and allows you to step through the code.
- Release
- The compiler tries to reduce code size and execution time of the application. This strips out the debug code so that you really cannot debug with this version.
You can launch the build from the Assistant window also, by selecting
.Figure:Assistant Window Display
The build process for hardware emulation can take some time, depending on your application code, the size of your hardware functions, and the various options you have selected. To compile the hardware functions, the tool stack includesSDx,VivadoHLS, and theVivadoSimulator.
After the system is compiled for emulation, you can invoke the system emulator using thesdsoc_emulator
from the command line.
Figure:Start/Stop Emulator
Disabling theShow Waveformoption allows you to run emulation with the output directed solely at the Emulation Console view, which shows all system messages including the results of any print statements in the source code. Some of these statements might include the values transferred to and from the hardware functions, or a statement that the application has completed successfully, which would verify that the source code running on the PL and the compiled hardware functions running in the PS are functionally correct.
Enabling theShow Waveformoption provides the same functionality in the console window, plus the behavioral simulation of the PL-resident IP with a waveform window in the Xsim tool. The waveform window allows you to see the value of any signal in the hardware functions over time.
When usingShow Waveform, you must manually add signals to the waveform window before starting the emulation. Use the Scopes pane to navigate the design hierarchy, then select the signals to monitor in the Object pane, and right-click to add the signals to the waveform pane. Select the option to start updates to the waveform window. For more information on working with theVivadosimulator waveform window, see theVivado Design Suite User Guide: Logic Simulation(UG900).
The system emulation can also be started by selecting the active project in the Project Explorer view and right-clicking to selectDebug Asmenu prompts you to change to the debug perspective to arrange the windows and views to facilitate debugging the project. SeeUnderstanding the SDx GUIfor more information on changing perspectives.
menu command, or the menu command. Launching the emulator from theThe program output is displayed in the console tab and if theShow Waveformoption is selected, you also see any appropriate response in the hardware functions in the RTL-PL waveform. During any pause in the execution of the code, the RTL-PL waveform window continues to execute and update, just like an FPGA running on the board.
The emulation can be stopped at any time using the menu optionStop.
and selectingA system emulation session with the quick emulation (QEMU) console is shown in the following figure.
Figure:QEMU Console
As shown in the following figure, the PL waveform displays if you selected the waveform option and theRun Alloption:
Figure:Waveform Window
The Assistant window enables you to right-click
.You can find more information about emulation in theSDSoC Environment Debugging Guide.
Building an SDSoC Library
Libraries can be used to encapsulate one or more accelerated functions into a shared or statically linked file. TheSDxIDE menu selection provides a means to create a library project. The shared library flow produces a library file which can be linked to anSDSoCapplication through theSDxIDE or the command line. TheSDSoClibrary flow is intended for exporting a library for use withgcc/g++
. Using this library, you can call the functions which are accelerated in hardware. The C-Callable IP library flow is used for linking aVivadopackaged IP block to anSDSoCapplication and is also described inC-Callable IP Libraries.
Figure:Specify Library Type
Shared Library
The shared library includes a Matrix Shared Library template with a multiply and add example provided with theSDxIDE. This library demonstrates how three different functions with unique entry points in the shared library can be called from a software application.
When running the results of an application build invoked through theSDxIDE, theBOOT.BINfile in thesd_carddirectory of the library project should be used to boot the board as it contains the accelerated hardware functions.
For command line use, an example is available in the
For more information on building a shared library, see the "Building a Shared Library" section inSDSoC Environment Programmers Guide(UG1278).