Async video encoding using NvEnc / cuda from a GL PBO


I have an application writing to a double buffered pixel buffer object. I want to encode the pbo to a h264 frame.
Is it possible to do this in a seperate thread? I am following the Encoding samples from the SDK, especially the cuda interop stuff. I register my PBOs using ‘cuGraphicsGLRegisterBuffer’ in the main thread. When trying to call ‘cuGraphicsMapResources’ from the encoding thread I get an error (Driver API error = 0219 “CUDA_ERROR not found”); the encoding thread ‘knows’ which of the two buffers to use (tested this with writing images to disk).

Is it even possible to do this asynchronously? My PBOs are created with the persistant flag, is it possible to use the persistant mapped pointer to feed the NvEnc encoder? Is it possible to map the resources once in the main thread and use the mapped pointers in the encoding thread?

Thanks for any hints