以下文章中缺少图片,请在百度网盘下载word观看
https://pan.baidu.com/s/1nuI2dRV
https://download.csdn.net/download/qccz123456/10567840
Debugging OpenCL™ Kernels on GPU
Intel® SDK for OpenCL™ Applications delivers aseamless debugging experience that enables you to debug both CPU and GPUportions of your application simultaneously.
This chapter provides OpenCL GPU Debuggerinstallation walkthrough and demonstrates how to use the debugger to debug anOpenCL sample application.
Usually the process requires two separatemachines (host machine and target machine) todebug OpenCL kernels on the GPU (unless you have a discrete graphics card, whenhost and target machines can be the same machine physically):
· HostMachine - The machineused for running the debugger (GDB or Microsoft Visual Studio* 2015/2017) andcontrolling the debugging process.
· TargetMachine - The machine usedfor running the OpenCL host app and kernel under debug.
NOTE: The reason forusing two separate machines is because the GPU is hung on the OpenCL kernelwhile it is under debugging. Therefore, the UI rendering seems frozen while itwaits for the GPU to render UI/desktop.
For more information, see the followingtopics:
· OpenCL™GPU Kernel Debugger for Windows*
· OpenCL™GPU Kernel Debugger for Linux* Beta
OpenCL™ GPU Kernel Debugger forWindows*
This chapter describes how to install theOpenCL™ Kernel Debugger on Microsoft Windows* OS and demonstrates how to use itfor debugging an OpenCL application.
For details, see the following topics:
· InstallingOpenCL™ Kernel Debugger for Windows*
Installing OpenCL™ KernelDebugger for Windows*
This topic provides a walkthrough for the installation of theOpenCL™ GPU Debugger on a Microsoft Windows* OS.
Supported OSes andPrerequisites
OpenCL™ Kernel Debugger for Windows* can be installed and run onthe following operating systems:
· Windows 7 (64-bit)
· Windows 8.1 (64-bit)
· Windows 10 (64-bit) (preferred)
Host machine
As a host machine you can use any machine with an Intel® CPUrunning a supported Windows* OS.
Target machine
A target machine is a 6th or 7th Generation Intel® Core™Processors machine running a supported Windows OS (Windows 10 is preferred)with the latest Graphics Driver is installed.
Installing OpenCL™ KernelDebugger
Installation of the OpenCL™ Kernel Debugger on Windows machinerequires installation on both host and target machines.
Installing on the Host
To install the debugger on the host machine, use the followingsteps:
1. Launch the Intel® SDK for OpenCL™ Applications installer andensure that IntelDebugger for Heterogeneous Compute is selected in the listof components to install.
2. Select either option you like and click Install:
3. Check the Opentarget installer folder option. Pay attention to thelocation of the target installer (in this instance it's C:\Intel\OpenCL\debugger
), youwill need it for installing on the target machine:
NOTE: Rebootis required (usually for environment variables to propagate after setup), somake sure you reboot prior to the first usage.
Installing on the Target
The target machine is the machine used for running the OpenCLhost application under debug. This is usually a different machine (not thehost), unless you have a discrete graphics card used for displaying the WindowsDesktop, in which case host and target can be the same machine. Complete thefollowing steps to install the debugger on your target machine:
1. Copy the gen_debugger_target_*.msi
installerfile from the host machine (from C:\Intel\OpenCL\debugger
bydefault) to your target machine.
2. Launch the installer and follow the instructions:
3. Click Finish andreboot the machine:
If you want to (remotely) debug your OpenCL kernels usingMicrosoft Visual Studio* 2015/2017, the following additional steps arerequired.
NOTE: Youcan skip these steps if you already have Visual Studio 2015/2017 installed onyour target machine.
To debug through Visual Studio 2015, do the following:
1. Open an elevated command prompt on your target machine
2. Create the RemoteDebugger
directory: mkdirC:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger
3. Copy the entire folder C:\Program Files (x86)\Microsoft Visual Studio14.0\Common7\IDE\Remote Debugger
from your host machine toyour target machine (into the same directory hierarchy)
4. Create a desktop shortcut (optional):
a. Open C:\Program Files(x86)\Microsoft Visual Studio 14.0\Common7\IDE\Remote Debugger\x64
b. Right-click on msvsmon.exe
> Send to > Desktop (create shortcut),rename the shortcut to VS2015Remote Debugger.
If you wish to debug through Visual Studio 2017, do thefollowing:
1. Open an elevated command prompt on your target machine
2. Create the RemoteDebugger
directory: mkdirC:\Program Files (x86)\Microsoft VisualStudio\2017\Professional\Common7\IDE\Remote Debugger
3. Copy the entire folder C:\Program Files (x86)\Microsoft VisualStudio\2017\Professional\Common7\IDE\Remote Debugger
fromyour host machine to your target machine (into the same directory hierarchy)
4. Create a desktop shortcut (optional):
a. Open C:\Program Files (x86)\MicrosoftVisual Studio\2017\Professional\Common7\IDE\Remote Debugger\x64
b. Right-click on msvsmon.exe
> Send to > Desktop (create shortcut),rename the shortcut to VS2017Remote Debugger.
Debugging OpenCL™ Kernels
This topic demonstrates how to use the OpenCL™GPU Kernel Debugger to debug an OpenCL sample application on a MicrosoftWindows* OS.
To debug your OpenCL™ Kernels on GPU usingOpenCL Kernel Debugger on a Microsoft Windows* OS, perform the following steps:
On the target machine, launch the RemoteDebugger:
NOTE: Make sure thatthe version of the Visual Studio Remote Debugger you run on the target machine,matches the version of the Visual Studio IDE you use on the host machine. Forexample, if you are using Visual Studio 2015 on the host, you should use VisualStudio 2015 Remote Debugger on the target machine.
On the host machine, start Microsoft VisualStudio* 2015/2017, go to Tools > Options > Code Builder > GPUKernel Debugger, set Enable Debugging to True and changethe Server field to the name of the target machine (e.g. localhost in thisexample):
Add the OpenCL kernel file to your project (ifit is not part of the project yet), and set breakpoints where needed.
Build your project and copy the executable and.cl files to the working directory on your target machine.
Configure your project for remote C++Debugging:
1. Right click on yourproject, choose Properties, open Configuration Properties > Debugging andselect Remote Windows Debugger in the Debugger tolaunch list:
2. Set RemoteCommand to the full path to your executable on the target machine.
3. Set WorkingDirectory to the directory where the binary file is located.
4. Set RemoteServer name to be the host name of your target machine.
5. Click OK:
After the dialog is closed, click on RemoteWindows Debugger, or press F5:
If you configured the project properly, thedebugger stops execution at the breakpoints you have set:
OpenCL™ GPU Kernel Debugger forLinux* Beta
This chapter describes how to install theOpenCL™ Kernel Debugger on Linux* OS and demonstrates how to use it fordebugging an OpenCL application.
For details, see the following topics:
· InstallingOpenCL™ Kernel Debugger for Linux*
Installing OpenCL™ KernelDebugger for Linux*
This topic provides a walkthrough for the installation of theOpenCL™ GPU Debugger on a Linux* machine.
Supported OSes andPrerequisites
OpenCL™ Kernel Debugger for Linux* can be installed and run onthe following Linux* operating systems:
· CentOS 7.2 or higher
· Ubuntu 14.04
· Ubuntu 16.04
NOTE: OpenCL™Kernel Debugger currently does not support a Yocto* operating system on aIntel® Processor formerly known as Broxton.
NOTE: ForCentOS users, sudo-E yum update
upgrades the system from 7.1 to 7.2.
Host Machine
As a host machine you can use any machine with an Intel® CPUrunning a Linux* OS.
Target Machine
A machine with 6th or 7th Generation Intel® Core™ Processorsrunning a Linux* OS with the OpenCL™ 2.0 GPU graphics driver (SRB5.0)installed. To install the driver using the installation script, see https://software.intel.com/en-us/articles/sdk-for-opencl-gsg. Formanual downloading and installation instructions, refer to the https://software.intel.com/en-us/articles/opencl-drivers#latest_linux_driver section.
If you are building on CentOS* machine, please use make rpm-pkg
insteadof makebinrpm-pkg
when building the Linux kernel, and make sure to installthe Linux headers RPM.
Make sure the dkms package is installed. Use the followingcommand to install:
· On Debian*: sudoapt-get install dkms
· On CentOS*: sudoyum install epel-release dkms
Using Target Machine as Host
On Linux, the host and target machine can be the same machine ifyou use one of these option:
· You have a discrete Graphics Card used for rendering the Desktopand the UI
· You connect remotely to the host machine.
This section describes the process assuming the second option,i.e. you can connect remotely to the host machine.
So for example, you may start a remote SSH (e.g. PuTTY) fromyour laptop to your development machine (onto which the SDK is installed), andlaunch gdb, gdbserver-igfx and your host application via the SSH session.
The example presented in this section uses three PuTTY windowsand two separate machines:
· A Windows* development machine
· A Linux host and target machine
The Windows development machine is used for the remote SSHsessions, but you can also start a remote SSH session through a Linux machine.
Sample Application
Download the Median Filter sample, whichwill be used for the debugging demonstration.
The sample is part of the "Code Samples" suiteavailable on Code Samples page: https://software.intel.com/en-us/intel-opencl-support/code-samples.
Installing OpenCL™ KernelDebugger
To install the OpenCL™ GPU Kernel Debugger for Linux* from anIntel® SDK for OpenCL™ applications release package, follow the steps below:
1. Unpack the installer package and launch:
|
| |
|
|
2.
|
|
3. Accept the EULA and follow the wizard instructions.
4. When the installation is complete, the following message isshown:
|
| |
|
|
|
| |
|
|
|
| |
|
|
Debugging OpenCL™ Kernels
This topic demonstrates how to use the OpenCL™ GPU KernelDebugger to debug an OpenCL sample application on a Linux* OS. The steps belowuse the "Median Filter" OpenCL sample application to show thedebugging process.
Building and Running theSample Application
Before you continue, make sure you have downloaded the MedianFilter sample application, which is used for furtherdemonstration.
Unpack the sample and build it running the make
commandfrom the unpacked MedianFilter directory:
|
| |
|
|
Run the sample:
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
|
If you were able to successfully run it, you will get an outputsimilar to the above, otherwise please consult the documentation for theGraphics Driver installation.
Debug Demonstration
In the demo, one physical Linux* machine is used both as thehost and target machine. The host machine (which is also the target) will beconnected remotely and three PuTTY* terminals will be used for launching gdb,gdbserver-igfx and the sample.
1. Launch gdbserver in the terminal 1:
|
|
2.
3. Launchthe sample under debug in the terminal 2:
|
| |
|
|
4.
|
|
5.
6. Launch gdb in the terminal 3:
|
| |
|
|
7.
|
| |
|
|
8.
|
| |
|
|
9.
|
| |
|
|
10.
|
| |
|
|
11.
|
| |
|
|
12.
|
| |
|
|
13.
|
| |
|
|
Now you stopped at the first instruction of the kernel (alsocalled "the initial breakpoint") and if all went well, you should seethe following screen:
From this point you may use standard gdb commands to examinememory, set breakpoints, change run control, etc.
For example, set a breakpoint at line 52 and continue:
|
| |
|
|
|
|
It should look like the following:
GDB* Cheat Sheet
Here is a GDB useful commands cheat sheet:
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
|
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
|
| |
|
|
For more information on GDB commands, see the GDB manual.