visual-studio-2010 - 错误:identifer "blockIdx" is undefined

标签 visual-studio-2010 visual-c++ cuda

我的 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 Studio 上。我仍然可以成功编译而不会出现错误消息,但这些错误仅在视觉上突出显示

  • “错误:标识符“blockIdx”未定义。”
  • “错误:标识符“blockDim”未定义。”
  • “错误:标识符“threadIdx”未定义。”

这是屏幕截图。

/image/v1LFx.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来完成构建工作,NVCC可以找到并识别这些关键字,在VS2010下只需添加以下代码即可解决此问题

 #include "device_launch_parameters.h"

关于visual-studio-2010 - 错误:identifer "blockIdx" is undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9131638/

相关文章:

c++ - 为什么 mysql c++ 连接器在 main() 中工作而不在类方法中工作?

c++ - 将问题与 libharu 联系起来

c++ - MSVC 的 _M_X64 预定义宏说明

c++ - 通过 GPU 计算部分并行程序的可能选项

cuda - 是否有可能在 GPU 上的一个时钟周期内添加 1,000,000 个 double ?

c++ - `g++ -E file.cxx` 的 Visual Studio 2010 模拟是什么?

c# - 我如何找到所有设置属性的地方?

visual-studio-2010 - 使用 Visual Studio 构建共享库

windows - 64 位 Windows API : what is the size of a C/C++ "DWORD"?

CUDA核函数