I’m trying to learn CUDA and just recently started with it. As a test, I wanted to add two vectors and see if they run on the GPU. The code I wrote works, and I followed the syntax from the NVIDIA CUDA introduction. With the syntax <<<…>>>, which according to the NVIDIA guide is the kernel call, the IDE shows an error for me, indicating that it’s underlined in red and an expression is still expected. Could you help me understand why this happens? I’m sorry for this, but I’m new to it and haven’t seen anyone else online encountering the same error
I expected that the IDE wouldn’t show any errors because the code runs without any issues, but with add<<<1, 1000>>> an expression is still expected. C++
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
__global__ void add(int *a, int *b, int *c)
{
int i = threadIdx.x + blockDim.x * blockIdx.x;
c[i] = a[i] + b[i];
}
__managed__ int vector_a[1000], vector_b[1000], vector_c[1000];
int main()
{
for (int i = 0; i < 1000; ++i) {
vector_a[i] = i;
vector_b[i] = 1000 - i;
}
add<<<1, 1000>>>(vector_a, vector_b, vector_c);
cudaDeviceSynchronize();
int result = 0;
for (int i = 0; i < 1000; ++i) {
result += vector_c[i];
}
printf("Result = %d", result);
return 0;
}
Apro9991 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1