简体   繁体   English

CUDA纹理和夹紧

[英]CUDA textures and clamping

Is there any way to clamp out of range texture addresses to a certain value? 有没有办法将范围纹理地址限制到某个值? In my case, I want them to be set to a simple zero, but the address mode I need doesn't seem to exist. 在我的情况下,我希望它们被设置为一个简单的零,但我需要的地址模式似乎不存在。

Thanks. 谢谢。

Edit: Any idea what the cudaAddressModeBorder setting does? 编辑:知道cudaAddressModeBorder设置有什么作用吗?

I don't think there's a way to specify the clamp but you can do the obvious and add a 1 pixel black (zero) border around the edge and offset your addressing by 1. It shouldn't be much more data and it'll get you the clamping for free. 我不认为有一种方法可以指定钳位,但你可以做到这一点,并在边缘周围添加一个1像素的黑色(零)边框,并将你的寻址偏移1.它不应该是更多的数据,它会让你免费夹紧。

If you have a maximum size 2D texture (for CUDA 2.x it is 64k x 64k) with 16 bytes per pixel (worst case) then you're looking at only 4 MB of extra data for the 1 pixel border which for a PCIe x16 card will take about 500 microseconds to copy to the card--hardly anything even in the worst case. 如果你有一个最大尺寸的2D纹理(对于CUDA 2.x它是64k x 64k),每个像素有16个字节(最坏的情况),那么对于1个像素边界,你只需要4 MB的额外数据x16卡需要大约500微秒才能复制到卡上 - 即使在最坏的情况下也几乎没有。

You can set the boundary mode to return zero when accessing to textures using Surface functions. 使用Surface函数访问纹理时,可以将边界模式设置为返回零。 I can not test it right now as you need a device of compute capability 2.0+ but you can check the reference in the NVIDIA CUDA C Programming Guide (version 3.2), Section B.9 p.114. 我现在无法测试它,因为您需要一个2.0+计算能力的设备,但您可以在NVIDIA CUDA C编程指南(版本3.2),第B.9节第114页中查看参考。

We can also clamp the boundary and trap it (make kernel fail) what is the default when using the surface memory. 我们还可以钳制边界并捕获它(使内核失败)使用表面存储器时的默认值。

Regards! 问候!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM