Project Ne10
An open, optimized software library for the ARM architecture.
test_suite_rotate.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_rotate.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 
45 #define SRC_HEIGHT 512
46 #define SRC_WIDTH 512
47 #define DST_HEIGHT 734 //sqrt(512*512 + 512*512) + 10
48 #define DST_WIDTH 734 //sqrt(512*512 + 512*512) + 10
49 #define TEST_COUNT 5000
50 
51 
52 /* ----------------------------------------------------------------------
53 ** Defines each of the tests performed
54 ** ------------------------------------------------------------------- */
55 
56 
57 //input and output
58 static ne10_uint8_t * in_c = NULL;
59 static ne10_uint8_t * in_neon = NULL;
60 
61 static ne10_uint8_t * out_c = NULL;
62 static ne10_uint8_t * out_neon = NULL;
63 
64 #ifdef ENABLE_NE10_IMG_ROTATE_RGBA_NEON
65 void test_rotate_conformance_case()
66 {
67  ne10_int32_t i;
68  ne10_int32_t channels = 4;
69  ne10_int32_t in_size = SRC_HEIGHT * SRC_WIDTH * channels;
70  ne10_int32_t out_size = DST_HEIGHT * DST_WIDTH * channels;
71  ne10_float32_t PSNR = 0.0f;
72  ne10_int32_t srcw = SRC_WIDTH;
73  ne10_int32_t srch = SRC_HEIGHT;
74  ne10_uint32_t dstw_c, dsth_c;
75  ne10_uint32_t dstw_neon, dsth_neon;
76  ne10_int32_t angle;
77 
78  /* init input memory */
79  in_c = NE10_MALLOC (in_size * sizeof (ne10_uint8_t));
80  in_neon = NE10_MALLOC (in_size * sizeof (ne10_uint8_t));
81 
82  /* init dst memory */
83  out_c = NE10_MALLOC (out_size * sizeof (ne10_uint8_t));
84  out_neon = NE10_MALLOC (out_size * sizeof (ne10_uint8_t));
85 
86  for (i = 0; i < in_size; i++)
87  {
88  in_c[i] = in_neon[i] = (rand() & 0xff);
89  }
90 
91  for (angle = -360; angle <= 360; angle += 30)
92  {
93  printf ("rotate angle %d \n", angle);
94 
95  memset (out_c, 0, out_size);
96  ne10_img_rotate_rgba_c (out_c, &dstw_c, &dsth_c, in_c, srcw, srch, angle);
97 
98  memset (out_neon, 0, out_size);
99  ne10_img_rotate_rgba_neon (out_neon, &dstw_neon, &dsth_neon, in_neon, srcw, srch, angle);
100 
101  PSNR = CAL_PSNR_UINT8 (out_c, out_neon, dstw_c * dsth_c * 4);
102  assert_false ( (PSNR < PSNR_THRESHOLD));
103  //printf ("PSNR %f \n", PSNR);
104  }
105  NE10_FREE (in_c);
106  NE10_FREE (in_neon);
107  NE10_FREE (out_c);
108  NE10_FREE (out_neon);
109 }
110 #endif // ENABLE_NE10_IMG_ROTATE_RGBA_NEON
111 
112 void test_rotate_performance_case()
113 {
114  ne10_int32_t i;
115  ne10_int32_t channels = 4;
116  ne10_int32_t in_size = SRC_HEIGHT * SRC_WIDTH * channels;
117  ne10_int32_t out_size = DST_HEIGHT * DST_WIDTH * channels;
118  ne10_int32_t srcw = SRC_WIDTH;
119  ne10_int32_t srch = SRC_HEIGHT;
120  ne10_uint32_t dstw_c, dsth_c;
121  ne10_uint32_t dstw_neon, dsth_neon;
122  ne10_int32_t angle;
123  ne10_int64_t time_c = 0;
124  ne10_int64_t time_neon = 0;
125 
126  /* init input memory */
127  in_c = NE10_MALLOC (in_size * sizeof (ne10_uint8_t));
128  in_neon = NE10_MALLOC (in_size * sizeof (ne10_uint8_t));
129 
130  /* init dst memory */
131  out_c = NE10_MALLOC (out_size * sizeof (ne10_uint8_t));
132  out_neon = NE10_MALLOC (out_size * sizeof (ne10_uint8_t));
133 
134  for (i = 0; i < in_size; i++)
135  {
136  in_c[i] = in_neon[i] = (rand() & 0xff);
137  }
138 
139  //for (angle = -360; angle <= 360; angle += 5)
140  for (angle = 45; angle <= 45; angle += 5)
141  {
142  printf ("rotate angle %d \n", angle);
143 
144  memset (out_c, 0, out_size);
145  GET_TIME
146  (
147  time_c,
148  {
149  for (i = 0; i < TEST_COUNT; i++)
150  ne10_img_rotate_rgba_c (out_c, &dstw_c, &dsth_c, in_c, srcw, srch, angle);
151  }
152  );
153 
154 #ifdef ENABLE_NE10_IMG_ROTATE_RGBA_NEON
155  memset (out_neon, 0, out_size);
156  GET_TIME
157  (
158  time_neon,
159  {
160  for (i = 0; i < TEST_COUNT; i++)
161  ne10_img_rotate_rgba_neon (out_neon, &dstw_neon, &dsth_neon, in_neon, srcw, srch, angle);
162  }
163  );
164 #endif // ENABLE_NE10_IMG_ROTATE_RGBA_NEON
165 
166  //printf ("time c %lld \n", time_c);
167  //printf ("time neon %lld \n", time_neon);
168  ne10_log (__FUNCTION__, "IMAGEROTATE%20d%20lld%20lld%19.2f%%%18.2f:1\n", angle, time_c, time_neon, 0, 0);
169  }
170 
171  NE10_FREE (in_c);
172  NE10_FREE (in_neon);
173  NE10_FREE (out_c);
174  NE10_FREE (out_neon);
175 }
176 
177 void test_rotate()
178 {
179 #ifdef ENABLE_NE10_IMG_ROTATE_RGBA_NEON
180 #if defined (SMOKE_TEST)||(REGRESSION_TEST)
181  test_rotate_conformance_case();
182 #endif
183 #endif // ENABLE_NE10_IMG_ROTATE_RGBA_NEON
184 
185 #if defined PERFORMANCE_TEST
186  test_rotate_performance_case();
187 #endif
188 }
189 
190 static void my_test_setup (void)
191 {
192  ne10_log_buffer_ptr = ne10_log_buffer;
193 }
194 
195 void test_fixture_rotate (void)
196 {
197  test_fixture_start(); // starts a fixture
198 
199  fixture_setup (my_test_setup);
200 
201  run_test (test_rotate); // run tests
202 
203  test_fixture_end(); // ends a fixture
204 }
uint8_t ne10_uint8_t
Definition: NE10_types.h:73
int32_t ne10_int32_t
Definition: NE10_types.h:76
void my_test_setup(void)
float ne10_float32_t
Definition: NE10_types.h:80
#define SRC_HEIGHT
#define DST_HEIGHT
int64_t ne10_int64_t
Definition: NE10_types.h:78
uint32_t ne10_uint32_t
Definition: NE10_types.h:77
void ne10_img_rotate_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_int32_t angle) asm("ne10_img_rotate_rgba_neon")
Specific implementation of ne10_img_rotate_rgba using NEON SIMD capabilities.
Definition: NE10_rotate.c:256
#define NE10_FREE(p)
Definition: NE10_macros.h:54
#define DST_WIDTH
void ne10_img_rotate_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_int32_t angle)
Specific implementation of ne10_img_rotate_rgba using plain C.
Definition: NE10_rotate.c:212
#define NE10_MALLOC
Definition: NE10_macros.h:53
#define SRC_WIDTH
#define TEST_COUNT