Kristian D'Amato
Kristian D'Amato

Reputation: 4046

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?

Upvotes: 4

Views: 1952

Answers (2)

pQB
pQB

Reputation: 3127

You can set the boundary mode to return zero when accessing to textures using Surface functions. 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.

We can also clamp the boundary and trap it (make kernel fail) what is the default when using the surface memory.

Regards!

Upvotes: 3

Ron Warholic
Ron Warholic

Reputation: 10074

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.

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.

Upvotes: 4

Related Questions