Using CUDA in Qt
Qt is an application framework for C++ that provides relatively easy cross-platform GUI creation. Unfortunately, it was not made with the CUDA application framework in mind – at all. To get Qt to work with CUDA, there are a few little tricks that you need to incorporate into your project’s .pro file. The approach I’m using has worked on Ubuntu 12 LTS, Mac OSX 10.8 (it’s buggy, though), and Windows.
First thing’s first: I have not gotten Qt to compile my CUDA code. If anyone can suggest a way to do that I’d like to hear it. Next, make sure you have the GPU Computing Toolkit installed in addition to the GPU SDK.
Next I just included the folders containing the
DEPENDPATH += /usr/local/cuda/lib .<br />
INCLUDEPATH += /usr/local/cuda/lib .
LIBS += -static-libgcc -L/usr/local/cuda/lib -lcudart \
QMAKE_LIBDIR += "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\lib\Win32"<br />
QMAKE_LIBDIR += "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\common\lib\Win32"<br />
QMAKE_LIBDIR += "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include"<br />
QMAKE_LIBDIR += "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2"
INCLUDEPATH += “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\lib\Win32\cudart.lib”
After you’ve got your include path set up, just add
LIBS += -lcudart
The difficult part, at least in Windows, was finding the right architecture settings. MS Visual Studio only compiled CUDA code to x32 at the time, hence the ‘Win32’ folder in the include path. Be sure to check the architecture settings of Qt as well, under the “Toolchain” settings. After you’re sure the architecture is right, add the CUDA object files to the
LIBS variable as we did with
Now when you attempt to build the project in CUDA, it should still fail! Don’t worry. We still need to add the CUDA object files into the now-generated output directory. Drop them into the
YourProjectName-build* folder, including any .h files from your CUDA project that you need to link.
Finally, attempt to build again. It should finally compile and then link with your CUDA object files.