Can NPP be safely used in multi-threaded code?

Question 1)
I tried using NPP in a program with several CPU threads and NPP returns unexpected results in some cases. Is there a way to use NPP safely in multi-threaded code?

Question 2)
If we use NPP in a program with several CPU threads and call the following function in each CPU thread:

void function X( cudaStream_t hStream )
{
nppSetStream( hStream ) ;

nppDoSomething(…) ; // Calling an NPP function.
}

Does NPP get the connection between CPU-Thread and the CUDA-Stream? Or if the active CPU thread changes between execution of “SetStream” and “DoSmt” everything gets mixed up?

Thank You.

Hi there.

NPP is currently not thread safe. There are two issues. The first is the way we implemented the Stream support. NPP holds a single unprotected global variable for the stream it is sending its kernel invocations to. That means, that any setStream-doSomething code would need to be in a critical section.

The second issue is, that we are internally using textures for some primitives (very few and we’re in the process of completely eliminating texture use inside of NPP). Because of the way textures were originally exposed in CUDA (global static variables), using such a texture-based primitive from different threads will likely cause one thread interferring with the other.

We are adressing issue 1 (global stream variable) in the upcoming 5.5 release. The stream variable is going to become a thread-local variable. This should address most of the multi-threading issues of previous releases.

Hello Frank,

Thank you very much. Can you give an estimation for when version 5.5 will be released?

did u solve your issue?