Skip to content

Commit

Permalink
avutil/cuda_check: Fix non-dynamic-loader implementation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
philipl committed Feb 16, 2019
1 parent 0e763c0 commit f028d81
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions libavutil/cuda_check.h
Expand Up @@ -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;
Expand All @@ -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 */

0 comments on commit f028d81

Please sign in to comment.