is it possible to get the same result as CL_INTENSITY of OpenCL in CUDA?
CL_INTENSITY ensures that when sampling a 4D vector from a single channel texture, the single channel is copied to all 4 components of the resulting vector.
CL_INTENSITY:
A single channel image format where the single channel represents an INTENSITY value. The INTENSITY value is replicated into the RED, GREEN, BLUE, and ALPHA components.
The background is, that we don’t want to write templated/different CUDA kernels when sampling a single channel or a four channel texture. We could always write *color = tex2D<float4>(tex, x, y) to write the result in a RGBA texture.
The same effect can be produced in OpenGL using GL_TEXTURE_SWIZZLE_RGBA.
It might be possible using a texture view descriptor (cudaResourceViewDesc). I don’t have a recipe for you. Typical texture usage leaves the view descriptor unused. I don’t know for sure that this is an option but you could try it. Basically if it were me I would try to see if I could create a multi-channel view descriptor for a single channel underlying texture, and if that were successful, I would take a look at how the channels are populated for a test case. A resource view descriptor can only be used if the underlying data is in a CUDA Array. Basically I’m suggesting creating a resource view that otherwise matches the texture but has a different format.
If its not successful I don’t have any further ideas.
Thank you, but we have to use pitched memory which does not support a view descriptor (sadly).
In PTX there is the texture property channel_order which can be CL_INTENSITY according to the PTX documentation. It seems to me, that PTX texture fetching supports the desired feature when the texture reference has the correct properties.
But I don’t see a way to set this property in CUDA. Any ideas?
Sure, but I have to set the texture property channel_order from host code via condition. cudaCreateTextureObject and its parameter don’t have this property.
Maybe there is a hidden way to set the property for the created texture object from host code?