diff mbox

[FFmpeg-devel,5/6] avutil/hwcontext_cuda: explicitly synchronize cuMemcpy calls

Message ID 20180508133132.28940-5-timo@rothenpieler.org
State Accepted
Commit 9b82e333b7c4235a3de7ce8d8fe115c53c11f50c
Headers show

Commit Message

Timo Rothenpieler May 8, 2018, 1:31 p.m. UTC
---
 libavutil/hwcontext_cuda.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 8024eec79d..7f55881ba5 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -267,13 +267,19 @@  static int cuda_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
             .Height        = src->height >> (i ? priv->shift_height : 0),
         };
 
-        err = cu->cuMemcpy2D(&cpy);
+        err = cu->cuMemcpy2DAsync(&cpy, device_hwctx->stream);
         if (err != CUDA_SUCCESS) {
             av_log(ctx, AV_LOG_ERROR, "Error transferring the data from the CUDA frame\n");
             return AVERROR_UNKNOWN;
         }
     }
 
+    err = cu->cuStreamSynchronize(device_hwctx->stream);
+    if (err != CUDA_SUCCESS) {
+        av_log(ctx, AV_LOG_ERROR, "Error synchronizing CUDA stream\n");
+        return AVERROR_UNKNOWN;
+    }
+
     cu->cuCtxPopCurrent(&dummy);
 
     return 0;
@@ -306,13 +312,19 @@  static int cuda_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
             .Height        = src->height >> (i ? priv->shift_height : 0),
         };
 
-        err = cu->cuMemcpy2D(&cpy);
+        err = cu->cuMemcpy2DAsync(&cpy, device_hwctx->stream);
         if (err != CUDA_SUCCESS) {
-            av_log(ctx, AV_LOG_ERROR, "Error transferring the data from the CUDA frame\n");
+            av_log(ctx, AV_LOG_ERROR, "Error transferring the data to the CUDA frame\n");
             return AVERROR_UNKNOWN;
         }
     }
 
+    err = cu->cuStreamSynchronize(device_hwctx->stream);
+    if (err != CUDA_SUCCESS) {
+        av_log(ctx, AV_LOG_ERROR, "Error synchronizing CUDA stream\n");
+        return AVERROR_UNKNOWN;
+    }
+
     cu->cuCtxPopCurrent(&dummy);
 
     return 0;