Skip to content

Commit f028d81

Browse files
committed
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.
1 parent 0e763c0 commit f028d81

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

libavutil/cuda_check.h

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
/**
2424
* Wrap a CUDA function call and print error information if it fails.
2525
*/
26-
static inline int ff_cuda_check(void *avctx,
27-
void *cuGetErrorName_fn, void *cuGetErrorString_fn,
28-
CUresult err, const char *func)
26+
#ifdef FFNV_CUDA_DYNLINK_LOADER_H
27+
static inline int ff_cuda_check_dl(void *avctx,
28+
void *cuGetErrorName_fn,
29+
void *cuGetErrorString_fn,
30+
CUresult err, const char *func)
2931
{
3032
const char *err_name;
3133
const char *err_string;
@@ -47,15 +49,41 @@ static inline int ff_cuda_check(void *avctx,
4749
}
4850

4951
/**
50-
* Convenience wrapper for ff_cuda_check when directly linking libcuda.
52+
* Convenience wrapper for ff_cuda_check when dynamically loading cuda symbols.
5153
*/
5254

53-
#define FF_CUDA_CHECK(avclass, x) ff_cuda_check(avclass, cuGetErrorName, cuGetErrorString, (x), #x)
55+
#define FF_CUDA_CHECK_DL(avclass, cudl, x) ff_cuda_check_dl(avclass, cudl->cuGetErrorName, cudl->cuGetErrorString, (x), #x)
56+
57+
#else
58+
59+
static inline int ff_cuda_check(void *avctx,
60+
CUresult err, const char *func)
61+
{
62+
const char *err_name;
63+
const char *err_string;
64+
65+
av_log(avctx, AV_LOG_TRACE, "Calling %s\n", func);
66+
67+
if (err == CUDA_SUCCESS)
68+
return 0;
69+
70+
cuGetErrorName(err, &err_name);
71+
cuGetErrorString(err, &err_string);
72+
73+
av_log(avctx, AV_LOG_ERROR, "%s failed", func);
74+
if (err_name && err_string)
75+
av_log(avctx, AV_LOG_ERROR, " -> %s: %s", err_name, err_string);
76+
av_log(avctx, AV_LOG_ERROR, "\n");
77+
78+
return AVERROR_EXTERNAL;
79+
}
5480

5581
/**
56-
* Convenience wrapper for ff_cuda_check when dynamically loading cuda symbols.
82+
* Convenience wrapper for ff_cuda_check when directly linking libcuda.
5783
*/
5884

59-
#define FF_CUDA_CHECK_DL(avclass, cudl, x) ff_cuda_check(avclass, cudl->cuGetErrorName, cudl->cuGetErrorString, (x), #x)
85+
#define FF_CUDA_CHECK(avclass, x) ff_cuda_check(avclass, (x), #x)
86+
87+
#endif /* FFNV_CUDA_DYNLINK_LOADER_H */
6088

6189
#endif /* AVUTIL_CUDA_CHECK_H */

0 commit comments

Comments
 (0)