I have been using visual studio 19 with cuda toolkit 10.1. I am able to get program examples to build and run properly. However, I always seem to have build errors that show up in visual studio. for example I get the following errors for an example that runs properly:
kernel.cu 5
Error (active) E0065 expected a ‘;’ part a example 3
kernel.cu 5
Error (active) E0169 expected a declaration part a example 3
kernel.cu 44
Error (active) E0169 expected a declaration part a example 3
kernel.cu 45
line 5
global void kernel(int* vec, int n) {
line 44-45
return 0;
}
full listing
#include <stdio.h>
#define N 10
global void kernel(int* vec, int n) {
shared int s_vec[N];
int tid = threadIdx.x;
if (tid < n)s_vec[tid] = vec[tid];
__syncthreads();
if (tid < n-1) {
int val = s_vec[tid + 1] - s_vec[tid];
vec[tid] = val;
}
}
host int main(int argc, char** argv) {
int vec_in[N] = { 6,1,7,3,2,9,10,5,4,9 };
int vec_out[N];
//char msg_in = “hello accelerator”;
//char msg_out[N];
//char* d_msg; // will be message on the device
int* d_vec;
int i;
//printf(“msg_in = %s\n”, msg_in);
cudaMalloc(&d_vec, N * sizeof(int));
//cudaMalloc(&d_msg, N * sizeof(char));
//cudaMemcpy(d_msg, msg_in, N * sizeof(char), cudaMemcpyHostToDevice);
//cudaMemcpy(msg_out, d_msg, N * sizeof(char), cudaMemcpyDeviceToHost);
//printf("msg_out= %s\n", msg_out);
cudaMemcpy(d_vec, vec_in, N * sizeof(int), cudaMemcpyHostToDevice);
kernel << <1, N >> > (d_vec, N);
cudaMemcpy(vec_out, d_vec, N * sizeof(int), cudaMemcpyDeviceToHost);
for (i = 0;i < N;++i)printf("vec_out9i)=%d\n", vec_out[i]);
//printf("vec_out[3]= %d\n", vec_out[3]);
//printf("vec_out[0]= %d\n", vec_out[0]);
//printf("vec_out[2]= %d\n", vec_out[2]);
//cudaFree(d_msg);
cudaFree(d_vec);
return 0;
}