在QtCreator中设置CUDA v7.0(VS 2010)

时间:2015-07-07 06:17:41

标签: c++ windows visual-studio-2010 cuda qt-creator

有没有人在QtCreator中成功使用最新版本的CUDA(即设置.pro文件)?如果是这样,你能与我分享一些简单的例子或教程吗?谢谢!

遇到问题并尝试:

我在QtCreator中设置和编译一个简单的CUDA程序时遇到了麻烦。我已经阅读了一些旧的教程(即CUDA with QT in Linux),但到目前为止我没有运气。

我无法让QtCreator在上面的教程示例中正确构建.cu文件,但我最终能够使用以下nvcc命令行编译.cu文件:

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

生成cuda_code_cuda.obj。当我尝试在Qt中构建项目时,我收到一条错误消息:

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

我绝对不能正确链接已编译的cuda_code_cuda.obj文件。我认为它与“空间”有关。在CUDA文件夹路径中(双引号似乎没有帮助)

其他信息:我的专业文件如下所示:

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

2 个答案:

答案 0 :(得分:2)

经过一些测试,我设法将pro文件设置为正确编译。我发布这个作为答案只是为了分享我得到的东西。但是,我仍然很好奇这是否是在最新版本的CUDA中实现它的方法。如果有人能与我确认这一点会很好。

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

答案 1 :(得分:0)

(我没有足够的声誉发表评论)

我在Qt Creator,Window 10中运行了Cuda 7.5。 在.pro文件中进行更改非常重要:对于标记QMAKE_LFLAGS_RELEASEQMAKE_LFLAGS_DEBUG,请使用+= = 。后者覆盖默认选项,可能会使您的构建无法调试! (花了我们几个小时来找到这个...)

另外,在我们的案例中,冲突的库是libcmt.lib而不是msvcrt.lib