First, I’ll give a general description of my problem. In my application I have a 1D float texture of length n. This texture is called “depthBufferTex_d”. This texture is bound to a 1D cudaArray called “cu_array.” I also have a 1D float array in global memory of length n. This is called “depthBufferGlobal_d”. After every kernel call, I want to take the values stored in “depthBufferGlobal_d”, and put them in “depthBufferTex_d”. Does anyone know how to do this?
So far I have tried two approaches, but have had no luck.
I have my texture declared at file scope as follows:
[codebox]texture<float, 1, cudaReadModeElementType> depthBufferTex_d;[/codebox]
Here is the first way I am trying to do this. I am using a “device to device” copy.
[codebox]host
void swapBuffers1( float* depthBufferGlobal_d, int width, int height, cudaArray* cu_array ){
//First, unbind the texture
cudaUnbindTexture( depthBufferTex_d );
//Copy data from device to device
cudaMemcpyToArray( cu_array , 0 , 0 , gData , width * height * sizeof(float) , cudaMemcpyDeviceToDevice );
//Now, finally, rebind the texture
cudaBindTextureToArray(depthBufferTex_d , cu_array );
}[/codebox]
The second way I am trying to do this has me copying data from the device back to the host, and then from the host back onto the device again! It still doesn’t work though :(
[codebox]host
void swapBuffers2( float* depthBufferGlobal_d, int width, int height, cudaArray* cu_array ){
//First, unbind the texture
cudaUnbindTexture( depthBufferTex_d );
//Copy the buffer from global mem to the texture array
//
// First, copy back to the host
// Next, copy from host to texture
// then, deallocate host memory
//Allocate space on host
float* depthBuffer_temp_h;
depthBuffer_temp_h = (float*) malloc( sizeof(float) * width * height );
//Copy from device->host
cudaMemcpy( depthBuffer_temp_h , depthBufferGlobal_d , sizeof(float) * width * height , cudaMemcpyDeviceToHost );
//Copy from host->device
cudaMemcpyToArray( cu_array , 0 , 0 , depthBuffer_temp_h , sizeof(float)*width*height , cudaMemcpyHostToDevice );
//Free host mem
free( depthBuffer_temp_h );
//Now, finally, rebind the textuer
cudaBindTextureToArray(depthBufferTex_d , cu_array );
}[/codebox]
Note that I am using CUDA 2.2 on Windows XP with a GTX 280 and 4GB of RAM.
Also, I want to say thanks to the people who post on the forum regularly, this place is a great source of CUDA knowledge.
~Colin