You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
4.7 KiB

  1. //=====================================================
  2. // File : bench.hh
  3. // Author : L. Plagne <laurent.plagne@edf.fr)>
  4. // Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002
  5. //=====================================================
  6. //
  7. // This program is free software; you can redistribute it and/or
  8. // modify it under the terms of the GNU General Public License
  9. // as published by the Free Software Foundation; either version 2
  10. // of the License, or (at your option) any later version.
  11. //
  12. // This program is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. //
  20. #ifndef BENCH_HH
  21. #define BENCH_HH
  22. #include "btl.hh"
  23. #include "bench_parameter.hh"
  24. #include <iostream>
  25. #include "utilities.h"
  26. #include "size_lin_log.hh"
  27. #include "xy_file.hh"
  28. #include <vector>
  29. #include <string>
  30. #include "timers/portable_perf_analyzer.hh"
  31. // #include "timers/mixed_perf_analyzer.hh"
  32. // #include "timers/x86_perf_analyzer.hh"
  33. // #include "timers/STL_perf_analyzer.hh"
  34. #ifdef HAVE_MKL
  35. extern "C" void cblas_saxpy(const int, const float, const float*, const int, float *, const int);
  36. #endif
  37. using namespace std;
  38. template <template<class> class Perf_Analyzer, class Action>
  39. BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point )
  40. {
  41. if (BtlConfig::skipAction(Action::name()))
  42. return;
  43. string filename="bench_"+Action::name()+".dat";
  44. INFOS("starting " <<filename);
  45. // utilities
  46. std::vector<double> tab_mflops(nb_point);
  47. std::vector<int> tab_sizes(nb_point);
  48. // matrices and vector size calculations
  49. size_lin_log(nb_point,size_min,size_max,tab_sizes);
  50. std::vector<int> oldSizes;
  51. std::vector<double> oldFlops;
  52. bool hasOldResults = read_xy_file(filename, oldSizes, oldFlops, true);
  53. int oldi = oldSizes.size() - 1;
  54. // loop on matrix size
  55. Perf_Analyzer<Action> perf_action;
  56. for (int i=nb_point-1;i>=0;i--)
  57. {
  58. //INFOS("size=" <<tab_sizes[i]<<" ("<<nb_point-i<<"/"<<nb_point<<")");
  59. std::cout << " " << "size = " << tab_sizes[i] << " " << std::flush;
  60. BTL_DISABLE_SSE_EXCEPTIONS();
  61. #ifdef HAVE_MKL
  62. {
  63. float dummy;
  64. cblas_saxpy(1,0,&dummy,1,&dummy,1);
  65. }
  66. #endif
  67. tab_mflops[i] = perf_action.eval_mflops(tab_sizes[i]);
  68. std::cout << tab_mflops[i];
  69. if (hasOldResults)
  70. {
  71. while (oldi>=0 && oldSizes[oldi]>tab_sizes[i])
  72. --oldi;
  73. if (oldi>=0 && oldSizes[oldi]==tab_sizes[i])
  74. {
  75. if (oldFlops[oldi]<tab_mflops[i])
  76. std::cout << "\t > ";
  77. else
  78. std::cout << "\t < ";
  79. std::cout << oldFlops[oldi];
  80. }
  81. --oldi;
  82. }
  83. std::cout << " MFlops (" << nb_point-i << "/" << nb_point << ")" << std::endl;
  84. }
  85. if (!BtlConfig::Instance.overwriteResults)
  86. {
  87. if (hasOldResults)
  88. {
  89. // merge the two data
  90. std::vector<int> newSizes;
  91. std::vector<double> newFlops;
  92. int i=0;
  93. int j=0;
  94. while (i<tab_sizes.size() && j<oldSizes.size())
  95. {
  96. if (tab_sizes[i] == oldSizes[j])
  97. {
  98. newSizes.push_back(tab_sizes[i]);
  99. newFlops.push_back(std::max(tab_mflops[i], oldFlops[j]));
  100. ++i;
  101. ++j;
  102. }
  103. else if (tab_sizes[i] < oldSizes[j])
  104. {
  105. newSizes.push_back(tab_sizes[i]);
  106. newFlops.push_back(tab_mflops[i]);
  107. ++i;
  108. }
  109. else
  110. {
  111. newSizes.push_back(oldSizes[j]);
  112. newFlops.push_back(oldFlops[j]);
  113. ++j;
  114. }
  115. }
  116. while (i<tab_sizes.size())
  117. {
  118. newSizes.push_back(tab_sizes[i]);
  119. newFlops.push_back(tab_mflops[i]);
  120. ++i;
  121. }
  122. while (j<oldSizes.size())
  123. {
  124. newSizes.push_back(oldSizes[j]);
  125. newFlops.push_back(oldFlops[j]);
  126. ++j;
  127. }
  128. tab_mflops = newFlops;
  129. tab_sizes = newSizes;
  130. }
  131. }
  132. // dump the result in a file :
  133. dump_xy_file(tab_sizes,tab_mflops,filename);
  134. }
  135. // default Perf Analyzer
  136. template <class Action>
  137. BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point ){
  138. // if the rdtsc is not available :
  139. bench<Portable_Perf_Analyzer,Action>(size_min,size_max,nb_point);
  140. // if the rdtsc is available :
  141. // bench<Mixed_Perf_Analyzer,Action>(size_min,size_max,nb_point);
  142. // Only for small problem size. Otherwize it will be too long
  143. // bench<X86_Perf_Analyzer,Action>(size_min,size_max,nb_point);
  144. // bench<STL_Perf_Analyzer,Action>(size_min,size_max,nb_point);
  145. }
  146. #endif