Project Ne10
An open, optimized software library for the ARM architecture.
test_suite_resize.c
Go to the documentation of this file.
1 /*
2  * Copyright 2013-16 ARM Limited and Contributors.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of ARM Limited nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  * NE10 Library : test_suite_resize.c
30  */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <math.h>
35 #include <string.h>
36 
37 #include "NE10_imgproc.h"
38 #include "seatest.h"
39 #include "unit_test_common.h"
40 
41 /* ----------------------------------------------------------------------
42 ** Global defines
43 ** ------------------------------------------------------------------- */
44 #define MEM_SIZE 128
45 
46 #define TEST_COUNT 5000
47 
48 
49 /* ----------------------------------------------------------------------
50 ** Defines each of the tests performed
51 ** ------------------------------------------------------------------- */
52 
53 
54 //input and output
55 static ne10_uint8_t * in_c = NULL;
56 static ne10_uint8_t * in_neon = NULL;
57 
58 static ne10_uint8_t * out_c = NULL;
59 static ne10_uint8_t * out_neon = NULL;
60 
61 void test_resize_conformance_case()
62 {
63  ne10_int32_t srcw;
64  ne10_int32_t srch;
65  ne10_int32_t dstw;
66  ne10_int32_t dsth;
67  ne10_int32_t w, h;
68  ne10_float32_t PSNR;
69  ne10_int32_t i;
70  ne10_int32_t channels = 4;
71  ne10_int32_t pic_size = MEM_SIZE * MEM_SIZE * channels * sizeof (ne10_uint8_t);
72 
73  /* init input memory */
74  in_c = NE10_MALLOC (pic_size);
75  in_neon = NE10_MALLOC (pic_size);
76 
77  /* init dst memory */
78  out_c = NE10_MALLOC (pic_size);
79  out_neon = NE10_MALLOC (pic_size);
80 
81  for (i = 0; i < pic_size; i++)
82  {
83  in_c[i] = in_neon[i] = (rand() & 0xff);
84  }
85 #if defined(REGRESSION_TEST)
86  for (h = 1; h < MEM_SIZE; h++)
87  {
88  for (w = 1; w < MEM_SIZE; w++)
89  {
90  srcw = h;
91  srch = h;
92  dstw = w;
93  dsth = w;
94 
95  printf ("srcw X srch = %d X %d \n", srcw, srch);
96  printf ("dstw X dsth = %d X %d \n", dstw, dsth);
97 
98  ne10_img_resize_bilinear_rgba_c (out_c, dstw, dsth, in_c, srcw, srch, srcw);
99  ne10_img_resize_bilinear_rgba_neon (out_neon, dstw, dsth, in_neon, srcw, srch, srcw);
100 
101  PSNR = CAL_PSNR_UINT8 (out_c, out_neon, dstw * dsth * channels);
102  assert_false ( (PSNR < PSNR_THRESHOLD));
103  }
104  }
105 #else // defined(SMOKE_TEST)
106  for (h = 96; h < MEM_SIZE; h++)
107  {
108  for (w = 96; w < MEM_SIZE; w++)
109  {
110  srcw = h;
111  srch = h;
112  dstw = w;
113  dsth = w;
114 
115  printf ("srcw X srch = %d X %d \n", srcw, srch);
116  printf ("dstw X dsth = %d X %d \n", dstw, dsth);
117 
118  ne10_img_resize_bilinear_rgba_c (out_c, dstw, dsth, in_c, srcw, srch, srcw);
119  ne10_img_resize_bilinear_rgba_neon (out_neon, dstw, dsth, in_neon, srcw, srch, srcw);
120 
121  PSNR = CAL_PSNR_UINT8 (out_c, out_neon, dstw * dsth * channels);
122  assert_false ( (PSNR < PSNR_THRESHOLD));
123  }
124  }
125 #endif
126 
127  NE10_FREE (in_c);
128  NE10_FREE (in_neon);
129  NE10_FREE (out_c);
130  NE10_FREE (out_neon);
131 }
132 
133 void test_resize_performance_case()
134 {
135  ne10_int32_t srcw;
136  ne10_int32_t srch;
137  ne10_int32_t dstw;
138  ne10_int32_t dsth;
139  ne10_int32_t i;
140  ne10_int32_t w, h;
141  ne10_int32_t channels = 4;
142  ne10_int32_t pic_size = MEM_SIZE * MEM_SIZE * channels * sizeof (ne10_uint8_t);
143  ne10_int64_t time_c = 0;
144  ne10_int64_t time_neon = 0;
145 
146  /* init input memory */
147  in_c = NE10_MALLOC (pic_size);
148  in_neon = NE10_MALLOC (pic_size);
149 
150  /* init dst memory */
151  out_c = NE10_MALLOC (pic_size);
152  out_neon = NE10_MALLOC (pic_size);
153 
154  for (i = 0; i < pic_size; i++)
155  {
156  in_c[i] = in_neon[i] = (rand() & 0xff);
157  }
158 
159  for (h = 16; h < MEM_SIZE; h += 4)
160  {
161  for (w = 16; w < MEM_SIZE; w += 4)
162  {
163  srcw = h;
164  srch = h;
165  dstw = w;
166  dsth = w;
167 
168  printf ("srcw X srch = %d X %d \n", srcw, srch);
169  printf ("dstw X dsth = %d X %d \n", dstw, dsth);
170 
171  GET_TIME
172  (
173  time_c,
174  {
175  for (i = 0; i < TEST_COUNT; i++)
176  ne10_img_resize_bilinear_rgba_c (out_c, dstw, dsth, in_c, srcw, srch, srcw);
177  }
178  );
179 
180  GET_TIME
181  (
182  time_neon,
183  {
184  for (i = 0; i < TEST_COUNT; i++)
185  ne10_img_resize_bilinear_rgba_neon (out_neon, dstw, dsth, in_neon, srcw, srch, srcw);
186  }
187  );
188  //printf ("time c %lld \n", time_c);
189  //printf ("time neon %lld \n", time_neon);
190  ne10_log (__FUNCTION__, "IMAGERESIZE%20d%20lld%20lld%19.2f%%%18.2f:1\n", (h * MEM_SIZE + w), time_c, time_neon, 0, 0);
191 
192  }
193  }
194  NE10_FREE (in_c);
195  NE10_FREE (in_neon);
196  NE10_FREE (out_c);
197  NE10_FREE (out_neon);
198 }
199 
200 void test_resize()
201 {
202 #if defined (SMOKE_TEST)||(REGRESSION_TEST)
203  test_resize_conformance_case();
204 #endif
205 
206 #if defined PERFORMANCE_TEST
207  test_resize_performance_case();
208 #endif
209 }
210 
211 static void my_test_setup (void)
212 {
213  ne10_log_buffer_ptr = ne10_log_buffer;
214 }
215 
216 void test_fixture_resize (void)
217 {
218  test_fixture_start(); // starts a fixture
219 
220  fixture_setup (my_test_setup);
221 
222  run_test (test_resize); // run tests
223 
224  test_fixture_end(); // ends a fixture
225 }
void ne10_img_resize_bilinear_rgba_c(ne10_uint8_t *dst, ne10_uint32_t dst_width, ne10_uint32_t dst_height, ne10_uint8_t *src, ne10_uint32_t src_width, ne10_uint32_t src_height, ne10_uint32_t src_stride)
Specific implementation of ne10_img_resize_bilinear_rgba using plain C.
Definition: NE10_resize.c:446
uint8_t ne10_uint8_t
Definition: NE10_types.h:73
int32_t ne10_int32_t
Definition: NE10_types.h:76
void ne10_img_resize_bilinear_rgba_neon(ne10_uint8_t *dst, ne10_uint32_t dst_width, ne10_uint32_t dst_height, ne10_uint8_t *src, ne10_uint32_t src_width, ne10_uint32_t src_height, ne10_uint32_t src_stride) asm("ne10_img_resize_bilinear_rgba_neon")
Specific implementation of ne10_img_resize_bilinear_rgba using NEON SIMD capabilities.
Definition: NE10_resize.c:487
void my_test_setup(void)
float ne10_float32_t
Definition: NE10_types.h:80
int64_t ne10_int64_t
Definition: NE10_types.h:78
#define TEST_COUNT
#define NE10_FREE(p)
Definition: NE10_macros.h:54
#define MEM_SIZE
#define NE10_MALLOC
Definition: NE10_macros.h:53