解决Thrust / CUDA警告“无法分辨指针指向哪个......”

时间:2011-03-06 19:37:15

标签: visual-studio-2010 cuda thrust

我正在尝试使用Thrust / CUDA 4.0构建一个简单的应用程序并获得大量警告“警告:无法告诉指针指向什么,假设全局内存空间”

是否有其他人看过这个以及如何禁用它们或修复我的代码?

谢谢,

阿德

这是我的代码。

Hello.h

class DECLSPECIFIER Hello   
{ 
private:
    thrust::device_vector<unsigned long> m_device_data;

public:
    Hello(const thrust::host_vector<unsigned long>& data);
    unsigned long Sum();
    unsigned long Max();
};

Hello.cu

#include "Hello.h"

Hello::Hello(const thrust::host_vector<unsigned long>& data)
{
    m_device_data = data;
}

unsigned long Hello::Sum()
{
    return thrust::reduce(m_device_data.cbegin(), m_device_data.cend(), 0, thrust::plus<unsigned long>());
}

unsigned long Hello::Max()
{
    return *thrust::max_element(m_device_data.cbegin(), m_device_data.cend(), thrust::less<unsigned long>());
}

输出

1>  Compiling CUDA source file Hello.cu...
1>  
1>  C:\SrcHg\blog\HelloWorld\HelloWorldCuda>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2008 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include"  -G0  --keep-dir "Debug" -maxrregcount=32  --machine 32 --compile  -D_NEXUS_DEBUG -g    -Xcompiler "/EHsc /nologo /Od /Zi  /MDd " -o "Debug\Hello.cu.obj" "C:\SrcHg\blog\HelloWorld\HelloWorldCuda\Hello.cu" 
1>  Hello.cu
1>  tmpxft_00001fac_00000000-0_Hello.cudafe1.gpu
1>  tmpxft_00001fac_00000000-5_Hello.cudafe2.gpu
1>  Hello.cu
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include\thrust/detail/internal_functional.h(197): warning : Cannot tell what pointer points to, assuming global memory space
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include\thrust/detail/internal_functional.h(197): warning : Cannot tell what pointer points to, assuming global memory space
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include\thrust/detail/internal_functional.h(197): warning : Cannot tell what pointer points to, assuming global memory space

有很多这些。

3 个答案:

答案 0 :(得分:12)

Fermi使用共享和全局内存空间的统一寻址,而前费米消息则不使用。

对于前费米案,当你得到一个地址时,你不知道它应该是共享的还是全局的。编译器试图找出它,但有时它不能。当发生这种情况时,弹出的消息 - “假设全局”在99.999%的情况下是正确的,因为当你想要一个指向共享内存的指针时,你通常会明确地获取一个共享变量的地址,编译器可以识别它。

对于费米卡,可以在运行时推导出共享或全局(基于地址),编译器不必做出任何假设。

Suggeston:忽略这些警告。

答案 1 :(得分:4)

所以......想出来,以为我会在这里发布。解决方案是

不要在NVCC上使用-G标志

如果要定位此类设备,请编译arch sm_20(Fermi)

这是NVCC的已知限制,而不是Thrust错误。参见:

http://groups.google.com/group/thrust-users/browse_thread/thread/1914198abf646c6d/8bc00e6030b0030b?#8bc00e6030b0030b

答案 2 :(得分:1)

如果您使用的是mirosoft visual studio:from project-&gt; properties-&gt; CUDA C / C ++ - &gt; Device-&gt; Code Generation;将compute_10,sm_10更改为compute_20,sm_20