CUDA

I am working with VS 2022 and CUDA 11.7. I am trying to run the following example named VectorAdd.cu and I just keep getting the same error in any different example.

Severity Code Description Project File Line Suppression State
Error	MSB3721	The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\bin\nvcc.exe"
 -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env -ccbin "C:\Program Files
\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\HostX64\x64" -x cu  
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\include" 
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\include"
-G   --keep-dir x64\Debug  -maxrregcount=0  --machine 64 --compile -cudart static
 -g  -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Fdx64\Debug\vc143.pdb
/FS /Zi /RTC1 /MDd " -o "D:\Tested Code\CudaRuntime2\x64\Debug\kernel.cu.obj" "D:\Tested Code\CudaRuntime2\
kernel.cu"" exited with code 1. CudaRuntime2 C:\Program Files\Microsoft Visual Studio\2022
\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\ CUDA 11.7.targets	790	



and
Severity Code Description Project File	Line Suppression State
Error (active)	E0029	expected an expression	CudaRuntime2	D:\Tested Code\CudaRuntime2\kernel.cu	42	


After previous problem, instead of building CUDA project, I built a C++ console application and added CUDA 11.7 C/C++ source and header files to the project and called these files in the source file of C++ project. This time the MSB3721 error disappeared but the syntax error is still there. I think the MSB3721 error in this case is gone because the compiler is treating the CUDA code as C++ code. I don't know what should I do exactly when I need C++ header and source files plus .cuh and .cu in my project. should I build an empty C++ project and then link the CUDA to my project? Thanks for your help in advance.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>

#define arraySize 1000

__global__ void addKernel( int *c, const int *a, const int *b )
{
    int i = threadIdx.x;

	if( i < arraySize )
		c[i] = a[i] + b[i];
}

int main()
{
    int a[arraySize];
    int b[arraySize];
    int c[arraySize];

	int *dev_a = 0;
    int *dev_b = 0;
    int *dev_c = 0;

	// fill the arrays 'a' and 'b' on the CPU
	for( int i = 0 ; i < arraySize ; i++ ) {
		a[i] = i;
		b[i] = i;
	}

	// Add vectors in parallel.
	// Allocate GPU buffers for three vectors (two input, one output)
	cudaMalloc((void**)&dev_c, arraySize * sizeof(int));
	cudaMalloc((void**)&dev_a, arraySize * sizeof(int));
	cudaMalloc((void**)&dev_b, arraySize * sizeof(int));

	// copy the arrays 'a' and 'b' to the GPU
	cudaMemcpy(dev_a, a, arraySize * sizeof(int), cudaMemcpyHostToDevice);
	cudaMemcpy(dev_b, b, arraySize * sizeof(int), cudaMemcpyHostToDevice);

	addKernel<<<1, arraySize>>>(dev_c, dev_a, dev_b);
	cudaDeviceSynchronize();

	// copy the array 'c' back from the GPU to the CPU
	cudaMemcpy(c, dev_c, arraySize * sizeof(int), cudaMemcpyDeviceToHost);

	// display the results
	for( int i = 0 ; i < arraySize ; i++ ) {
		printf( "%d + %d = %d\n", a[i], b[i], c[i] );
	}

	// free the memory allocated on the GPU
	cudaFree(dev_c);
    cudaFree(dev_a);
    cudaFree(dev_b);
    
    return 0;
} 
Last edited on
You might find better help over at the nVidia forums.

https://forums.developer.nvidia.com/c/accelerated-computing/5

If I was wanting to work with CUDA and having issues that is where I'd be asking for assistance.
Thanks.
Topic archived. No new replies allowed.