I want to use texture objects (not references) with doubles. The code below works when using floats, but double is not a supported data type.
Can I get around this using 2d textures and if so, how do I set up such a texture?
There is a similar question for texture references, but none for texture objects. Support for double type in texture memory in CUDA
__global__ void my_print(cudaTextureObject_t texObject)
{
printf("%f\n",tex1Dfetch<double>(texObject,0));
return;
}
int main()
{
double i = 0.35;
int numel = 50;
double* d_data;
cudaMalloc(&d_data,numel*sizeof(double));
cudaMemcpy((void*)d_data,&i,1*sizeof(double), cudaMemcpyHostToDevice);
cudaTextureDesc td;
memset(&td, 0, sizeof(td));
td.normalizedCoords = 0;
td.addressMode[0] = cudaAddressModeClamp;
td.readMode = cudaReadModeElementType;
struct cudaResourceDesc resDesc;
memset(&resDesc, 0, sizeof(resDesc));
resDesc.resType = cudaResourceTypeLinear;
resDesc.res.linear.devPtr = d_data;
resDesc.res.linear.sizeInBytes = numel*sizeof(double);
resDesc.res.linear.desc.f = cudaChannelFormatKindFloat;
resDesc.res.linear.desc.x = 32;
cudaTextureObject_t texObject = 0;
gpuErrchk(cudaCreateTextureObject(&texObject, &resDesc, &td, NULL));
my_print<<<1,1>>>(texObject);
gpuErrchk(cudaDeviceSynchronize());
return 0;
}