Skip to content

Commit

Permalink
Return specific error on CUDA OOM
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberj0g authored and ad-astra-video committed Feb 25, 2024
1 parent 002167b commit 57ff63c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions libavutil/cuda_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

#include "compat/cuda/dynlink_loader.h"
#include "error.h"
/*
* Defined in the driver API
* https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__TYPES.html
*/
#define CUDA_ERROR_OUT_OF_MEMORY 2

typedef CUresult CUDAAPI cuda_check_GetErrorName(CUresult error, const char** pstr);
typedef CUresult CUDAAPI cuda_check_GetErrorString(CUresult error, const char** pstr);
Expand Down Expand Up @@ -49,6 +54,9 @@ static inline int ff_cuda_check(void *avctx,
av_log(avctx, AV_LOG_ERROR, " -> %s: %s", err_name, err_string);
av_log(avctx, AV_LOG_ERROR, "\n");

if (err == CUDA_ERROR_OUT_OF_MEMORY)
return AVERROR(ENOMEM);

return AVERROR_EXTERNAL;
}

Expand Down
3 changes: 2 additions & 1 deletion libavutil/hwcontext_cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ static int cuda_device_create(AVHWDeviceContext *device_ctx,

ret = cuda_context_init(device_ctx, flags);
if (ret < 0) {
ret = AVERROR_UNKNOWN;
if (ret == AVERROR_EXTERNAL)
ret = AVERROR_UNKNOWN;
goto error;
}

Expand Down

0 comments on commit 57ff63c

Please sign in to comment.