Error: No Instance of Overloaded Function "tex1Dfetch" Matches the Argument List Argument Types Are: (Texture, Int)

问题

在使用cuda的纹理存储器时,编译器报错

1
2
3
4
stencilexample.cu(147): error:
no instance of overloaded function "tex1Dfetch"
matches the argument list argument types are:
(texture<double, 1, cudaReadModeElementType>, int)

解决方法

经过研究,发现原来cuda的纹理存储器不能直接支持double

The type of a texel, which is restricted to the basic integer and single-precision floating-point types and any of the 1-, 2-, and 4-component vector types defined in char, short, int, long, longlong, float, double that are derived from the basic integer and single-precision floating-point types. 出处:cuda-c-programming-guide

非要加速的话,可以使用一个int2类型的向量拼接成一个double

1
2
3
4
5
6
7
//declarate the texture using int2 type
texture <int2,1,cudaReadModeElementType> Atex;


//used in global function(cuda kernel)
int2 A1=tex1Dfetch(Atex,(texoff+(ll+offset) *lda +ty+offset));
Bs[ty+offset][tx] -= __hiloint2double(A1.y,A1.x)*temp;