I am using a CUDA texture in border addressing mode (cudaAddressModeBorder
). I am reading texture coordinates using tex2D<float>()
. When the texture coordinates fall outside the texture, tex2D<float>()
returns 0
.
How can I change this returned border value from 0
to something else? I could check the texture coordinate manually and set the border value myself. I was wondering if there was CUDA API where I can set such a border value.
As of now (CUDA 5.5), the CUDA texture fetch behavior is not customizable. Only 1 of the 4 automatic built-in modes (i.e. Border, Clamp, Wrap and Mirror) can be utilized for out of range texture fetch.
As mentioned by sgarizvi, CUDA supports only four, non-customizable address modes, namely, clamp, border, wrap and mirror, which are described in Section 3.2.11.1. of the CUDA programming guide.
The former two work in both unnormalized and normalized coordinates, while the latter two in normalized coordinates only.
To describe the first two, let us consider the unnormalized coordinates case and consider 1D signals, for the sake of simplicity. In this case, the input sequence is
c[k]
, withk=0,...,M-1
.cudaAddressModeClamp
The signal
c[k]
is continued outsidek=0,...,M-1
so thatc[k] = c[0]
fork < 0
, andc[k] = c[M-1]
fork >= M
.cudaAddressModeBorder
The signal
c[k]
is continued outsidek=0,...,M-1
so thatc[k] = 0
fork < 0
and fork >= M
.Now, to describe the last two address modes, we are forced to consider normalized coordinates, so that the 1D input signal samples are assumed to be
c[k / M]
, withk=0,...,M-1
.cudaAddressModeWrap
The signal
c[k / M]
is continued outsidek=0,...,M-1
so that it is periodic with period equal toM
. In other words,c[(k + p * M) / M] = c[k / M]
for any (positive, negative or vanishing) integerp
.cudaAddressModeMirror
The signal
c[k / M]
is continued outsidek=0,...,M-1
so that it is periodic with period equal to2 * M - 2
. In other words,c[l / M] = c[k / M]
for anyl
andk
such that(l + k)mod(2 * M - 2) = 0
.The following code illustrates all the four available address modes
Those are the outputs