[FFmpeg-devel] [PATCH v2 FFmpeg 12/20] libavfilter/dnn/dnn_backend_torch: Add ClxpContext to THModel
m.kaindl0208 at gmail.com
m.kaindl0208 at gmail.com
Mon Mar 10 21:54:37 EET 2025
Signed-off-by: MaximilianKaindl <m.kaindl0208 at gmail.com>
---
libavfilter/dnn/dnn_backend_torch.cpp | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/libavfilter/dnn/dnn_backend_torch.cpp b/libavfilter/dnn/dnn_backend_torch.cpp
index 062821949d..ea09845e05 100644
--- a/libavfilter/dnn/dnn_backend_torch.cpp
+++ b/libavfilter/dnn/dnn_backend_torch.cpp
@@ -39,6 +39,13 @@ extern "C" {
#include <c10/cuda/CUDAStream.h>
#endif
+typedef struct THClxpContext {
+ torch::Tensor *tokenized_text;
+ torch::Tensor *attention_mask;
+ int *softmax_units;
+ int softmax_units_count;
+} THClxpContext;
+
typedef struct THModel {
DNNModel model;
DnnContext *ctx;
@@ -46,6 +53,7 @@ typedef struct THModel {
SafeQueue *request_queue;
Queue *task_queue;
Queue *lltask_queue;
+ THClxpContext *clxp_ctx;
} THModel;
typedef struct THInferRequest {
@@ -116,6 +124,21 @@ static inline void destroy_request_item(THRequestItem **arg)
av_freep(arg);
}
+static void free_clxp_context(THClxpContext *clxp_ctx)
+{
+ if (!clxp_ctx)
+ return;
+ if (clxp_ctx->tokenized_text) {
+ delete clxp_ctx->tokenized_text;
+ clxp_ctx->tokenized_text = nullptr;
+ }
+ if (clxp_ctx->attention_mask) {
+ delete clxp_ctx->attention_mask;
+ clxp_ctx->attention_mask = nullptr;
+ }
+ av_freep(&clxp_ctx);
+}
+
static void dnn_free_model_th(DNNModel **model)
{
THModel *th_model;
@@ -143,6 +166,9 @@ static void dnn_free_model_th(DNNModel **model)
}
ff_queue_destroy(th_model->task_queue);
delete th_model->jit_model;
+#if (CONFIG_LIBTOKENIZERS == 1)
+ free_clxp_context(th_model->clxp_ctx);
+#endif
av_freep(&th_model);
*model = NULL;
}
--
2.34.1
More information about the ffmpeg-devel
mailing list