如何替换已弃用的 tex2D(texture<T, 2, cudaReadModeElementType>, float, float) [with T=float]?

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

在 cuda 11.3 程序中,我正在使用

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

已在 texture_fetch_functions.h(198) 中宣布弃用。什么取代了它?以及如何使用它?

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

Textures have historically come in 2 usage models: texture references and texture objects。纹理引用是 CUDA 提供的“原始”机制,纹理对象是随开普勒一代 GPU 引入的。

纹理引用的使用在 CUDA 11.3 中被弃用。几乎任何你能用纹理引用做的事情都可以用纹理对象来做,并进行一些重构。

您指定的替换 API 已记录在案 here. There are many questions here on the cuda tag discussing both texture reference usage and texture object usage, and this introductory blog 涵盖了重构以使用纹理对象的好处。

是对纹理对象使用 tex2D() 的完整示例。