[英]cuda 10.2 in Qt 5.14 ubuntu 18.04
I am planning to start cuda programming in Qt framework.我打算在 Qt 框架中开始 cuda 编程。 i wanna start with a simple example.
我想从一个简单的例子开始。
system information:系统信息:
OS: ubuintu 18.04 LTS操作系统:ubuintu 18.04 LTS
Qt version: 5.14 Qt 版本:5.14
Compiler: GCC编译器:GCC
CUDA version: 10.2 CUDA 版本:10.2
GPU: NVIDIA GTX 1060 with compute capability 6.1 GPU:NVIDIA GTX 1060,计算能力 6.1
i searched a lot and find this usefull topic: https://cudaspace.wordpress.com/2012/07/05/qt-creator-cuda-linux-review/我搜索了很多,发现这个有用的主题: https://cudaspace.wordpress.com/2012/07/05/qt-creator-cuda-linux-review/
I followed the topic step by step and made my project.pro file with my own cuda architecture and other essentials.我一步一步地按照主题,用我自己的 cuda 架构和其他要点制作了我的 project.pro 文件。 This is my project.pro file contents:
这是我的 project.pro 文件内容:
QT -= gui
QT += core
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += QT_DEPRECATED_WARNINGS
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
DESTDIR = $$system(pwd)
OBJECTS_DIR = $$DESTDIR/Obj
# C++ flags
QMAKE_CXXFLAGS_RELEASE =-03
CUDA_SOURCES += cuda_code.cu=
SOURCES += main.cpp \
cuda_code.cu
CUDA_DIR = /usr/local/cuda
INCLUDEPATH += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib64
LIBS += -lcudart -lcuda
CUDA_ARCH = sm_61
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
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} \
2>&1 | sed -r \"s/\\(([0-9]+)\\)/:\\1/g\" 1>&2
cuda.dependency_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
QMAKE_EXTRA_COMPILERS += cuda
Now this is the main.cpp contents现在这是 main.cpp 内容
#include <QtCore/QCoreApplication>
#include <iostream>
using namespace std;
#include <cuda_runtime.h>
#include <cuda_code.cu>
extern "C"
cudaError_t cuda_main();
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// run your cuda application
cudaError_t cuerr = cuda_main();
// check for errors is always a good practice!
if (cuerr != cudaSuccess) cout << "CUDA Error: " << cudaGetErrorString( cuerr ) << endl;
return a.exec();
}
And this is the.cu file contents:这是.cu文件内容:
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/sort.h>
extern "C"
cudaError_t cuda_main()
{
// generate 16M random numbers on the host
thrust::host_vector<int> h_vec(1 << 24);
thrust::generate(h_vec.begin(), h_vec.end(), rand);
// transfer data to the device
thrust::device_vector<int> d_vec = h_vec;
// sort data on the device (805 Mkeys/sec on GeForce GTX 480)
thrust::sort(d_vec.begin(), d_vec.end());
// transfer data back to host
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
return cudaGetLastError();
}
first i make it with build -> run qmak and it is made successfully.but when i wanna run it, this error appears:首先我使用 build -> run qmak 并成功制作它。但是当我想运行它时,出现此错误:
make: *** No rule to make target 'cuda_code.o', needed by 'Obj/cuda_code_cuda.o'. Stop.
19:18:20: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled6 (kit: Desktop Qt 5.14.0 GCC 64bit)
When executing step "Make"
I searched a lot and tested solutions couple of days without any success.我搜索了很多并测试了几天的解决方案,但没有任何成功。
I solved this problem with @Gred solution in this link:我在此链接中使用@Gred 解决方案解决了这个问题:
https://forum.qt.io/topic/114853/cuda-10-2-in-qt-5-14-ubuntu-18-04/12
https://forum.qt.io/topic/114853/cuda-10-2-in-qt-5-14-ubuntu-18-04/12
This line in.pro file:这一行 in.pro 文件:
SOURCES += main.cpp \
cuda_code.cu
should changed to:应改为:
SOURCES += main.cpp
And then remove #include "cuda_code.cu" from main.cpp.然后从 main.cpp 中删除#include "cuda_code.cu" 。 And now all things work good:).
现在一切都很好:)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.