From e77e6fd4a700b1ac32275850d3e2fe6243d03fd7 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Sun, 5 Feb 2023 20:00:04 +0900 Subject: [PATCH] cudamemory: Skip sync if no I/O operation happend on free() Synchronization for unused memory is not required Part-of: --- .../gst-plugins-bad/gst-libs/gst/cuda/gstcudamemory.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudamemory.cpp b/subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudamemory.cpp index 64578d6ed9..a813428b07 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudamemory.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/cuda/gstcudamemory.cpp @@ -56,6 +56,8 @@ struct _GstCudaMemoryPrivate /* Per plane, and point/linear sampling textures respectively */ CUtexObject texture[GST_VIDEO_MAX_PLANES][2]; + + gboolean saw_io = FALSE; }; /* *INDENT-ON* */ @@ -251,7 +253,7 @@ gst_cuda_allocator_free (GstAllocator * allocator, GstMemory * memory) gst_cuda_context_push (mem->context); /* Finish any pending operations before freeing */ - if (priv->stream && + if (priv->stream && priv->saw_io && GST_MEMORY_FLAG_IS_SET (mem, GST_CUDA_MEMORY_TRANSFER_NEED_SYNC)) { CuStreamSynchronize (gst_cuda_stream_get_handle (priv->stream)); } @@ -383,6 +385,8 @@ cuda_mem_map (GstMemory * mem, gsize maxsize, GstMapFlags flags) std::lock_guard < std::mutex > lk (priv->lock); + priv->saw_io = TRUE; + if ((flags & GST_MAP_CUDA) == GST_MAP_CUDA) { if (!gst_cuda_memory_upload (self, cmem)) return nullptr;