简体   繁体   中英

Cuda cudaGetTextureReference returns “invalid texture reference”

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

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 );

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 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM