I only have a single .cu file.
I have declared texture as global and static and outside main{} function as:-
static texture<float,3,cudaReadModeElementType> tex;
Now inside main i have loaded a 3D Binary Image in a 1D array(h_image) in host memory and then copied it into the device memory using following code.
//To Load the Same Image in Device Memory in cudaArray.
cudaArray* d_image;
// setup texture dimension
cudaExtent extent;
extent.width = width;
extent.height = height;
extent.depth = depth;
// texture channel descriptor
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc();
// memory allocation for texture, on GPU, allocates GPU memory as 3D cuda memory
cudaMalloc3DArray(&d_image, &channelDesc, extent);
// copy from host memory to device memory
cudaMemcpy3DParms copyParams = {0};
copyParams.srcPtr = make_cudaPitchedPtr((void*)h_image, height*sizeof(float), height, depth);
copyParams.dstArray = d_image;
copyParams.extent = extent;
copyParams.kind = cudaMemcpyHostToDevice;
//copy from host memory to device memory
safecall( cudaMemcpy3D(©Params), “cudaMemcpy3D” );
// set texture parameters
tex.normalized = true;
tex.filterMode = cudaFilterModeLinear;
tex.addressMode[0] = cudaAddressModeWrap;
tex.addressMode[1] = cudaAddressModeWrap;
tex.addressMode[2] = cudaAddressModeWrap;
// bind cudaArray to the texture
cudaBindTextureToArray(tex, d_image,channelDesc);
cuda_kernel<<<64,64*64>>>();
NOW
The code compiles but when i run it it gives me error as “invalid texture reference.”
I dont know what am i doing wrong here.
I am loading 3D image into 1D array in host then copying it into device. Are my steps correct for this?
Also we can directly fetch values from cudaArray (i read it in this forum iteself), so we have to bind it to texture so i was trying to do the same and its the same thing giving error. What is wrong here?
Also after binding, i am confused about how do i write my kernel to loop through the values in the texture.?
Please help me, i am stuck here.