Error: identifier "blockIdx" is undefined

My setup for CUDA

Visual Studio 2010 and 2008 SP1 (CUDA required). Parallel NSight 1.51 CUDA 4.0 RC or 3.2 and Thrust

Basically, I followed the guide: http://www.ademiller.com/blogs/tech/2011/03/using-cuda-and-thrust-with-visual-studio-2010/

Then I started to compile successfully without error messages.

So I tried using CUDA code examples from the Internet. These errors appeared on Visual Studios. I can still compile successfully without error messages, but these errors only appear visually.

  • "Error: identifier" blockIdx "not specified."
  • "Error: identifier" blockDim "not specified."
  • "Error: identifier" threadIdx "not specified."

Here is a screenshot.

http://i.imgur.com/RVBfW.png

Should I be bothered? Is this a Visual Studios error or is the configuration incorrectly configured? Any help is appreciated. Thanks guys!

PS I am very new to Visual Studios and CUDA.

// incrementArray.cu
#include "Hello.h"
#include <stdio.h>
#include <assert.h>
#include <cuda.h>
void incrementArrayOnHost(float *a, int N)
{
  int i;
  for (i=0; i < N; i++) a[i] = a[i]+1.f;
}
__global__ void incrementArrayOnDevice(float *a, int N)
{
  int idx = blockIdx.x*blockDim.x + threadIdx.x;
  if (idx<N) a[idx] = a[idx]+1.f;
}
int main(void)
{
  float *a_h, *b_h;           // pointers to host memory
  float *a_d;                 // pointer to device memory
  int i, N = 10;
  size_t size = N*sizeof(float);
  // allocate arrays on host
  a_h = (float *)malloc(size);
  b_h = (float *)malloc(size);
  // allocate array on device 
  cudaMalloc((void **) &a_d, size);
  // initialization of host data
  for (i=0; i<N; i++) a_h[i] = (float)i;
  // copy data from host to device
  cudaMemcpy(a_d, a_h, sizeof(float)*N, cudaMemcpyHostToDevice);
  // do calculation on host
  incrementArrayOnHost(a_h, N);
  // do calculation on device:
  // Part 1 of 2. Compute execution configuration
  int blockSize = 4;
  int nBlocks = N/blockSize + (N%blockSize == 0?0:1);
  // Part 2 of 2. Call incrementArrayOnDevice kernel 
  incrementArrayOnDevice <<< nBlocks, blockSize >>> (a_d, N);
  // Retrieve result from device and store in b_h
  cudaMemcpy(b_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
  // check results
  for (i=0; i<N; i++) assert(a_h[i] == b_h[i]);
  // cleanup
  free(a_h); free(b_h); cudaFree(a_d); 

  return 0;
}
+5
source share
3 answers

This is just a Visual Intellisense keyword issue run by VS himself. Codes can be successfully created, because VS asks NVCC, which can find and recognize these keywords, to perform construction work, you can simply add the following code to solve this problem in VS2010

 #include "device_launch_parameters.h"
+27
source

, Visual Intellisense, . , "" , CUDA- (threadIdx, __device__ ..), .cu :

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

, Intellisense myhack.h CUDA. nvcc- __CUDACC__ .

+2

CygnusX1 , CUDA, blockDim, usertype.dat Visual Studio 2010.

Intellisense .

+1

All Articles