FFmpeg
dnn_backend_native_layer_maximum.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Guo Yejun
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * DNN native backend implementation.
24  */
25 
26 #include "dnn_backend_native.h"
28 
29 int ff_dnn_load_layer_maximum(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
30 {
31  DnnLayerMaximumParams *params;
32  int dnn_size = 0;
33  params = av_malloc(sizeof(*params));
34  if (!params)
35  return 0;
36 
37  params->val.u32 = avio_rl32(model_file_context);
38  dnn_size += 4;
39  layer->params = params;
40  layer->input_operand_indexes[0] = (int32_t)avio_rl32(model_file_context);
41  layer->output_operand_index = (int32_t)avio_rl32(model_file_context);
42  dnn_size += 8;
43 
44  if (layer->input_operand_indexes[0] >= operands_num || layer->output_operand_index >= operands_num) {
45  return 0;
46  }
47 
48  return dnn_size;
49 }
50 
51 int ff_dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand_indexes,
52  int32_t output_operand_index, const void *parameters, NativeContext *ctx)
53 {
54  const DnnOperand *input = &operands[input_operand_indexes[0]];
55  DnnOperand *output = &operands[output_operand_index];
56  const DnnLayerMaximumParams *params = parameters;
57  int dims_count;
58  const float *src;
59  float *dst;
60 
61  for (int i = 0; i < 4; ++i)
62  output->dims[i] = input->dims[i];
63 
64  output->data_type = input->data_type;
66  if (output->length <= 0) {
67  av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
68  return DNN_ERROR;
69  }
70  output->data = av_realloc(output->data, output->length);
71  if (!output->data) {
72  av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
73  return DNN_ERROR;
74  }
75 
77  src = input->data;
78  dst = output->data;
79  for (int i = 0; i < dims_count; ++i)
80  dst[i] = FFMAX(src[i], params->val.y);
81 
82  return 0;
83 }
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
DnnLayerMaximumParams::y
float y
Definition: dnn_backend_native_layer_maximum.h:36
DnnLayerMaximumParams::val
union DnnLayerMaximumParams::@200 val
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
DnnLayerMaximumParams
Definition: dnn_backend_native_layer_maximum.h:33
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
DnnLayerMaximumParams::u32
uint32_t u32
Definition: dnn_backend_native_layer_maximum.h:35
ff_calculate_operand_data_length
int32_t ff_calculate_operand_data_length(const DnnOperand *oprd)
Definition: dnn_backend_native.c:499
ff_dnn_execute_layer_maximum
int ff_dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, const void *parameters, NativeContext *ctx)
Definition: dnn_backend_native_layer_maximum.c:51
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
ctx
AVFormatContext * ctx
Definition: movenc.c:48
Layer::params
void * params
Definition: dnn_backend_native.h:66
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:152
src
#define src
Definition: vp8dsp.c:255
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:759
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
Layer::output_operand_index
int32_t output_operand_index
Definition: dnn_backend_native.h:65
NativeContext
Definition: dnn_backend_native.h:118
ff_dnn_load_layer_maximum
int ff_dnn_load_layer_maximum(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
Definition: dnn_backend_native_layer_maximum.c:29
Layer
Definition: dnn_backend_native.h:57
Layer::input_operand_indexes
int32_t input_operand_indexes[4]
a layer can have multiple inputs and one output.
Definition: dnn_backend_native.h:64
dnn_backend_native.h
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
DNN_ERROR
@ DNN_ERROR
Definition: dnn_interface.h:33
DnnOperand
Definition: dnn_backend_native.h:69
ff_calculate_operand_dims_count
int32_t ff_calculate_operand_dims_count(const DnnOperand *oprd)
Definition: dnn_backend_native.c:490
int32_t
int32_t
Definition: audioconvert.c:56
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
dnn_backend_native_layer_maximum.h