[FFmpeg-devel] [PATCH] avcodec/nvenc: remove useless context pop

2021-09-08 Thread leozhang
Signed-off-by: leozhang 
---
 libavcodec/nvenc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index ae25afd7f8..fdf06d6102 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -607,9 +607,6 @@ static av_cold int nvenc_check_device(AVCodecContext 
*avctx, int idx)
 ctx->cu_context = ctx->cu_context_internal;
 ctx->cu_stream = NULL;
 
-if ((ret = nvenc_pop_context(avctx)) < 0)
-goto fail2;
-
 if ((ret = nvenc_open_session(avctx)) < 0)
 goto fail2;
 
-- 
2.28.0.windows.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH] avcodec/nvenc: remove useless context pop

2021-09-08 Thread leozhang
Signed-off-by: leozhang 
---
 libavcodec/nvenc.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index ae25afd7f8..fdf06d6102 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -607,9 +607,6 @@ static av_cold int nvenc_check_device(AVCodecContext 
*avctx, int idx)
 ctx->cu_context = ctx->cu_context_internal;
 ctx->cu_stream = NULL;
 
-if ((ret = nvenc_pop_context(avctx)) < 0)
-goto fail2;
-
 if ((ret = nvenc_open_session(avctx)) < 0)
 goto fail2;
 
-- 
2.28.0.windows.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2] avcodec/cuviddec: fix CUDA_ERROR_INVALID_CONTEXT error found by cuda-memcheck tool

2020-11-19 Thread leozhang
Test command like below:
cuda-memcheck ./ffmpeg -hwaccel cuvid -c:v h264_cuvid -i input_file -c:v 
h264_nvenc -f null -

Signed-off-by: leozhang 
---
 libavcodec/cuviddec.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 5e698d4cd0..61d7f36c79 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -673,15 +673,22 @@ static int cuvid_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 static av_cold int cuvid_decode_end(AVCodecContext *avctx)
 {
 CuvidContext *ctx = avctx->priv_data;
+AVHWDeviceContext *device_ctx = (AVHWDeviceContext *)ctx->hwdevice->data;
+AVCUDADeviceContext *device_hwctx = device_ctx->hwctx;
+CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
 
 av_fifo_freep(>frame_queue);
 
+ctx->cudl->cuCtxPushCurrent(cuda_ctx);
+
 if (ctx->cuparser)
 ctx->cvdl->cuvidDestroyVideoParser(ctx->cuparser);
 
 if (ctx->cudecoder)
 ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
 
+ctx->cudl->cuCtxPopCurrent();
+
 ctx->cudl = NULL;
 
 av_buffer_unref(>hwframe);
-- 
2.11.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avcodec/cuviddec: fix CUDA_ERROR_INVALID_CONTEXT error found by cuda-memcheck tool

2020-11-19 Thread leozhang
Timo Rothenpieler  于2020年11月20日周五 上午12:29写道:
>
> On 18.11.2020 09:24, leozhang wrote:
> > Test command like below:
> > cuda-memcheck ./ffmpeg -hwaccel cuvid -c:v h264_cuvid -i input_file -c:v 
> > h264_nvenc -f null -
> >
> > Signed-off-by: leozhang 
> > ---
> >   libavcodec/cuviddec.c | 15 +++
> >   1 file changed, 15 insertions(+)
> >
> > diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
> > index 5e698d4cd0..816a9c1b3c 100644
> > --- a/libavcodec/cuviddec.c
> > +++ b/libavcodec/cuviddec.c
> > @@ -673,15 +673,27 @@ static int cuvid_decode_frame(AVCodecContext *avctx, 
> > void *data, int *got_frame,
> >   static av_cold int cuvid_decode_end(AVCodecContext *avctx)
> >   {
> >   CuvidContext *ctx = avctx->priv_data;
> > +AVHWDeviceContext *device_ctx = (AVHWDeviceContext 
> > *)ctx->hwdevice->data;
> > +AVCUDADeviceContext *device_hwctx = device_ctx->hwctx;
> > +CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
> > +int ret;
> >
> >   av_fifo_freep(>frame_queue);
> >
> > +ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
> > +if (ret < 0)
> > +goto error;
> > +
> >   if (ctx->cuparser)
> >   ctx->cvdl->cuvidDestroyVideoParser(ctx->cuparser);
> >
> >   if (ctx->cudecoder)
> >   ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
> >
> > +ret = CHECK_CU(ctx->cudl->cuCtxPopCurrent());
> > +if (ret < 0)
> > +goto error;
>
> This will cause it to leak all other resources in case Push/Pop fails
> for some reason, which is very much not ideal.
Good catch! I will fix it.
>
> I'd probably just leave all CUDA calls unchecked here. Or check them,
> but ignore the result and just go on anyway.
> Nothing sensible to be done when stuff fails on uninit anyway.
>
> >   ctx->cudl = NULL;
> >
> >   av_buffer_unref(>hwframe);
> > @@ -693,6 +705,9 @@ static av_cold int cuvid_decode_end(AVCodecContext 
> > *avctx)
> >   cuvid_free_functions(>cvdl);
> >
> >   return 0;
> > +
> > +error:
> > +return ret;
> >   }
> >
> >   static int cuvid_test_capabilities(AVCodecContext *avctx,
> >
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avcodec/cuviddec: fix CUDA_ERROR_INVALID_CONTEXT error found by cuda-memcheck tool

2020-11-18 Thread leozhang
Test command like below:
cuda-memcheck ./ffmpeg -hwaccel cuvid -c:v h264_cuvid -i input_file -c:v 
h264_nvenc -f null -

Signed-off-by: leozhang 
---
 libavcodec/cuviddec.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c
index 5e698d4cd0..816a9c1b3c 100644
--- a/libavcodec/cuviddec.c
+++ b/libavcodec/cuviddec.c
@@ -673,15 +673,27 @@ static int cuvid_decode_frame(AVCodecContext *avctx, void 
*data, int *got_frame,
 static av_cold int cuvid_decode_end(AVCodecContext *avctx)
 {
 CuvidContext *ctx = avctx->priv_data;
+AVHWDeviceContext *device_ctx = (AVHWDeviceContext *)ctx->hwdevice->data;
+AVCUDADeviceContext *device_hwctx = device_ctx->hwctx;
+CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
+int ret;
 
 av_fifo_freep(>frame_queue);
 
+ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
+if (ret < 0)
+goto error;
+
 if (ctx->cuparser)
 ctx->cvdl->cuvidDestroyVideoParser(ctx->cuparser);
 
 if (ctx->cudecoder)
 ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
 
+ret = CHECK_CU(ctx->cudl->cuCtxPopCurrent());
+if (ret < 0)
+goto error;
+
 ctx->cudl = NULL;
 
 av_buffer_unref(>hwframe);
@@ -693,6 +705,9 @@ static av_cold int cuvid_decode_end(AVCodecContext *avctx)
 cuvid_free_functions(>cvdl);
 
 return 0;
+
+error:
+return ret;
 }
 
 static int cuvid_test_capabilities(AVCodecContext *avctx,
-- 
2.11.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH v2] nv-codec-headers: add cuMemcpy

2020-11-15 Thread leozhang
Signed-off-by: leozhang 
---
 include/ffnvcodec/dynlink_cuda.h   | 2 ++
 include/ffnvcodec/dynlink_loader.h | 4 
 2 files changed, 6 insertions(+)

diff --git a/include/ffnvcodec/dynlink_cuda.h b/include/ffnvcodec/dynlink_cuda.h
index 117fdc5..baafa49 100644
--- a/include/ffnvcodec/dynlink_cuda.h
+++ b/include/ffnvcodec/dynlink_cuda.h
@@ -365,6 +365,8 @@ typedef CUresult CUDAAPI tcuMemAlloc_v2(CUdeviceptr *dptr, 
size_t bytesize);
 typedef CUresult CUDAAPI tcuMemAllocPitch_v2(CUdeviceptr *dptr, size_t 
*pPitch, size_t WidthInBytes, size_t Height, unsigned int ElementSizeBytes);
 typedef CUresult CUDAAPI tcuMemsetD8Async(CUdeviceptr dstDevice, unsigned char 
uc, size_t N, CUstream hStream);
 typedef CUresult CUDAAPI tcuMemFree_v2(CUdeviceptr dptr);
+typedef CUresult CUDAAPI tcuMemcpy(CUdeviceptr dst, CUdeviceptr src, size_t 
bytesize);
+typedef CUresult CUDAAPI tcuMemcpyAsync(CUdeviceptr dst, CUdeviceptr src, 
size_t bytesize, CUstream hStream);
 typedef CUresult CUDAAPI tcuMemcpy2D_v2(const CUDA_MEMCPY2D *pcopy);
 typedef CUresult CUDAAPI tcuMemcpy2DAsync_v2(const CUDA_MEMCPY2D *pcopy, 
CUstream hStream);
 typedef CUresult CUDAAPI tcuGetErrorName(CUresult error, const char** pstr);
diff --git a/include/ffnvcodec/dynlink_loader.h 
b/include/ffnvcodec/dynlink_loader.h
index b9995c3..85aebf4 100644
--- a/include/ffnvcodec/dynlink_loader.h
+++ b/include/ffnvcodec/dynlink_loader.h
@@ -152,6 +152,8 @@ typedef struct CudaFunctions {
 tcuMemAllocPitch_v2 *cuMemAllocPitch;
 tcuMemsetD8Async *cuMemsetD8Async;
 tcuMemFree_v2 *cuMemFree;
+tcuMemcpy *cuMemcpy;
+tcuMemcpyAsync *cuMemcpyAsync;
 tcuMemcpy2D_v2 *cuMemcpy2D;
 tcuMemcpy2DAsync_v2 *cuMemcpy2DAsync;
 tcuGetErrorName *cuGetErrorName;
@@ -290,6 +292,8 @@ static inline int cuda_load_functions(CudaFunctions 
**functions, void *logctx)
 LOAD_SYMBOL(cuMemAllocPitch, tcuMemAllocPitch_v2, "cuMemAllocPitch_v2");
 LOAD_SYMBOL(cuMemsetD8Async, tcuMemsetD8Async, "cuMemsetD8Async");
 LOAD_SYMBOL(cuMemFree, tcuMemFree_v2, "cuMemFree_v2");
+LOAD_SYMBOL(cuMemcpy, tcuMemcpy, "cuMemcpy");
+LOAD_SYMBOL(cuMemcpyAsync, tcuMemcpyAsync, "cuMemcpyAsync");
 LOAD_SYMBOL(cuMemcpy2D, tcuMemcpy2D_v2, "cuMemcpy2D_v2");
 LOAD_SYMBOL(cuMemcpy2DAsync, tcuMemcpy2DAsync_v2, "cuMemcpy2DAsync_v2");
 LOAD_SYMBOL(cuGetErrorName, tcuGetErrorName, "cuGetErrorName");
-- 
2.11.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] nv-codec-headers: add cuMemcpy

2020-11-15 Thread leozhang
Timo Rothenpieler  于2020年11月13日周五 下午8:20写道:
>
> Please also add cuMemcpyAsync while at it.
Will add it.
>
> What for and where is this needed?
cuMemcpy is used to copy 1D array between host and device. For
example, the gauss blur filter weights can be calculated by CPU, then
memcpy to device memory, and futher load to shared memory to later
use. It's much speed up then calculating duplicated weights by per GPU
thread.
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] nv-codec-headers: add cuMemcpy

2020-11-13 Thread leozhang
Signed-off-by: leozhang 
---
 include/ffnvcodec/dynlink_cuda.h   | 1 +
 include/ffnvcodec/dynlink_loader.h | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/include/ffnvcodec/dynlink_cuda.h b/include/ffnvcodec/dynlink_cuda.h
index 117fdc5..1686894 100644
--- a/include/ffnvcodec/dynlink_cuda.h
+++ b/include/ffnvcodec/dynlink_cuda.h
@@ -365,6 +365,7 @@ typedef CUresult CUDAAPI tcuMemAlloc_v2(CUdeviceptr *dptr, 
size_t bytesize);
 typedef CUresult CUDAAPI tcuMemAllocPitch_v2(CUdeviceptr *dptr, size_t 
*pPitch, size_t WidthInBytes, size_t Height, unsigned int ElementSizeBytes);
 typedef CUresult CUDAAPI tcuMemsetD8Async(CUdeviceptr dstDevice, unsigned char 
uc, size_t N, CUstream hStream);
 typedef CUresult CUDAAPI tcuMemFree_v2(CUdeviceptr dptr);
+typedef CUresult CUDAAPI tcuMemcpy(CUdeviceptr dst, CUdeviceptr src, size_t 
bytesize);
 typedef CUresult CUDAAPI tcuMemcpy2D_v2(const CUDA_MEMCPY2D *pcopy);
 typedef CUresult CUDAAPI tcuMemcpy2DAsync_v2(const CUDA_MEMCPY2D *pcopy, 
CUstream hStream);
 typedef CUresult CUDAAPI tcuGetErrorName(CUresult error, const char** pstr);
diff --git a/include/ffnvcodec/dynlink_loader.h 
b/include/ffnvcodec/dynlink_loader.h
index b9995c3..6ce3009 100644
--- a/include/ffnvcodec/dynlink_loader.h
+++ b/include/ffnvcodec/dynlink_loader.h
@@ -152,6 +152,7 @@ typedef struct CudaFunctions {
 tcuMemAllocPitch_v2 *cuMemAllocPitch;
 tcuMemsetD8Async *cuMemsetD8Async;
 tcuMemFree_v2 *cuMemFree;
+tcuMemcpy *cuMemcpy;
 tcuMemcpy2D_v2 *cuMemcpy2D;
 tcuMemcpy2DAsync_v2 *cuMemcpy2DAsync;
 tcuGetErrorName *cuGetErrorName;
@@ -290,6 +291,7 @@ static inline int cuda_load_functions(CudaFunctions 
**functions, void *logctx)
 LOAD_SYMBOL(cuMemAllocPitch, tcuMemAllocPitch_v2, "cuMemAllocPitch_v2");
 LOAD_SYMBOL(cuMemsetD8Async, tcuMemsetD8Async, "cuMemsetD8Async");
 LOAD_SYMBOL(cuMemFree, tcuMemFree_v2, "cuMemFree_v2");
+LOAD_SYMBOL(cuMemcpy, tcuMemcpy, "cuMemcpy");
 LOAD_SYMBOL(cuMemcpy2D, tcuMemcpy2D_v2, "cuMemcpy2D_v2");
 LOAD_SYMBOL(cuMemcpy2DAsync, tcuMemcpy2DAsync_v2, "cuMemcpy2DAsync_v2");
 LOAD_SYMBOL(cuGetErrorName, tcuGetErrorName, "cuGetErrorName");
-- 
2.11.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [RFC] support half-precision float in *_cuda filters

2020-10-21 Thread leozhang
Half precision float is supported for those devices  sm capacity
>=5.3. Theoretically, half float can achieve 2x performance speed up.
So is there any plan to support half float in FFmpeg? Or any problem
so that half float can't be met up?

BR
leozhang
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] avfilter/vf_scale_cuda: unload cuModule when uninit

2020-10-12 Thread leozhang
Signed-off-by: leozhang 
---
 libavfilter/vf_scale_cuda.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/libavfilter/vf_scale_cuda.c b/libavfilter/vf_scale_cuda.c
index 1ffb73f831..46d69b00ee 100644
--- a/libavfilter/vf_scale_cuda.c
+++ b/libavfilter/vf_scale_cuda.c
@@ -119,7 +119,15 @@ static av_cold int cudascale_init(AVFilterContext *ctx)
 static av_cold void cudascale_uninit(AVFilterContext *ctx)
 {
 CUDAScaleContext *s = ctx->priv;
+CUcontext dummy;
 
+if (s->hwctx && s->cu_module) {
+CudaFunctions *cu = s->hwctx->internal->cuda_dl;
+CHECK_CU(cu->cuCtxPushCurrent(s->hwctx->cuda_ctx));
+CHECK_CU(cu->cuModuleUnload(s->cu_module));
+s->cu_module = NULL;
+CHECK_CU(cu->cuCtxPopCurrent());
+}
 av_frame_free(>frame);
 av_buffer_unref(>frames_ctx);
 av_frame_free(>tmp_frame);
-- 
2.11.0

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-devel] [PATCH] avutil/video_enc_params: fix code comment

2020-08-19 Thread leozhang
zhilizhao  于2020年8月13日周四 下午12:55写道:
>
>
>
> > On Aug 13, 2020, at 11:57 AM, leozhang  wrote:
> >
> > Signed-off-by: leozhang 
> > ---
> > libavutil/video_enc_params.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavutil/video_enc_params.h b/libavutil/video_enc_params.h
> > index 43fa443..e3b422d 100644
> > --- a/libavutil/video_enc_params.h
> > +++ b/libavutil/video_enc_params.h
> > @@ -153,7 +153,7 @@ AVVideoEncParams *av_video_enc_params_alloc(enum 
> > AVVideoEncParamsType type,
> > /**
> >  * Allocates memory for AVEncodeInfoFrame plus an array of
> >  * {@code nb_blocks} AVEncodeInfoBlock in the given AVFrame {@code frame}
> > - * as AVFrameSideData of type AV_FRAME_DATA_ENCODE_INFO
> > + * as AVFrameSideData of type AV_FRAME_DATA_VIDEO_ENC_PARAMS
> >  * and initializes the variables.
> >  */
> > AVVideoEncParams*
>
> LGTM.
Thanks for the review. So could someone help to push it?
>
> > --
> > 1.8.3.1
> >
> > ___
> > ffmpeg-devel mailing list
> > ffmpeg-devel@ffmpeg.org
> > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> >
> > To unsubscribe, visit link above, or email
> > ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".