John Yang
John Yang

Reputation: 577

Set up CUDA v7.0 in QtCreator (VS 2010)

Has anybody successfully use the latest version of CUDA in QtCreator (i.e. setting up the .pro file)? If so, can you share some simple example or tutorial with me? Thanks!

Problem encountered and attempts:

I was having trouble to set up and compile a simple CUDA program in QtCreator. I have read some old tutorials (i.e. CUDA with QT in Linux), but I have no luck so far.

I wasn't able to get QtCreator to build the .cu file properly itself in the above tutorial example, but I was able to compile the .cu file eventually using the following nvcc command line:

nvcc -m32 --gpu-architecture=sm_20 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:/PROGRA~1/NVIDIA GPU Computing Toolkit/CUDA/v7.0/include"  -lcudart -lcuda ..\CUDA_TEST_EXAMPLE\hello.cu -o ..\Release\release\obj\cuda_code_cuda.obj

So cuda_code_cuda.obj is generated. When I try to build the project in Qt, I got an error saying:

error: LNK1181: cannot open input file 'C:\PROGRA~1\NVIDIA.obj'

I am definitely not linking with the compiled cuda_code_cuda.obj file properly. I assume it has to do with the 'space' in the CUDA folder path (the double quotation doesn't seem very helpful)

Additional Info: my pro file looks like this:

QT       += core
QT       -= gui
TARGET = CUDA_TEST_EXAMPLE
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app

# Define output directories
DESTDIR = release
OBJECTS_DIR = release/obj/
CUDA_OBJECTS_DIR = release/cuda

# Source files
SOURCES += main.cpp
# Cuda sources
OTHER_FILES +=  cuda_code.cu

# CUDA settings <-- may change depending on your system
CUDA_SOURCES += cuda_code.cu
#CUDA_DIR = "C:/PROGRA~1/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v7.0"                    
# Path to header and libs files
INCLUDEPATH  += "C:\PROGRA~1\NVIDIA GPU Computing Toolkit\CUDA\v7.0\include"
QMAKE_LIBDIR += "C:\PROGRA~1\NVIDIA GPU Computing Toolkit\CUDA\v7.0\lib\Win32"    # Note I'm using a 64 bits Operating system
# libs used in your code
LIBS += -lcudart -lcuda

cuda.output = "C:\Users\johnyang\Documents\Release\release\obj\cuda_code_cuda.obj"

LIBS += "C:\Users\johnyang\Documents\Release\release\obj\cuda_code_cuda.obj"

## Tell Qt that we want add more stuff to the Makefile
QMAKE_EXTRA_COMPILERS += cuda

Upvotes: 0

Views: 813

Answers (1)

John Yang
John Yang

Reputation: 577

With some testing, I managed to set up the pro file to compile properly now. I post this as an answer just to share what I have got. However, I am still curious whether this is the way to do it in the latest version of CUDA. It would be good if someone can confirm this with me.

QT       += core
QT       -= gui

TARGET = CUDA_TEST_EXAMPLE
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app

QMAKE_LFLAGS_RELEASE =/NODEFAULTLIB:msvcrt.lib
QMAKE_LFLAGS_DEBUG =/NODEFAULTLIB:msvcrtd.lib

# Define output directories
DESTDIR = release
OBJECTS_DIR = release\obj
CUDA_OBJECTS_DIR = release/cuda

# Source files
SOURCES += main.cpp
# Cuda sources
#OTHER_FILES +=  cuda_code.cu

# CUDA settings <-- may change depending on your system
CUDA_SOURCES += cuda_code.cu
CUDA_DIR = "C:\PROGRA~1\NVIDIA~2\CUDA\v7.0"            # Path to cuda toolkit install

# Path to header and libs files
INCLUDEPATH  += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib/Win32    # Note I'm using a 64 bits Operating system
# libs used in your code
LIBS += -lcudart -lcuda

## GPU architecture
CUDA_ARCH     = sm_20                # Yeah! I've a new device. Adjust with your compute capability
## Here are some NVCC flags I've always used by default.
#NVCCFLAGS     = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v

## Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
#CUDA_INC = -I"C:/PROGRA~1/NVIDIA~2/CUDA/v7.0/include"
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')

cuda.commands = $${CUDA_DIR}/bin/nvcc -m32 --gpu-architecture=$$CUDA_ARCH -c \
                $$CUDA_INC $$LIBS  ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}
# nvcc error printout format ever so slightly different from gcc
# http://forums.nvidia.com/index.php?showtopic=171651

cuda.dependency_type = TYPE_C # there was a typo here. Thanks workmate!
cuda.depend_command = $$(CUDA_DIR)/bin/nvcc $$CUDA_INC ${QMAKE_FILE_NAME}

cuda.input = CUDA_SOURCES
cuda.output = ..\Release/$${OBJECTS_DIR}/${QMAKE_FILE_BASE}_cuda.obj

## Tell Qt that we want add more stuff to the Makefile
QMAKE_EXTRA_COMPILERS += cuda

Upvotes: 2

Related Questions