Error:identifer "blockIdx" is undefined

It's just a keyword Visual Intellisense problem conducted by VS itself. Codes can be built successfully because VS requests NVCC, who can find and recognize these keywords, to do the building work, you can just add the following code to solve this problem under VS2010

 #include "device_launch_parameters.h"

The code is compiled correctly, it is the Visual Intellisense which is trying to parse the code and catch errors on its own. The trick I do usually is to have a "hacked" header file which defines all CUDA-specific symbols (threadIdx, __device__, etc.) and then include it in the .cu file like this:

#ifndef __CUDACC__
#include "myhack.h"
#endif

This way, Intellisense will read in myhack.h and won't complain about CUDA stuff. The real nvcc compiler will recognise the __CUDACC__ macro and won't read the hack file.