NvSciBuf with Cuda memory and NvMediaImage


i’m trying to fill NvMediaImage frame with my device-memory-frame.
I cannot use NvMediaImagePutBits since it supports only client memory.
So i decided to try my luck with NvSciBuf.
I’m want to create NvSciBuf object, get NvMediaImage from it using NvMediaImageCreateFromNvSciBuf and import the object as cuda external memory. And then copy my device-memory-frame into this imported cuda memory.
But it doesn’t work, i copy the frame, but NvMediaImage stays empty.

(too keep it small, it removed all the error checks here)

//init NvSciBuf
status = NvMediaImageNvSciBufInit();
err = NvSciBufModuleOpen(&m_sci_buf_module);

// fill initial list of attributes for current surface type
err = NvSciBufAttrListCreate(m_sci_buf_module, &attrlist);
NvMediaImageFillNvSciBufAttrs(m_device, surface_type, surf_alloc_attrs,
num_surf_alloc_attrs, 0, attrlist);

// fill additional attributes
cuResult = cuDeviceGetUuid(&uuid, 0);
gpuId[0] = (uint64_t)uuid.bytes;
NvSciBufAttrValAccessPerm perm = NvSciBufAccessPerm_ReadWrite;
NvSciBufAttrKeyValuePair rawbuffattrs = {
{NvSciBufGeneralAttrKey_RequiredPerm, &perm, sizeof(perm)},
//{ NvSciBufRawBufferAttrKey_Size, &rawsize, sizeof(rawsize) },
{NvSciBufGeneralAttrKey_GpuId, &gpuId, sizeof(gpuId)}};

// add addditional attributes, reconsile them and create NvSciBuf object
err = NvSciBufAttrListSetAttrs(attrlist, rawbuffattrs, 2);
err = NvSciBufAttrListReconcileAndObjAlloc(&attrlist, 1, &m_buf_object, &conflictlist);

// create NvMediaImage from buffer object
status = NvMediaImageCreateFromNvSciBuf(m_device, m_buf_object, &m_image_frame);

// import buffer as cuda external memory
cudaExternalMemoryHandleDesc memHandleDesc;
memset(&memHandleDesc, 0, sizeof(memHandleDesc));
memHandleDesc.type = cudaExternalMemoryHandleTypeNvSciBuf;
memHandleDesc.handle.nvSciBufObject = m_buf_object;
memHandleDesc.size = width*height;
cudaImportExternalMemory(&m_cuda_external_memory_buffer, &memHandleDesc);
m_cuda_external_memory_buffer_initialised = true;

cudaExternalMemoryBufferDesc bufferDesc;
memset(&bufferDesc, 0, sizeof(bufferDesc));
bufferDesc.offset = 0;
bufferDesc.size = widthheight;
cudaExternalMemoryGetMappedBuffer(&dev_pointer, m_cuda_external_memory_buffer, &bufferDesc);
m_cuda_frame = static_caststd::uint8_t*(dev_pointer);

// and finally copy frame into cuda external memory
cudaMemcpy(output_frame, input_frame,
width * height),

I checked the content of m_image_frame by encoding and by simple NvMediaImageGetBits, but in both cases i saw the empty frame (everything was 0x00)