1 diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
2 index 718a449b6e..84685fe1d9 100644
3 --- a/libavutil/hwcontext_cuda.c
4 +++ b/libavutil/hwcontext_cuda.c
5 @@ -269,9 +269,11 @@ static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
6 CudaFunctions *cu = hwctx->internal->cuda_dl;
8 if (hwctx->internal->is_allocated && hwctx->cuda_ctx) {
9 +#ifdef CUDA_PRIMARY_CTX
10 if (hwctx->internal->flags & AV_CUDA_USE_PRIMARY_CONTEXT)
11 CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal->cuda_device));
14 CHECK_CU(cu->cuCtxDestroy(hwctx->cuda_ctx));
16 hwctx->cuda_ctx = NULL;
17 @@ -321,7 +323,7 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
18 cu = hwctx->internal->cuda_dl;
20 hwctx->internal->flags = flags;
22 +#ifdef CUDA_PRIMARY_CTX
23 if (flags & AV_CUDA_USE_PRIMARY_CONTEXT) {
24 ret = CHECK_CU(cu->cuDevicePrimaryCtxGetState(hwctx->internal->cuda_device,
25 &dev_flags, &dev_active));
26 @@ -342,7 +344,9 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
27 hwctx->internal->cuda_device));
34 ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
35 hwctx->internal->cuda_device));