QMake build script for CUDA

To complement the CMake scripts posted by Abe, here is a small script to use qmake to generate CUDA projects on both linux and windows (where it can generate Visual Studio projects):

########################################################################

#  CUDA

########################################################################

win32 {

  INCLUDEPATH += $(CUDA_INC_DIR)

  QMAKE_LIBDIR += $(CUDA_LIB_DIR)

  LIBS += -lcudart

 cuda.output = $$OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj

  cuda.commands = $(CUDA_BIN_DIR)/nvcc.exe -c -Xcompiler $$join(QMAKE_CXXFLAGS,",") $$join(INCLUDEPATH,'" -I "','-I "','"') ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

}

unix {

  # auto-detect CUDA path

  CUDA_DIR = $$system(which nvcc | sed 's,/bin/nvcc$,,')

  INCLUDEPATH += $$CUDA_DIR/include

  QMAKE_LIBDIR += $$CUDA_DIR/lib

  LIBS += -lcudart

 cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.obj

  cuda.commands = nvcc -c -Xcompiler $$join(QMAKE_CXXFLAGS,",") $$join(INCLUDEPATH,'" -I "','-I "','"') ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

  cuda.depends = nvcc -M -Xcompiler $$join(QMAKE_CXXFLAGS,",") $$join(INCLUDEPATH,'" -I "','-I "','"') ${QMAKE_FILE_NAME} | sed "s,^.*: ,," | sed "s,^ *,," | tr -d '\\n'

}

cuda.input = CUDA_SOURCES

QMAKE_EXTRA_UNIX_COMPILERS += cuda

########################################################################

You can add this in you .pro files and then you just have to specify the CUDA source files in CUDA_SOURCES variable. I tested it on both windows and linux. On windows it works fine for generating Makefile but requires a change in qmake to generate VS projects. I have to package and submit the required patch to Trolltech…

Edit: missing code in unix part

For me the dependencies work better using

 cuda.dependcy_type = TYPE_C

  cuda.depend_command = nvcc -M -Xcompiler $$join(QMAKE_CXXFLAGS,",") $$join(INCLUDEPATH,'" -I "','-I "','"') ${QMAKE_FILE_NAME} | sed "s,^.*: ,," | sed "s,^ *,," | tr -d '\\n'

instead of the [font=“Courier”]cuda.depends[/font] variable.

But thanks for the initial post. It helped me a lot External Image

Thanks for the great head start!
But I have a questen, which I was unable to get answered by google.
Maybe one of your guys could help me with that.

Is is possible to add another configuration like ‘debug’ or ‘release’ to the project by using qmake? I’d like to have a special Device-Emu-Config, just like in the SDK-Examples.
How would I accomplish that?

Thanks.

hi all,

sorry for the newbie question, but I’m having hard time incorporating the above code into my qmake file. Can someone please post a complete qmake file using, for example, the matrixMul project in the 1.1 SDK? I’m using ubuntu 7.10 with SDK 1.1, 8800GTS.

Thank you very much,

I also made small integration example CUDA+Qt.

Please check full code here: http://sourceforge.net/projects/cuda-z/

Here is my fragment of qmake’s pro-file.

TEMPLATE = app

QT = gui core

CONFIG += qt release warn_on

#CONFIG += console

FORMS = ui/czdialog.ui

HEADERS = \

	src/version.h \

	src/czdialog.h \

	src/cudainfo.h

SOURCES = src/czdialog.cpp \

	src/main.cpp

RESOURCES = res/cuda-z.qrc

win32:RC_FILE += res/cuda-z.rc

CUSOURCES = src/cudainfo.cu

unix:LIBS += -lcuda

win32:LIBS += \

	$(CUDA_LIB_PATH)\cuda.lib \

	$(CUDA_LIB_PATH)\cudart.lib

...

#

# Cuda extra-compiler for handling files specified in the CUSOURCES variable

#

QMAKE_CUC = $(CUDA_BIN_PATH)/nvcc.exe

{

	cu.name = Cuda ${QMAKE_FILE_IN}

	cu.input = CUSOURCES

	cu.CONFIG += no_link

	cu.variable_out = OBJECTS

	isEmpty(QMAKE_CUC) {

  win32:QMAKE_CUC = $(CUDA_BIN_PATH)/nvcc.exe

  else:QMAKE_CUC = nvcc

	}

	isEmpty(CU_DIR):CU_DIR = .

	isEmpty(QMAKE_CPP_MOD_CU):QMAKE_CPP_MOD_CU = 

	isEmpty(QMAKE_EXT_CPP_CU):QMAKE_EXT_CPP_CU = .cu

	INCLUDEPATH += $(CUDA_INC_PATH)

	QMAKE_CUFLAGS += $$QMAKE_CXXFLAGS $$QMAKE_CXXFLAGS_RELEASE $$QMAKE_CXXFLAGS_RTTI_ON $$QMAKE_CXXFLAGS_WARN_ON $$QMAKE_CXXFLAGS_STL_ON

	QMAKE_CUEXTRAFLAGS += -Xcompiler $$join(QMAKE_CUFLAGS, ",")

	QMAKE_CUEXTRAFLAGS += $(DEFINES) $(INCPATH) $$join(QMAKE_COMPILER_DEFINES, " -D", -D)

	QMAKE_CUEXTRAFLAGS += -c

	cu.commands = $$QMAKE_CUC $$QMAKE_CUEXTRAFLAGS -o $$OBJECTS_DIR/$${QMAKE_CPP_MOD_CU}${QMAKE_FILE_BASE}$${QMAKE_EXT_OBJ} ${QMAKE_FILE_NAME}$$escape_expand(\n\t)

	cu.output = $$OBJECTS_DIR/$${QMAKE_CPP_MOD_CU}${QMAKE_FILE_BASE}$${QMAKE_EXT_OBJ}

	silent:cu.commands = @echo nvcc ${QMAKE_FILE_IN} && $$cu.commands

	QMAKE_EXTRA_COMPILERS += cu

	build_pass|isEmpty(BUILDS):cuclean.depends = compiler_cu_clean

	else:cuclean.CONFIG += recursive

	QMAKE_EXTRA_TARGETS += cuclean

}

Tested with VS2005 and Qt 4.4.0.

I can’t test it in linux yet…

WBR,

AG

Hi,

   I am also using Qt to develop cuda code, but I can not debug my .cu code. I can step into .cu file, but I can not step into the cuda kernels. I also tried run cuda-gdb in terminal, but I can not step into the cuda kernels either. What do I need to change for my .pro file? Thank you very much.

Best,

Wu

[codebox]

Path to opencv install

OPENCV_DIR = /usr/local/opencv

Path to cuda SDK install

CUDA_SDK = /home/wu/NVIDIA_GPU_Computing_SDK/C

Path to cuda toolkit install

CUDA_DIR = /usr/local/cuda

#CUDA_DIR = $$system(which nvcc | sed ‘s,/bin/nvcc$,’)

GPU architecture

CUDA_ARCH = sm_13

PROJECT_DIR = $$system(pwd)

#CONFIG += create_prl

#CONFIG += link_prl

TEMPLATE = app

#TARGET = release_binary

#CONFIG += release

QMAKE_CXXFLAGS_RELEASE =-O3

DESTDIR = …/bin

LIBS += -lcudart -lcutil

LIBS += -lGLEW -lGL -lGLU

LIBS += -lcxcore -lcv -lhighgui -lcvaux -lml

RESOURCES += ressources.qrc

OBJECTS_DIR = $$PROJECT_DIR/Obj

NVCCFLAGS = --compile --host-compilation 'C++' \

        --compiler-options -fno-strict-aliasing -use_fast_math 

DEPENDPATH += $$PROJECT_DIR/Gui

DEPENDPATH += $$PROJECT_DIR/Motion

DEPENDPATH += $$PROJECT_DIR/Cuda

DEPENDPATH += $$PROJECT_DIR/Core

DEPENDPATH += $$PROJECT_DIR/Media

DEPENDPATH += $$PROJECT_DIR/OpenGL

DEPENDPATH += $$PROJECT_DIR

INCLUDEPATH += $$PROJECT_DIR/Gui

INCLUDEPATH += $$PROJECT_DIR/Motion

INCLUDEPATH += $$PROJECT_DIR/Cuda

INCLUDEPATH += $$PROJECT_DIR/Media

INCLUDEPATH += $$PROJECT_DIR/Core

INCLUDEPATH += $$PROJECT_DIR/OpenGL

INCLUDEPATH += $$PROJECT_DIR

QT += opengl

INCLUDEPATH += $$CUDA_DIR/include

QMAKE_LIBDIR += $$CUDA_DIR/lib64

INCLUDEPATH += $$CUDA_SDK/common/inc/

QMAKE_LIBDIR += $$CUDA_SDK/lib

QMAKE_LIBDIR += $$CUDA_SDK/common/lib

INCLUDEPATH += $$OPENCV_DIR/include

QMAKE_LIBDIR += $$OPENCV_DIR/lib

Input

FORMS += paramsFolki.ui

HEADERS += LIVA.hpp

HEADERS += Logger.hpp

HEADERS += Singleton.hpp

HEADERS += mainwindows.h

HEADERS += paramsFolki.hpp

HEADERS += LiGL2Dwidget.hpp

HEADERS += MediaPlayer.hpp

HEADERS += LkCvWidget.hpp

HEADERS += FolkiOpticalFlow.hpp

HEADERS += OpticalFlow.hpp

HEADERS += endianness.h

HEADERS += FlotRender.hpp

HEADERS += GestionBuffer.hpp

SOURCES += main.cpp

SOURCES += paramsFolki.cpp

SOURCES += LiGL2Dwidget.cpp

SOURCES += MediaPlayer.cpp

SOURCES += LkCvWidget.cpp

SOURCES += FolkiOpticalFlow.cpp

SOURCES += OpticalFlow.cpp

SOURCES += endianness.c

SOURCES += FlotRender.cpp

CUDA_SOURCES += ConvolutionSeparable.cu

CUDA_SOURCES += ConvolutionSeparableFlat.cu

CUDA_SOURCES += ConvolutionSeparableU.cu

CUDA_SOURCES += ConvolutionSeparableFlatU.cu

CUDA_SOURCES += DeriveGradient.cu

CUDA_SOURCES += FolkiOpticalFlowKernels.cu

CUDA_SOURCES += PyramidBurt.cu

CUDA_SOURCES += PyramidHaar.cu

CUDA_SOURCES += DivRot.cu

CUDA_SOURCES += RenderGL.cu

CUDA_SOURCES += Morpho.cu

CUDA_SOURCES += Reduction.cu

CUDA_SOURCES += Propage.cu

HEADERS += ConvolutionSeparableFlat.hpp

HEADERS += ConvolutionSeparable.hpp

HEADERS += ConvolutionSeparableFlatU.hpp

HEADERS += ConvolutionSeparableU.hpp

HEADERS += DeriveGradient.hpp

HEADERS += FolkiOpticalFlowKernels.hpp

HEADERS += LiCuda.hpp

HEADERS += PyramidBurt.hpp

HEADERS += PyramidHaar.hpp

HEADERS += DivRot.hpp

HEADERS += RenderGL.hpp

HEADERS += Morpho.hpp

HEADERS += Reduction.hpp

HEADERS += Propage.hpp

CUDA_INC = $$join(INCLUDEPATH,’ -I’,‘-I’,’ ')

cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o

cuda.commands = $$CUDA_DIR/bin/nvcc -g -G -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 -g -G -M $$CUDA_INC $$NVCCFLAGS ${QMAKE_FILE_NAME} |sed “s,^.*:,”|sed “s,^ *,” | tr -d ‘\\n’

cuda.input = CUDA_SOURCES

QMAKE_EXTRA_UNIX_COMPILERS += cuda

Qt+= network[/codebox]

Hello,

I have a little problem.

I am using Qt Creator 2010.01 on Windows 7 and want to combine Qt with CUDA.

I have copied the following into the .pro file and was hoping that it works now.

[codebox]###################################################

#####################

CUDA

############################################################

############

win32 {

INCLUDEPATH += $(CUDA_INC_PATH) "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common\inc"

QMAKE_LIBDIR += $(CUDA_LIB_PATH)

LIBS += -lcudart -lcuda

cuda.output = $$OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj

cuda.commands = $(CUDA_BIN_PATH)/nvcc.exe -c -Xcompiler $$join(QMAKE_CXXFLAGS,",") $$join(INCLUDEPATH,'" -I "','-I "','"') ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

}

unix {

    # auto-detect CUDA path

CUDA_DIR = /usr/local/cuda

CUDA_CC = $$CUDA_DIR/bin/nvcc

#$$system(which nvcc | sed ‘s,/bin/nvcc$,’)

message("nvcc resides in :" $$CUDA_CC)

INCLUDEPATH += $$CUDA_DIR/include

QMAKE_CXXFLAGS =

macx {

    INCLUDEPATH += /Developer/CUDA/common/inc/

    QMAKE_LIBDIR += $$CUDA_DIR/lib

}

else {

INCLUDEPATH += /usr/local/cudasdk/C/common/inc

QMAKE_LIBDIR += $$CUDA_DIR/lib64

}

LIBS += -lcudart

cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.obj

macx {

    cuda.commands = $$CUDA_CC -c -arch sm_11 $$join(QMAKE_CXXFLAGS,",") $$join(INCLUDEPATH,'" -I "','-I "','"') ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

}

else {

    cuda.commands = $$CUDA_CC -c -arch sm_13 $$join(QMAKE_CXXFLAGS,",") $$join(INCLUDEPATH,'" -I "','-I "','"') ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

}

cuda.dependcy_type = TYPE_C

cuda.depend_command = nvcc -M -Xcompiler $$join(QMAKE_CXXFLAGS,",") $$join(INCLUDEPATH,'" -I "','-I "','"') ${QMAKE_FILE_NAME} | sed "s,^.*: ,," | sed "s,^ *,," | tr -d '\\\n'

}

#CUDA_SOURCES = cuda_part/mipmap.cu

cuda.input = cuda_part/mipmap.cu

QMAKE_EXTRA_UNIX_COMPILERS += cuda

############################################################

############

[/codebox]

But unfortunately I get the compiler output only:

[codebox]mingw32-make: Entering directory `D:/Eigene Dateien/Studium/radiosity/CUDA_Matrix_Coar’

C:/Qt/2010.01/mingw/bin/mingw32-make -f Makefile.Debug

mingw32-make[1]: Entering directory `D:/Eigene Dateien/Studium/radiosity/CUDA_Matrix_Coar’

c:\Qt\2010.01\qt\bin\uic.exe host_part\HemicubeMipMapper\MainWindow.ui -o ui_MainWindow.h

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2010.01\qt\include\QtCore" -I"c:\Qt\2010.01\qt\include\QtGui" -I"c:\Qt\2010.01\qt\include" -I"C:\CUDA\include" -I"c:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common\inc" -I"c:\Qt\2010.01\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2010.01\qt\mkspecs\win32-g++" -o debug\main.o host_part\HemicubeMipMapper\main.cpp

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2010.01\qt\include\QtCore" -I"c:\Qt\2010.01\qt\include\QtGui" -I"c:\Qt\2010.01\qt\include" -I"C:\CUDA\include" -I"c:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common\inc" -I"c:\Qt\2010.01\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2010.01\qt\mkspecs\win32-g++" -o debug\MainWindow.o host_part\HemicubeMipMapper\MainWindow.cpp

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2010.01\qt\include\QtCore" -I"c:\Qt\2010.01\qt\include\QtGui" -I"c:\Qt\2010.01\qt\include" -I"C:\CUDA\include" -I"c:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common\inc" -I"c:\Qt\2010.01\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2010.01\qt\mkspecs\win32-g++" -o debug\test_host.o host_part\HemicubeMipMapper\test_host.cpp

In file included from host_part\HemicubeMipMapper/…/…/cuda_part/mipmap.h:4,

from host_part\HemicubeMipMapper\test_host.cpp:8:

c:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common\inc/cutil.h:19: warning: ignoring #pragma warning

host_part\HemicubeMipMapper\test_host.cpp: In member function ‘void MainWindow::test_main(const std::vector<int, std::allocator >&, const std::vector<double, std::allocator >&)’:

host_part\HemicubeMipMapper\test_host.cpp:131: warning: unused variable ‘mem_size_pi’

host_part\HemicubeMipMapper\test_host.cpp:133: warning: unused variable ‘mem_size_p2p’

host_part\HemicubeMipMapper\test_host.cpp:140: warning: unused variable ‘p2p_ptr’

C:/Qt/2010.01/qt/bin\moc.exe -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2010.01\qt\include\QtCore" -I"c:\Qt\2010.01\qt\include\QtGui" -I"c:\Qt\2010.01\qt\include" -I"C:\CUDA\include" -I"c:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common\inc" -I"c:\Qt\2010.01\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2010.01\qt\mkspecs\win32-g++" -D__GNUC__ -DWIN32 host_part\HemicubeMipMapper\MainWindow.h -o debug\moc_MainWindow.cpp

g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"c:\Qt\2010.01\qt\include\QtCore" -I"c:\Qt\2010.01\qt\include\QtGui" -I"c:\Qt\2010.01\qt\include" -I"C:\CUDA\include" -I"c:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\common\inc" -I"c:\Qt\2010.01\qt\include\ActiveQt" -I"debug" -I"." -I"c:\Qt\2010.01\qt\mkspecs\win32-g++" -o debug\moc_MainWindow.o debug\moc_MainWindow.cpp

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\HemicubeMipMapper.exe debug/main.o debug/MainWindow.o debug/test_host.o debug/moc_MainWindow.o -L"C:\CUDA\lib" -L"c:\Qt\2010.01\qt\lib" -lmingw32 -lqtmaind -lcudart -lcuda -lQtGuid4 -lQtCored4

mingw32-make[1]: Leaving directory `D:/Eigene Dateien/Studium/radiosity/CUDA_Matrix_Coar’

mingw32-make: Leaving directory `D:/Eigene Dateien/Studium/radiosity/CUDA_Matrix_Coar’

debug/test_host.o:D:\Eigene Dateien\Studium\radiosity\CUDA_Matrix_Coar/host_part/HemicubeMipMapper/test_host.cpp:148: undefined reference to `Mipmapper::Mipmapper(int*, int*, int, int)’

debug/test_host.o:D:\Eigene Dateien\Studium\radiosity\CUDA_Matrix_Coar/host_part/HemicubeMipMapper/test_host.cpp:149: undefined reference to `Mipmapper::run()’

debug/test_host.o:D:\Eigene Dateien\Studium\radiosity\CUDA_Matrix_Coar/host_part/HemicubeMipMapper/test_host.cpp:152: undefined reference to `Mipmapper::~Mipmapper()’

debug/test_host.o:D:\Eigene Dateien\Studium\radiosity\CUDA_Matrix_Coar/host_part/HemicubeMipMapper/test_host.cpp:152: undefined reference to `Mipmapper::~Mipmapper()’

collect2: ld returned 1 exit status

mingw32-make[1]: *** [debug\HemicubeMipMapper.exe] Error 1

mingw32-make: *** [debug] Error 2[/codebox]

Have you perhaps an idea how I can solve the problem?

Thanks in advance

Hi guys,

I have used this thread to design my own project file, which works fine with CUDA 3.0 but does not with the latest version 3.2.
Please see this thread for more details: http://forums.nvidia.com/index.php?showtopic=188501

Does someone know what is wrong pleeeeease? :)

Regards,
Martin Peniak

hello!I have runned a program on windows 7 used QT according to your codes,but it did not work.

notice :i used cuda 4.0RC

erro!!:

[/cuda_file_cuda.obj] Erro 1

      no such file

so i think the erro may result from the code

$$OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj