FFmpeg
Data Structures | Macros | Functions | Variables
dnn_backend_torch.cpp File Reference
#include <torch/torch.h>
#include <torch/script.h>
#include "../internal.h"
#include "dnn_io_proc.h"
#include "dnn_backend_common.h"
#include "libavutil/opt.h"
#include "libavutil/mem.h"
#include "queue.h"
#include "safe_queue.h"

Go to the source code of this file.

Data Structures

struct  THModel
 
struct  THInferRequest
 
struct  THRequestItem
 

Macros

#define OFFSET(x)   offsetof(THOptions, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM
 

Functions

static int extract_lltask_from_task (TaskItem *task, Queue *lltask_queue)
 
static void th_free_request (THInferRequest *request)
 
static void destroy_request_item (THRequestItem **arg)
 
static void dnn_free_model_th (DNNModel **model)
 
static int get_input_th (DNNModel *model, DNNData *input, const char *input_name)
 
static void deleter (void *arg)
 
static int fill_model_input_th (THModel *th_model, THRequestItem *request)
 
static int th_start_inference (void *args)
 
static void infer_completion_callback (void *args)
 
static int execute_model_th (THRequestItem *request, Queue *lltask_queue)
 
static int get_output_th (DNNModel *model, const char *input_name, int input_width, int input_height, const char *output_name, int *output_width, int *output_height)
 
static THInferRequestth_create_inference_request (void)
 
static DNNModeldnn_load_model_th (DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
 
static int dnn_execute_model_th (const DNNModel *model, DNNExecBaseParams *exec_params)
 
static DNNAsyncStatusType dnn_get_result_th (const DNNModel *model, AVFrame **in, AVFrame **out)
 
static int dnn_flush_th (const DNNModel *model)
 

Variables

static const AVOption dnn_th_options []
 
const DNNModule ff_dnn_backend_torch
 

Detailed Description

DNN Torch backend implementation.

Definition in file dnn_backend_torch.cpp.

Macro Definition Documentation

◆ OFFSET

#define OFFSET (   x)    offsetof(THOptions, x)

Definition at line 60 of file dnn_backend_torch.cpp.

◆ FLAGS

#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM

Definition at line 61 of file dnn_backend_torch.cpp.

Function Documentation

◆ extract_lltask_from_task()

static int extract_lltask_from_task ( TaskItem task,
Queue lltask_queue 
)
static

Definition at line 67 of file dnn_backend_torch.cpp.

Referenced by dnn_execute_model_th(), and get_output_th().

◆ th_free_request()

static void th_free_request ( THInferRequest request)
static

◆ destroy_request_item()

static void destroy_request_item ( THRequestItem **  arg)
inlinestatic

◆ dnn_free_model_th()

static void dnn_free_model_th ( DNNModel **  model)
static

Definition at line 116 of file dnn_backend_torch.cpp.

Referenced by dnn_load_model_th().

◆ get_input_th()

static int get_input_th ( DNNModel model,
DNNData input,
const char *  input_name 
)
static

Definition at line 147 of file dnn_backend_torch.cpp.

Referenced by dnn_load_model_th(), and fill_model_input_th().

◆ deleter()

static void deleter ( void *  arg)
static

Definition at line 159 of file dnn_backend_torch.cpp.

Referenced by fill_model_input_th().

◆ fill_model_input_th()

static int fill_model_input_th ( THModel th_model,
THRequestItem request 
)
static

Definition at line 164 of file dnn_backend_torch.cpp.

Referenced by execute_model_th().

◆ th_start_inference()

static int th_start_inference ( void *  args)
static

Definition at line 223 of file dnn_backend_torch.cpp.

Referenced by dnn_load_model_th(), and execute_model_th().

◆ infer_completion_callback()

static void infer_completion_callback ( void *  args)
static

Definition at line 264 of file dnn_backend_torch.cpp.

Referenced by dnn_load_model_th(), and execute_model_th().

◆ execute_model_th()

static int execute_model_th ( THRequestItem request,
Queue lltask_queue 
)
static

Definition at line 322 of file dnn_backend_torch.cpp.

Referenced by dnn_execute_model_th(), dnn_flush_th(), and get_output_th().

◆ get_output_th()

static int get_output_th ( DNNModel model,
const char *  input_name,
int  input_width,
int  input_height,
const char *  output_name,
int output_width,
int output_height 
)
static

Definition at line 366 of file dnn_backend_torch.cpp.

Referenced by dnn_load_model_th().

◆ th_create_inference_request()

static THInferRequest* th_create_inference_request ( void  )
static

Definition at line 409 of file dnn_backend_torch.cpp.

Referenced by dnn_load_model_th().

◆ dnn_load_model_th()

static DNNModel* dnn_load_model_th ( DnnContext ctx,
DNNFunctionType  func_type,
AVFilterContext filter_ctx 
)
static

Definition at line 420 of file dnn_backend_torch.cpp.

◆ dnn_execute_model_th()

static int dnn_execute_model_th ( const DNNModel model,
DNNExecBaseParams exec_params 
)
static

Definition at line 503 of file dnn_backend_torch.cpp.

◆ dnn_get_result_th()

static DNNAsyncStatusType dnn_get_result_th ( const DNNModel model,
AVFrame **  in,
AVFrame **  out 
)
static

Definition at line 552 of file dnn_backend_torch.cpp.

◆ dnn_flush_th()

static int dnn_flush_th ( const DNNModel model)
static

Definition at line 558 of file dnn_backend_torch.cpp.

Variable Documentation

◆ dnn_th_options

const AVOption dnn_th_options[]
static
Initial value:
= {
{ "optimize", "turn on graph executor optimization", OFFSET(optimize), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS},
{ NULL }
}

Definition at line 62 of file dnn_backend_torch.cpp.

◆ ff_dnn_backend_torch

const DNNModule ff_dnn_backend_torch
Initial value:
= {
.clazz = DNN_DEFINE_CLASS(dnn_th),
.type = DNN_TH,
.load_model = dnn_load_model_th,
.execute_model = dnn_execute_model_th,
.get_result = dnn_get_result_th,
.flush = dnn_flush_th,
.free_model = dnn_free_model_th,
}
FLAGS
#define FLAGS
Definition: dnn_backend_torch.cpp:61
dnn_execute_model_th
static int dnn_execute_model_th(const DNNModel *model, DNNExecBaseParams *exec_params)
Definition: dnn_backend_torch.cpp:503
dnn_load_model_th
static DNNModel * dnn_load_model_th(DnnContext *ctx, DNNFunctionType func_type, AVFilterContext *filter_ctx)
Definition: dnn_backend_torch.cpp:420
NULL
#define NULL
Definition: coverity.c:32
dnn_get_result_th
static DNNAsyncStatusType dnn_get_result_th(const DNNModel *model, AVFrame **in, AVFrame **out)
Definition: dnn_backend_torch.cpp:552
DNN_DEFINE_CLASS
#define DNN_DEFINE_CLASS(fname)
Definition: dnn_backend_common.h:39
OFFSET
#define OFFSET(x)
Definition: dnn_backend_torch.cpp:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:245
DNN_TH
@ DNN_TH
Definition: dnn_interface.h:38
dnn_flush_th
static int dnn_flush_th(const DNNModel *model)
Definition: dnn_backend_torch.cpp:558
dnn_free_model_th
static void dnn_free_model_th(DNNModel **model)
Definition: dnn_backend_torch.cpp:116