CUDA. Windows. Can't get build to work in QTCreator
-
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
-
@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).
-
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.
-
@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: -
@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??
-
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! -