将纹理与 CUDA 中的固定映射内存绑定
我试图将零拷贝映射的主机内存绑定到纹理,但看起来这是不可能的。
这是一个代码示例:
float* a;
float* d_a;
cudaSetDeviceFlags(cudaDeviceMapHost);
cudaHostAlloc( (void **)&a, bytes, cudaHostAllocMapped);
cudaHostGetDevicePointer((void **)&d_a, (void *)a, 0);
texture<float, 2, cudaReadModeElementType> tex;
cudaBindTexture2D( 0, &tex, d_a, &channelDesc, width, height, pitch);
是否建议您使用固定内存并将其复制到绑定到纹理的设备内存?
I was trying to bind a host memory that was mapped for zero-copy to a texture, but it looks like it isn't possible.
Here is a code sample:
float* a;
float* d_a;
cudaSetDeviceFlags(cudaDeviceMapHost);
cudaHostAlloc( (void **)&a, bytes, cudaHostAllocMapped);
cudaHostGetDevicePointer((void **)&d_a, (void *)a, 0);
texture<float, 2, cudaReadModeElementType> tex;
cudaBindTexture2D( 0, &tex, d_a, &channelDesc, width, height, pitch);
Is it recommended that you used pinned memory and just copy it over to device memory that is bind to texture?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的,但您必须确保音高正确对齐 - 至少 64B 粒度。我在 cudaDeviceProp 中没有看到您可以使用的对齐要求。 cudaDeviceProp::textureAlignment 将为您提供不错的指导 - 这是纹理基地址的对齐要求,而不是间距;但我认为对齐要求比音高对齐要求更严格。
不幸的是,没有 cudaHostAllocPitch() 来为您处理这个问题。
公平警告:我已经对主机内存中的一维纹理进行了大量的定向性能测试,而且速度很慢。 Tesla 级硬件的速度为 2G/s,Fermi 级硬件的速度为 0.5 G/s。我没有理由相信 2D 纹理会更快。
It is possible, but you have to make sure the pitch is correctly aligned - at least 64B granularity. I do not see an alignment requirement in cudaDeviceProp that you can use. cudaDeviceProp::textureAlignment will give you decent guidance - that is the alignment requirement for the base address of the texture, not the pitch; but I believe that alignment requirement is stricter than the pitch alignment requirement.
Unfortunately there is no cudaHostAllocPitch() to take care of this for you.
Fair warning: I have done quite a bit of directed performance testing of 1D texture-from-host-memory, and it is s-l-o-w. Tesla class hardware goes at 2G/s and Fermi class hardware at 0.5 G/s. I have no reason to believe 2D texturing will be any faster.