2014-02-18 30 views
0

考虑以下主机功能:CUDA指针reintepret_cast的行为?

uint64_t * SomeDevPtr =... 
/* Where SomeDevPtr is a pointer pointed to some device memory address allocated by cudaMalloc(); */ 

uint32_t * SomeDevIntPtr = reintepret_cast<uint32_t *>(SomeDevPtr); 

因为函数的,cudaMalloc将automatcially fullfill一些aligment要求(我认为它被对准以某些128字节存储器边界),因此,我认为既SomeDevIntPtrSomeDevPtr应该从GPU全局内存中的相同物理内存地址开始,我对此是否正确?

我只是想确定一下,因为我写的一些函数依赖于它。

回答

5

一个指针reinterpret_cast指针does not(即不应)改变指针的基础的数值(比特模式表示)。

因此,存在任何对齐条件都不会受到这种类型演员的影响。

当然,将正确对齐的指针转换为不再具有正确对齐的类型是可能的。例如,对于CUDA设备使用,未正确对齐的指针(该指针不是可以被均匀划分的偏移量(索引))无法正确投射到float4指针。一些CUDA指针需要自然对齐。

您可能也有兴趣this question