Using cudaGetTextureReference

I’m looking to have a CPP wrapper to deal with textures in cuda that only needs to know the name of the texture in the *.cu kernel file. It seems that if I know the name of the texture the function “cudaGetTextureReference” should allow me to get a pointer to the textureReference…which I would then be able to modify/bind/unbind etc.

In my constructor I pass in the texture name, a char* named symbol.

The following line gives me problems:

textureReference* m_texReference;

CUDA_SAFE_CALL( cudaGetTextureReference(&m_texReference, symbol));

I get the following error:

I would like to later do things like

m_texReference->normalized =0;

Someone posted in October they thought it was a mistake in the cuda_runtime_api.h…exturereference

but that stance appeared to be contested.

I thought I would raise the topic again here and see what you all think or if you have any ideas for ways to work around it.

Thank You.

**Note: This extends the work of a generalized C++ wrapper library I found at

If all goes well, I post my extended version here.

Here is what happens (MSVC8, Cuda2.0)

textureReference* texRefPtr;

	cudaGetTextureReference(&texRefPtr, "MyTexture");

Results in : error C2664: ‘cudaGetTextureReference’ : cannot convert parameter 1 from 'textureReference **__w64 ’ to ‘const textureReference **’

Can someone explain that to me ?


const textureReference* texRefPtr=NULL;

cudaGetTextureReference(&texRefPtr, “MyTexture”);

in cuda reference manual

the cudagettexturereference’s prototype is

cudaError_t cudaGetTextureReference (const struct textureReference **texref, const char *symbol)

In CUDA 3.2, Declaring texRefPtr as const do not serve the purpose to modify its members.

In cuda_runtime_api.h, changing the following line

extern __host__ cudaError_t CUDARTAPI cudaGetTextureReference(const struct textureReference **texref, const char *symbol);

to the line

extern __host__ cudaError_t CUDARTAPI cudaGetTextureReference(struct textureReference **texref, const char *symbol);

solves the problem.

In C++ you can use:

const textureReference* constTexRefPtr=NULL;

textureReference* texRefPtr=NULL;

texRefPtr = const_cast<textureReference*>( constTexRefPtr );

cudaGetTextureReference(&constTexRefPtr, "MyTexture");

texRefPtr->normalized = true; // cannot do this with constTexRefPtr.