Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. cuda 10.2 in Qt 5.14 ubuntu 18.04

cuda 10.2 in Qt 5.14 ubuntu 18.04

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 3.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Naser 0
    wrote on last edited by Naser 0
    #1

    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.1

    i 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 :

    cuda.png

    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.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Naser 0
      wrote on last edited by
      #11

      @jsulm ok i got it. i am going to try .
      thank you sir

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gerd
        wrote on last edited by
        #2

        Hi,
        you should read the part
        Q. How to add cu-files to the Qt Creator Projects tree
        in that page you have linked.
        I think you missed the line
        SOURCES -= cuda_code.cu

        gerd

        1 Reply Last reply
        1
        • N Offline
          N Offline
          Naser 0
          wrote on last edited by
          #3

          @Gerd thank you for your response.
          im sorry i forgot to add SOURCES -= cuda_code.cu
          But no thing changed and i have the old error yet.
          Can you test this code or provided link code on your local system ?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gerd
            wrote on last edited by
            #4

            hi ,
            adding the line
            cuda.CONFIG += no_link
            helps for me...

            1 Reply Last reply
            2
            • N Offline
              N Offline
              Naser 0
              wrote on last edited by
              #5

              @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)
              

              cuda2.png

              what means system here ? does it mean my local system ?
              Do you have a solution for this issue ?
              Thanks in advance

              jsulmJ 1 Reply Last reply
              0
              • N Naser 0

                @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)
                

                cuda2.png

                what means system here ? does it mean my local system ?
                Do you have a solution for this issue ?
                Thanks in advance

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Naser-0 said in cuda 10.2 in Qt 5.14 ubuntu 18.04:

                what means system here ?

                The system you're building for

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2
                • N Offline
                  N Offline
                  Naser 0
                  wrote on last edited by
                  #7

                  @jsulm thank you
                  But what i have to do now ?
                  Should i change my OS ?

                  jsulmJ 1 Reply Last reply
                  0
                  • N Naser 0

                    @jsulm thank you
                    But what i have to do now ?
                    Should i change my OS ?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by jsulm
                    #8

                    @Naser-0 You should check what is actually not implemented.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      Naser 0
                      wrote on last edited by
                      #9

                      @jsulm Im wondering this is a big problem for a newbie like me.
                      i searched this problem and found just this link but it is about cmake.
                      https://stackoverflow.com/questions/58349473/thrust-static-assertion-when-using-in-cpp-files

                      jsulmJ 1 Reply Last reply
                      0
                      • N Naser 0

                        @jsulm Im wondering this is a big problem for a newbie like me.
                        i searched this problem and found just this link but it is about cmake.
                        https://stackoverflow.com/questions/58349473/thrust-static-assertion-when-using-in-cpp-files

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @Naser-0 Take a look at your screen-shot (Issues tab): you need to find the file where this throws this assertion. Then you will know what is not implemented.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2
                        • N Offline
                          N Offline
                          Naser 0
                          wrote on last edited by
                          #11

                          @jsulm ok i got it. i am going to try .
                          thank you sir

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            Gerd
                            wrote on last edited by
                            #12

                            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 ```
                            1 Reply Last reply
                            3
                            • N Offline
                              N Offline
                              Naser 0
                              wrote on last edited by Naser 0
                              #13

                              @Gerd Thank you sir.

                              Yeah your solution is the correct answer and now i can run this code successfully.
                              i am newbie in cuda and i didn't know that should not include the cuda_code.cu in my headers.
                              Thank you so so much again.you made my day.

                              1 Reply Last reply
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved