1D texture


texture<int, 1, cudaReadModeElementType> cenTex;

cudaArray *d_centerArray = 0;

// create 1D array
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc();

CUDA_SAFE_CALL( cudaMallocArray(&d_centerArray, &channelDesc, 3*size, 1) );
printf("create cuda array: %s\n", cudaGetErrorString(cudaGetLastError()));

cudaMemcpyToArray(d_centerArray, 0, 0, h_cenList, 3*size*sizeof(int), cudaMemcpyHostToDevice);

// bind array to 1D texture
CUDA_SAFE_CALL(cudaBindTextureToArray(cenTex, d_centerArray, channelDesc));

The error is: create cuda array: invalid argument


If I want to use 1D texture, I also can use 2D texture with height = 1. Which one is better?

If you don’t need filtering or normalized coordinates, 1D textures with tex1Dfetch are superior.

  1. You can address larger textures (up to 2^27 elements)

  2. You can bind the texture directly to device memory without copies to intermediate cudaArrays


I will use 1D texture. Another question is If I use texture, all the threads share the cache? IF it does, do I need to use share memory?