cudaMemcpy: invalid argument when retrieving raw image

Please provide complete information as applicable to your setup.

**• Jetson Xavier **
• Deepstream version 6.0.1
• Jetpack version 4.6.2
**• TensorRT Version 8.5.1.7 **
• Issue Type bugs

I’m trying to retrieve the raw image in C++, in order to do that I get the image pointer and I copy the raw image from GPU to CPU, however cudaMemcpy returns invalid argument. Hence I was wondering if params.dataPtr is indeed the address in the GPU space and if cudaMemcpy is appropriate for that use?

I put the following probe on the tracker sink pad in order to retrieve the image:

GstPadProbeReturn retrieve_image (GstPad * pad, GstPadProbeInfo * info,
    gpointer u_data) {  
  GstBuffer* inbuf = (GstBuffer *) info->data;

  GstMapInfo in_map_info;
  NvBufSurface* surface = NULL;

  memset (&in_map_info, 0, sizeof (in_map_info));
  if (!gst_buffer_map (inbuf, &in_map_info, GST_MAP_READ)) {
      g_print ("Error: Failed to map gst buffer\n");
      return -1;
  }
  
  surface = (NvBufSurface *) in_map_info.data;
  
  size_t offset = 0;
  for(size_t i = 0; i < surface->batchSize; ++i) {
    cJSON* image = cJSON_CreateObject();
    NvBufSurfaceParams params = surface->surfaceList[i];
    
    void* shared_mem = malloc(params.dataSize);
  
    cudaError_t error = cudaMemcpy(shared_mem + offset, params.dataPtr, params.dataSize, cudaMemcpyDeviceToHost);

    const char * errstr = cudaGetErrorString(error);
    
    offset += params.dataSize;
    
    free(shared_mem);
  }
  return GST_PAD_PROBE_OK;  
}

Please upgrade to the latest DeepStream 6.3 GA

Please refer to DeepStream SDK FAQ - Intelligent Video Analytics / DeepStream SDK - NVIDIA Developer Forums for how to get video data from NvBufSurface

Thanks,

in the end I used the following in order to get the raw image in the CPU:

  NvBufSurfaceMap (surface, -1, -1, NVBUF_MAP_READ);
  NvBufSurfaceSyncForCpu (surface, 0, 0);
  void* addr = surface->surfaceList[0].mappedAddr.addr[0];

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