2
* Automatically Tuned Linear Algebra Software v3.2
3
* (C) Copyright 1997 R. Clint Whaley
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions, and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. The name of the University of Tennessee, the ATLAS group,
14
* or the names of its contributers may not be used to endorse
15
* or promote products derived from this software without specific
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE
22
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
* POSSIBILITY OF SUCH DAMAGE.
36
#include "atlas_misc.h"
37
#include "atlas_fopen.h"
39
#define Mmin(x, y) ( (x) > (y) ? (y) : (x) )
42
double GetAvg(int n, double tolerance, double *mflop)
47
* Sort results, largest first
49
for (i=0; i != n; i++)
51
for (j=i+1; j < n; j++)
53
if (mflop[i] < mflop[j])
63
* Throw out result if it is outside tolerance; rerun if two mflop not within
64
* tolerance; this code assumes n == 3
66
if (tolerance*mflop[1] < mflop[0]) /* too big a range in results */
68
if (tolerance*mflop[2] < mflop[1]) return(-1.0);
69
tavg = (mflop[1] + mflop[2]) / 2.0;
71
else if (tolerance*mflop[2] < mflop[0]) tavg = (mflop[0] + mflop[1]) / 2.0;
72
else tavg = (mflop[0] + mflop[1] + mflop[2]) / 3.0;
77
void PrintUsage(char *nam)
79
fprintf(stderr, "USAGE: %s -p <pre> -n <nb> -C <m/n/k>\n", nam);
83
main(int nargs, char *args[])
85
char ln[127], pre='d', ln2[127], ch;
91
for (i=1; i < nargs; i++)
93
if (args[i][0] != '-') PrintUsage(args[0]);
101
nb = atoi(args[++i]);
107
sprintf(ln, "res/M%cNB%d_4x1x1_0-1.mflop", pre, nb);
110
sprintf(ln2, "make %chc_cases nb=%d\n", pre, nb);
111
assert(system(ln2) == 0);
113
fpin = fopen(ln, "r");
115
for (i=0; i < 3; i++) assert( fscanf(fpin, "%lf", mflops+i) );
116
mf1 = GetAvg(3, 1.2, mflops);
119
sprintf(ln, "res/M%cNB%d_4x4x1_0-1.mflop", pre, nb);
122
sprintf(ln2, "make %chc_cases nb=%d\n", pre, nb);
123
if (system(ln2) != 0)
125
sprintf(ln, "rm -f res/M%cNB*\n", pre);
127
fprintf(stderr, "Error in command: %s", ln2);
131
fpin = fopen(ln, "r");
133
for (i=0; i < 3; i++) assert( fscanf(fpin, "%lf", mflops+i) );
134
mf4 = GetAvg(3, 1.2, mflops);
137
sprintf(ln, "res/%cmmcase.h", pre);
140
fprintf(fp, "#ifndef %cMMCASE_H\n", Mupcase(pre));
141
fprintf(fp, " #define %cMMCASE_H\n", Mupcase(pre));
142
if (mf1 >= mf4) fprintf(fp, " #define Use4x1\n");
143
else fprintf(fp, " #define Use4x4\n");
144
fprintf(fp, "#endif\n");
146
sprintf(ln, "res/%cHCRES", pre);
149
fprintf(fp, "%f\n", mf1);
150
fprintf(fp, "%f\n", mf4);