Why it must call cuGraphicsUnregisterResource after cudaMemcpy from surfacebuffer to cuda memory

Hi,
My jetpack version: 5.1.2 and AGX Orin with 64G.
I mapped surfacebuffer to cuda memory then use cudaMemcpy to other cuda memory:

 if (-1 == NvBufSurfaceMapEglImage(surface_, 0)) {
    AERROR << "Failed to map surface.";
    return false;
  }
  
  auto eglImage = surface_->surfaceList[0].mappedAddr.eglImage;
  CUresult status;
  status = cuGraphicsEGLRegisterImage(&pResource_, eglImage,
                                      CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
  if (status != CUDA_SUCCESS) {
    AERROR << "cuGraphicsEGLRegisterImage failed: " << status
           << ", cuda process stop";
    return false;
  }

  status = cuGraphicsResourceGetMappedEglFrame(&eglFrame_, pResource_, 0, 0);
  if (status != CUDA_SUCCESS) {
    AERROR << "cuGraphicsSubResourceGetMappedArray failed";
    return false;
  }
  status = cuCtxSynchronize();
  if (status != CUDA_SUCCESS) {
    AERROR << "cuCtxSynchronize failed";
    return false;
  }
  gpu_address_ = static_cast<uint8_t*>(eglFrame_.frame.pPitch[0]);
  cuAssert(cudaMemcpy(gpu_address_, cuda_memory,
                      src.cols * src.rows * src.elemSize(),
                      cudaMemcpyDeviceToDevice));
  cuGraphicsUnregisterResource(pResource_);

Actually I want call cudaMemcpy multi-times, but everytime I call cudaMemcpy must followed with cuGraphicsUnregisterResource, otherwise it will lost image data.
Could you tell me the reason? And is there any better API to call?
Thanks!
BR/Tim

Hi,

cuGraphicsUnregisterResource is to release resources registered by the cuGraphicsEGLRegisterImage.
It isn’t used by cudaMemcpy.

Would you mind sharing a complete source code to reproduce the lost image data issue?
We want to check it further.

Thanks,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.