1. Introduction
OpenCL™ JumpStart Kit is a plug-in for Microsoft Visual Studio* that enables developers to quickly create OpenCL projects in the Visual Studio IDE. JumpStart is a new feature in the Intel® SDK for OpenCL™ Applications.
Creating an OpenCL application involves a lot of boiler-plate code: create/query the platform, create/query devices, create context, command queues, etc. At every step proper error checking on the return codes of every API call needs to be done too. JumpStart allows you to create OpenCL projects from existing templates or based on existing samples with all the object creation and OpenCL setup done automatically, so that you can start working on the algorithm or application design. It also allows you to create empty projects. You can read more about JumpStart and its features in the Developer Guide for Intel® SDK for OpenCL™ Applications.
In this tutorial we will show you how to use JumpStart to create an image processing application for Sobel edge detection of a given image, by creating an OpenCL project based on a project template.
This tutorial is intended for beginners with no prior OpenCL experience to help them get started with OpenCL development.
2. Creating a project from a template
Download and install the Intel SDK for OpenCL Applications.
To create a project from a template, create a new OpenCL project by selecting File: New: Project or by typing Ctrl+Shift+N. Select OpenCL under Visual C++ templates. Select CodeBuilder Project for Windows. Select the location of the project and enter a name for the project, say sobel. Click Ok, and the Code Builder wizard will be displayed.
You will then be presented with the Code Builder wizard for OpenCL API dialog:
In the settings dialog you can set the target device (CPU or GPU) and change other settings as appropriate. For this exercise keep all the default settings and click Finish to complete the project creation. The following are the auto-generated files and a brief explanation.
- utils.[h|cpp] – define functions for reading OpenCL kernel file and for logging debug and error messages
- <sample_name>.cpp – is the main file where all the OpenCL host-side processing happens including building the kernel, setting kernel arguments, enqueuing the kernel, etc.
- <sample_name>.cl – is the main OpenCL kernel file
The project can be built and run successfully, but this doesn’t do much. In the next section we will show how to make simple changes to the project to create our application.
3. Creating Sobel filter application
First we need to add code to open and read the input image file to which we will apply the edge detection. We will use OpenCV for doing so, but it can be done in a number of other ways.
Since our Sobel kernel accepts an input buffer and an output buffer as arguments, we will modify CreateBufferArguments()
function to delete the creation of the second input buffer (delete the below lines):
Accordingly, we will change the function signature from
to
Next we will modify the SetKernelArguments()
function as shown below:
Modify ReadOutputBuffer
to return unsigned char data instead of unsigned int
.
Finally in the main()
routine, change the code to use the image data for OpenCL processing instead of the random input. Delete the input generation and buffer allocation of inputA, inputB, and output. Make the following changes:
Pass the required kernel arguments:
Read the output buffer and display the result of applying the kernel to the input image:
4. Summary
In this basic tutorial we showed how to quickly create an OpenCL application using the new JumpStart kit which is part of the Intel SDK for OpenCL Applications. We showed two ways to create a project and showed how to make minimal changes to implement an OpenCL sobel edge detection application.
Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
Copyright © 2014-2016 Intel Corporation. All rights reserved.
*Other names and brands may be claimed as the property of others.
OpenCL and the OpenCL logo are trademarks of Apple Inc and are used by permission by Khronos.
"