Copying device memory into texture memory

Hi I was wondering if there is an easy way to copy device memory directly into texture memory?

So I have an image I am working on via cuda kernels to preform different operations. Currently the output is being placed into an array in the following format:

__device__ ushort *image;

So is there anyway that I can easily transfer it to a texture memory, which I have in the following format:

texture<ushort, 2, cudaReadModeElementType> texImage;
cudaChannelFormatDesc descTexImage = cudaCreateChannelDesc<ushort>();

Any assistance or direction would be greatly appreciated

The usual approach is to map a texture to existing storage using cudaBindTexture(), no need to copy data.

Hi, thank you for the reply, I have tried that and am stuck at getting it to work, I mean it runs with no errors, but the output is not what is expected.

Currently all my texture data is being read as 0.

Data Declarations:

texture<ushort, 2, cudaReadModeElementType> texImage;
cudaChannelFormatDesc descTexImage = cudaCreateChannelDesc<ushort>();

ushort *host_Image;
__device__ ushort *dev_Image;

int imageW;
int imageH;

I am doing the following:

cudaBindTexture2D(0, texImage, host_Image, descTexImage, 
                        imageW, imageH, imageW*sizeof(ushort));

This is after I link the host_Image ptr to the device image ptr

cudaMalloc((void**)&host_Image, imageW * imageH * sizeof(ushort));
cudaMemcpyToSymbol(dev_Image, &host_Image, sizeof(imageW * imageH * sizeof(ushort)));

I am accessing the Data via:

ushort pixel = tex2D(texImage, x, y);

Thanks

Don’t forget to add an offset of 0.5 to x-coordinate (to get the center of the pixel).
see cuda - Texture memory-tex2D basics - Stack Overflow
here is an working example with texture obejcts
http://devblogs.nvidia.com/parallelforall/cuda-pro-tip-kepler-texture-objects-improve-performance-and-flexibility/