Reputation: 839
I am trying to integrate Qt with CUDA. I am working on Ubuntu 12.04. I already have CUDA and Qt installed.
I followed the steps here - 'linker input file unused because linking not done' when trying to setup QT creator & Cuda
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
// CUDA-C includes
#include <cuda.h>
extern "C"
void runCudaPart();
// Main cuda function
void runCudaPart() {
// all your cuda code here *smile*
}
main.cpp
#include <QtCore/QCoreApplication>
extern "C"
void runCudaPart();
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
runCudaPart();
return a.exec();
}
I added the following lines to the .pro file
QT += core
QT -= gui
TARGET = cuda2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
# Source files for C/C++ compiler
SOURCES += main.cpp
# project build directories
DESTDIR = $$system(pwd)
OBJECTS_DIR = $$DESTDIR/Obj
# and C/C++ flags
QMAKE_CFLAGS_RELEASE =-O3
QMAKE_CXXFLAGS_RELEASE =-O3
# cuda source
CUDA_SOURCES += cuda_interface.cu
# Path to cuda toolkit install
CUDA_DIR = /usr/local/cuda
INCLUDEPATH += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib
# GPU architecture
CUDA_ARCH = sm_20
# NVCC flags
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
# Path to libraries
LIBS += -lcudart -lcuda
# join the includes in a line
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -O3 -arch=$$CUDA_ARCH -c $$NVCCFLAGS $$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
cuda.dependcy_type = TYPE_C
cuda.depend_command = $$CUDA_DIR/bin/nvcc -O3 -M $$CUDA_INC $$NVCCFLAGS ${QMAKE_FILE_NAME}
cuda.input = CUDA_SOURCES
cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o
# Tell Qt that we want add more stuff to the Makefile
QMAKE_EXTRA_COMPILERS += cuda
I ran qmake to generate the makefile. When I click on 'build', I get this error -
13:33:35: Running build steps for project CUDA2...
13:33:35: Configuration unchanged, skipping qmake step.
13:33:35: Starting: "/usr/bin/make" -w
make: Entering directory `/home/alex/CUDA2'
Makefile:541: warning: overriding commands for target `Obj/main.o'
Makefile:538: warning: ignoring old commands for target `Obj/main.o'
/usr/local/cuda/bin/nvcc -m64 -O3 -arch=sm_20 -c --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v -I/usr/local/cuda/include -lcudart -lcuda cuda_interface.cu -o Obj/cuda_interface_cuda.o
ptxas info : Compiling entry function '__cuda_dummy_entry__' for 'sm_20'
ptxas info : Used 2 registers, 32 bytes cmem[0]
g++ -c -pipe -O3 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB - DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore - I/usr/include/qt4 -I/usr/local/cuda/include -I. -o Obj/main.o main.cpp
gcc -c -pipe -O3 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_CORE_LIB - DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore - I/usr/include/qt4 -I/usr/local/cuda/include -I. -o Obj/cuda_interface.o cuda_interface.cu
gcc: warning: cuda_interface.cu: linker input file unused because linking not done
g++ -Wl,-O1 -o cuda2 Obj/cuda_interface_cuda.o Obj/main.o Obj/main.o Obj/cuda_interface.o -L/usr/local/cuda/lib -L/usr/lib/x86_64-linux-gnu -lcudart -lcuda - lQtCore -lpthread
g++: error: Obj/cuda_interface.o: No such file or directory
make: *** [cuda2] Error 1
make: Leaving directory `/home/alex/CUDA2'
13:33:36: The process "/usr/bin/make" exited with code 2.
Error while building project CUDA2 (target: Desktop)
When executing build step 'Make'
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?
Thanks!
Upvotes: 2
Views: 4160
Reputation: 3127
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:
QMAKE_LIBDIR += $$CUDA_DIR/lib64 # for 64bits operating system
or
QMAKE_LIBDIR += $$CUDA_DIR/lib # for 32bits operating system
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:
PS: As @aland commented, your GPU device compute capability is 1.2, so adjust CUDA_ARCH = sm_12.
Upvotes: 3
Reputation: 121649
This is the problem:
g++: error: Obj/cuda_interface.o: No such file or directory
I would delete all of your CUDA source and libraries, make sure everything is completely clean, and reinstall from scratch.
Here is a good guide:
http://laurencedawson.com/ubuntu-11.10-and-cuda-4.1
<= Assuming you already have Ubuntu and your NVidia drivers installed, then just reinstall and rebuild the CUDA toolkit and source.
Forget Qt and forget your graphical IDE until you get things working.
Please reinstall and rebuild CUDA from the command line.
Make sure you can run "deviceQuery" from the command line before you go back to Qt and the IDE.
Another good resource:
Upvotes: 0