I apologise for asking, but I have really spent quite a long time looking at this code and I can’t see what is wrong with it:
#include <stdio.h>
#define M 5
#define N 5
texture<int, 2> oldtex;
texture<int, 2> edgetex;
__global__ void computeker(int *buf3){
*(buf3 + blockIdx.y*(M+2) + blockIdx.x)=tex2D(oldtex, blockIdx.y, blockIdx.x);
}
main(){
int i, j;
int buf_h[N][M], buf2[N+2][M+2], *zero, *buf3;
cudaArray *old, *edge;
dim3 block(1, 1);
dim3 grid(M+2, N+2);
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<int>();
size_t zerop;
cudaMallocArray(&edge, &channelDesc, M, N);
cudaMallocArray(&old, &channelDesc, (M+2), (N+2));
for(i=0;i<N;i++){
 for(j=0;j<M;j++){
�  buf_h[i][j]=123;
 }
}
cudaMemcpyToArray(edge, 0, 0, buf_h, sizeof(int)*N*M, cudaMemcpyHostToDevice);
cudaMallocPitch((void **) &zero, &zerop, sizeof(int)*(M+2), (N+2));
cudaMemset2D(zero, zerop, 5, sizeof(int)*(M+2), (N+2));
cudaMemcpy2DToArray(old, 0, 0, zero, zerop, sizeof(int)*(M+2), (N+2), cudaMemcpyDeviceToDevice);
cudaFree(zero);
cudaMemcpyArrayToArray(old, sizeof(int), 1, edge, 0, 0, sizeof(int)*N*M, cudaMemcpyDeviceToDevice);
cudaMalloc((void **) &buf3, sizeof(int)*(M+2)*(N+2));
cudaBindTextureToArray(oldtex, old);
cudaBindTextureToArray(edgetex, edge);
computeker<<<grid, block>>>(buf3);
cudaMemcpy(buf2, buf3, sizeof(int)*(M+2)*(N+2), cudaMemcpyDeviceToHost);
for(i=0;i<N+2;i++){
 for(j=0;j<M+2;j++){
�  printf("%d ", buf2[i][j]);
 }
 printf("\n");
}
cudaFreeArray(old);
cudaFreeArray(edge);
cudaFree(buf3);
}
It should output:
5 5 5 5 5 5 5
5 123 123 123 123 123 5
5 123 123 123 123 123 5
5 123 123 123 123 123 5
5 123 123 123 123 123 5
5 123 123 123 123 123 5
5 5 5 5 5 5 5
But instead I get:
84215045 84215045 123 123 123 84215045 84215045
84215045 123 123 123 123 84215045 84215045
84215045 123 123 123 123 84215045 84215045
84215045 123 123 123 123 84215045 84215045
84215045 123 123 123 123 84215045 84215045
84215045 123 123 123 84215045 84215045 84215045
84215045 123 123 123 84215045 84215045 84215045
Once again I apologise.
Thank you very much for any ideas