检测指针是否指向CUDA中的设备或主机 [英] Detection if a pointer is pointing in the device or host in CUDA

查看:384
本文介绍了检测指针是否指向CUDA中的设备或主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CUDA中有任何方法可以知道指针是否指向设备或主机上的内存。

In CUDA are there any way of knowing if the pointer is pointing in memory on the device or the host.

这样做的操作示例可以是: / p>

A made op example of this could be:

int *dev_c, *host_c;
cudaMalloc( (void**)&dev_c, sizeof(int) );
host_c = (int*) malloc(sizeof(int));

我当然可以看看名称,但是有什么办法看广告的指针dev_c和

I can of course look at the name, but are there any way of looking ad the pointer dev_c and host_c and saying, host_c points ad the host and dev_c points ad the device.

推荐答案

开始(我认为)CUDA 4和Fermi GPU。 Nvidia支持 UVA(统一虚拟地址空间)
功能 cudaPointerGetAttributes 似乎在做什么你要的。注意,我相信它只适用于分配了cudaHostAlloc(而不是c malloc)的主机指针。

Starting (I think) CUDA 4 and Fermi GPUs. Nvidia supports UVA (Unified Virtual Address Space). Function cudaPointerGetAttributes seems to do exactly what you're asking for. Note that I believe it only works for host pointers allocated with cudaHostAlloc (and not c malloc).

这篇关于检测指针是否指向CUDA中的设备或主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆