How to replace the deprecated tex2D(texture<T, 2, cudaReadModeElementType>, float, float) [with T=float]?

Viewed 1999

In a cuda 11.3 program, I'm using

tex2D(texture<T, 2, cudaReadModeElementType>, float, float)

which was declared deprecated in texture_fetch_functions.h(198). What replaces it ? and how do I use it ?

warning : function "tex2D(texture<T, 2, cudaReadModeElementType>, float, float) [with T=float]" 2>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include\texture_fetch_functions.h(198): here was declared deprecated

1 Answers

Textures have historically come in 2 usage models: texture references and texture objects. Texture references were the "original" mechanism supplied with CUDA and texture objects were introduced with the Kepler generation of GPUs.

Texture reference usage is being deprecated in CUDA 11.3. Nearly anything you can do with texture references can be done with texture objects, with some refactoring.

The replacement API for the one you indicate is documented here. There are many questions here on the cuda tag discussing both texture reference usage and texture object usage, and this introductory blog covers the benefits of refactoring to use texture objects.

Here is a complete worked example of using tex2D() for texture objects.

Related