I have a question on how to define texture memory properly.
In the host memory, I have a float array and a point 2Darray, where each point is composed of a (x, y, z, w) struct.
I define the texture as:
texture<float, 1, cudaReadModeElementType> tex_U;
texture<float4, 2, cudaReadModeElementType> tex_p;
In the host function, I define the texture to get a copy of the float array:
cudaChannelFormatDesc channelDescU = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaArray* cu_arrayU;
CUDA_SAFE_CALL( cudaMallocArray( &cu_arrayU, &channelDescU, n, 1 ));
CUDA_SAFE_CALL( cudaMemcpyToArray( cu_arrayU, 0, 0, U, U_mem_size, cudaMemcpyHostToDevice));
// set texture parameters
tex_U.addressMode[0] = cudaAddressModeWrap;
tex_U.filterMode = cudaFilterModePoint;
tex_U.normalized = false;
// Bind the array to the texture
CUDA_SAFE_CALL( cudaBindTextureToArray( tex_U, cu_arrayU, channelDescU));
I also define the texture to get a copy of the point 2D array:
cudaChannelFormatDesc channelDescP = cudaCreateChannelDesc();
cudaArray* cu_arrayP;
CUDA_SAFE_CALL( cudaMallocArray( &cu_arrayP, &channelDescP, n, m ));
CUDA_SAFE_CALL( cudaMemcpyToArray( cu_arrayP, 0, 0, P, p_mem_size, cudaMemcpyHostToDevice));
// set texture parameters
tex_p.addressMode[0] = cudaAddressModeWrap;
tex_p.addressMode[1] = cudaAddressModeWrap;
tex_p.filterMode = cudaFilterModePoint;
tex_p.normalized = false;
// Bind the array to the texture
CUDA_SAFE_CALL( cudaBindTextureToArray( tex_p, cu_arrayP, channelDescPole));
When I tried to access these texture in a global function:
tex1D(tex_U, 1.0f);
tex2D(tex_p, 1.0f, 1.0f);
They throw cudaError and all the threads quit in the device simulation mode.
I guess I did not define the texture correctly. How to define it? Thank you,