My first program threadIdx: undeclared Identifier

I’ve been searching for the answer and read about 10 thread with similar problems, but have not been able to fix my problem.

Error 2 error C2065: ‘threadIdx’ : undeclared identifier c:\users\craig\appdata\local\nvidia corporation\nvidia gpu computing sdk\c\src\particleengine\ParticleEngine.cu 6 cuParticleEngine

I get 7 errors total. All just like that one but with blockIdx etc.

I created my Visual Studio project file using the template file provided and have renamed some of the files.

I originally wrote the program as a console application using all CPU. I copied the files into my new project, and it compiled and ran fine (though at about half the FPS). Now I’m trying to add my CUDA function, and I’m getting these errors.

These are my files:

ParticleEngine.h

ParticleEngine.cpp (holds the particle engine class)

ParticleEngine.cu (holds CUDA accelerated code, the one throwing the errors)

template.cu (holds main code)

template_gold.cpp (included by default)

template_kernel.cu(included by default)

I tried removing ParticleEngine.cu and re-adding it, and it told me there were no build rules for .cu files, and asked if I wanted to make a custom build rule.

Here is the beginning of my ParticleEngine.cu file

#include <cutil_inline.h>

#include <math.h>

__global__ void cuUpdateParticles(PARTICLES*particles, bool mousePressed, int mouseX, int mouseY,

								  float mouseForce, float gravity, float boxHeight, float boxWidth)

{

Sounds like pre compiler not being run
or its not finding a needed file like a .h

I also had that kind of trouble with it not finding atomicAdd.

I would suggest :
pick one of the SDK examples save it, as is, to a zip file
then add a printf(“Hello”); to the original and build that (add it in the main, or add it into the kernel and run in EmuDebug )

if that works and displays the “Hello” then you know that all header files and precompilers are being picked up OK
can now work in steps modifying/pruning the original code and bringing in your code

at some point rename the VS project and move it to a different folder so you can restore the original SDK code again (from that zip file.)

I had this problem in 2020. The solution was to take the new device file, in this case, ParticleEngine.cu, and open the General properties, and change ItemType to “CUDA C/C++”