如何将双打数组绑定到 texture2D?

How to bind array of doubles to texture2D?

我尝试使用纹理memory/binding代替全局内存,但我无法通过绑定纹理。我首先了解到的是 CUDA 不支持 double 纹理,所以需要转换,好的。

我声明了全局纹理变量:

texture<int2, 2> texData;

然后在分配大小(以字节为单位)的设备内存 (cudaMalloc) 之后立即 width*height * sizeof(double) 我尝试绑定它:

cudaChannelFormatDesc desc = cudaCreateChannelDesc<int2>();
cudaStatus = cudaBindTexture2D(nullptr, &texData, dev_data, &desc,  width, height, 0);
if (cudaStatus != cudaSuccess) {
    fprintf(stderr, "Binding texture failed: %s\n", cudaGetErrorString(cudaStatus));
    goto Error;
}

此绑定失败并出现错误 "invalid argument"。宽度和高度为 2048,远低于纹理 2d 限制:65536 x 65536 x 1048544。

那我做错了什么?

旁注:cudaBindTexture2D的签名:

extern __host__ cudaError_t CUDARTAPI cudaBindTexture2D(size_t *offset, 
    const struct textureReference *texref, const void *devPtr, 
    const struct cudaChannelFormatDesc *desc, size_t width, size_t height, size_t pitch);

你应该做一个适当的倾斜分配

size_t pitch;
cudaMallocPitch((void**)&dev_data, &pitch, width* sizeof(double),height);

cudaChannelFormatDesc desc = cudaCreateChannelDesc<int2>();

cudaStatus = cudaBindTexture2D(nullptr, texData, dev_data, desc,  width, height, pitch);

请注意,虽然 CUDA 错误通常信息量不大,但您得到的“"invalid argument"”信息量很大。您在函数中输入的参数无效。