-1

I am working on a CUDA C project, adding new functionalities step by step. Everything was going fine until I added to the code a particular kernel: the nvcc compiler now gives me 4 errors, all related to the same kernel (the new one). Here are the error-generating lines:

__global__ void update(float* original, float* new, float* current, int nhalf) {  // line 104
  int i = threadIdx.x + blockDim.x*blockIdx.x;  // line 105
  if (i < nhalf) {  // line 106
    current[i] /= nhalf;  // line 107 
    new[i] = (original[i] < current[i]) ? current[i] : original[i]; // line 108  
  }
} 

Since I write the kernel bodies before the main function, I don't use prototypes.

In the main function I launch the kernel at line 384:

update<<<p->gridSize,p->blockSize>>>(p->deviceEnv, p->deviceTrueEnv, p->deviceSmoothTrueEnv, Nhalf);

The first three arguments are pointers to float, while the fourth argument is just an integer number.

When I try compiling with nvcc I get the following errors:

project.cu(106): error: expected a ")"
project.cu(107): error: identifier "current" is undefined
project.cu(108): error: expected a type specifier
project.cu(384): error: too many arguments in function call

I use the following bash command to compile:

nvcc -O0 -shared -o libproject.so project.cu -Xcompiler "-fPIC" -I$HOME/include/csound -arch=sm_30 -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcufft -g -G 

I am really confused, also because in the very same project I have many other kernels which are very similar and they compile all right. I launch them without any problems in the same exact way. Can somebody please help me identifying the problem here? Many thanks in advance.

PS: I am using the cuda toolkit 7.0 on Ubuntu.

Andrea Crespi
  • 21
  • 1
  • 4
  • 3
    `new` is a reserved keyword in c++. Change that parameter name to something else, like `my_new`, both at the parameter and for usage within the `update` function body. – Robert Crovella Dec 14 '15 at 18:12
  • Aaargh, so simple! Thanks a lot! – Andrea Crespi Dec 14 '15 at 18:43
  • @RobertCrovella, by the way, do you think there is a better way to find the element-wise max of two arrays? I am wondering whether this is a low performance solution or not... (thanks again for answering all these cuda-related questions) – Andrea Crespi Dec 15 '15 at 11:41

1 Answers1

1

This was caused by using a variable in a kernel whose name conflicted with a reserved keyword (new in this case).

[This community wiki answer has been added from comments to get this question off the unanswered list].

talonmies
  • 70,661
  • 34
  • 192
  • 269