~ubuntu-branches/ubuntu/vivid/atlas/vivid

« back to all changes in this revision

Viewing changes to tune/blas/gemm/hcsearch.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2002-04-13 10:07:52 UTC
  • Revision ID: james.westby@ubuntu.com-20020413100752-va9zm0rd4gpurdkq
Tags: upstream-3.2.1ln
ImportĀ upstreamĀ versionĀ 3.2.1ln

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *             Automatically Tuned Linear Algebra Software v3.2
 
3
 *                    (C) Copyright 1997 R. Clint Whaley                     
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
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
 
16
 *      written permission.
 
17
 *
 
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. 
 
29
 *
 
30
 */
 
31
 
 
32
#include <stdio.h>
 
33
#include <stdlib.h>
 
34
#include <assert.h>
 
35
#include <string.h>
 
36
#include "atlas_misc.h"
 
37
#include "atlas_fopen.h"
 
38
 
 
39
#define Mmin(x, y) ( (x) > (y) ? (y) : (x) )
 
40
 
 
41
#define TOLERANCE 1.2
 
42
double GetAvg(int n, double tolerance, double *mflop)
 
43
{
 
44
   int i, j;
 
45
   double t0, tavg;
 
46
/*
 
47
 * Sort results, largest first
 
48
 */
 
49
   for (i=0; i != n; i++)
 
50
   {
 
51
      for (j=i+1; j < n; j++)
 
52
      {
 
53
         if (mflop[i] < mflop[j])
 
54
         {
 
55
            t0 = mflop[i];
 
56
            mflop[i] = mflop[j];
 
57
            mflop[j] = t0;
 
58
         }
 
59
      }
 
60
   }
 
61
 
 
62
/*
 
63
 * Throw out result if it is outside tolerance; rerun if two mflop not within
 
64
 * tolerance;  this code assumes n == 3
 
65
 */
 
66
   if (tolerance*mflop[1] < mflop[0])  /* too big a range in results */
 
67
   {
 
68
      if (tolerance*mflop[2] < mflop[1]) return(-1.0);
 
69
      tavg = (mflop[1] + mflop[2]) / 2.0;
 
70
   }
 
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;
 
73
 
 
74
   return(tavg);
 
75
}
 
76
 
 
77
void PrintUsage(char *nam)
 
78
{
 
79
   fprintf(stderr, "USAGE: %s -p <pre> -n <nb> -C <m/n/k>\n", nam);
 
80
   exit(-1);
 
81
}
 
82
 
 
83
main(int nargs, char *args[])
 
84
{
 
85
   char ln[127], pre='d', ln2[127], ch;
 
86
   int i, nb=28;
 
87
   double mflops[3];
 
88
   double mf1, mf4;
 
89
   FILE *fpin, *fp;
 
90
 
 
91
   for (i=1; i < nargs; i++)
 
92
   {
 
93
      if (args[i][0] != '-') PrintUsage(args[0]);
 
94
      switch(args[i][1])
 
95
      {
 
96
      case 'p':
 
97
         ch = args[++i][0];
 
98
         pre = Mlowcase(ch);
 
99
         break;
 
100
      case 'n':
 
101
         nb = atoi(args[++i]);
 
102
         break;
 
103
      default: 
 
104
         PrintUsage(args[0]);
 
105
      }
 
106
   }
 
107
   sprintf(ln, "res/M%cNB%d_4x1x1_0-1.mflop", pre, nb);
 
108
   if (!FileExists(ln))
 
109
   {
 
110
      sprintf(ln2, "make %chc_cases nb=%d\n", pre, nb);
 
111
      assert(system(ln2) == 0);
 
112
   }
 
113
   fpin = fopen(ln, "r");
 
114
   assert(fpin);
 
115
   for (i=0; i < 3; i++) assert( fscanf(fpin, "%lf", mflops+i) );
 
116
   mf1 = GetAvg(3, 1.2, mflops);
 
117
   fclose(fpin);
 
118
 
 
119
   sprintf(ln, "res/M%cNB%d_4x4x1_0-1.mflop", pre, nb);
 
120
   if (!FileExists(ln))
 
121
   {
 
122
      sprintf(ln2, "make %chc_cases nb=%d\n", pre, nb);
 
123
      if (system(ln2) != 0)
 
124
      {
 
125
         sprintf(ln, "rm -f res/M%cNB*\n", pre);
 
126
         system(ln);
 
127
         fprintf(stderr, "Error in command: %s", ln2);
 
128
         exit(-1);
 
129
      }
 
130
   }
 
131
   fpin = fopen(ln, "r");
 
132
   assert(fpin);
 
133
   for (i=0; i < 3; i++) assert( fscanf(fpin, "%lf", mflops+i) );
 
134
   mf4 = GetAvg(3, 1.2, mflops);
 
135
   fclose(fpin);
 
136
 
 
137
   sprintf(ln, "res/%cmmcase.h", pre);
 
138
   fp = fopen(ln, "w");
 
139
   assert(fp);
 
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");
 
145
   fclose(fp);
 
146
   sprintf(ln, "res/%cHCRES", pre);
 
147
   fp = fopen(ln, "w");
 
148
   assert(fp);
 
149
   fprintf(fp, "%f\n", mf1);
 
150
   fprintf(fp, "%f\n", mf4);
 
151
   fclose(fp);
 
152
 
 
153
   exit(0);
 
154
}