纹理对象API
使用cudaCreateTextureObject()函数从一个用来指定纹理并从纹理类型定义而来的资源描述类型结构(resource description of type struct)cudaResourceDesc建立纹理对象。
struct cudaTeextureDesc
{
enum cudaTextureAddressMode addess_mode[3];
enum cudaTextureFilterMode filter_mode;
enum cudaTextureReadMode read_mode;
enum cudaTexturefilterMode mipmap_fileter_mod;
int sRGB;
int normalized_coords;
unsigned int max_anisotropy;
float mipmap_level_bias;
float min_mipmap_level_clamp;
float max_mipmap_level_clamp;
};
下面程序是用纹理内存实现的图像sobel边缘检测的代码,作为纹理内存使用的例子:
int main()
{
int width, height;
float *image_buffer;
image_buffer=loadImage(width, height);
cudaChannelFormatDesc channel_format = cudaCreateChannelDesc(32,0,0,0,
cudaChannelFormatKindFloat);
//创建CUDA数组,作为纹理结构的Resource
cudaArray_t de_arr;
CheckErr(cudaMallocArray(&de_arr, &channel_format, width, height), "malloc cuda arrary");
CheckEr