Files
ffmpeg/libavfilter
Raja-89 09bf8dab5b avfilter/dnn: implement zero-copy CUDA tensor mapping for Torch backend
When a CUDA frame with a supported RGB sw_format is received, map the
GPU device pointer directly into a LibTorch tensor using
torch::from_blob() with CUDA device options, bypassing cudaMemcpy
entirely.

Changes:

 - Add fill_model_input_cuda() that extracts the CUdeviceptr from the
   AVHWFramesContext and wraps it in a PyTorch GPU tensor with a no-op
   deleter (memory owned by FFmpeg AVBuffer ref-counting).
 - Handle GPU memory alignment padding via custom strides derived from
   AVFrame linesize.
 - Permute the mapped NHWC tensor to NCHW (PyTorch convention).
 - Manage CUDA context explicitly with cuCtxPushCurrent/cuCtxPopCurrent
   for thread safety in async filter graphs.
 - Implement zero-copy Device-to-Device output mapping that writes the
   model result directly into the output frame's VRAM, bypassing
   ff_proc_from_dnn_to_frame / sws_scale entirely for CUDA frames.
 - Add torch::cuda::synchronize() to prevent async race conditions
   with downstream encoders (e.g. NVENC reading uninitialized frames).
 - Add format validation in ff_dnn_zero_copy_supported_cuda() to reject
   unsupported sw_formats and batching with CUDA zero-copy early.
 - Register AV_PIX_FMT_CUDA in vf_dnn_processing pixel format list.
 - Gracefully fall back to CPU path when sw_format is not a supported
   RGB variant or when CONFIG_CUDA is not enabled.

Signed-off-by: Raja-89 <imraja729@gmail.com>
2026-08-09 02:13:24 +00:00
..
2025-08-03 13:48:47 +02:00
2025-08-03 13:48:47 +02:00
2026-07-13 18:16:18 +00:00
2025-12-14 12:41:00 +05:30
2025-08-03 13:48:47 +02:00
2026-07-13 18:16:18 +00:00
2025-08-03 13:48:47 +02:00
2025-08-03 13:48:47 +02:00
2025-08-03 13:48:47 +02:00
2025-10-16 18:41:19 +02:00
2026-05-15 20:29:29 +02:00
2026-05-15 20:29:29 +02:00
2025-08-03 13:48:47 +02:00
2025-08-03 13:48:47 +02:00