Using Creator for OpenCL - 05-25-2010 by vincent - StreamComputing - http://streamcomputing.eu

Using for OpenCL by vincent – Tuesday, May 25, 2010 http://streamcomputing.eu/blog/2010-05-25/using-qt-creator-for-opencl/

More and more ways are getting available to bring easy OpenCL to you. Most of the convenience libraries are wrappers for other languages, so it seems that and C++ have the hardest time. Since a while my favourite way to go is Qt: it is multi-platform, has a good IDE, is very extensive, has good multi-core and OpenGL-support and… has an extension for OpenCL: http://labs.trolltech.com/blogs/2010/04/07/using-opencl-with-qt http://blog.qt.digia.com/blog/2010/04/07/using-opencl-with-qt/

Other multi-platform choices are , CodeLite, Netbeans and . I will discuss them later, but wanted to give Qt an advantage because it also simplifies your OpenCL-development. While it is great for learning OpenCL-concepts, please know that the the commercial version of Qt Creator costs at least €2995,- a year. I must also warn the plugin is still in beta.

StreamComputing.eu is not affiliated with Qt.

Getting it all

Qt Creator is available in most -repositories: install packages ‘qtcreator’ and ‘qt4-’. For Windows, MAC and the other Linux-distributions there are installers available: http://qt.nokia.com/downloads. People who are not familiar with Qt, really should take a look around on http://qt.nokia.com/.

You can get the source for the plugin QtOpenCL, by using :

git clone http://git.gitorious.org/qt-labs/opencl.git QtOpenCL

See http://qt.gitorious.org/qt-labs/opencl for more information about the status of the project.

You can download it here: https://dl.dropbox.com/u/1118267/QtOpenCL_20110117.zip (version 17 January 2011)

Building the plugin

For Linux and MAC you need to have the ‘build-essentials’. For Windows it might be a lot harder, since you need make, gcc and a lot of other build-tools which are not easily packaged for the Windows-OS. If you’ve made a win32-binary and/or a Windows-specific how-to, let me know.

page 1 / 6 Using Qt Creator for OpenCL - 05-25-2010 by vincent - StreamComputing - http://streamcomputing.eu

You might have seen that people have problems building the plugin. The trick is to use the options -qmake and -I (capital i) with the configure-script:

./configure -qmake -I

make

Notice the spaces. The program qmake is provided by Qt (package ‘qt4-qmake’), the OpenCL-headers by the SDK of ATI or NVidia (you’ll need the SDK anyway), or by Khronos. By example, on my laptop (NVIDIA, Ubuntu 32bit, with Qt 4.7):

./configure -qmake /usr/bin/qmake-qt4 -I/opt/NVIDIA_GPU_Computing_SDK_3.2/OpenCL/common/inc/

make

This should work. On MAC the directory is not CL, but OpenCL – I haven’t tested it if Qt took that into account.

After building , test it by setting a environment-setting “LD_LIBRARY_PATH” to the lib-directory in the plugin, and run the provided example-app ‘clinfo’. By example, on Linux:

export LD_LIBRARY_PATH=`pwd`/lib:$LD_LIBRARY_PATH

cd util/clinfo/

./clinfo

This should give you information about your OpenCL-setup. If you need further help, please go to the Qt forums.

Configuring Qt Creator

Now it’s time to make a new project with support for OpenCL. This has to be done in two steps.

page 2 / 6 Using Qt Creator for OpenCL - 05-25-2010 by vincent - StreamComputing - http://streamcomputing.eu

First make a project and edit the .pro-file by adding the following:

page 3 / 6 Using Qt Creator for OpenCL - 05-25-2010 by vincent - StreamComputing - http://streamcomputing.eu

LIBS += -L/lib -L -lOpenCL -lQtOpenCL

INCLUDEPATH += /lib/

/src/opencl/

By example:

LIBS += -L/opt/qt-opencl/lib -L/usr/local/cuda/lib -lOpenCL -lQtOpenCL

INCLUDEPATH += /opt/qt-opencl/lib/

/usr/local/cuda/include/

/opt/qt-opencl/src/opencl/

The following screenshot shows how it could look like:

Second we edit (or add) the LD_LIBRARY_PATH in the project-settings (click on ‘Projects’ as seen in screenshot):

/usr/lib/qtcreator:location of opencl-plugin>::

By example:

/usr/lib/qtcreator:/opt/qt-opencl/lib:/usr/local/cuda/lib:

As you see, we now also need to have the Qt-creator-libraries and SDK-libraries included.

The following screenshot shows the edit-field for the project-environment:

page 4 / 6 Using Qt Creator for OpenCL - 05-25-2010 by vincent - StreamComputing - http://streamcomputing.eu

Testing your setup

Just add something from the clinfo-source to your project:

printf("OpenCL Platforms:n"); QList platforms = QCLPlatform::platforms(); foreach (QCLPlatform platform, platforms) { printf(" Platform ID : %ldn", long(platform.platformId( ))); printf(" Profile : %sn", platform.profile().toLatin 1().constData()); printf(" Version : %sn", platform.version().toLatin 1().constData()); printf(" Name : %sn", platform.name().toLatin1() .constData()); printf(" Vendor : %sn", platform.vendor().toLatin1 ().constData()); printf(" Extension Suffix : %sn", platform.extensionSuffix() .toLatin1().constData()); printf(" Extensions :n"); } QStringList extns = platform.extensions(); foreach (QString ext, extns) printf(" %sn", ext.toLatin1().c onstData()); printf("n");

If it gives errors during programming (underlined includes, etc), focus on INCLUDEPATH in the project-file. If it complaints when building the application, focus on LIBS. If it complaints when running the successfully built application, focus on LD_LIBRARY_PATH.

Ok, it is maybe not that easy to get it running, but I promise it gets easier after this. Check out our Hello World, the provided examples and http://doc.qt.nokia.com/opencl-snapshot/ to start building.

______

PDF generated by Kalin’s PDF Creation Station

Related content:

1. ImageJ and OpenCL 2. Private: Wrappers and libraries

page 5 / 6 Using Qt Creator for OpenCL - 05-25-2010 by vincent - StreamComputing - http://streamcomputing.eu

3. Qt Creator OpenCL

Also check out these posts

Intel OpenCL CPU-drivers 2013 beta with OpenC...

How expensive is an operation on a CPU?

Basic Concepts: online kernel compiling

Kernels and the GPL. Are we safe and linking?

page 6 / 6

Powered by TCPDF (www.tcpdf.org)