NPP and CUDA Kernel interop

Hey all,

I would like to write a CUDA kernel that operates on an NPP primitive, so lets say I’ve loaded an image from file like from the examples:

[codebox] // declare a host image object for an 8-bit grayscale image

npp::ImageCPU_8u_C1 oHostSrc;

        // load gray-scale image from disk

npp::loadImage(sFilename, oHostSrc);

        // declara a device image and copy construct from the host image,

        // i.e. upload host to device

npp::ImageNPP_8u_C1 oDeviceSrc(oHostSrc);[/codebox]

Now the image is uploaded to the GPU. I would now like to have a CUDA kernel (in .cu file), that operates on the image, preferably using texture lookups (tex2D). I can’t see how I can get a relevant handle on the uploaded image from the NPP interfaces & the examples don’t appear to show anything like that. Maybe I’m missing a trick…

Thanks in advance,


Hi James,

what you’d do is you simply bind the image data (the image class has an accessor method to the GPU global memory data pointer) to a texture object:


texture hTexture;

size_t nTexOffset;

cudaBindTexture(&nTexOffset, hTexture, pSrc, nSrcStep * oSizeROI.height)


In this example I’m binding to a 1D texture, 2D texture works similarly. The CUDA Programming Guide has information on the details.

You can then use that hTexture handle inside your kernel code for sampling from that texture.


Brilliant, thanks again Frank!