From 09a455a24649af36e8eea81029be7a410201be4c Mon Sep 17 00:00:00 2001 From: "Guo, Yejun" Date: Thu, 29 Aug 2019 13:53:33 +0800 Subject: dnn: introduce dnn operand (in c code) to hold operand infos within network the info can be saved in dnn operand object without regenerating again and again, and it is also needed for layer split/merge, and for memory reuse. to make things step by step, this patch just focuses on c code, the change within python script will be added later. Signed-off-by: Guo, Yejun Signed-off-by: Pedro Arthur --- tests/dnn/Makefile | 2 +- tests/dnn/dnn-layer-pad-test.c | 60 +++++++++++++++++++++++++++++++++--------- 2 files changed, 49 insertions(+), 13 deletions(-) (limited to 'tests/dnn') diff --git a/tests/dnn/Makefile b/tests/dnn/Makefile index 0e050ea218..fabed7510f 100644 --- a/tests/dnn/Makefile +++ b/tests/dnn/Makefile @@ -5,7 +5,7 @@ DNNTESTPROGS := $(DNNTESTPROGS:%=$(DNNTESTSDIR)/%-test$(EXESUF)) -include $(wildcard $(DNNTESTOBJS:.o=.d)) $(DNNTESTPROGS): %$(EXESUF): %.o $(FF_STATIC_DEP_LIBS) - $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(filter %.o,$^) $(FF_STATIC_DEP_LIBS) $(ELIBS) + $(LD) $(LDFLAGS) $(LDEXEFLAGS) $(LD_O) $(filter %.o,$^) $(FF_STATIC_DEP_LIBS) $(EXTRALIBS-avcodec) $(EXTRALIBS-avfilter) $(EXTRALIBS-avformat) $(EXTRALIBS-avutil) $(EXTRALIBS-swresample) $(EXTRALIBS) testclean:: $(RM) $(addprefix $(DNNTESTSDIR)/,$(CLEANSUFFIXES) *-test$(EXESUF)) diff --git a/tests/dnn/dnn-layer-pad-test.c b/tests/dnn/dnn-layer-pad-test.c index 28a49eb55a..1fb2be1590 100644 --- a/tests/dnn/dnn-layer-pad-test.c +++ b/tests/dnn/dnn-layer-pad-test.c @@ -44,6 +44,8 @@ static int test_with_mode_symmetric(void) */ LayerPadParams params; + DnnOperand operands[2]; + int32_t input_indexes[1]; float input[1*4*4*3] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47 }; @@ -57,8 +59,7 @@ static int test_with_mode_symmetric(void) 27.0, 28.0, 29.0, 24.0, 25.0, 26.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 33.0, 34.0, 35.0, 30.0, 31.0, 32.0, 18.0, 19.0, 20.0, 15.0, 16.0, 17.0, 12.0, 13.0, 14.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 21.0, 22.0, 23.0, 18.0, 19.0, 20.0 }; - float output[1*9*9*3]; - memset(output, 0, sizeof(output)); + float *output; params.mode = LPMP_SYMMETRIC; params.paddings[0][0] = 0; @@ -70,15 +71,26 @@ static int test_with_mode_symmetric(void) params.paddings[3][0] = 0; params.paddings[3][1] = 0; - dnn_execute_layer_pad(input, output, ¶ms, 1, 4, 4, 3); + operands[0].data = input; + operands[0].dims[0] = 1; + operands[0].dims[1] = 4; + operands[0].dims[2] = 4; + operands[0].dims[3] = 3; + operands[1].data = NULL; - for (int i = 0; i < sizeof(output) / sizeof(float); i++) { + input_indexes[0] = 0; + dnn_execute_layer_pad(operands, input_indexes, 1, ¶ms); + + output = operands[1].data; + for (int i = 0; i < sizeof(expected_output) / sizeof(float); i++) { if (fabs(output[i] - expected_output[i]) > EPSON) { printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output[i]); + av_freep(&output); return 1; } } + av_freep(&output); return 0; } @@ -102,6 +114,8 @@ static int test_with_mode_reflect(void) */ LayerPadParams params; + DnnOperand operands[2]; + int32_t input_indexes[1]; float input[3*2*2*3] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 }; @@ -110,8 +124,7 @@ static int test_with_mode_reflect(void) 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0, 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0 }; - float output[6*2*2*3]; - memset(output, 0, sizeof(output)); + float *output; params.mode = LPMP_REFLECT; params.paddings[0][0] = 1; @@ -123,15 +136,26 @@ static int test_with_mode_reflect(void) params.paddings[3][0] = 0; params.paddings[3][1] = 0; - dnn_execute_layer_pad(input, output, ¶ms, 3, 2, 2, 3); + operands[0].data = input; + operands[0].dims[0] = 3; + operands[0].dims[1] = 2; + operands[0].dims[2] = 2; + operands[0].dims[3] = 3; + operands[1].data = NULL; + + input_indexes[0] = 0; + dnn_execute_layer_pad(operands, input_indexes, 1, ¶ms); - for (int i = 0; i < sizeof(output) / sizeof(float); i++) { + output = operands[1].data; + for (int i = 0; i < sizeof(expected_output) / sizeof(float); i++) { if (fabs(output[i] - expected_output[i]) > EPSON) { printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output[i]); + av_freep(&output); return 1; } } + av_freep(&output); return 0; } @@ -155,6 +179,8 @@ static int test_with_mode_constant(void) */ LayerPadParams params; + DnnOperand operands[2]; + int32_t input_indexes[1]; float input[1*2*2*3] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; @@ -163,8 +189,7 @@ static int test_with_mode_constant(void) 728.0, 728.0, 0.0, 1.0, 2.0, 728.0, 728.0, 728.0, 3.0, 4.0, 5.0, 728.0, 728.0, 728.0, 6.0, 7.0, 8.0, 728.0, 728.0, 728.0, 9.0, 10.0, 11.0, 728.0, 728.0 }; - float output[1*3*2*6]; - memset(output, 0, sizeof(output)); + float *output; params.mode = LPMP_CONSTANT; params.constant_values = 728; @@ -177,15 +202,26 @@ static int test_with_mode_constant(void) params.paddings[3][0] = 1; params.paddings[3][1] = 2; - dnn_execute_layer_pad(input, output, ¶ms, 1, 2, 2, 3); + operands[0].data = input; + operands[0].dims[0] = 3; + operands[0].dims[1] = 2; + operands[0].dims[2] = 2; + operands[0].dims[3] = 3; + operands[1].data = NULL; + + input_indexes[0] = 0; + dnn_execute_layer_pad(operands, input_indexes, 1, ¶ms); - for (int i = 0; i < sizeof(output) / sizeof(float); i++) { + output = operands[1].data; + for (int i = 0; i < sizeof(expected_output) / sizeof(float); i++) { if (fabs(output[i] - expected_output[i]) > EPSON) { printf("at index %d, output: %f, expected_output: %f\n", i, output[i], expected_output[i]); + av_freep(&output); return 1; } } + av_freep(&output); return 0; } -- cgit v1.2.3