nvcodec: Peer direct access support
authorSeungha Yang <seungha.yang@navercorp.com>
Wed, 16 Oct 2019 13:21:05 +0000 (22:21 +0900)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 16 Oct 2020 15:56:49 +0000 (15:56 +0000)
If support direct access each other, use device to device memory copy
without staging host memory

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1633>

sys/nvcodec/gstnvbaseenc.c
sys/nvcodec/gstnvdec.c

index 2b780f1..34bbffa 100644 (file)
@@ -2450,10 +2450,12 @@ gst_nv_base_enc_handle_frame (GstVideoEncoder * enc, GstVideoCodecFrame * frame)
         gst_is_cuda_memory (mem)) {
       GstCudaMemory *cmem = GST_CUDA_MEMORY_CAST (mem);
 
-      /* FIXME: enhance CUDA memory copy over multiple-gpu */
       if (cmem->context == nvenc->cuda_ctx ||
           gst_cuda_context_get_handle (cmem->context) ==
-          gst_cuda_context_get_handle (nvenc->cuda_ctx)) {
+          gst_cuda_context_get_handle (nvenc->cuda_ctx) ||
+          (gst_cuda_context_can_access_peer (cmem->context, nvenc->cuda_ctx) &&
+              gst_cuda_context_can_access_peer (nvenc->cuda_ctx,
+                  cmem->context))) {
         use_device_memory = TRUE;
         in_map_flags |= GST_MAP_CUDA;
       }
index b67bdbe..039ee13 100644 (file)
@@ -1151,10 +1151,12 @@ gst_nvdec_copy_device_to_memory (GstNvDec * nvdec,
       gst_is_cuda_memory (mem)) {
     GstCudaMemory *cmem = GST_CUDA_MEMORY_CAST (mem);
 
-    /* FIXME: enhance CUDA memory copy over multiple-gpu */
     if (cmem->context == nvdec->cuda_ctx ||
         gst_cuda_context_get_handle (cmem->context) ==
-        gst_cuda_context_get_handle (nvdec->cuda_ctx)) {
+        gst_cuda_context_get_handle (nvdec->cuda_ctx) ||
+        (gst_cuda_context_can_access_peer (cmem->context, nvdec->cuda_ctx) &&
+            gst_cuda_context_can_access_peer (nvdec->cuda_ctx,
+                cmem->context))) {
       cuda_mem = cmem;
     }
   }