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. Windows. Can't get build to work in QTCreator
QtWS25 Last Chance

CUDA. Windows. Can't get build to work in QTCreator

Scheduled Pinned Locked Moved Solved General and Desktop
cudawindows 10
6 Posts 3 Posters 1.3k 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.
  • J Offline
    J Offline
    JayG
    wrote on 24 Jul 2023, 16:37 last edited by JayG
    #1

    I am brand new to QT Creator and for the past week I've had issues trying to get my very basic CUDA program to work in QT Creator. It works fine in CMake on VSCode, but I need to use QT Creator to begin developing a CUDA branch for an existing QT project. The problem is that I don't understand .pro files very well and can't seem to get this to build.

    I am using QTCreator 10.0.2, the "qmake" build system, and the “Desktop Qt 5.15.2 MSVC2019 64bit” kit (to match the existing non-CUDA project). I have CUDA installed at C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1 and I'm using an NVIDIA Quadro T1000 Graphic Card. I have 3 files: main.cpp, cuda_test.cu, and cuda.pro.

    1.) main.cpp:

    void cudaKernel();
    
    int main() {
        cudaKernel();
        return 0;
    }
    

    2.) cuda_test.cu:

    #include <iostream>
    #include <cuda.h>
    #include <curand_kernel.h>
    
    __global__ void myKernel() {
        int blockNum = blockIdx.y*gridDim.x + blockIdx.x;
        int blockThreads = blockNum * blockDim.x * blockDim.y;
        int gid = blockThreads + threadIdx.y*blockDim.x + threadIdx.x;
    }
    
    void cudaKernel() {
        myKernel<<<1, 1>>>();
        cudaDeviceSynchronize();
        std::cout << "working.\n";
    }
    

    3.) need_help.pro

    TEMPLATE = app
    
    # Sources
    SOURCES += main.cpp
    
    # CUDA settings
    CUDA_SOURCES += cuda_test.cu
    CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1"
    CUDA_ARCH = sm_75
    
    # Compile CUDA source files using NVCC
    cuda.input = CUDA_SOURCES
    cuda.output = ${QMAKE_FILE_OUT}
    cuda.commands = $$CUDA_DIR/bin/nvcc -c -arch=$$CUDA_ARCH ${QMAKE_FILE_NAME} --cuda-path=$$CUDA_DIR
    QMAKE_EXTRA_COMPILERS += cuda
    

    I have tried multiple passes to get the .pro file working, but I can't seem to get it to build error-free. The thing that never seems to go away is the "Cannot find CUDA installation errors" at the top of the .pro file. That, and the inability to recognize CUDA defined keywords such as blockID or opening and closing chevrons <<<>>>. Plus, it seems that cuda_test.cu is not recognized as a part of the current project. Again, the main.cpp and cuda_test.cu works outside of QT, so I believe that the problems exist solely in the need_help.pro file. I have been stuck on this for a long time so any help to get this running would be greatly appreciated. Here is an image of the (current) errors in the cuda_test.cu

    5d14ea6a-d363-451c-a6f7-a8c1c20c787a-image.png

    P 1 Reply Last reply 24 Jul 2023, 16:41
    0
    • J JayG
      24 Jul 2023, 16:37

      I am brand new to QT Creator and for the past week I've had issues trying to get my very basic CUDA program to work in QT Creator. It works fine in CMake on VSCode, but I need to use QT Creator to begin developing a CUDA branch for an existing QT project. The problem is that I don't understand .pro files very well and can't seem to get this to build.

      I am using QTCreator 10.0.2, the "qmake" build system, and the “Desktop Qt 5.15.2 MSVC2019 64bit” kit (to match the existing non-CUDA project). I have CUDA installed at C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1 and I'm using an NVIDIA Quadro T1000 Graphic Card. I have 3 files: main.cpp, cuda_test.cu, and cuda.pro.

      1.) main.cpp:

      void cudaKernel();
      
      int main() {
          cudaKernel();
          return 0;
      }
      

      2.) cuda_test.cu:

      #include <iostream>
      #include <cuda.h>
      #include <curand_kernel.h>
      
      __global__ void myKernel() {
          int blockNum = blockIdx.y*gridDim.x + blockIdx.x;
          int blockThreads = blockNum * blockDim.x * blockDim.y;
          int gid = blockThreads + threadIdx.y*blockDim.x + threadIdx.x;
      }
      
      void cudaKernel() {
          myKernel<<<1, 1>>>();
          cudaDeviceSynchronize();
          std::cout << "working.\n";
      }
      

      3.) need_help.pro

      TEMPLATE = app
      
      # Sources
      SOURCES += main.cpp
      
      # CUDA settings
      CUDA_SOURCES += cuda_test.cu
      CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.1"
      CUDA_ARCH = sm_75
      
      # Compile CUDA source files using NVCC
      cuda.input = CUDA_SOURCES
      cuda.output = ${QMAKE_FILE_OUT}
      cuda.commands = $$CUDA_DIR/bin/nvcc -c -arch=$$CUDA_ARCH ${QMAKE_FILE_NAME} --cuda-path=$$CUDA_DIR
      QMAKE_EXTRA_COMPILERS += cuda
      

      I have tried multiple passes to get the .pro file working, but I can't seem to get it to build error-free. The thing that never seems to go away is the "Cannot find CUDA installation errors" at the top of the .pro file. That, and the inability to recognize CUDA defined keywords such as blockID or opening and closing chevrons <<<>>>. Plus, it seems that cuda_test.cu is not recognized as a part of the current project. Again, the main.cpp and cuda_test.cu works outside of QT, so I believe that the problems exist solely in the need_help.pro file. I have been stuck on this for a long time so any help to get this running would be greatly appreciated. Here is an image of the (current) errors in the cuda_test.cu

      5d14ea6a-d363-451c-a6f7-a8c1c20c787a-image.png

      P Online
      P Online
      Pl45m4
      wrote on 24 Jul 2023, 16:41 last edited by
      #2

      @JayG said in CUDA. Windows. Can't get build to work in QTCreator:

      It works fine in CMake on VSCode, but I need to use QT Creator to begin developing a CUDA branch for an existing QT project

      Shouldn't it be easier to use Visual Studio instead? I think it's easier to migrate from VSCode to MSVS than to QtCreator (and then also with QMake instead of CMake).


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      J 1 Reply Last reply 24 Jul 2023, 16:47
      0
      • P Pl45m4
        24 Jul 2023, 16:41

        @JayG said in CUDA. Windows. Can't get build to work in QTCreator:

        It works fine in CMake on VSCode, but I need to use QT Creator to begin developing a CUDA branch for an existing QT project

        Shouldn't it be easier to use Visual Studio instead? I think it's easier to migrate from VSCode to MSVS than to QtCreator (and then also with QMake instead of CMake).

        J Offline
        J Offline
        JayG
        wrote on 24 Jul 2023, 16:47 last edited by
        #3

        @Pl45m4

        Utilizing this code on VSCode is easier, but porting the rest of the project (which is massive) has been providing a different/larger set of headaches. If we can get this branch integrated into the current system, then it'll be a much simpler process.

        P 1 Reply Last reply 24 Jul 2023, 17:52
        0
        • J JayG
          24 Jul 2023, 16:47

          @Pl45m4

          Utilizing this code on VSCode is easier, but porting the rest of the project (which is massive) has been providing a different/larger set of headaches. If we can get this branch integrated into the current system, then it'll be a much simpler process.

          P Online
          P Online
          Pl45m4
          wrote on 24 Jul 2023, 17:52 last edited by Pl45m4
          #4

          @JayG said in CUDA. Windows. Can't get build to work in QTCreator:

          Utilizing this code on VSCode is easier, but porting the rest of the project (which is massive) has been providing a different/larger set of headaches

          No, I mean VS instead of QtCreator. Since it seems to work with CMake and VSCode as you have written, why you dont use Qt, CMake and Visual Studio for your CUDA project?! And you are already using the MSVC kit anyway.
          Just a thought... that might simplify your problem.

          Unfortunately I cannot help you with CUDA itself :( No CUDA experience here, except some TensorFlow + CUDA

          Have you used the search function already?
          Found some (probably) related topics:

          • https://forum.qt.io/topic/98858/compiling-cuda-files-with-qt-5-12
          • https://forum.qt.io/topic/112907/qtcreator-cuda-make-final-linking-with-nvcc

          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          C 1 Reply Last reply 24 Jul 2023, 17:59
          0
          • P Pl45m4
            24 Jul 2023, 17:52

            @JayG said in CUDA. Windows. Can't get build to work in QTCreator:

            Utilizing this code on VSCode is easier, but porting the rest of the project (which is massive) has been providing a different/larger set of headaches

            No, I mean VS instead of QtCreator. Since it seems to work with CMake and VSCode as you have written, why you dont use Qt, CMake and Visual Studio for your CUDA project?! And you are already using the MSVC kit anyway.
            Just a thought... that might simplify your problem.

            Unfortunately I cannot help you with CUDA itself :( No CUDA experience here, except some TensorFlow + CUDA

            Have you used the search function already?
            Found some (probably) related topics:

            • https://forum.qt.io/topic/98858/compiling-cuda-files-with-qt-5-12
            • https://forum.qt.io/topic/112907/qtcreator-cuda-make-final-linking-with-nvcc
            C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 24 Jul 2023, 17:59 last edited by
            #5

            @Pl45m4 said in CUDA. Windows. Can't get build to work in QTCreator:

            why you dont use Qt, CMake and Visual Studio for your CUDA project?

            Or Qt, CMake and QtCreator - but why the hell going back to qmake??

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            J 1 Reply Last reply 24 Jul 2023, 18:36
            0
            • C Christian Ehrlicher
              24 Jul 2023, 17:59

              @Pl45m4 said in CUDA. Windows. Can't get build to work in QTCreator:

              why you dont use Qt, CMake and Visual Studio for your CUDA project?

              Or Qt, CMake and QtCreator - but why the hell going back to qmake??

              J Offline
              J Offline
              JayG
              wrote on 24 Jul 2023, 18:36 last edited by
              #6

              @Christian-Ehrlicher

              That would be ideal, but QMake was the system used when the project started. We're considering porting everything to CMake, but it looks like it's going to take some doing.

              @Pl45m4
              I tried to use the search function, but those seem to be good sources that I hadn't seen yet. I'll take a look at those right now. But I was able to find an answer on StackOverflow that I somehow missed until now:
              https://stackoverflow.com/questions/32279193/cuda-win7-qt-creator-lnk1104-cannot-open-file-cuda-file-obj
              I just copy-pasted it and it worked (after changing the version number from 7.0 to 12.1). Then I used the code I pasted above and it worked. Then I used a legit CUDA program and it worked. So I'm going to go through it line by line to understand why that .pro works. Thank you for the links!

              1 Reply Last reply
              0
              • J JayG has marked this topic as solved on 24 Jul 2023, 18:37

              6/6

              24 Jul 2023, 18:36

              • Login

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