2

我正在尝试将 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

我究竟做错了什么?

谢谢!

4

2 回答 2

3

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:

  1. Build -> Clean Project # to clean old stuff
  2. Build -> Run qmake # to take the .pro changes
  3. Build -> Build Project # obvious

PS: As @aland commented, your GPU device compute capability is 1.2, so adjust CUDA_ARCH = sm_12.

于 2012-05-28T15:54:37.867 回答
0
  1. 这就是问题:

    g++:错误:Obj/cuda_interface.o:没有这样的文件或目录

  2. 我会删除你所有的 CUDA 源代码和库,确保一切都完全干净,然后从头开始重新安装。

  3. 这是一个很好的指南:

    http://laurencedawson.com/ubuntu-11.10-and-cuda-4.1

    <= 假设您已经安装了 Ubuntu 和 NVidia 驱动程序,那么只需重新安装并重建 CUDA 工具包和源代码。

  4. 忘记 Qt 并忘记您的图形 IDE,直到您开始工作。

    请从命令行重新安装并重建 CUDA。

  5. 在返回 Qt 和 IDE 之前,请确保您可以从命令行运行“deviceQuery”。

另一个好资源:

http://developer.download.nvidia.com/compute/DevZone/docs/html/C/doc/CUDA_C_Getting_Started_Linux.pdf

于 2012-05-27T18:11:55.927 回答