sl@0
|
1 |
/*
|
sl@0
|
2 |
* LIBOIL - Library of Optimized Inner Loops
|
sl@0
|
3 |
* Copyright (c) 2004 David A. Schleef <ds@schleef.org>
|
sl@0
|
4 |
* All rights reserved.
|
sl@0
|
5 |
*
|
sl@0
|
6 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
7 |
* modification, are permitted provided that the following conditions
|
sl@0
|
8 |
* are met:
|
sl@0
|
9 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
10 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
11 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
12 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
13 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
sl@0
|
16 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
sl@0
|
17 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
sl@0
|
19 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
sl@0
|
20 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
sl@0
|
21 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
23 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
sl@0
|
24 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
sl@0
|
25 |
* POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
26 |
*/
|
sl@0
|
27 |
|
sl@0
|
28 |
|
sl@0
|
29 |
#include <stdio.h>
|
sl@0
|
30 |
#include <liboil/liboilprototype.h>
|
sl@0
|
31 |
#include <liboil/liboiltest.h>
|
sl@0
|
32 |
#include <liboil/liboilcpu.h>
|
sl@0
|
33 |
#include <liboil/liboilrandom.h>
|
sl@0
|
34 |
#include <liboil/liboil.h>
|
sl@0
|
35 |
#include <ctype.h>
|
sl@0
|
36 |
#include <stdlib.h>
|
sl@0
|
37 |
#include <string.h>
|
sl@0
|
38 |
#include <math.h>
|
sl@0
|
39 |
|
sl@0
|
40 |
|
sl@0
|
41 |
#define LOG_FILE "c:\\logs\\testsuite_stride_log1.txt"
|
sl@0
|
42 |
#include "std_log_result.h"
|
sl@0
|
43 |
#define LOG_FILENAME_LINE __FILE__, __LINE__
|
sl@0
|
44 |
|
sl@0
|
45 |
void create_xml(int result)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
if(result)
|
sl@0
|
48 |
assert_failed = 1;
|
sl@0
|
49 |
|
sl@0
|
50 |
testResultXml("testsuite_stride");
|
sl@0
|
51 |
close_log_file();
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
void hist(OilTest *Test);
|
sl@0
|
55 |
|
sl@0
|
56 |
int verbose = 0;
|
sl@0
|
57 |
int fail = 0;
|
sl@0
|
58 |
|
sl@0
|
59 |
int main (int argc, char *argv[])
|
sl@0
|
60 |
{
|
sl@0
|
61 |
OilFunctionClass *klass;
|
sl@0
|
62 |
OilFunctionImpl *impl;
|
sl@0
|
63 |
OilTest *test;
|
sl@0
|
64 |
int i;
|
sl@0
|
65 |
int n;
|
sl@0
|
66 |
int j;
|
sl@0
|
67 |
int ret;
|
sl@0
|
68 |
unsigned int cpu_flags;
|
sl@0
|
69 |
//xmlfile = "stride";
|
sl@0
|
70 |
std_log(LOG_FILENAME_LINE, "Test Started testsuite_stride");
|
sl@0
|
71 |
|
sl@0
|
72 |
if (argc > 1 && strcmp(argv[1],"-v") == 0) {
|
sl@0
|
73 |
verbose = 1;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
oil_init ();
|
sl@0
|
76 |
|
sl@0
|
77 |
cpu_flags = oil_cpu_get_flags ();
|
sl@0
|
78 |
n = oil_class_get_n_classes ();
|
sl@0
|
79 |
|
sl@0
|
80 |
for (i=0;i<n; i++ )
|
sl@0
|
81 |
{
|
sl@0
|
82 |
klass = oil_class_get_by_index(i);
|
sl@0
|
83 |
std_log(LOG_FILENAME_LINE,"Class Name %s %d\n",klass->name, i);
|
sl@0
|
84 |
|
sl@0
|
85 |
test = oil_test_new (klass);
|
sl@0
|
86 |
|
sl@0
|
87 |
if (test == NULL)
|
sl@0
|
88 |
{
|
sl@0
|
89 |
std_log(LOG_FILENAME_LINE,"class \"%s\" has bad prototype\n", klass->name);
|
sl@0
|
90 |
assert_failed = fail = 1;
|
sl@0
|
91 |
continue;
|
sl@0
|
92 |
}
|
sl@0
|
93 |
oil_test_set_iterations (test, 1);
|
sl@0
|
94 |
test->n = 1 + oil_rand_u8();
|
sl@0
|
95 |
test->m = 1 + oil_rand_u8();
|
sl@0
|
96 |
|
sl@0
|
97 |
std_log(LOG_FILENAME_LINE, "ref impl %s",klass->reference_impl->name);
|
sl@0
|
98 |
oil_test_check_impl (test, klass->reference_impl); //Testing whether an appropriate implementation is suitable or not
|
sl@0
|
99 |
//Runs the testing procedure described by test on the implementation impl
|
sl@0
|
100 |
|
sl@0
|
101 |
for(j=0;j<OIL_ARG_LAST;j++)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
if (test->params[j].is_stride)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
test->params[j].value += oil_type_sizeof(test->params[j].type) *
|
sl@0
|
106 |
(oil_rand_u8()&0xf);
|
sl@0
|
107 |
}
|
sl@0
|
108 |
}
|
sl@0
|
109 |
test->inited = 0;
|
sl@0
|
110 |
|
sl@0
|
111 |
for (impl = klass->first_impl; impl; impl = impl->next)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
std_log(LOG_FILENAME_LINE," %s\n", impl->name);
|
sl@0
|
114 |
if ((impl->flags & OIL_CPU_FLAG_MASK) & ~cpu_flags){
|
sl@0
|
115 |
std_log(LOG_FILENAME_LINE, "Not supported");
|
sl@0
|
116 |
}
|
sl@0
|
117 |
else
|
sl@0
|
118 |
{
|
sl@0
|
119 |
ret = oil_test_check_impl (test, impl);
|
sl@0
|
120 |
if (!ret)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
assert_failed = fail = 1;
|
sl@0
|
123 |
oil_test_free (test);
|
sl@0
|
124 |
std_log(LOG_FILENAME_LINE, "Test Failed");
|
sl@0
|
125 |
create_xml(1);
|
sl@0
|
126 |
return fail;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
oil_test_free (test);
|
sl@0
|
134 |
}
|
sl@0
|
135 |
|
sl@0
|
136 |
if(assert_failed)
|
sl@0
|
137 |
std_log(LOG_FILENAME_LINE,"Test Fail");
|
sl@0
|
138 |
else
|
sl@0
|
139 |
std_log(LOG_FILENAME_LINE,"Test Successful");
|
sl@0
|
140 |
create_xml(0);
|
sl@0
|
141 |
return fail;
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
void
|
sl@0
|
145 |
hist(OilTest *test)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
double ave;
|
sl@0
|
148 |
double std;
|
sl@0
|
149 |
int max_i;
|
sl@0
|
150 |
double off;
|
sl@0
|
151 |
double s;
|
sl@0
|
152 |
double s2;
|
sl@0
|
153 |
int i;
|
sl@0
|
154 |
int n;
|
sl@0
|
155 |
double x;
|
sl@0
|
156 |
|
sl@0
|
157 |
do {
|
sl@0
|
158 |
s = s2 = 0;
|
sl@0
|
159 |
n = 0;
|
sl@0
|
160 |
max_i = -1;
|
sl@0
|
161 |
for(i=0;i<10;i++){
|
sl@0
|
162 |
x = test->prof.hist_time[i];
|
sl@0
|
163 |
s2 += x * x * test->prof.hist_count[i];
|
sl@0
|
164 |
s += x * test->prof.hist_count[i];
|
sl@0
|
165 |
n += test->prof.hist_count[i];
|
sl@0
|
166 |
if (test->prof.hist_count[i] > 0) {
|
sl@0
|
167 |
if (max_i == -1 || test->prof.hist_time[i] > test->prof.hist_time[max_i]) {
|
sl@0
|
168 |
max_i = i;
|
sl@0
|
169 |
}
|
sl@0
|
170 |
}
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
ave = s / n;
|
sl@0
|
174 |
std = sqrt (s2 - s * s / n + n*n) / (n-1);
|
sl@0
|
175 |
off = (test->prof.hist_time[max_i] - ave)/std;
|
sl@0
|
176 |
|
sl@0
|
177 |
printf(" ave=%g std=%g max=%ld off=%g %s\n",
|
sl@0
|
178 |
ave, std, test->prof.hist_time[max_i], off, (off>4.0)?"yes":"no");
|
sl@0
|
179 |
|
sl@0
|
180 |
if (off > 4.0) {
|
sl@0
|
181 |
test->prof.hist_count[max_i] = 0;
|
sl@0
|
182 |
}
|
sl@0
|
183 |
} while (off > 4.0);
|
sl@0
|
184 |
printf(" ave=%g std=%g\n", ave, std);
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
|