FFmpeg
dnn-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 #include <stdio.h>
22 #include <string.h>
23 #include <math.h>
25 
26 #define EPSON 0.00001
27 
28 static int test(void)
29 {
30  DnnLayerMaximumParams params;
31  DnnOperand operands[2];
32  int32_t input_indexes[1];
33  float input[1*1*2*3] = {
34  -3, 2.5, 2, -2.1, 7.8, 100
35  };
36  float *output;
37 
38  params.val.y = 2.3;
39 
40  operands[0].data = input;
41  operands[0].dims[0] = 1;
42  operands[0].dims[1] = 1;
43  operands[0].dims[2] = 2;
44  operands[0].dims[3] = 3;
45  operands[1].data = NULL;
46 
47  input_indexes[0] = 0;
48  ff_dnn_execute_layer_maximum(operands, input_indexes, 1, &params, NULL);
49 
50  output = operands[1].data;
51  for (int i = 0; i < sizeof(input) / sizeof(float); i++) {
52  float expected_output = input[i] > params.val.y ? input[i] : params.val.y;
53  if (fabs(output[i] - expected_output) > EPSON) {
54  printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output);
55  av_freep(&output);
56  return 1;
57  }
58  }
59 
60  av_freep(&output);
61  return 0;
62 
63 }
64 
65 int main(int argc, char **argv)
66 {
67  if (test())
68  return 1;
69 
70  return 0;
71 }
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
Definition: dnn_backend_native_layer_maximum.h:33
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
DnnOperand::data
void * data
data pointer with data length in bytes.
Definition: dnn_backend_native.h:104
EPSON
#define EPSON
Definition: dnn-layer-maximum.c:26
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
NULL
#define NULL
Definition: coverity.c:32
DnnOperand::dims
int32_t dims[4]
there are two memory layouts, NHWC or NCHW, so we use dims, dims[0] is Number.
Definition: dnn_backend_native.h:74
printf
printf("static const uint8_t my_array[100] = {\n")
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:269
DnnOperand
Definition: dnn_backend_native.h:69
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
main
int main(int argc, char **argv)
Definition: dnn-layer-maximum.c:65
test
static int test(void)
Definition: dnn-layer-maximum.c:28
int32_t
int32_t
Definition: audioconvert.c:56
dnn_backend_native_layer_maximum.h
DnnLayerMaximumParams::val
union DnnLayerMaximumParams::@205 val