Loading...
Texture memory
Mon, 10/11/2010 - 04:05
Hi all,
I have a question on how to use texture memory in the context I will describe below:
I have a structure:
typedef struct {
double x;
double y;
double z;
} VecR;
I want to use the texture memory for a vector of elements VecR.
The size of the vector of VecR elements is N.
Is it correct to use the texture like this:
int widthTex = ceil(sqrt(N));
texture<double, 2, cudaReadModeElementType> texCoord;
texCoord.addressMode[0] = cudaAddressModeClamp;
texCoord.addressMode[1] = cudaAddressModeClamp;
texCoord.filterMode = cudaFilterModePoint;
texCoord.normalized = false;
cudaChannelFormatDesc channelDesc_V;
channelDesc_V = cudaCreateChannelDesc<double>();
// coordDev is a vector of N elements of type VecR which resides on the device memory
cudaArray *coordCuArray;
cudaMallocArray (&coordCuArray, &channelDesc_V, 3*widthTex, widthTex);
cudaMemcpyToArray(coordCuArray, 0, 0, coordDev, sizeof(VecR)*(N), cudaMemcpyDeviceToDevice);
cudaBindTextureToArray (texCoord, coordCuArray, channelDesc_V );
and then for retrieving the elements of VecR of the element index of the vector (coordDev[index]):
VecR temp;
temp.x = tex2D(texCoord, (index)%(3*widthTex), index/widthTex);
temp.y = tex2D(texCoord, (index+1)%(3*widthTex), index/widthTex);
temp.z = tex2D(texCoord, (index+2)%(3*widthTex), index/widthTex);
I cannot even compile using texture memory like this. How can I do to resolve my problem?
Does anyone have any idea for that?
Thank you in advance,
Ardita

BayWebSoft
The problem here is "double". The GPU's texture mapping hardware currently only supports "float". As of CUDA 3.1, the headers don't even have overloads for "double" datatypes stored in textures, so I don't think this feature will be coming soon.
You can either switch the computation to "float", or access your "double" data via pointers instead of textures.