CUDA textures How do cuda textures work?

I’ve been studying the manual about cuda textures, few things are unclear:

channelDesc “describes value that is returned”. Is this independent of the source format of the texture? Is it describing the value returned to me, or the format of the source data?

Linear filtering, I’m unclear when this actually works. It needs to use cudaarray allocated memory, but:

-Under the filtering section it says “is only available for floating-point textures”.
-But under filtermode, it says “cudaFilterModeLinear is only valid for returned values of floating-point type”. It doens’t say the texture must be floating point source. The GPU certainly supports filtering non-floating point textures so I don’t understand why cuda would impose this limitation.

The texture<Type, Dim, ReadMode> has some confusing descriptions.

It says “Type” “data that is returned when fetching the texture”. This seems to do the same thing as channelDesc. I think what this really means is it’s how fetched data is interpreted. The actual returned value comes from channelDesc, so a conversion can take place if they are different?

In that case, is it valid to have say a Type of uchar4, but channeldesc is 32-bit per component “cudaChannelFormatKindFloat”? I’m trying to do something very simple - read an 8:8:8:8 RGBA texture as a cuda texture with linear filtering enabled, and write it out to another RGBA texture.

I looked at the functions defined in texture_fetch_functions.h and there seem to be explicit conversions going on from float to int and vice versa. For example:

template<> inline device int4 tex2D(texture<int4, 2, cudaReadModeElementType> t, float x, float y)
int4 v = __itexfetch(t, make_float4(x, y, 0, 0));

return make_int4(v.x, v.y, v.z, v.w);


static inline device float4 tex2D(texture<uchar4, 2, cudaReadModeNormalizedFloat> t, float x, float y)
uint4 v = __utexfetch(t, make_float4(x, y, 0, 0));
float4 w = make_float4(__int_as_float(v.x), __int_as_float(v.y), __int_as_float(v.z), __int_as_float(v.w));

return make_float4(w.x, w.y, w.z, w.w);

This last function seems to take a uchar4 textures (standard rgba) and return a float4 so presumably the gpu is doing a conversion there. Also, the boxfilter sample has a bunch of dead code in it.

Another question is, can you read out of a cuda array/texture as it it were linear memory, or do you have to use the tex2d() semantic?

It’s the format of the source data (the array).

I agree this is unclear - it means filtering is supported if the texture read mode is cudaReadModeNormalizedFloat. This a hardware restriction, we don’t do filtering on integer format textures. I’ll try and get this clarified in the manual.

Yes, the texture “type” field is just a convenience that casts the value returned by texture to the appropriate type. Normally this will match the type of the array declared earlier.

I know.

No, you need to use the tex1Dfetch() function.