Cuda Compilation Error - Expected Primary Expression

this program seems great, but am I still getting erro, any suggestion?

Program:

#include "dot.h" #include <cuda.h> #include <cuda_runtime.h> #include <stdio.h> int main(int argc, char** argv) { int *a, *b, *c; int *dev_a, *dev_b, *dev_c; int size = N * sizeof(int); cudaMalloc((void**)&dev_a, size); cudaMalloc((void**)&dev_b, size); cudaMalloc((void**)&dev_c, sizeof(int)); a = (int *)malloc (size); b = (int *)malloc (size); c = (int *)malloc (sizeof(int)); random_ints(a, N); random_ints(b, N); cudaMemcpy(dev_a, a, size, cudaMemcpyHostToDevice); cudaMemcpy(dev_b, b, size, cudaMemcpyHostToDevice); int res = N/THREADS_PER_BLOCK; dot<<< res, THREADS_PER_BLOCK >>> (dev_a, dev_b, dev_c); //helloWorld<<< dimGrid, dimBlock >>>(d_str); cudaMemcpy (c, dev_c, sizeof(int), cudaMemcpyDeviceToHost); free(a); free(b); free(c); cudaFree(dev_a); cudaFree(dev_b); cudaFree(dev_c); return 0; } 

mistake:

DotProductCuda.cpp: 27: error: expected primary expression before token '<'
DotProductCuda.cpp: 27: error: expected primary expression before the token '>'

+8
c ++ gpgpu cuda
source share
4 answers

The syntax <<< >>> for invoking the kernel is not standard C or C ++. These calls must be in a file compiled by the NVCC compiler. These files are usually named with the extension .cu. Other API calls for CUDA, such as cudaMalloc , may be in regular .c or .cpp files.

+12
source share

It seems that the compiler cannot recognize the syntax <<<<<, →>. I have no experience with CUDA, but I think you need to compile this file with a special compiler, not a regular C compiler.

+4
source share

nvcc uses the file extension to determine how to handle the contents of the file. If you have CUDA syntax inside the file, it must have a .cu extension, otherwise nvcc will just pass the file untouched to the host compiler, resulting in a syntax error.

+3
source share

Perhaps you are using a host function (e.g. printf) inside the kernel?

-3
source share

All Articles