Project Ne10
An Open Optimized Software Library Project for the ARM Architecture
Loading...
Searching...
No Matches
unit_test_common.h
1/*
2 * Copyright 2012-15 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/include/unit_test_common.h
30 */
31
32#ifndef __UNIT_TEST_COMMON__
33#define __UNIT_TEST_COMMON__
34
35// Make sure the following values are defined before including this header file:
36// 1- length of the data arrays
37// #define ARRLEN
38// 2- number of the operations in a given unit
39// #define OP_COUNT
40// 3- number of the different implementations of each of the functions (C, ASM, NEON, ...)
41// #define IMPL_COUNT
42
43#include <stdio.h>
44#include <assert.h>
45#include <math.h>
46
47#include <stdlib.h>
48#include <string.h>
49
50#include "NE10.h"
51#include "NE10_random.h"
52
53//detect that it is regression test or smoke test
54#if defined REGRESSION_TEST
55# define TEST_ITERATION 2048
56#else
57# ifdef SMOKE_TEST
58# define TEST_ITERATION 11
59# endif
60#endif
61
62//detect that it is performance test
63#if defined PERFORMANCE_TEST
64# define PERF_TEST_ITERATION 1024
65#endif
66
67// length of the test data arrays
68// A number that is not divisible by 2 3 and 4 so that all the
69// execution paths are tested; The larger the number the more
70// number of random values are stored in the array and passed
71// into the array as the input stream.
72// 2^11 + 3 = 2051, it is not divisible by 2, 3, or 4
73//#define TEST_ARRLEN 2051
74//#define TEST_ARRLEN_MATRICES 1051
75
76#define ARRAY_GUARD_LEN 4
77#define MAX_FUNC_COUNT 8 //C and NEON version with 4 different data type
78
79// The sign bit mask
80#define SIGNBIT_MASK 0x7FFFFFFF
81
82// What's the acceptable error between the integer representations of two ne10_float32_t values
83#define ERROR_MARGIN_SMALL 1
84#define ERROR_MARGIN_LARGE 1
85#define SNR_THRESHOLD 50.0f
86#define PSNR_THRESHOLD 30.0f
87
88// What's the acceptable number of warnings in a test
89#define ACCEPTABLE_WARNS 12
90#define ACCEPTABLE_WARNS_MATRICES 48
91
92#define NE10_SRC_ALLOC(src, guarded_src, length) { \
93 (guarded_src) = (ne10_float32_t*) calloc (2*ARRAY_GUARD_LEN + (length), sizeof(ne10_float32_t)); \
94 if ((guarded_src) == NULL) \
95 printf ("error: calloc src failed\n"); \
96 (src) = (guarded_src) + ARRAY_GUARD_LEN; \
97 FILL_FLOAT_ARRAY((src), (length)); \
98 }
99
100#define NE10_SRC_ALLOC_LIMIT(src, guarded_src, length) { \
101 (guarded_src) = (ne10_float32_t*) calloc (2*ARRAY_GUARD_LEN + (length), sizeof(ne10_float32_t)); \
102 if ((guarded_src) == NULL) \
103 printf ("error: calloc src failed\n"); \
104 (src) = (guarded_src) + ARRAY_GUARD_LEN; \
105 FILL_FLOAT_ARRAY_LIMIT((src), (length)); \
106 }
107
108#define NE10_DST_ALLOC(dst, guarded_dst, length) { \
109 (guarded_dst) = (ne10_float32_t*) calloc (2*ARRAY_GUARD_LEN + (length), sizeof(ne10_float32_t)); \
110 if ((guarded_dst) == NULL) \
111 printf ("error: calloc dst failed\n"); \
112 (dst) = (guarded_dst) + ARRAY_GUARD_LEN; \
113 }
114
115#define GET_TIME(time, code) { \
116 (time) = GetTickCount(); \
117 code \
118 (time) = GetTickCount() - (time);\
119 }
120
121typedef ne10_result_t (*ne10_func_5args_t) (void * dst, void * acc, void * src1, void * src2, ne10_uint32_t count);
122typedef ne10_result_t (*ne10_func_4args_t) (void * dst, void * src1, void * src2, ne10_uint32_t count);
123typedef ne10_result_t (*ne10_func_3args_t) (void * dst, void * src, ne10_uint32_t count);
124typedef ne10_result_t (*ne10_func_2args_t) (void * dst, ne10_uint32_t count);
125typedef ne10_result_t (*ne10_func_5args_cst_t) (void * dst, void * acc, void * src, ne10_float32_t cst, ne10_uint32_t count);
126typedef ne10_result_t (*ne10_func_4args_cst_t) (void * dst, void * src, const ne10_float32_t cst, ne10_uint32_t count);
127typedef ne10_result_t (*ne10_func_3args_cst_t) (void * dst, const ne10_float32_t cst, ne10_uint32_t count);
128
129extern void FILL_FLOAT_ARRAY( ne10_float32_t *arr, ne10_uint32_t count );
130extern void FILL_FLOAT_ARRAY_LIMIT( ne10_float32_t *arr, ne10_uint32_t count );
131extern void FILL_FLOAT_ARRAY_LIMIT_GT1( ne10_float32_t *arr, ne10_uint32_t count );
132
133// this function checks whether the difference between two ne10_float32_t values is within the acceptable error range
134extern int EQUALS_FLOAT( ne10_float32_t fa, ne10_float32_t fb , ne10_uint32_t err );
135extern int GUARD_ARRAY( ne10_float32_t* array, ne10_uint32_t array_length );
136extern int CHECK_ARRAY_GUARD( ne10_float32_t* array, ne10_uint32_t array_length );
137extern ne10_int32_t GUARD_ARRAY_UINT8 (ne10_uint8_t* array, ne10_uint32_t array_length);
138extern ne10_int32_t CHECK_ARRAY_GUARD_UINT8 (ne10_uint8_t* array, ne10_uint32_t array_length);
139extern ne10_float32_t CAL_SNR_FLOAT32(ne10_float32_t *pRef, ne10_float32_t *pTest, ne10_uint32_t buffSize);
140extern ne10_float32_t CAL_PSNR_UINT8 (ne10_uint8_t *pRef, ne10_uint8_t *pTest, ne10_uint32_t buffSize);
141
142extern char ne10_log_buffer[];
143extern char *ne10_log_buffer_ptr;
144extern void ne10_log(const char *func_name,
145 const char *format_str,
146 ne10_int32_t n,
147 ne10_int32_t time_c,
148 ne10_int32_t time_neon,
149 ne10_float32_t time_savings,
150 ne10_float32_t time_speedup);
151extern void ne10_performance_print(ne10_print_target_t target,
152 long int neon_ticks,
153 long int c_ticks,
154 char *info);
155extern void diff(const ne10_uint8_t *mat1,
156 const ne10_uint8_t *mat2,
157 ne10_int32_t *dst,
158 ne10_uint32_t dst_stride,
159 ne10_uint32_t width,
160 ne10_uint32_t height,
161 ne10_uint32_t src_stride,
162 ne10_uint32_t channel);
163extern int diff_count(const ne10_int32_t *mat,
164 ne10_int32_t width,
165 ne10_int32_t height,
166 ne10_int32_t stride,
167 ne10_int32_t channel);
168
169#endif // __UNIT_TEST_COMMON
170