Get dimensions of texture.

HLSL has method Texture2D::GetDimensions(), GLSL has function textureSize2D().
Is there anything like that in CUDA kernel?

I found only one very old topic about this subject: [url]https://devtalk.nvidia.com/default/topic/393353/get-texture-size-in-kernel-/[/url]
As I can see, such function did not exist 10 years ago but the situation could changed.

To my knowledge, there is no such function for texture references, which is what you seem to be using right now. The analogy to a texture reference is a plain old C-style array, which is referenced by a pointer that gets passed around. If some code also needs the array dimensions, the size information needs to be passed separately.

A modern and somewhat more flexible alternative to classical texture references are texture objects. These are worth looking into, but I don’t know whether they are useful for graphics interop (my hunch is: no). For those, one can use cudaGetTextureObjectResourceDesc() to retrieve relevant size information.

I assume there is an equivalent driver API function, but I don’t know that.

I agree that simply capturing size information at creation/binding time and passing that around is probably the only way.

I think texture objects are usable with graphics interop.

I interpret the request here to be for an API usable in device code. I know of no such device API, either for objects or references. The cuda runtime API that is usable in device code is ostensibly enumerated here:

[url]Programming Guide :: CUDA Toolkit Documentation

There is no driver API functionality exposed in device code, at all, AFAIK.

I can get this information inside the program using cuArrayGetDescriptor (), and I can (potentially) send this information to the driver side, but it looks somewhat ugly, because I use up to 16 different textures together.
Since the shader can read the texture property, it means that it is stored on the device and potentially available. Unfortunately, CUDA developers obviously forgot to add this function to the API.

OK, thanks. I’ll come up with a workaround.

Maybe it wasn’t so much of an oversight, but consciously resisting turning CUDA into yet another graphics API?

You can always file an enhancement request with NVIDIA using the bug reporting form at https://developer.nvidia.com (login required). Simply prefix the synopsis with “RFE:” so it is clear it is for an enhancement request not for a functional bug.