I allocated one big chunk of memory using cudaMalloc() and I partioned/divided that into some parts…
When I bind one of the sub part of the memory by using cudaBindTexture() API, it is returning cudaErrorInvalidValue.
Below is the code…
[b]unsigned char* gpuMem=NULL;
cudaMalloc( (void**)&gpuMem, 10KB); // allocated 10 Kilo Bytes memory
unsigned short int* partOfGpuMem = (unsigned short int*)(gpuMem+2KB); // 2 kilo bytes is the offset
cudaError error = cudaBindTexture( 0, texHandle, partOfGpuMem, sizeof(unsigned short int)*srcW ); // Here srcW is 800 [/b]
Here error is cudaErrorInvalidValue.
I searched for this on internet, I found the usgae of cudaBindTexture() link
After that, I changed the code like below…
cudaError error = cudaBindTexture( &offset, texHandle, partOfGpuMem, sizeof(unsigned short int)*srcW ); // Here srcW is 800
Here, “error” is cudaErrorInvalidValue and “offset” is 128.
The below is the discription of cudaBindTexture() from the above link
Since the hardware enforces an alignment requirement on texture base addresses, cudaBindTexture() returns in *offset a byte offset that must be applied to texture fetches in order to read from the desired memory. This offset must be divided by the texel size and passed to kernels that read from the texture so they can be applied to the tex1Dfetch() function
But Im not getting how to use “offset” in fetching and what is “texel size” and why I should devide offesrt by the texel size.
please help me on how to use the “offset” in texture fetching?.