我正在尝试将 Qt 与 CUDA 集成。我正在开发 Ubuntu 12.04。我已经安装了 CUDA 和 Qt。
我按照此处的步骤进行操作 - 尝试设置 QT creator 和 Cuda 时“未使用链接器输入文件,因为链接未完成”
但是它仍然给我一个错误。
这是我的做法。
我在我的主目录中创建了一个名为“CUDA2”的空 Qt 项目。
我添加了以下文件
cuda_interface.cu
// CUDA-C includes
#include <cuda.h>
extern "C"
void runCudaPart();
// Main cuda function
void runCudaPart() {
// all your cuda code here *smile*
}
主文件
#include <QtCore/QCoreApplication>
extern "C"
void runCudaPart();
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
runCudaPart();
return a.exec();
}
我将以下行添加到 .pro 文件中
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
我运行 qmake 来生成 makefile。当我单击“构建”时,出现此错误 -
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'
我不确定 .pro 文件是否适用于 Linux。看起来它是为 OSX 制作的。另外,我不知道 CUDA_ARCH = sm_20 行是否正确。有没有办法找到我的 gpu 架构?我正在使用 NVIDIA Quadro FX 380M
我究竟做错了什么?
谢谢!