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

« back to all changes in this revision

Viewing changes to tune/sysinfo/masearch.c

  • Committer: Bazaar Package Importer
  • Author(s): Sylvestre Ledru
  • Date: 2009-09-17 23:31:54 UTC
  • mto: (2.2.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090917233154-9esw88ub02twbuab
Tags: upstream-3.8.3
ImportĀ upstreamĀ versionĀ 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *             Automatically Tuned Linear Algebra Software v3.6.0
 
2
 *             Automatically Tuned Linear Algebra Software v3.8.3
3
3
 *                    (C) Copyright 1997 R. Clint Whaley
4
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
62
62
   assert(fpout != NULL);
63
63
   if (MULADD) ma = "Combined MULADD";
64
64
   else ma = "Separate multiply and add";
65
 
   fprintf(fpout, "#include <stdio.h>\n#include<assert.h>\n");
 
65
   fprintf(fpout,
 
66
           "#include <stdio.h>\n#include <stdlib.h>\n#include <assert.h>\n");
66
67
   fprintf(fpout, "#if defined(PentiumCPS) || defined(WALL)\n");
67
68
   fprintf(fpout, "   #define time00 ATL_walltime\n");
68
69
   fprintf(fpout, "#else\n   #define time00 ATL_cputime\n#endif\n");
77
78
   for (i=1; i < lat; i++) fprintf(fpout, ", c%d", i);
78
79
   if (!MULADD) for (i=0; i < lat; i++) fprintf(fpout, ", m%d", i);
79
80
   fprintf(fpout, ";\n\n");
 
81
   fprintf(fpout,
 
82
      "   if (!(rand()|rand()|rand()|rand()|rand()|rand())) nreps = rand();\n");
80
83
 
81
 
   fprintf(fpout, "   if (nreps > 0) c0 = 0.0;\n   else c0 = 2.2*nreps;\n");
82
 
   if (lat > 1 || !MULADD)
83
 
   {
84
 
      fprintf(fpout, "   ");
85
 
      for (i=1; i < lat; i++) fprintf(fpout, "c%d = ", i);
86
 
      if (!MULADD) for (i=0; i < lat; i++) fprintf(fpout, "m%d = ", i);
87
 
      fprintf(fpout, "c0;\n");
88
 
   }
 
84
/*
 
85
 * Try to make sure compiler cannot figure out ops can be reduced to asg
 
86
 */
 
87
   for (i=0; i < lat; i++)
 
88
      fprintf(fpout,
 
89
      "   if (rand()|rand()|rand()) c%d = 0.0;\n   else c%d = 1.%d*rand();\n",
 
90
              i, i, i);
 
91
   if (!MULADD)
 
92
      for (i=0; i < lat; i++)
 
93
         fprintf(fpout,
 
94
      "   if (rand()|rand()|rand()) m%d = 0.0;\n   else m%d = 0.%d*rand();\n",
 
95
                 i, i, i+1);
89
96
   fprintf(fpout, "   t0 = time00();\n");
90
97
   fprintf(fpout, "   do\n   {\n");
91
98
   for (j=0; j < nama; j++)
100
107
   fprintf(fpout, "   }\n   while(--i);\n");
101
108
   fprintf(fpout, "   tim = time00() - t0;\n");
102
109
   fprintf(fpout, "   c0 = c0");
103
 
   for (i=1; i < lat; i++) fprintf(fpout, " + c%d", i);
104
 
   if (!MULADD) for (i=0; i < lat; i++) fprintf(fpout, " + m%d", i);
 
110
   if (!MULADD)
 
111
   {
 
112
      fprintf(fpout, "*m0");
 
113
      for (i=1; i < lat; i++) fprintf(fpout, " + c%d*m%d", i, i);
 
114
   }
 
115
   else
 
116
      for (i=1; i < lat; i++) fprintf(fpout, " + c%d", i);
105
117
   fprintf(fpout, ";\n");
106
118
   mf = (2.0 * nama)*lat ;
107
119
   fprintf(fpout, "   if (tim < 0.0) mf = tim = 0.0;\n");
150
162
   if (fp == NULL)
151
163
   {
152
164
      emit_muladd(type, pre, MULADD, lat, nlma, mflops);
153
 
      assert(system("make xmuladd\n") == 0);
 
165
      sprintf(ln, "make x%cmuladd\n", pre);
 
166
      assert(!system(ln));
154
167
      assert( (fp = fopen(fnam, "r")) != NULL );
155
168
   }
156
169
   t0 = 0.0;
177
190
   }
178
191
 
179
192
/*
180
 
 * Throw out result if it is outside tolerance; rerun if two mflop not within
181
 
 * tolerance
 
193
 * For walltime, return min time, else return median
182
194
 */
183
 
   if (TOLERANCE*mflop[1] < mflop[0])  /* too big a range in results */
184
 
   {
185
 
      if (TOLERANCE*mflop[2] < mflop[1])
186
 
      {
187
 
         fprintf(stderr, "MULADD=%d, lat=%d: kill file and rerun with higher reps; variation exceeds tolerence\n", MULADD, lat);
188
 
         exit(-1);
189
 
      }
190
 
      tavg = (mflop[1] + mflop[2]) / 2.0;
191
 
   }
192
 
   else if (TOLERANCE*mflop[2] < mflop[0]) tavg = (mflop[0] + mflop[1]) / 2.0;
193
 
   else tavg = (mflop[0] + mflop[1] + mflop[2]) / 3.0;
194
 
 
195
 
   return(tavg);
 
195
   #if defined(PentiumCPS) || defined(WALL)
 
196
      return(mflop[0]);
 
197
   #else
 
198
      return(mflop[NTIM/2]);
 
199
   #endif
196
200
}
197
201
 
198
202
int FindSafeNumRegs(char pre, char *type, int nlma, int mflops,
274
278
   }
275
279
}
276
280
 
 
281
static int Mylcm(const int M, const int N)
 
282
/*
 
283
 * Returns least common multiple (LCM) of two positive integers M & N by
 
284
 * computing greatest common divisor (GCD) and using the property that
 
285
 * M*N = GCD*LCM.
 
286
 */
 
287
{
 
288
   register int tmp, max, min, gcd=0;
 
289
 
 
290
   if (M != N)
 
291
   {
 
292
      if (M > N) { max = M; min = N; }
 
293
      else { max = N; min = M; }
 
294
      if (min > 0)  /* undefined for negative numbers */
 
295
      {
 
296
         do  /* while (min) */
 
297
         {
 
298
            if ( !(min & 1) ) /* min is even */
 
299
            {
 
300
               if ( !(max & 1) ) /* max is also even */
 
301
               {
 
302
                  do
 
303
                  {
 
304
                     min >>= 1;
 
305
                     max >>= 1;
 
306
                     gcd++;
 
307
                     if (min & 1) goto MinIsOdd;
 
308
                  }
 
309
                  while ( !(max & 1) );
 
310
               }
 
311
               do min >>=1 ; while ( !(min & 1) );
 
312
            }
 
313
/*
 
314
 *          Once min is odd, halve max until it too is odd.  Then, use
 
315
 *          property that gcd(max, min) = gcd(max, (max-min)/2)
 
316
 *          for odd max & min
 
317
 */
 
318
MinIsOdd:
 
319
            if (min != 1)
 
320
            {
 
321
               do  /* while (max >= min */
 
322
               {
 
323
                  max -= (max & 1) ? min : 0;
 
324
                  max >>= 1;
 
325
               }
 
326
               while (max >= min);
 
327
            }
 
328
            else return( (M*N) / (1<<gcd) );
 
329
            tmp = max;
 
330
            max = min;
 
331
            min = tmp;
 
332
         }
 
333
         while(tmp);
 
334
      }
 
335
      return( (M*N) / (max<<gcd) );
 
336
   }
 
337
   else return(M);
 
338
}
 
339
 
277
340
main(int nargs, char *args[])
278
341
{
279
342
   char pre, *type, fnam[64];
298
361
   }
299
362
   maxlat = atoi(args[2]);
300
363
   mflop = atoi(args[3]);  /* this is ignored now */
301
 
 
 
364
   if (nargs == 5) nlma = atoi(args[4]);
 
365
   else
 
366
   {
 
367
      nlma = 2;
 
368
      for (k=3; k < maxlat; k++)
 
369
         nlma = Mylcm(nlma, k);
 
370
      nlma = ((512+nlma-1)/nlma)*nlma;
 
371
   }
302
372
   if (maxlat <= 0)
303
373
   {
304
374
      RunTime(pre, type, nlma, mflop);
305
375
      exit(0);
306
376
   }
307
 
   if (nargs == 5) nlma = atoi(args[4]);
308
377
 
309
378
   kma = kno = kbest = -1;
310
379
   mf = mfma = mfno = 0.0;
311
380
 
312
 
   #ifdef ATL_ARCH_IA64Itan
313
 
      if (maxlat == 6) maxlat = 14; /* temporary kludge for IA64 */
314
 
   #endif
 
381
   maxlat = 16;
315
382
   for (k=0; k < maxlat; k++)
316
383
   {
317
384
      mf0 = macase(type, pre, 1, k, nlma, mflop);
321
388
         kma = k;
322
389
      }
323
390
      fprintf(stdout, "      MULADD=%d, lat=%d, mf=%.2lf\n", 1, k+1, mf0);
 
391
/*
 
392
 *    If we've timed the short lengths and longer is not improving perf, quit
 
393
 */
 
394
      if (k > 6 && mf0 < mfma)
 
395
         break;
324
396
   }
325
397
   for (k=0; k < maxlat; k++)
326
398
   {
331
403
         kno = k;
332
404
      }
333
405
      fprintf(stdout, "      MULADD=%d, lat=%d, mf=%.2lf\n", 0, k+1, mf0);
 
406
/*
 
407
 *    If we've timed the short lengths and longer is not improving perf, quit
 
408
 */
 
409
      if (k > 6 && mf0 < mfma)
 
410
         break;
334
411
   }
335
412
/*
336
413
 * Award ties to separate multiply/add, since it may just be the compiler