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.

67 lines
1.3 KiB

  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <StormEigen/Core>
  5. #include "../../BenchTimer.h"
  6. using namespace StormEigen;
  7. #ifndef SCALAR
  8. #error SCALAR must be defined
  9. #endif
  10. typedef SCALAR Scalar;
  11. typedef Matrix<Scalar,Dynamic,Dynamic> Mat;
  12. STORMEIGEN_DONT_INLINE
  13. void gemm(const Mat &A, const Mat &B, Mat &C)
  14. {
  15. C.noalias() += A * B;
  16. }
  17. STORMEIGEN_DONT_INLINE
  18. double bench(long m, long n, long k)
  19. {
  20. Mat A(m,k);
  21. Mat B(k,n);
  22. Mat C(m,n);
  23. A.setRandom();
  24. B.setRandom();
  25. C.setZero();
  26. BenchTimer t;
  27. double up = 1e8*4/sizeof(Scalar);
  28. double tm0 = 4, tm1 = 10;
  29. if(NumTraits<Scalar>::IsComplex)
  30. {
  31. up /= 4;
  32. tm0 = 2;
  33. tm1 = 4;
  34. }
  35. double flops = 2. * m * n * k;
  36. long rep = std::max(1., std::min(100., up/flops) );
  37. long tries = std::max(tm0, std::min(tm1, up/flops) );
  38. BENCH(t, tries, rep, gemm(A,B,C));
  39. return 1e-9 * rep * flops / t.best();
  40. }
  41. int main(int argc, char **argv)
  42. {
  43. std::vector<double> results;
  44. std::ifstream settings("gemm_settings.txt");
  45. long m, n, k;
  46. while(settings >> m >> n >> k)
  47. {
  48. //std::cerr << " Testing " << m << " " << n << " " << k << std::endl;
  49. results.push_back( bench(m, n, k) );
  50. }
  51. std::cout << RowVectorXd::Map(results.data(), results.size());
  52. return 0;
  53. }