cuda 10.2 in Qt 5.14 ubuntu 18.04
-
Hello everybody
I am planning to start cuda programming in qt framework. i wanna start with a simple example.
system information :
OS : ubuintu 18.04 LTS
Qt version : 5.14
Compiler : GCC
CUDA version : 10.2
GPU : NVIDIA GTX 1060 with compute capability 6.1i searched a lot and find this usefull topic:
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.
This is my project .pro file contents :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 # 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 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 (last five lines are not commented in my .pro file)
Now this is main.cpp contents
#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(); }
I know that device code should be implemented in an other file with .cu postfix. so i have it with the name of cuda_code.cu with contents of :
#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(); }
This is my project overview :
first i run build -> run qmak and it is made successfully.but when i wanna run it , this error appears :
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 for a couple of days without any success.
Please help me to solve this problem.
Any help would be appreciated.
Thank you guys. -
@Gerd said in cuda 10.2 in Qt 5.14 ubuntu 18.04:
cuda.CONFIG += no_link
Hi @Gerd
Thank you so so much.
My old error now gone with your solution.
Now i have this error :error: static assertion failed: unimplemented for this system # define THRUST_STATIC_ASSERT_MSG(B, msg) static_assert(B, msg)
what means system here ? does it mean my local system ?
Do you have a solution for this issue ?
Thanks in advance -
@Naser-0 said in cuda 10.2 in Qt 5.14 ubuntu 18.04:
what means system here ?
The system you're building for
-
looking somewhat deeper in your code i found this:
#include <cuda_code.cu>
why did you do that?
with this line the cu code is included here and compiled with the regular c-compiler.
this leads to the error messages you see.remove that line from your main.cpp, use the following .pro-file and try again
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_DIR = /usr/local/cuda INCLUDEPATH += $$CUDA_DIR/include QMAKE_LIBDIR += $$CUDA_DIR/lib64 LIBS += -lcudart -lcuda CUDA_ARCH = sm_61 # 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 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}| sed \"s/^.*: //\" cuda.input = CUDA_SOURCES cuda.output = $${OBJECTS_DIR}/${QMAKE_FILE_BASE}$${QMAKE_EXT_OBJ} QMAKE_EXTRA_COMPILERS += cuda ```
-