Question

Im developing a small cuda lib, stuck by this annoying tex ref issue.

This is the sample code from Cuda C Programming Guide, Page43~44:

texture<float, cudaTextureType2D,cudaReadModeElementType> texRef;
textureReference* texRefPtr;
cudaGetTextureReference(&texRefPtr, "texRef");
cudaChannelFormatDesc channelDesc;
cudaGetChannelDesc(&channelDesc, cuArray);
cudaBindTextureToArray(texRef, cuArray, &channelDesc);

When i execute it, the line cudaGetTextureReference(...) returns the error code cudaErrorInvalidTexture. I couldn't find many other samples about cudaGetTextureReference on the internet, most of them are following the exact same procedure as the sample code above.

Frustrated, i tried the high-level API afterwards:

texture<float, cudaTextureType2D,cudaReadModeElementType> texRef;
cudaBindTextureToArray(texRef, cuArray);

same problem. If read from that texture in the kernel, zero values are all i get.

My full toy test code, 100% reproduce-rate: (win7, cuda 5.0)

texture<float, cudaTextureType2D, cudaReadModeElementType> texRef;

int main ()
{
    const textureReference *tref = NULL;
    checkSuccess( cudaGetTextureReference( &tref, "texRef" ) );
    pauseConsole();
    return 0;
}

Any insight for this problem would be greatly appreciated. Thanks

Was it helpful?

Solution

Use of a string naming a variable as the symbol paramater was removed in CUDA 5.0.

Stated in CUDA Toolkit Reference Manual 5.0, Section 5.20.2.8 /Note.

Do the following instead:

cudaGetTextureReference( &tref, &texRef );

OTHER TIPS

Pass the symbol directly, not as a string. The string look method is a deprecated version of the API that was removed completely in CUDA 5. Your texture lookup should be written as

cudaGetTextureReference( &tref, &texRef );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top