解决 Thrust/CUDA 警告“无法判断指针指向...”

发布于 2024-10-20 11:02:31 字数 2232 浏览 3 评论 0原文

我正在尝试使用 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

有很多这样的。

I'm trying to build a trivial application using Thrust/CUDA 4.0 and get lots of warnings "warning : Cannot tell what pointer points to, assuming global memory space"

Has anyone else seen this and how do I either disable them or fix my code?

Thanks,

Ade

Here's my code.

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>());
}

The output

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

There's a lot of these.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妄司 2024-10-27 11:02:31

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

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

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

建议:忽略这些警告。

Fermi uses uniform addressing of shared and global memory space, while pre-Fermi messages don't.

For the pre-Fermi case, when you get an address, you don't know if it should be shared or global. The compiler tries to figure it out, but sometimes it can't. When that happens, the message pops up - "assuming global" is correct in 99.999% of cases, because when you want a pointer to shared memory, you usually explicitly take an address of a shared variable and the compiler can recognise that.

For Fermi cards, shared-or-global can be deduced at runtime (based on the address) and no assumptions have to be made by the compiler.

Suggeston: Ignore those warnings.

遗忘曾经 2024-10-27 11:02:31

所以...弄清楚了并想我将其发布在这里。解决方案是

不要在 NVCC 上使用 -G 标志

,或者

如果您的目标是此类设备,请编译 arch sm_20 (Fermi)。

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

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

So... figured it out and thought I'd post it here. The solution is either

Don't use the -G flag on NVCC

or

Compile for arch sm_20 (Fermi) if you are targetting such a device

This is a known limitation of NVCC and not a Thrust bug. See:

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

记忆で 2024-10-27 11:02:31

如果您使用的是 mirosoft Visual Studio:从项目 -> 属性 -> CUDA C/C++ -> 设备 -> 代码生成;将compute_10,sm_10更改为compute_20,sm_20

if you are using mirosoft visual studio: from project->properties->CUDA C/C++->Device->Code Generation; change the compute_10,sm_10 to compute_20,sm_20

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文