2 * Copyright (c) 2019 Guo Yejun
4 * This file is part of FFmpeg.
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.
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.
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
23 * DNN native backend implementation.
26 #include "dnn_backend_native.h"
27 #include "libavutil/avassert.h"
28 #include "dnn_backend_native_layer_maximum.h"
30 int dnn_load_layer_maximum(Layer *layer, AVIOContext *model_file_context, int file_size, int operands_num)
32 DnnLayerMaximumParams *params;
34 params = av_malloc(sizeof(*params));
38 params->val.u32 = avio_rl32(model_file_context);
40 layer->params = params;
41 layer->input_operand_indexes[0] = (int32_t)avio_rl32(model_file_context);
42 layer->output_operand_index = (int32_t)avio_rl32(model_file_context);
45 if (layer->input_operand_indexes[0] >= operands_num || layer->output_operand_index >= operands_num) {
52 int dnn_execute_layer_maximum(DnnOperand *operands, const int32_t *input_operand_indexes,
53 int32_t output_operand_index, const void *parameters, NativeContext *ctx)
55 const DnnOperand *input = &operands[input_operand_indexes[0]];
56 DnnOperand *output = &operands[output_operand_index];
57 const DnnLayerMaximumParams *params = (const DnnLayerMaximumParams *)parameters;
62 for (int i = 0; i < 4; ++i)
63 output->dims[i] = input->dims[i];
65 output->data_type = input->data_type;
66 output->length = calculate_operand_data_length(output);
67 if (output->length <= 0) {
68 av_log(ctx, AV_LOG_ERROR, "The output data length overflow\n");
71 output->data = av_realloc(output->data, output->length);
73 av_log(ctx, AV_LOG_ERROR, "Failed to reallocate memory for output\n");
77 dims_count = calculate_operand_dims_count(output);
80 for (int i = 0; i < dims_count; ++i)
81 dst[i] = FFMAX(src[i], params->val.y);