Hi,
I have a c++ QT project in which I would like to perform some calculations with CUDA, but I am having trouble adding CUDA to my already existing project. I’ve successfully installed CUDA and am able to run the samples and create CUDA runtime projects and compile/run them.
I’ve tried to add CUDA by right clicking on my QT project and selecting “Build Dependencies > Build Customization” and checking the box for “CUDA 9.2(.targets, .props)”. This seems to allow me to import CUDA dependencies properly but I’m still getting errors when trying to compile the project:
Test.cu
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
__global__ void test_kernel(void) {
}
void wrapper(void) {
test_kernel <<<1, 1 >>> ();
}
main.cpp
#include "Test.cu"
#include <cuda.h>
int main(void) {
wrapper();
return 0;
}
When compiling with visual studio I get error code E0029, “expected an expression” at line 10 in Test.cu. I guessed that this was because of visual studio not compiling with nvcc and thus the “<<<X,Y>>>” syntax was invalid. I tried to handle this by compiling manually from terminal with “nvcc main.cpp” but then I received the error “error C2059: syntax error: ‘<’”. Finally, I moved the main function into Test.cu and just compiled that file (just a sanity check) and it compiled and ran successfully. I tried to rename the main.cpp file to main.cu and calling the function this way works when manually compiling “nvcc main.cu” but not from visual studio.
As I’d like to call the CUDA functions from my c++ code, I now wonder how would I go about doing this in visual studio? Alternatively, how do I set Visual Studio to compile using nvcc, and will this work with QT?