rhoads
July 22, 2008, 2:02am
1
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:
./cud_Texture.h:62: error: invalid conversion from ‘textureReference**’ to ‘const textureReference**’
./cud_Texture.h:62: error: initializing argument 1 of ‘cudaError_t cudaGetTextureReference(const textureReference**, const char*)’
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
http://forums.nvidia.com/index.php?showtop…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
http://www.gpgpu.org/forums/viewtopic.php?p=19654
If all goes well, I post my extended version here.
sudoca
April 2, 2009, 3:18pm
2
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 ?
use:
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.