]> git.sesse.net Git - ffmpeg/blob - libavfilter/dnn/dnn_backend_native_layer_maximum.c
libavfilter/dnn: add layer maximum for native mode.
[ffmpeg] / libavfilter / dnn / dnn_backend_native_layer_maximum.c
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"
27 #include "libavutil/avassert.h"
28 #include "dnn_backend_native_layer_maximum.h"
29
30 int dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand_indexes, int32_t output_operand_index, const DnnLayerMaximumParams *params)
31 {
32     const DnnOperand *input = &operands[input_operand_indexes[0]];
33     DnnOperand *output = &operands[output_operand_index];
34     int dims_count;
35     const float *src;
36     float *dst;
37
38     for (int i = 0; i < 4; ++i)
39         output->dims[i] = input->dims[i];
40
41     output->data_type = input->data_type;
42     output->length = calculate_operand_data_length(output);
43     output->data = av_realloc(output->data, output->length);
44     if (!output->data)
45         return DNN_ERROR;
46
47     dims_count = calculate_operand_dims_count(output);
48     src = input->data;
49     dst = output->data;
50     for (int i = 0; i < dims_count; ++i)
51         dst[i] = FFMAX(src[i], params->val.y);
52
53     return 0;
54 }