34 #include "unit_test_common.h" 36 void FILL_FLOAT_ARRAY (ne10_float32_t *arr, ne10_uint32_t count)
42 NE10_float_rng_init (time (NULL));
44 for (i = 0; i < count; i++)
46 arr[i] = NE10_float_rng_next();
50 void FILL_FLOAT_ARRAY_LIMIT (ne10_float32_t *arr, ne10_uint32_t count)
56 NE10_float_rng_limit_init (time (NULL));
58 for (i = 0; i < count; i++)
60 arr[ i ] = NE10_float_rng_limit_next();
64 void FILL_FLOAT_ARRAY_LIMIT_GT1 (ne10_float32_t *arr, ne10_uint32_t count)
70 NE10_float_rng_limit_gt1_init (time (NULL));
72 for (i = 0; i < count; i++)
74 arr[ i ] = NE10_float_rng_limit_gt1_next();
79 ne10_int32_t EQUALS_FLOAT (ne10_float32_t fa, ne10_float32_t fb , ne10_uint32_t err)
80 { ne10_float32_t tolerance = (ne10_float32_t)err / 200000;
81 if (abs(fa-fb) <= tolerance)
91 ne10_float32_t ARRAY_GUARD_SIG[ARRAY_GUARD_LEN] = { 10.0f, 20.0f, 30.0f, 40.0f };
93 ne10_int32_t GUARD_ARRAY (ne10_float32_t* array, ne10_uint32_t array_length)
95 ne10_float32_t* the_array = array - ARRAY_GUARD_LEN;
96 memcpy (the_array, ARRAY_GUARD_SIG,
sizeof (ARRAY_GUARD_SIG));
97 the_array = array + array_length;
98 memcpy (the_array, ARRAY_GUARD_SIG,
sizeof (ARRAY_GUARD_SIG));
103 ne10_int32_t CHECK_ARRAY_GUARD (ne10_float32_t* array, ne10_uint32_t array_length)
105 ne10_float32_t* the_array = array - ARRAY_GUARD_LEN;
107 for (i = 0; i < ARRAY_GUARD_LEN; i++)
109 if (! EQUALS_FLOAT (the_array[i], ARRAY_GUARD_SIG[i], ERROR_MARGIN_SMALL))
111 fprintf (stderr,
" ERROR: prefix array guard signature is wrong. \n");
116 the_array = array + array_length;
117 for (i = 0; i < ARRAY_GUARD_LEN; i++)
119 if (! EQUALS_FLOAT (the_array[i], ARRAY_GUARD_SIG[i], ERROR_MARGIN_SMALL))
121 fprintf (stderr,
" ERROR: suffix array guard signature is wrong. \n");
130 ne10_uint8_t ARRAY_GUARD_SIG_UINT8[ARRAY_GUARD_LEN] = { 0x12, 0x34, 0x56, 0x78 };
132 ne10_int32_t GUARD_ARRAY_UINT8 (ne10_uint8_t* array, ne10_uint32_t array_length)
134 ne10_uint8_t* the_array = array - ARRAY_GUARD_LEN;
135 memcpy (the_array, ARRAY_GUARD_SIG_UINT8,
sizeof (ARRAY_GUARD_SIG_UINT8));
136 the_array = array + array_length;
137 memcpy (the_array, ARRAY_GUARD_SIG_UINT8,
sizeof (ARRAY_GUARD_SIG_UINT8));
142 ne10_int32_t CHECK_ARRAY_GUARD_UINT8 (ne10_uint8_t* array, ne10_uint32_t array_length)
144 ne10_uint8_t* the_array = array - ARRAY_GUARD_LEN;
146 for (i = 0; i < ARRAY_GUARD_LEN; i++)
148 if (the_array[i] != ARRAY_GUARD_SIG_UINT8[i])
150 fprintf (stderr,
" ERROR: prefix array guard signature is wrong. \n");
155 the_array = array + array_length;
156 for (i = 0; i < ARRAY_GUARD_LEN; i++)
158 if (the_array[i] != ARRAY_GUARD_SIG_UINT8[i])
160 fprintf (stderr,
" ERROR: suffix array guard signature is wrong. \n");
178 ne10_float32_t CAL_SNR_FLOAT32 (ne10_float32_t *pRef, ne10_float32_t *pTest, ne10_uint32_t buffSize)
180 ne10_float32_t EnergySignal = 0.0, EnergyError = 0.0;
184 for (i = 0; i < buffSize; i++)
186 EnergySignal += pRef[i] * pRef[i];
187 EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]);
189 SNR = 10 * log10 (EnergySignal / EnergyError);
204 ne10_float32_t CAL_PSNR_UINT8 (ne10_uint8_t *pRef, ne10_uint8_t *pTest, ne10_uint32_t buffSize)
206 ne10_float64_t mse = 0.0, max = 255.0;
210 for (i = 0; i < buffSize; i++)
212 mse += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]);
215 PSNR = 10 * log10 (max*max / mse);
219 char ne10_log_buffer[5000];
220 char *ne10_log_buffer_ptr;
222 void ne10_log(
const char *func_name,
223 const char *format_str,
226 ne10_int32_t time_neon,
227 ne10_float32_t time_savings,
228 ne10_float32_t time_speedup)
231 byte_count = sprintf(ne10_log_buffer_ptr,
232 "{ \"name\" : \"%s %d\", \"time_c\" : %d, " 233 "\"time_neon\" : %d },",
234 func_name, n, time_c, time_neon);
235 ne10_log_buffer_ptr += byte_count;
239 "%25d%20d%20d%19.2f%%%18.2f:1\n",
252 void ne10_performance_print(ne10_print_target_t target,
257 double f = (double)c_ticks / neon_ticks;
259 case UBUNTU_COMMAND_LINE:
260 printf(
"\n%s\nneon(ms): %.2f c(ms): %.2f(ms) speedup: %.2f",
273 void diff(
const ne10_uint8_t *mat1,
274 const ne10_uint8_t *mat2,
276 ne10_uint32_t dst_stride,
278 ne10_uint32_t height,
279 ne10_uint32_t src_stride,
280 ne10_uint32_t channel)
282 assert(mat1 != 0 && mat2 != 0 && dst != 0);
286 for(k = 0; k < channel; k++)
288 for(j = 0; j < height; j++)
290 const ne10_uint8_t *row1 = mat1 + j * src_stride;
291 const ne10_uint8_t *row2 = mat2 + j * src_stride;
292 ne10_int32_t *row_dst = dst + j * dst_stride /
sizeof(ne10_int32_t);
293 for(i = 0; i < width; i++)
295 *(row_dst + i * channel + k) =
296 (ne10_int32_t) (*(row1 + i * channel + k)) -
297 *(row2 + i * channel + k);
304 int diff_count(
const ne10_int32_t *mat,
308 ne10_int32_t channel)
314 for(j = 0; j < height; j++)
316 const ne10_int32_t *row = mat + j * stride /
sizeof(ne10_int32_t);
317 for(i = 0; i < width; i++)
319 for(k = 0; k < channel; k++)
321 const ne10_int32_t val = *(row + i * channel + k);
322 if (val != -1 && val != 0 && val != -2 && val != 1 && val != 2)
333 void progress_bar(
float progress)
335 assert(progress <= 1);
337 static float progress_prev = 0;
338 if (progress != progress_prev)
343 int pos = bar_width * progress;
345 for (i = 0; i < bar_width; ++i) {
353 printf(
"] %d%%\r", (
int)(progress * 100.0));
355 progress_prev = progress;