From f028d813709cb14bdf08de898bc560e41e630763 Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sat, 16 Feb 2019 09:50:46 -0800 Subject: [PATCH] avutil/cuda_check: Fix non-dynamic-loader implementation The switch to an inline function means that the dynamic-loader dependent typing can only work if the including file uses the dynamic loader. If not, we'll get compilation errors. While not ideal, the least complicated way to solve this is to have a completely separate implementation when using a linked cuda library and #ifdef against the presence of the loader. This fixes compilation of the various SDK-linked cuda filters. --- libavutil/cuda_check.h | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/libavutil/cuda_check.h b/libavutil/cuda_check.h index ec1705b000b18..4a000938fb874 100644 --- a/libavutil/cuda_check.h +++ b/libavutil/cuda_check.h @@ -23,9 +23,11 @@ /** * Wrap a CUDA function call and print error information if it fails. */ -static inline int ff_cuda_check(void *avctx, - void *cuGetErrorName_fn, void *cuGetErrorString_fn, - CUresult err, const char *func) +#ifdef FFNV_CUDA_DYNLINK_LOADER_H +static inline int ff_cuda_check_dl(void *avctx, + void *cuGetErrorName_fn, + void *cuGetErrorString_fn, + CUresult err, const char *func) { const char *err_name; const char *err_string; @@ -47,15 +49,41 @@ static inline int ff_cuda_check(void *avctx, } /** - * Convenience wrapper for ff_cuda_check when directly linking libcuda. + * Convenience wrapper for ff_cuda_check when dynamically loading cuda symbols. */ -#define FF_CUDA_CHECK(avclass, x) ff_cuda_check(avclass, cuGetErrorName, cuGetErrorString, (x), #x) +#define FF_CUDA_CHECK_DL(avclass, cudl, x) ff_cuda_check_dl(avclass, cudl->cuGetErrorName, cudl->cuGetErrorString, (x), #x) + +#else + +static inline int ff_cuda_check(void *avctx, + CUresult err, const char *func) +{ + const char *err_name; + const char *err_string; + + av_log(avctx, AV_LOG_TRACE, "Calling %s\n", func); + + if (err == CUDA_SUCCESS) + return 0; + + cuGetErrorName(err, &err_name); + cuGetErrorString(err, &err_string); + + av_log(avctx, AV_LOG_ERROR, "%s failed", func); + if (err_name && err_string) + av_log(avctx, AV_LOG_ERROR, " -> %s: %s", err_name, err_string); + av_log(avctx, AV_LOG_ERROR, "\n"); + + return AVERROR_EXTERNAL; +} /** - * Convenience wrapper for ff_cuda_check when dynamically loading cuda symbols. + * Convenience wrapper for ff_cuda_check when directly linking libcuda. */ -#define FF_CUDA_CHECK_DL(avclass, cudl, x) ff_cuda_check(avclass, cudl->cuGetErrorName, cudl->cuGetErrorString, (x), #x) +#define FF_CUDA_CHECK(avclass, x) ff_cuda_check(avclass, (x), #x) + +#endif /* FFNV_CUDA_DYNLINK_LOADER_H */ #endif /* AVUTIL_CUDA_CHECK_H */