SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision...

39
SDAccel Environment Tutorial Introducon UG1021 (v2017.1) June 20, 2017

Transcript of SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision...

Page 1: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

SDAccel Environment Tutorial

Introduction

UG1021 (v2017.1) June 20, 2017

Page 2: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Revision History

The following table shows the revision history for this document.

Date Version Revision06/20/17 2017.1 Added new Lab 2 to tutorial.

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

2

Page 3: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Table of ContentsIntroduction

Flow Overview

Lab 1: Introduction to the SDAccel Development Environment .....................................................6

Lab 2: Introduction to the SDAccel Makefile ...............................................................................25

Additional Resources and Legal Notices

References .................................................................................................................................38

Please Read: Important Legal Notices.........................................................................................39

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

3

Page 4: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

IntroductionThe Xilinx SDAccel™ Development Environment is part of the SDx Development Toolchain. Thistoolchain allows you to create FPGA accelerated designs using C/C++, OpenCL™ C, or RTLprogramming languages. You can create these designs in the SDx GUI environment or through aMakefile flow.

This tutorial walks you through the steps of building a basic OpenCL™ based design using theSDx GUI and learning some of the features that enable you to do performance profiling, andoptimization.

Tutorial Design Description

This tutorial is based on the Smith-Waterman algorithm, which is a database search algorithmdeveloped by T.F. Smith and M.S. Waterman. It is based on the earlier Needleman and Wunschalgorithm.

The design targets the Alpha Data Kintex® Ultrascale™ PCIe® board using the xcku060 device.

TIP: Although this tutorial design targets a xcku060 Kintex Ultrascale board, you can choose any otherboard, such as the xc7k690t Kintex-7 board. Tutorial results should be similar.

Hardware and Software Requirements

Refer to the Vivado Design Suite User Guide: Release Notes, Installation, and Licensing, (UG973)for a complete list and description of the system and software requirements for the Vivado®Design Suite.

Locating Tutorial Design Files

You can find the files for this tutorial in the SDx Suite examples directory at the followinglocation:

<SDx_install_area>/SDx/<version>/examples/getting_started

NOTE: SDAccel is only available on Linux operating systems that support the GLIBC 2.9 or higher compiledlibrary. See the SDx Environments Release Notes, Installation, and Licensing Guide (UG1238) for adescription of the software requirements for the SDAccel Development Environment.

Chapter 1

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

4

Page 5: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

For Lab 2: Introduction to the SDAccel Makefile tutorial uses a makefile which you can locate byfollowing these steps:

1. Download the reference design files from the Xilinx website.2. Extract the ZIP file contents into any write-accessible location.

Chapter 1: Introduction

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

5

Page 6: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Flow Overview

Lab 1: Introduction to the SDAccel DevelopmentEnvironment

Step 1: Creating SDAccel Project

1. Launch SDx™ with the command sdx and you will see the Workspace Launcher window.Select a location for your workspace, this is where the project will reside.

Figure 1: Workspace Launcher

2. In the the SDx Welcome window, click Create SDx Project.

Chapter 2

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

6

Page 7: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 2: SDx Welcome Window

3. In the Create a New SDx project window in the Project name field, type smithwatermanand click Next.

4. In the Choose Hardware Platform window choose the ADM-PCIE-KU3 (2ddr) platform andclick Next.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

7

Page 8: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 3: Hardware Platform

5. The Software Platform window only has Linux on x86 as a valid option, click Next. TheSoftware Platform window only has Linux on x86 as the system configuration and theRuntime will only be OpenCL.

6. The Templates window has a list of possible templates that you can use to get started inbuilding an SDAccel project. For this tutorial, select Empty Application and click Finish.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

8

Page 9: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 4: New Project

Step 2: Importing Design Files

1. In the Project Explorer window, expand smithwaterman > src. Right-click src and selectImport.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

9

Page 10: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 5: SDx Settings Overview

2. In the Import dialog box, under General, select File System, and click Next.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

10

Page 11: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 6: Eclipse Import Dialog

3. In the Import dialog box labeled From directory, navigate to the getting_started directoryfrom the install directory (<install location>/SDx/<version>/examples), and select thesrc directory. Click OK.

4. In the Import dialog box, select the following files:

• kernel.cl• main.cpp• oclErrorCodes.cpp• oclHelper.cpp• oclHelper.h• soft.cpp

Click Finish.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

11

Page 12: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 7: Import Dialog

5. You can now expand the src directory in the Project Explorer to see that all the files are nowpopulated in the project.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

12

Page 13: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Step 3: Running CPU Emulation

This step shows you how to run CPU Emulation of a design, by setting Run Configurationsettings, opening reports, and showing how to launch Debug. Details on reports and Debug canbe found in the SDAccel Environment User Guide, (UG1023).

1. To run CPU Emulation, go to SDx Project Settings and ensure that Active buildconfiguration is set to Emulation-CPU.

Figure 8: SDx Project Settings

2. Create an accelerator that will be the container for the kernel found in kernel.cl. In this view,click the Add Hardware button: . SDx™ Environment analyzes the design for all possiblekernels in the design, as well as the ability to filter the list if there are multiple kernels. For thisdesign, only the smithwaterman exists. Ensure that the function name smithwaterman isselected and click OK. This creates a binary container for the kernel, which can be renamed ifnecessary.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

13

Page 14: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 9: Add HW Functions Dialog

3. Click the Run button: to run CPU Emulation. This builds the project before running theemulation.

4. Take note that the design successfully builds, but the emulation test fails. This can be viewedby looking for FAILED TO LOAD KERNEL in the Console window. Look at the main.cpp andnotice that there are arguments that need to be provided. The Run Configurations field needto be adjusted to account for these arguments.

5. Go to the Run menu and select Run Configurations... .

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

14

Page 15: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

6. Under the Arguments tab we see only the container that holds the kernel as an argument.For this design, the following arguments need to be adjusted:

-d acc -k ../binary_container_1.xclbin -i 2 -l -1

• -d - Specifies what type of device it is. In this case, acc specifies an accelerator.• -k - Specifies the kernel to use. If -d is set to acc then this must be a binary file.• -i - Specifies the number of iterations to run.• -l - Specifies the sequence length to be used in the algorithm default length.

NOTE: In the arguments window, make sure the Automatically add binary container(s) to argumentscheckbox is checked if you do not know the name of the binary container.(To view more information about the argument list, use -h for the executable to see an entirelist) Click Run.

Figure 10: Run Configuration

7. The Console window should show PASSED TEST. If you want to see a verbose output of whatthe algorithm is doing, go back into Run Configurations... and add the -v to the arguments(verbose output will start in the terminal window on the next run).

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

15

Page 16: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

8. After the emulation run is complete, you can look at two reports to design details for furtheroptimization. In the Reports window, double-click Profile Summary. Here, you can viewoperations, execution time, bandwidth, and other useful data that you can use to optimize thedesign. Note that the summary numbers may vary.

Figure 11: Emulation-CPU Profile Summary

9. To view the Application Timeline report, in the Reports window, double-click ApplicationTimeline. This shows a breakdown of the host code and the kernel code, and execution timefor each.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

16

Page 17: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 12: Application Timeline Report

10. From the Profile Summary and the Application Timeline you can see issues in how the hostand kernel communicate with each other. Using the Debug feature can help pinpoint theseissues.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

17

Page 18: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

11. To run in Debug, you need to set a breakpoint. Setting breakpoints at key points in theexecution helps identify problems. From the Application Timeline, notice that the API Callsare staggered around the end of the timeline. If you zoom in by clicking and dragging themouse near the end of the timeline, you can see the fluctuation more easily. Hovering themouse over the Queue line over the green boxes, you will notice that the tooltip shows thatclEnqueueReadBuffer is being called several times. Set a breakpoint at the main for loop inmain.cpp, (line 435), by right-clicking the line number on the line and selecting ToggleBreakpoint. This is the iteration loop where clEnqueueReadBuffer is executed in the code.

Figure 13: Setting Breakpoint

12. To run Debug, click on this icon: . A dialog box opens up asking you to switch to thatperspective. Click Yes.

13. Using Eclipse debugging, the host and kernel code can be examined in more detail. All thecontrols with which to do step-by-step debugging are in the Run menu.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

18

Page 19: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 14: Eclipse Debugging

14. After you start, Debug stops at line 479. This is the first line of main to be executed. In theRuns Configuration dialog, there is an option to stop on the main function (see the followingfigure). This is helpful in case of a problematic function in need of more thorough debugging.Press F8 to continue to the next breakpoint.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

19

Page 20: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 15: Run Configuration

15. The debugger is now at the for loop where you set the breakpoint. The run was configuredto go through two iterations. Step through the loop while looking at the Variables window,and see the variables changing as the stepping occurs.

16. Close the Debug Perspective by going to the upper-right of the window where it shows thebutton, right-click and select Close.

Step 4: Running Hardware Emulation

This step covers running Hardware Emulation feature as well as looking at the basics of profilingand reports.

1. To run Hardware Emulation, go to SDx Project Settings and make sure that Active buildconfiguration is set to Emulation-HW then click Run. This takes some time to complete.

NOTE: The main difference between Emulation-CPU and Emulation-HW is that emulating hardwarebuilds a design that is closer to what is seen on the platform. This means data related to bandwidth,throughput, and execution time are more accurate. The design also takes longer to compile.

2. In the Reports tab, open System Estimate. This is a text report that provides informationrelated to kernel information, timing about the design, clock cycles, and area used in thedevice.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

20

Page 21: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 16: System Estimate

3. In the Reports tab, open Profile Summary. This summary report provides detailedinformation related to kerenl operation, data transfers, and OpenCL™ API calls as well asprofiling information related to the resource usage, and data transfer to/from the kernel/host.It also provides detailed guidance in how to meet the profile rule checks.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

21

Page 22: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 17: Profile Summary Report

4. Scroll to the right in the Profile Rule Checks and look for the header column labeledGuidance. This is where unmet checks provide some information on how to optimize thekernel.

Figure 18: Profile Rule Checks

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

22

Page 23: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

NOTE: To see other performance optimization techniques and methodologies, please go to the SDAccelPerformance Optimization Methodology Guide (UG1207).

5. Open the Application Timeline report. This report shows the estimated time it takes for thehost and kernel to complete the task and provides finer grained information on wherebottlenecks can be. In this example, it is iterated twice and this timeline shows the kernel isrun twice. Adding a marker, zooming, and expanding signals can help in identifyingbottlenecks.

Figure 19: Application Timeline Report

6. Open the HLS Report. This report provides detailed information provided by Vivado® HLS onthe kernel transformation and synthesis. The tabs at the bottom provide more information onwhere most of the time is spent in the kernel and other performance related data. Someperformance data may be latency and clock period.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

23

Page 24: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 20: HLS Report

Step 5: Makefile Flow

This step explains the basics of the Makefile flow and how SDx uses it. The advantages of usingthis flow include the following:

• Easy automation into any system.• Faster turnaround time on small design changes.

1. In the Project Explorer, navigate to the Emulation-CPU directory and look for the makefilefile. Double-click the file to open it in the editor. This is the makefile that SDx creates and usesfor building and running emulations.

2. In the Project Explorer, navigate to the Emulation-HW directory and look for the makefilefile. Open the file.

3. While the project is building, go back into the makefile editor window and look at line 21 inboth files. Notice that each one is set to either hw_emu or sw_emu.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

24

Page 25: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 21: Makefile Editor window

4. The makefile can also access SDx without using the GUI. Open up a new terminal session andnavigate to the workspace and then navigate to the Emulation-CPU directory and type: makeincremental. The process produces a typical SDx log output.

Lab 2 of this tutorial goes into more detail on how to use the makefile and command line flow.

Summary

After completing this tutorial, you should be able to do the following:

• Create an SDAccel™ project and import the required design files.• Create a binary container and accelerator for the design.• Run CPU Emulation and use the Debug environment on host and kernel code.• Run Hardware Emulation and use the reports to understand possible optimization.• Understand differences between CPU and Hardware Emulation reports.• Read the project makefile and run the makefile command line.

Lab 2: Introduction to the SDAccel Makefile

Step 1: Preparing and Setting up the SDAccel Environment

1. Launch a terminal and source the settings scripts found in the SDx™ environment using thecommand:

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

25

Page 26: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

source <SDx_install_location>/2017.1/settings64.csh

or

source <SDx_install_location>/2017.1/settings64.sh

This allows you to run the SDx command lines without the need to use the GUI.

2. In the SDx install location, find the getting_started directory and copy it to a workspace inyour location, using the command:

cp -r <SDx_install_location>/2017.1/examples/getting_started<your_workspace_location>

In the newly copied getting_started directory, create a work directory and navigate to it.

You should now have a getting_started directory that contains two folders: src, whichcontains the source files of the smithwaterman design, and work, which is the workingdirectory where all commands should be executed.

3. Create a makefile directory under getting_started. Download the makefile located here(zip file) and extract it to the makefile directory that you created. Navigate into the workdirectory.

When you are done, your folder structure should look like this:

[sdaccel@localhost work ]$ ls ..makefile src work[sdaccel@localhost work ]$ ls ../makefilemakefile.mk[sdaccel@localhost work ]$ ls ../srccommon_gs.mk main.cpp oclHelper.cpp soft.cppkernel.cl oclErrorCodes.cpp oclHelper.h

Step 2: Initial Design and Makefile Exploration

1. In the getting_started/makefile directory contains the makefile.mk file, which will beused to compile the design in both Hardare and CPU Emulation, as well as generate a SystemRun.

2. Open the makefile.mk in a text editor. View the content and become familiar with how it iswritten. Makefiles are written in a bash style syntax.

3. The first few lines are used to determine if the SDx™ Environment has been setup forcompilation.

ifndef XILINX_SDX$(error Environment variable XILINX_SDX is required and should point toSDx install area)endif

4. This section is where the device you are targetting is defined. It follows the VBNV naming ofvendor:board:name:version. In this tutorial, use the following device: xilinx:adm-pcie-ku3:2ddr-xpr:3.3.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

26

Page 27: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

# --------------------------# Set Default OpenCL device# --------------------------XDEVICE = xilinx:adm-pcie-ku3:2ddr-xpr:3.3

5. Next, look at the TARGET section of the makefile. Use the TARGET variable to determine if thevalue is valid. The valid values are: sw_emu (CPU Emulation), hw_emu (Hardware Emulation), orhw (System). In this example, the value is set to compile CPU Emulation.

# --------------------# Check TARGET value# --------------------TARGET = sw_emu

ifeq ($(TARGET),sw_emu)else ifeq ($(TARGET),hw_emu)else ifeq ($(TARGET),hw)else$(error "TARGET does not support the $(TARGET) value. Supported valuesare: sw_emu, hw_emu, hw")endif

6. The next section defines the host source files, and any library directories required forcompiliation.

# =========================================================# HOST Sources and Host Executable files# =========================================================HOST_EXE = host.exeHOST_SRC_CPP = ../src/main.cpp ../src/oclErrorCodes.cpp ../src/oclHelper.cpp ../src/soft.cppHOST_SRC_H = ../src/oclHelper.h

# -----------------# Runtime Libraries# -----------------OPENCL_INC = $(XILINX_SDX)/runtime/include/1_2OPENCL_LIB = $(XILINX_SDX)/runtime/lib/x86_64

Here, we need to define the executable name, the source files it requires, and any header filesit requires.

When it comes time to compile an OpenCL™ kernel, we need to define the runtime librariesthat are needed in order to successfully compile the kernel.

7. The next section is where we define the kernel location and the name of the binary container.

# =========================================================# Kernel Sources and XCLBIN files, Target Device# =========================================================XCLBIN = kernels.$(TARGET).xclbinKERNEL_SRC_CL = ../src/kernel.cl

In this makefile, we are defining the binary container to be related to the target (sw_emu,hw_emu, hw). This allows us to have multiple variations of binary containers to be used fortesting. Lastly, the KERNEL_SRC_CL tells us where the kernel file that is to be compiled islocated.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

27

Page 28: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

8. The final section of the makefile is where we define how these files are to be compiled.

a. The Host code ($(HOST_EXE): ...) tells us the name host.exe will be compiled using the($HOST_SRC_CPP) and the $(HOST_SRC_H) files. The following line tells us how it will becompiled in such that $(CXX) is the compiler we are using, in this case xcpp (which containsgcc and what the SDx GUI uses).

b. Next is the kernel compilation, which uses xocc, or the Xilinx OpenCL Compiler. Followingthe same from above, we know that the binary container will be compiled using the kernelsource, targeting the same device, and will generate an estimate report.

# =========================================================# Compilation# =========================================================.PHONY: allall: $(HOST_EXE) $(XCLBIN)

# -----------------# Host# -----------------$(HOST_EXE): $(HOST_SRC_CPP) $(HOST_SRC_H)

$(CXX) -lxilinxopencl -I$(OPENCL_INC) -L$(OPENCL_LIB)-DTARGET_DEVICE=\"${XDEVICE}\" -o $@ $(HOST_SRC_CPP)

# -----------------# Kernels# -----------------$(XCLBIN): $(KERNEL_SRC_CL)

$(XOCC) -t $(TARGET) --xdevice $(XDEVICE) --report estimate -o$@ $(KERNEL_SRC_CL)

Step 3: Running CPU Emulation

Now that we understand the makefile construction, it is time to compile the code to run CPUEmulation.

1. To compile the application for CPU Emulation, you need to run one of the followingcommands:

make -f ../makefile/makefile.mk

OR

make -f ../makefile/makefile.mk TARGET=sw_emu

The three files that should be generated are host.exe (host executable),kernels.sw_emu.xclbin (binary container), and a system estimate report. To double check,run an ls command in the directory and you should get the follow:

[sdaccel@localhost work ]$ lshost.exe kernels.sw_emu.xclbin system_estimate.xtxt

2. To run the application in emulation, run the following commands:

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

28

Page 29: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

emconfigutil --platform xilinx:adm-pcie-ku3:2ddr-xpr:3.3export XCL_EMULATION_MODE=true

NOTE: If you are using a c-shell environment use:

setenv XCL_EMULATION_MODE true

The emconfigutil tool generates a emconfig.json file which contains the information aboutthe target device. This file is used by the system in the emulation flow.

NOTE: Make sure that the --platform used in emconfigutil is the same that matches what is in themakefile.

The XCL_EMULATION_MODE environment variable instructs the system that the program will berun in emulation mode, and that the emconfig.json file should be used.

3. Now the application can be run in CPU Emulation mode by running the following command:

./host.exe -d acc -k kernels.sw_emu.xclbin -i 2 -l -1

Where:

• -d - Specifies the type of device that it is to use. In this case, acc specifies the accelerator• -k - Specifies which kernel to use. If -d is set to acc this much be a binary file• -i - Specifies the number of iterations to run• -l - Specifies the default sequence length to be used in the algorithm.

If the application is successfully run, you should observe the follow messages in the terminal:

[sdaccel@localhost work]$ ./host.exe -d acc -k kernels.sw_emu.xclbin -i 2-l -1

Input sequence1:TAGGCAAGACCACTTTAGCATGGTCTACAACGCCTAGACCTTTGGCAAAGCAGATCGGCCCGCCCATCACTAGTGGGACTATCCInput sequence2:TAATGGGAACACCTGCTGCAATCGGATCGTTGCAGCGGTAATGTGTCGGTATATGCGAGTAGGGTAATCCAAACGTCCCATTGC

Platform = XilinxDevice = xilinx:adm-pcie-ku3:2ddr-xpr:3.3OpenCL Version = 1.0Loading kernels.sw_emu.xclbinGlobal size = 1Local size = 1

Align sequence1:T-A-GGCAAGACCACT-TTAGC-AT-GG-TC--TACAACGCCTAGACCT-T-T-GGCA-AAGCAGA-T-CGG----CC---CG-CCCATAlign sequence2:TAATGGGAACA-C-CTGCT-GCAATCGGATCGTTGCAGCG-GTA-A--TGTGTCGGTATATGC-GAGTAGGGTAATCCAAACGTCCCAT

OpenCL kernel time: 0 secPASSED TEST

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

29

Page 30: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

NOTE: If you see PASSED TEST and your terminal prompt has not returned, press Ctrl-C to end theprocess.

4. The application generates a profiling summary report called sdaccel_profile_summary intwo formats: HTML and CSV. Here we will look at the HTML version.

Figure 22: Makefile SDAccel Profile Summary

For the CSV, we can convert this into a report that we see in Lab 1 profile summary andexplore in the SDx™ IDE. To do this run the command:

sda2protobuf sdaccel_profile_summary.csv

This generates a sdaccel_profile_summary.xprf file. To view this report, open up SDx IDE,select File > Open and click the file from the menu. The report is shown below:

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

30

Page 31: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 23: SDx Profile Summary in SDx GUI

NOTE: CPU Emulation does not provide all the profiling information (data transfer between kernel andglobal memory). This information will be available in Hardware Emulation and System.

5. The System Estimate report (system_estimate.xtxt) is also generated. This is from the --report switch used when compiling using the xocc command.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

31

Page 32: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 24: SDx Makefile System Estimate

6. If you want to generate additional reports you will need to set either environment variables orcreate a file called sdaccel.ini with appropriate information and permissions. For theenvironment variables use:

#bashexport SDACCEL_TIMELINE_REPORT=trueexport SDACCEL_DEVICE_PROFILE=true# OR CSHsetenv SDACCEL_TIMELINE_REPORT truesetenv SDACCEL_DEVICE_PROFILE true

In this tutorial, you want to create the sdaccel.ini file, and add the follow contents:

[Debug]timeline_trace = truedevice_profile = trueapp_debug = true

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

32

Page 33: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Run the same command as before:

./host.exe -d acc -k kernels.sw_emu.xclbin -i 2 -l -1

After the application completes, there will be an additional timeline trace file calledsdaccel_timeline_trace.csv. To view this trace report in the GUI, you need to convert theCSV file into a WDB file using this command:

sda2wdb sdaccel_timeline_trace.csv

As you did earlier, launch SDx IDE and using the File > Open File, locate the file:sdaccel_timeline_trace.wdb. You should get the report shown in the following figure:

Figure 25: SDx Makefile Application Timeline GUI

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

33

Page 34: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

There is also an HTML version of the timeline trace generated that looks like this:

Figure 26: SDx Makefile Application Timeline HTML

Step 4: Running HW Emulation

1. Now that CPU Emulation is complete, we can run HW Emulation. To do this without changingthe makefile, run the following command:

make -f ../makefile/makefile.mk TARGET=hw_emu

By defining the TARGET this way, it passes the value and overwrites the default that was set inthe makefile that we saw in Step 2.

NOTE: Like in Lab 1, Hardware Emulation takes longer to compile than the CPU Emulation.

Notice how the host code is not recompiled, only the kernel is recompiled for HardwareEmulation.

2. Next, we can re-run the application. We do not need to regenerate emconfig.json since thedevice information has not changed. Re-run the application with the following command:

./host.exe -d acc -k kernels.hw_emu.xclbin -i 2 -l -1

NOTE: Running this time takes longer since more data is being generated. If it took an instant to run, youmight be targetting the sw_emu binary container. If you see PASSED TEST and your terminal prompt hasnot returned, go ahead and Ctrl-C to end the process.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

34

Page 35: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

3. The output should be similar to the CPU Emulation with the following reports generated.

[sdaccel@localhost work]$ ./host.exe -d acc -k kernels.sw_emu.xclbin -i 2-l -1

Input sequence1: TAGGCAAGACCACTTTAGCATGGTCTACAACGCCTAGACCTTTGGCAAAGCAGATCGGCCCGCCCATCACTAGTGGGACTATCCInput sequence2: TAATGGGAACACCTGCTGCAATCGGATCGTTGCAGCGGTAATGTGTCGGTATATGCGAGTAGGGTAATCCAAACGTCCCATTGC

Platform = XilinxDevice = xilinx:adm-pcie-ku3:2ddr-xpr:3.3OpenCL Version = 1.0Loading kernels.hw_emu.xclbinGlobal size = 1Local size = 1INFO: [SDx-EM 01] Hardware emulation runs detailed simulation underneath.It may take long time for large data set. Please use a small dataset forfaster execution. You can still get performance trend for your kernelwithsmaller dataset.Global size = 1Local size = 1INFO: [SDx-EM 22] [Wall clock time: 10:02, Emulation time: 0.310073 ms]Data transfer between kernel(s) and global memory(s)BANK0 RD = 1.312 KB WR = 56.508 KBBANK1 RD = 0.000 KB WR = 0.000 KB

Align sequence1: T-A-GGCAAGACCACT-TTAGC-AT-GG-TC--TACAACGCCTAGACCT-T-T-GGCA-AAGCAGA-T-CGG----CC---CG-CCCATAlign sequence2: TAATGGGAACA-C-CTGCT-GCAATCGGATCGTTGCAGCG-GTA-A--TGTGTCGGTATATGC-GAGTAGGGTAATCCAAACGTCCCAT

OpenCL kernel time: 11 secPASSED TEST

4. To view the profile summary and timeline trace, run the following commands to convert themfor the SDx IDE to read and view the updated information for the profile summary below:

sda2protobuf sdaccel_profile_summary.csvsda2wdb sdaccel_timeline_trace.csv

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

35

Page 36: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Figure 27: SDx Makefile Hardware Emulation Profile Summary

Step 5: Running System

1. To compile for a System Run, run the following command:

make -f ../makefile/makefile.mk TARGET=hw

NOTE: Building for System will take a long time depending on computer resources.2. Once the build is complete, prepare the board installation by using the following command:

xbints --platform xilinx:adm-pcie-ku3:2ddr-xpr:3.3 -z d .

Where:

--platform, the platform to be used by the design-z, archive the board installation files for deployment-d, the destination directory to use (Required)

3. Once complete, a folder called xbinst is created that contains all the files and scripts neededto deploy the design. To do this, run the install.sh script. The script installs the appropriatelibraries, and firmware, and creates a setup.sh to be used to setup the runtime environment.

4. Run setup.sh to prepare the runtime environment.

NOTE: Running the setup.sh script unsets environment variables related to emulation. If you want tokeep running emulation with the current runtime environment, you will have to re-set theXCL_EMULATION_MODE environment variable.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

36

Page 37: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

5. With the System Run completed, you can re-run this in emulation if desired. To do this, re-setthe XCL_EMULATION_MODE environment variable to TRUE and run the follow command:

./host.exe -d acc -k kernels.hw.xclbin -i 2 -l -1

As in the earlier step, the following reports are generated: profile summary, timeline trace, andsystem estimates.

Use the following commands to convert the profile summary and timeline trace into files thatSDx can read:

sda2protobuf sdaccel_profile_summary.csvsda2wdb sdaccel_timeline_trace.csv

Summary

After completing this tutorial, you should be able to do the following:

• Setup the SDx™ enviornment to run all commands in a terminal.• Be able to run xcpp, xocc, emconfig, sda2protobuf, sda2wdb commands to generate the

application, binary container, emulation model.• Write a makefile to compile an OpenCL™ kernel and host code.• View the generated files from emulation in a text editor or SDx IDE.• Setup the environment and deploy the design to be used with the platform.

Chapter 2: Flow Overview

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

37

Page 38: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Additional Resources and Legal Notices

Xilinx Resources

For support resources such as Answers, Documentation, Downloads, and Forums, see XilinxSupport.

Solution Centers

See the Xilinx Solution Centers for support on devices, software tools, and intellectual propertyat all stages of the design cycle. Topics include design assistance, advisories, andtroubleshooting tips

References

1. SDx Environments Release Notes, Installation, and Licensing Guide (UG1238)2. SDAccel Environment User Guide (UG1023)3. SDAccel Environment Optimization Guide (UG1207)4. SDAccel Environment Tutorial: Introduction (UG1021)5. SDAccel Environment Platform Development Guide (UG1164)6. SDAccel Development Environment web page7. Vivado® Design Suite Documentation8. Vivado Design Suite User Guide: Creating and Packaging Custom IP (UG1118)9. Vivado Design Suite User Guide: High level Synthesis (UG902)10. UltraFast Design Methodology Guide for the Vivado Design Suite, (UG949)11. Vivado Design Suite Properties Reference Guide, (UG912)12. Khronos Group web page: Documentation for the OpenCL standard13. Alpha Data web page: Documentation for the ADM-PCIE-7V3 Card14. Pico Computing web page: Documentation for the M-505-K325T card and the EX400 Card

Appendix A

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

38

Page 39: SDAccel Environment Tutorial - Xilinx · Revision History The following table shows the revision history for this document. Date Version Revision 06/20/17 2017.1 Added new Lab 2 to

Please Read: Important Legal Notices

The information disclosed to you hereunder (the “Materials”) is provided solely for the selectionand use of Xilinx products. To the maximum extent permitted by applicable law: (1) Materials aremade available "AS IS" and with all faults, Xilinx hereby DISCLAIMS ALL WARRANTIES ANDCONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TOWARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULARPURPOSE; and (2) Xilinx shall not be liable (whether in contract or tort, including negligence, orunder any other theory of liability) for any loss or damage of any kind or nature related to,arising under, or in connection with, the Materials (including your use of the Materials),including for any direct, indirect, special, incidental, or consequential loss or damage (includingloss of data, profits, goodwill, or any type of loss or damage suffered as a result of any actionbrought by a third party) even if such damage or loss was reasonably foreseeable or Xilinx hadbeen advised of the possibility of the same. Xilinx assumes no obligation to correct any errorscontained in the Materials or to notify you of updates to the Materials or to productspecifications. You may not reproduce, modify, distribute, or publicly display the Materialswithout prior written consent. Certain products are subject to the terms and conditions ofXilinx’s limited warranty, please refer to Xilinx’s Terms of Sale which can be viewed atwww.xilinx.com/legal.htm#tos; IP cores may be subject to warranty and support terms containedin a license issued to you by Xilinx. Xilinx products are not designed or intended to be fail-safeor for use in any application requiring fail-safe performance; you assume sole risk and liabilityfor use of Xilinx products in such critical applications, please refer to Xilinx’s Terms of Sale whichcan be viewed at www.xilinx.com/legal.htm#tos.

AUTOMOTIVE APPLICATIONS DISCLAIMER

AUTOMOTIVE PRODUCTS (IDENTIFIED AS “XA” IN THE PART NUMBER) ARE NOT WARRANTEDFOR USE IN THE DEPLOYMENT OF AIRBAGS OR FOR USE IN APPLICATIONS THAT AFFECTCONTROL OF A VEHICLE (“SAFETY APPLICATION”) UNLESS THERE IS A SAFETY CONCEPT ORREDUNDANCY FEATURE CONSISTENT WITH THE ISO 26262 AUTOMOTIVE SAFETY STANDARD(“SAFETY DESIGN”). CUSTOMER SHALL, PRIOR TO USING OR DISTRIBUTING ANY SYSTEMSTHAT INCORPORATE PRODUCTS, THOROUGHLY TEST SUCH SYSTEMS FOR SAFETY PURPOSES.USE OF PRODUCTS IN A SAFETY APPLICATION WITHOUT A SAFETY DESIGN IS FULLY AT THERISK OF CUSTOMER, SUBJECT ONLY TO APPLICABLE LAWS AND REGULATIONS GOVERNINGLIMITATIONS ON PRODUCT LIABILITY.

© Copyright 2017 Xilinx, Inc. Xilinx, the Xilinx logo, Artix, ISE, Kintex, Spartan, Virtex, Vivado,Zynq, and other designated brands included herein are trademarks of Xilinx in the United Statesand other countries. OpenCL and the OpenCL logo are trademarks of Apple Inc. used bypermission by Khronos. PCI, PCIe and PCI Express are trademarks of PCI-SIG and used underlicense. All other trademarks are the property of their respective owners.

Appendix A: Additional Resources and Legal Notices

Send FeedbackSDAccel Environment Tutorial: IntroductionUG1021 (v2017.1) June 20, 2017 www.xilinx.com

39