cudaspace
I’ve been googling for a while looking for info about Qt Creator and CUDA and there is not too much information about this topic, at least useful. The topic ‘QMake build script for CUDA‘ in the nvidia forum pointed me the way. Basically we need to tell our qt project file how to generate the Makefile to include the CUDA stuff. A basic .pro file to run the HelloQtCuda World program looks like this:
Great! We have added the files that we are going to use in our Qt project. Next the CUDA configuration
Finally, we can customize our Makefile output (more info about this topic)
That’s all. Now you can add your only c++ code in the main.cpp (i.e. check parameters, load an image from file…):
And the cuda functions and kernels in the cuda_interface.cu:
So, what do i get with all this work?. Of course, this is a matter of taste! I’ve been using Eclipse IDE for years, programming in C/C++ and also CUDA but it has been a long since i wanted give a chance to the Qt Creator IDE. First, it is a light and clean IDE. Second, i got a template for future projects :). I can also auto-complete code and the best and most important i can easily debug all the cpp and cu code! – but not the kernels. Anyway, debug cpp and cu files into the IDE is a plus compared to Eclipse, at least, i wasn’t able to do it with eclipse.
Rate this:
Share this:
Like this:
17 thoughts on “ Qt Creator + CUDA + Linux ”
How can i write this file on windows 7,thank you very much!
i’ve not tried it on windows and i’ve not a windows machine at the moment but it’s supposed to be the same. Just try to fix the directories with the CUDA includes and libs. Oh! and be aware about the x86_64 flags if you have a 32bits machine.
Hope this help and best regards!
Hi, thanks for the tutorial. Since you write that you are using qtcreator, how is it possible to add cu-files to the qtcreator project such that they are not added to SOURCES automatically but to CUDA_SOURCES.
Best regards
-Flo-
Hello Flo, welcome.
You can use a ‘old trick’ for that purpose. First, add the .cu files to the SOURCES:
SOURCES += main.cpp \
cuda_interface.cu
At this point, the Qt Designer will add the cuda_interface.cu file to the project tree. Below those lines remove the .cu files from the SOURCES:
The Qt Designer will not remove the file from the project tree and the SOURCES variable will hold only the C++ files. This trick also work with the HEADERS.
Hope this help and best regards!
Hello,
Thanks for the post. I am trying to compile a project with Qt on Mac OS and I am getting the following error:
ld: warning: ignoring file ../qt4_mandelbrot/obj/kernelPBO_cuda.o, file was built for i386 which is not the architecture being linked (x86_64)
After googling, I found that setting CONFIG+=x86_64 in .pro file would fix this. But that is not working with me. How to set a particular architecture for Qt? Any ideas?
I also get another error:
ld: symbol(s) not found for architecture x86_64
What does this mean?
Thanks in advance.
Did you prepare the project from the scratch? or started from another project? Some users have reported that this tutorial has worked on Mac OS, but with a few issues with the CUDA SDK. Did you compile and execute the SDK examples successfully?
The ‘symbol(s) not found for architecture x86_64’ sounds like you are not linking against the library correctly. Maybe it’s missing?.
Hello Pablo,
I am still getting the same error. But I have few doubts:
When I am running qmake, following is the compiler output:
18:40:32: Running steps for project test…
18:40:32: Starting: “/usr/local/Trolltech/Qt-4.8.2/bin/qmake” /Users/apple/Documents/Qt_apps/test/test/test.pro -r -spec macx-g++ CONFIG+=debug CONFIG+=x86_64 CONFIG+=declarative_debug
18:40:33: The process “/usr/local/Trolltech/Qt-4.8.2/bin/qmake” exited normally
Why is there the flag ‘CONFIG+=x86_64′? I am using Mac OS. So, I need to compile with a 32-bit architecture.
When I build the project, this is the compiler output:
g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o ../bin/QtCuda ../test/Obj/cuda_interface_cuda.o ../test/Obj/main.o -F/usr/local/Trolltech/Qt-4.8.2/lib -L/usr/local/cuda/lib -L/Developer/Qt_CUDA_SDK/C/lib -L/Developer/Qt_CUDA_SDK/C/common/lib -L/usr/local/Trolltech/Qt-4.8.2/lib -lcudart -framework QtCore -L/usr/local/Trolltech/Qt-4.8.2/lib
ld: warning: ignoring file ../test/Obj/cuda_interface_cuda.o, file was built for i386 which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
“_runCudaPart”, referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [../bin/QtCuda] Error 1
make: Leaving directory `/Users/apple/Documents/Qt_apps/test/test-build-desktop-Qt_4_8_2__Qt-4_8_2__Debug’
18:42:38: The process “/usr/bin/make” exited with code 2.
Error while building/deploying project test (target: Desktop)
When executing step ‘Make’
Why is it trying to compile with x86_64 flag? In the properties under ‘Build & Run’ options I chose ‘GCC (x86 32bit)’. So, even then why is it compiling with 64 bit flag? Am I missing any other flag anywhere?
Try to remove line 22. Change the cutil lib with the 32bit name (note the comment). And remove the flag -m64 from the line 33 (or change it for -m32).
Note the line numbers are related to the .pro file off the post:)
Run qmake and let me know.
Regards and good luck.
Hey, this seems interesting, I’ll start out with a CUDA project this fall and looking for a usable IDE in linux, I’m not familiar with qt creator.
Not sure if the part about QCoreAppliaction is “separate”, I was wondering if it’s necessary to add the qt includes and QCoreApplication etc. for a pure c++/CUDA project to be developed in qt-creator, it would be inconvenient if it ended up IDE dependent (at least without editing the project). I suppose that can be removed for such purposes?
It’s not necessary add the qt includes. I added them because I’m using some Qt file handler and I’d like to make a UI in the future.
Maybe you are familiar with Eclipse IDE which has support for Parallel Nsight in CUDA 5.0. The Nsight can be used for debugging the CUDA kernels, which is obviously a plus.
Right now, I prefer Qt creator IDE because is lighter and cleaner and because I’ve not tried CUDA 5.0 and I’ve not seen the Nsight working. Maybe I’ll jump to Eclipse in the future.
I was googling an appropriate IDE for CUDA programming on linux, and found this nice post. I am wondering which IDE you are using now, Eclipse or Qt Creator?
I have switched to Nsight Eclipse Edition that is shipped with CUDA. It has many interesting features sych as the profiler.
After switching to Nsight Eclipse Edition, do you still use Qt libraries for your UI needs?
A feature that I like in Qt Creator is the .pro file, seems to give more control about the compilation. I’m new in the world of linux/cuda development, and I’m currently using a Jetson TK1 board.
Dear Edson, currently I’m not using Qt. I’m using a custom Makefile within the Nsight projects and adding different flags and variables to manage my applications. It’s more convenient when I want to test the program in different machines which have different GPUs.
Best,
Pablo.
Dear Pablo, thanks for your reply! It’s very important to me receive best practices from more experienced developers. In this sense, if you’d have to develop a project with complex GUI (windows, menus, tree explorer, dialogs, etc…), what UI toolkit/framework would be your preferred choice to work with? I mean…GTK-based libraries..Qt-based (although you’ve just said above that doesn’t use Qt anymore, but maybe for GUI related needs can be a choice..)…
Источник
Cuda qt creator linux
Hi, I’m trying to compile my Qt project containing a CUDA file (.cu). In QtCreator, I’ve edited the .pro file based on http://blog.qt.io/blog/2015/03/03/qt-weekly-28-qt-and-cuda-on-the-jetson-tk1/. The relevant part is as follows —
Yet when I try to build this, I get the error
[Edit]
In the automatically generated Makefile, I see this —
Which is then followed by a long list of CUDA headers. If I manually change this to the following, my project compiles and runs correctly —
Any ideas what is causing the ‘incorrect’ generation of my Makefile?
What platform are you on ?
I’m on (Arch) Linux, 64-bit.
I don’t know why it tries to generate that dependency, but as a long shot can you try without changing the objects file name, i.e.:
Tested it on macOS and it worked correctly.
Can you show the rest of your .pro file ?
Thanks guys for looking into it. @kshegunov, in that case the error changes to
Part of the Makefile then looks like this —
This is the entire .pro file —
I’m using Qt Creator 4.8.1, QMake version 3.1, and Qt version 5.12.0.
What if you try with:
Unfortunately that does not make a difference. Hmm, could it be a setting somewhere in Build Settings? Effective qmake call is set to
Manually changing the Makefile is not a big issue, at this point I’m just curious why it is generated like it is.
That version of qmake is the one from your distribution and likely not the one from your 5.12 installation.
Use the full path to it to ensure the correct one is used.
Hmm, it’s the only qmake I have on my machine. Info —
In that case, can you try with the pre-built version ? Just to compare the output.
This is definitely a problem when upgrading from an older version of qmake to qmake 3.1 which is part of Qt 5.12.3.
For some reason qmake 3.1 parses the output of a compile depend_command differently than before, which breaks existing .pro files that use a custom compiler for CUDA. Qmake ends up constructing a dependency list that looks like this:
The solution is to pipe the output of nvcc to:
Источник
Интеграция CUDA с Qt на Ubuntu 12.04
Я пытаюсь интегрировать Qt с CUDA. Я работаю над Ubuntu 12.04. У меня уже установлены CUDA и Qt.
Однако он все еще дает мне ошибку.
Вот как я это сделал.
В моем домашнем каталоге я создал пустой проект Qt под названием “CUDA2”.
Я добавил следующие файлы
cuda_interface.cu
main.cpp
Я добавил следующие строки в файл .pro
Я запустил qmake для создания make файла. Когда я нажимаю “build”, я получаю эту ошибку –
Я не уверен, что файл .pro будет работать с Linux. Похоже, он был сделан для OSX.
Кроме того, я не знаю, правильна ли линия CUDA_ARCH = sm_20. Есть ли способ найти мою архитектуру gpu? Я использую NVIDIA Quadro FX 380M
Что я делаю неправильно?
Основываясь на комментариях, у вас были некоторые “распространенные ошибки” в вашем файле .pro.
Во-первых, набор инструментов CUDA разделяет библиотеки для 32 и 64 бит. Итак, вам нужно настроить QMAKE_LIBDIR следующим образом:
Не включайте файлы .cu в качестве ИСТОЧНИКОВ в .pro файле, поскольку они не скомпилированы с помощью g++. Файл .pro вашего вопроса не показывает этот случай, но вы прокомментировали, что файл .cu находится в проекте в Qt, чтобы удалить их.
Наконец, чтобы убедиться, что все ваши изменения вступили в силу, выполните следующие действия в меню IDE QT Creator:
- Сборка → Очистить проект # для очистки старого материала
- Сборка → Запустите qmake #, чтобы выполнить изменения .pro.
- Сборка → Сборка проекта # очевидна
PS: Как комментирует @aland, ваша вычислительная способность устройства GPU составляет 1,2, поэтому настройте CUDA_ARCH = sm_12.
В этом проблема:
g++: ошибка: Obj/cuda_interface.o: нет такого файла или каталога
Я бы удалил все ваши источники и библиотеки CUDA, убедитесь, что все полностью очищено и переустанавливается с нуля.
Источник
Integrating CUDA with Qt on Ubuntu 12.04
I am trying to integrate Qt with CUDA. I am working on Ubuntu 12.04. I already have CUDA and Qt installed.
However it still gives me an error.
Here is how I did it.
I created an empty Qt project called ‘CUDA2’ in my home directory.
I added the following files
cuda_interface.cu
main.cpp
I added the following lines to the .pro file
I ran qmake to generate the makefile. When I click on ‘build’, I get this error —
I am not sure if the .pro file will work with Linux. Looks like it was made for OSX. Also, I don’t know if the line CUDA_ARCH = sm_20 is correct. Is there a way I can find my gpu architecture? I am using an NVIDIA Quadro FX 380M
What am I doing wrong?
2 Answers 2
Based on the comments, you had some ‘common mistakes’ on your .pro file.
First, the CUDA toolkit has separated libraries directories for 32 and 64 bits. So, you need adjust the QMAKE_LIBDIR as follows:
Do not include the .cu files as SOURCES in the .pro file as they are not compiled with g++. The .pro file of your question does not show this case, but you commented that the .cu file were in the project in Qt remove them.
Finally, to be sure all your changes take effect do the following in the QT Creator IDE menu:
- Build -> Clean Project # to clean old stuff
- Build -> Run qmake # to take the .pro changes
- Build -> Build Project # obvious
PS: As @aland commented, your GPU device compute capability is 1.2, so adjust CUDA_ARCH = sm_12.
Источник
Qt Weekly #28: Qt and CUDA on the Jetson TK1
Tuesday March 03, 2015 by Laszlo Agocs | Comments
NVIDIA’s Jetson TK1 is a powerful development board based on the Tegra K1 chip. It comes with a GPU capable of OpenGL 4.4, OpenGL ES 3.1 and CUDA 6.5. From Qt’s perspective this is a somewhat unorthodox embedded device because its customized Linux system is based on Ubuntu 14.04 and runs the regular X11 environment. Therefore the approach that is typical for low and medium-end embedded hardware, running OpenGL-accelerated Qt apps directly on the framebuffer using the eglfs platform plugin, will not be suitable.
In addition, the ability to do hardware-accelerated computing using CUDA is very interesting, especially when it comes to interoperating with OpenGL. Let’s take a look at how CUDA code can be integrated with a Qt-based application.
Building Qt
This board is powerful enough to build everything on its own without any cross-compilation. Configuring and building Qt is no different than in any desktop Linux environment. One option that needs special consideration however is -opengl es2 because Qt can be built either in a GLX + OpenGL or EGL + OpenGL ES configuration.
For example, the following configures Qt to use GLX and OpenGL:
while adding -opengl es2 requests the usage of EGL and OpenGL ES:
If you are planning to run applications relying on modern, non-ES OpenGL features, or use CUDA, then go for the first. If you however have some existing code from the mobile or embedded world relying on EGL or OpenGL ES then it may be useful to go for #2.
The default platform plugin will be xcb, so running Qt apps without specifying the platform plugin will work just fine. This is the exact same plugin that is used on any ordinary X11-based Linux desktop system.
Vsync gotchas
Once the build is done, you will most likely run some OpenGL-based Qt apps. And then comes the first surprise: applications are not synchronized to the vertical refresh rate of the screen.
When running for instance the example from qtbase/examples/opengl/qopenglwindow, we expect a nice and smooth 60 FPS animation with the rendering thread throttled appropriately. This unfortunately isn’t the case. Unless the application is fullscreen. Therefore many apps will want to replace calls like show() or showMaximized() with showFullScreen(). This way the thread is throttled as expected.
A further surprise may come in QWidget-based applications when opening a popup or a dialog. Unfortunately this also disables synchronization, even though the main window still covers the entire screen. In general we can conclude that the standard embedded recommendation of sticking to a single fullscreen window is very valid for this board too, even when using xcb, although for completely different reasons.
After installing CUDA, the first and in fact the only challenge is to tackle the integration of nvcc with our Qt projects.
Unsurprisingly, this has been tackled by others before. Building on this excellent article, the most basic integration in our .pro file could look like this:
In addition to Linux this will also work out of the box on OS X. Adapting it to Windows should be easy. For advanced features like reformatting nvcc’s error messages to be more of Creator’s liking, see the article mentioned above.
A QOpenGLWindow-based application that updates an image via CUDA on every frame could now look something like the following. The approach is the same regardless of the OpenGL enabler in use: QOpenGLWidget or a custom Qt Quick item would operate along the same principles: call cudaGLSetGLDevice when the OpenGL context is available, register the OpenGL resources to CUDA, and then do map — invoke CUDA kernel — unmap — draw on every frame.
Note that in this example we are using a single pixel buffer object. There are other ways to do interop, for example we could have registered the GL texture, got a CUDA array out of it and bound that either to a CUDA texture or surface.
The corresponding cuda_stuff.cu:
This is all that’s needed to integrate the power of Qt, OpenGL and CUDA. Happy hacking!
Источник