visual-studio-2010 – 错误:标识符“blockIdx”未定义

我的CUDA设置

Visual Studio 2010和2008 SP1(CUDA要求).
并行NSight 1.51
CUDA 4.0 RC或3.2和Thrust

基本上,我按照指南:
http://www.ademiller.com/blogs/tech/2011/03/using-cuda-and-thrust-with-visual-studio-2010/

然后我继续编译成功,没有错误消息.

所以我尝试了更多来自网络的CUDA代码示例. Visual Studios上出现了这些错误.我仍然可以成功编译没有错误消息,但这些错误只是在视觉上突出显示

>“错误:标识符”blockIdx“未定义.”
>“错误:标识符”blockDim“未定义.”
>“错误:标识符”threadIdx“未定义.”

这是截图.

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

我应该担心吗?它是Visual Studios错误还是我的设置配置错误?任何帮助表示赞赏.多谢你们!

P.S我对Visual Studios和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;
}
它只是由VS本身进行的关键词Visual Intellisense问题.代码可以成功构建,因为VS请求NVCC,谁可以找到并识别这些关键字,进行构建工作,你可以在VS2010下添加以下代码来解决这个问题

#include "device_launch_parameters.h"
相关文章
相关标签/搜索