r/CUDA•
tykel

cuGraphicsResourceGetMappedPointer returning CUDA_ERROR_INVALID_CONTEXT

Hi, CUDA noob here.

I am using FFmpeg/libav to do video decoding using the NVDEC backend. The video decode in CUVID seems to be happening fine.

However, I am running into an error when stepping up to run a kernel to color-convert the decoded image to a D3D11 texture.

Here is the troublesome snippet, with error handling removed:

CUdeviceptr devptr;
size_t devptrSize;
ID3D11Resource *targetTex = GetScreenTexture();

cuCtxPushCurrent(ffCudaCtx);
cuGraphicsD3D11RegisterResource(&resource, targetTex, 0);
cuGraphicsResourceSetMapFlags(resource, CU_GRAPHICS_MAP_RESOURCE_FLAGS_READONLY);
cuGraphicsMapResources(1, &resource, ffCudaStream);
cuCtxSynchronize();
cuGraphicsResourceGetMappedPointer(&devptr, &devptrSize, resource);
// afterwards: kernel launch, unmap, ctx pop.

That last line is returning 201, CUDA_ERROR_INVALID_CONTEXT. I don't understand why, as the preceding calls all succeeded.

Thanks!

Posted Jan 10, 2020, 11:42 AM UTC

44
CATALUNA84•

Are you running this on Windows or Ubuntu? If you use the debugging tools in the Nvidia’s IDE, you can get more info about the memory mapped space and from there you can refer to the variable that causes the above

1
tykelOP•

This is on Windows 10.

1
CATALUNA84•

Sorry, no idea on the windows operating system

1
tykelOP•

It turns out that the CUDA resource I am obtaining is likely not mappable to a device pointer.

Instead, I replaced the cuGraphicsResourceGetMappedPointer call with

cuGraphicsSubresourceGetMappedArray(&array, resource, 0, 0);

and successfully accessed it as a CUarray in the kernel instead.

So I wonder if this isn't a CUDA driver API bug - shouldn't I have been getting 213, CUDA_ERROR_NOT_MAPPED_AS_POINTER ?

1