Hi all, I’m trying to use textures in my cuda code but I’m getting a load of errors and I’m not sure why. Any help or insight into what I might be doing wrong would be much appreciated.
I’m trying to bind a double precision one dimensional array to texture. I understand that textures don’t support double so I’ve used the built-in int2 vector type and hiloint2double. Here’s the test code which I’ve been developing with:
File scope
[codebox]texture<int2,1> texrefa;[/codebox]
Host code
[codebox]int main()
{
int n=100;
double a[n], b[n];
int i;
for ( i=0; i<n; i++){
a[i]=(i+3)/2;
}
int size;
size = n * sizeof(double);
double* Ad;
cudaMalloc((void**)&Ad, size);
double* Bd;
cudaMalloc((void**)&Bd, size);
cudaMemcpy(Ad, a, size, cudaMemcpyHostToDevice);
cudaMemcpy(Bd, b, size, cudaMemcpyHostToDevice);
cudaBindTexture(0, texrefa, &Ad, size);
texkernel<<<10,10>>>(Ad ,n, Bd);
cudaThreadSynchronize();
return 0;
}[/codebox]
Kernel code
[codebox]global void texkernel(double *a, int n, double b )
{
int i;
/*Block index*/
int bx=blockIdx.x;
/*Thread index*/
int tx=threadIdx.x;
int2 sha=make_int2(n,n);
sha=tex1Dfetch(texrefa, a);
i=bx*10+tx;
double aa[n];
for (i=0;i<n;i++){
aa[i]=__hiloint2double(sha.x,sha.y);
}
b[i]=aa[i];
}[/codebox]
If I keep argument a as a pointer in the kernel argument list (as above) then I get this compiler error:
[html]texture.cu:65:2: warning: no newline at end of file
texture.cu(26): error: no instance of overloaded function “tex1Dfetch” matches the argument list
argument types are: (texture<int2, 1, cudaReadModeElementType>, double *)[/html]
If I change the above code so the argument is no longer double *a instead justdouble a I get the following compile time errors:
[html]texture.cu:66:2: warning: no newline at end of file
Signal: Segmentation fault in Code_Expansion phase.
(0): Error: Signal Segmentation fault in phase Code_Expansion – processing aborted
*** Internal stack backtrace:
/usr/local/cuda2.3/open64/lib//be [0x6c09bf]
/usr/local/cuda2.3/open64/lib//be [0x6c1609]
/usr/local/cuda2.3/open64/lib//be [0x6c0d5d]
/usr/local/cuda2.3/open64/lib//be [0x6c1fa6]
/lib64/libc.so.6 [0x347b0302d0]
/usr/local/cuda2.3/open64/lib//be [0x544449]
/usr/local/cuda2.3/open64/lib//be [0x56fcec]
/usr/local/cuda2.3/open64/lib//be [0x56c7bc]
/usr/local/cuda2.3/open64/lib//be [0x56dc31]
/usr/local/cuda2.3/open64/lib//be [0x56c7a8]
/usr/local/cuda2.3/open64/lib//be [0x57132b]
/usr/local/cuda2.3/open64/lib//be [0x571e46]
/usr/local/cuda2.3/open64/lib//be [0x5723fc]
/usr/local/cuda2.3/open64/lib//be [0x54e980]
/usr/local/cuda2.3/open64/lib//be [0x405443]
/usr/local/cuda2.3/open64/lib//be [0x4061f1]
/usr/local/cuda2.3/open64/lib//be [0x40751d]
/lib64/libc.so.6(__libc_start_main+0xf4) [0x347b01d994]
/usr/local/cuda2.3/open64/lib//be [0x4038da]
nvopencc INTERNAL ERROR: /usr/local/cuda2.3/open64/lib//be died due to signal 4[/html]
Thanks in advance.