mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
imported a reworked version of BTL (Benchmark for Templated Libraries).
the modifications to initial code follow: * changed build system from plain makefiles to cmake * added eigen2 (4 versions: vec/novec and fixed/dynamic), GMM++, MTL4 interfaces * added "transposed matrix * vector" product action * updated blitz interface to use condensed products instead of hand coded loops * removed some deprecated interfaces * changed default storage order to column major for all libraries * new generic bench timer strategy which is supposed to be more accurate * various code clean-up
This commit is contained in:
90
bench/btl/generic_bench/bench.hh
Normal file
90
bench/btl/generic_bench/bench.hh
Normal file
@@ -0,0 +1,90 @@
|
||||
//=====================================================
|
||||
// File : bench.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef BENCH_HH
|
||||
#define BENCH_HH
|
||||
#include "bench_parameter.hh"
|
||||
#include <iostream>
|
||||
#include "utilities.h"
|
||||
#include "size_lin_log.hh"
|
||||
#include "dump_file_x_y.hh"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "timers/portable_perf_analyzer.hh"
|
||||
//#include "timers/mixed_perf_analyzer.hh"
|
||||
//#include "timers/x86_perf_analyzer.hh"
|
||||
//#include "timers/STL_perf_analyzer.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <template<class> class Perf_Analyzer, class Action>
|
||||
void bench( int size_min, int size_max, int nb_point ){
|
||||
|
||||
// bench name
|
||||
|
||||
string filename="bench_"+Action::name()+".dat";
|
||||
|
||||
INFOS("starting " <<filename);
|
||||
|
||||
// utilities
|
||||
|
||||
std::vector<double> tab_mflops(nb_point);
|
||||
std::vector<int> tab_sizes(nb_point);
|
||||
|
||||
// matrices and vector size calculations
|
||||
|
||||
size_lin_log(nb_point,size_min,size_max,tab_sizes);
|
||||
|
||||
// loop on matrix size
|
||||
|
||||
Perf_Analyzer<Action> perf_action;
|
||||
|
||||
for (int i=nb_point-1;i>=0;i--)
|
||||
{
|
||||
//INFOS("size=" <<tab_sizes[i]<<" ("<<nb_point-i<<"/"<<nb_point<<")");
|
||||
std::cout << " " << "size = " << tab_sizes[i] << " " << std::flush;
|
||||
tab_mflops[i] = perf_action.eval_mflops(tab_sizes[i]);
|
||||
std::cout << tab_mflops[i] << " MFlops (" << nb_point-i << "/" << nb_point << ")" << std::endl;
|
||||
}
|
||||
// std::cout << "\n";
|
||||
|
||||
// dump the result in a file :
|
||||
|
||||
dump_file_x_y(tab_sizes,tab_mflops,filename);
|
||||
|
||||
}
|
||||
|
||||
// default Perf Analyzer
|
||||
|
||||
template <class Action>
|
||||
void bench( int size_min, int size_max, int nb_point ){
|
||||
|
||||
// if the rdtsc is not available :
|
||||
bench<Portable_Perf_Analyzer,Action>(size_min,size_max,nb_point);
|
||||
// if the rdtsc is available :
|
||||
// bench<Mixed_Perf_Analyzer,Action>(size_min,size_max,nb_point);
|
||||
|
||||
|
||||
// Only for small problem size. Otherwize it will be too long
|
||||
//bench<X86_Perf_Analyzer,Action>(size_min,size_max,nb_point);
|
||||
//bench<STL_Perf_Analyzer,Action>(size_min,size_max,nb_point);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
53
bench/btl/generic_bench/bench_parameter.hh
Normal file
53
bench/btl/generic_bench/bench_parameter.hh
Normal file
@@ -0,0 +1,53 @@
|
||||
//=====================================================
|
||||
// File : bench_parameter.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef BENCH_PARAMETER_HH
|
||||
#define BENCH_PARAMETER_HH
|
||||
|
||||
// minimal time for each measurement
|
||||
#define REAL_TYPE float
|
||||
// minimal time for each measurement
|
||||
#define MIN_TIME 1.0
|
||||
// nb of point on bench curves
|
||||
#define NB_POINT 100
|
||||
// min vector size for axpy bench
|
||||
#define MIN_AXPY 2
|
||||
// max vector size for axpy bench
|
||||
#define MAX_AXPY 1000000
|
||||
// min matrix size for matrix vector product bench
|
||||
#define MIN_MV 2
|
||||
// max matrix size for matrix vector product bench
|
||||
#define MAX_MV 1024
|
||||
// min matrix size for matrix matrix product bench
|
||||
#define MIN_MM 2
|
||||
// max matrix size for matrix matrix product bench
|
||||
#define MAX_MM 1024
|
||||
// min matrix size for LU bench
|
||||
#define MIN_LU 10
|
||||
// max matrix size for LU bench
|
||||
#define MAX_LU 1000
|
||||
// max size for tiny vector and matrix
|
||||
#define TINY_MV_MAX_SIZE 16
|
||||
// default nb_sample for x86 timer
|
||||
#define DEFAULT_NB_SAMPLE 1000
|
||||
|
||||
// how many times we run a single bench (keep the best perf)
|
||||
#define NB_TRIES 3
|
||||
|
||||
#endif
|
||||
55
bench/btl/generic_bench/init/init_function.hh
Normal file
55
bench/btl/generic_bench/init/init_function.hh
Normal file
@@ -0,0 +1,55 @@
|
||||
//=====================================================
|
||||
// File : init_function.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, lun sep 30 14:23:18 CEST 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef INIT_FUNCTION_HH
|
||||
#define INIT_FUNCTION_HH
|
||||
|
||||
double simple_function(int index)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
double simple_function(int index_i, int index_j)
|
||||
{
|
||||
return index_i+index_j;
|
||||
}
|
||||
|
||||
double pseudo_random(int index)
|
||||
{
|
||||
// INFOS("random="<<(std::rand()/double(RAND_MAX)));
|
||||
return std::rand()/double(RAND_MAX);
|
||||
}
|
||||
|
||||
double pseudo_random(int index_i, int index_j)
|
||||
{
|
||||
return std::rand()/double(RAND_MAX);
|
||||
}
|
||||
|
||||
|
||||
double null_function(int index)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double null_function(int index_i, int index_j)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
#endif
|
||||
53
bench/btl/generic_bench/init/init_matrix.hh
Normal file
53
bench/btl/generic_bench/init/init_matrix.hh
Normal file
@@ -0,0 +1,53 @@
|
||||
//=====================================================
|
||||
// File : init_matrix.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef INIT_MATRIX_HH
|
||||
#define INIT_MATRIX_HH
|
||||
|
||||
// The Vector class must satisfy the following part of STL vector concept :
|
||||
// resize() method
|
||||
// [] operator for setting element
|
||||
// value_type defined
|
||||
template<double init_function(int,int), class Vector>
|
||||
void init_row(Vector & X, int size, int row){
|
||||
|
||||
X.resize(size);
|
||||
|
||||
for (int j=0;j<X.size();j++){
|
||||
X[j]=typename Vector::value_type(init_function(row,j));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Matrix is a Vector of Vector
|
||||
// The Matrix class must satisfy the following part of STL vector concept :
|
||||
// resize() method
|
||||
// [] operator for setting rows
|
||||
template<double init_function(int,int),class Vector>
|
||||
void init_matrix(Vector & A, int size){
|
||||
|
||||
A.resize(size);
|
||||
for (int row=0; row<A.size() ; row++){
|
||||
init_row<init_function>(A[row],size,row);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
37
bench/btl/generic_bench/init/init_vector.hh
Normal file
37
bench/btl/generic_bench/init/init_vector.hh
Normal file
@@ -0,0 +1,37 @@
|
||||
//=====================================================
|
||||
// File : init_vector.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, lun sep 30 14:23:18 CEST 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef INIT_VECTOR_HH
|
||||
#define INIT_VECTOR_HH
|
||||
|
||||
// The Vector class must satisfy the following part of STL vector concept :
|
||||
// resize() method
|
||||
// [] operator for setting element
|
||||
// value_type defined
|
||||
template<double init_function(int), class Vector>
|
||||
void init_vector(Vector & X, int size){
|
||||
|
||||
X.resize(size);
|
||||
|
||||
for (int i=0;i<X.size();i++){
|
||||
X[i]=typename Vector::value_type(init_function(i));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
75
bench/btl/generic_bench/static/bench_static.hh
Normal file
75
bench/btl/generic_bench/static/bench_static.hh
Normal file
@@ -0,0 +1,75 @@
|
||||
//=====================================================
|
||||
// File : bench_static.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef BENCH_STATIC_HH
|
||||
#define BENCH_STATIC_HH
|
||||
#include "bench_parameter.hh"
|
||||
#include <iostream>
|
||||
#include "utilities.h"
|
||||
#include "dump_file_x_y.hh"
|
||||
#include "static/static_size_generator.hh"
|
||||
#include "timers/portable_perf_analyzer.hh"
|
||||
#include "timers/mixed_perf_analyzer.hh"
|
||||
#include "timers/x86_perf_analyzer.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
template <template<class> class Perf_Analyzer, template<class> class Action, template<class,int> class Interface>
|
||||
void bench_static(void)
|
||||
{
|
||||
string filename = "bench_" + Action<Interface<REAL_TYPE,10> >::name() + ".dat";
|
||||
|
||||
INFOS("starting " << filename);
|
||||
|
||||
const int max_size = TINY_MV_MAX_SIZE;
|
||||
|
||||
std::vector<double> tab_mflops;
|
||||
std::vector<double> tab_sizes;
|
||||
|
||||
static_size_generator<max_size,Perf_Analyzer,Action,Interface>::go(tab_sizes,tab_mflops);
|
||||
|
||||
dump_file_x_y(tab_sizes,tab_mflops,filename);
|
||||
}
|
||||
|
||||
// default Perf Analyzer
|
||||
template <template<class> class Action, template<class,int> class Interface>
|
||||
void bench_static(void)
|
||||
{
|
||||
bench_static<Portable_Perf_Analyzer,Action,Interface>();
|
||||
//bench_static<Mixed_Perf_Analyzer,Action,Interface>();
|
||||
//bench_static<X86_Perf_Analyzer,Action,Interface>();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
66
bench/btl/generic_bench/static/intel_bench_fixed_size.hh
Normal file
66
bench/btl/generic_bench/static/intel_bench_fixed_size.hh
Normal file
@@ -0,0 +1,66 @@
|
||||
//=====================================================
|
||||
// File : intel_bench_fixed_size.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar déc 3 18:59:37 CET 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef _BENCH_FIXED_SIZE_HH_
|
||||
#define _BENCH_FIXED_SIZE_HH_
|
||||
|
||||
#include "utilities.h"
|
||||
#include "function_time.hh"
|
||||
|
||||
template <class Action>
|
||||
double bench_fixed_size(int size, unsigned long long & nb_calc,unsigned long long & nb_init)
|
||||
{
|
||||
|
||||
Action action(size);
|
||||
|
||||
double time_baseline=time_init(nb_init,action);
|
||||
|
||||
while (time_baseline < MIN_TIME) {
|
||||
|
||||
//INFOS("nb_init="<<nb_init);
|
||||
//INFOS("time_baseline="<<time_baseline);
|
||||
nb_init*=2;
|
||||
time_baseline=time_init(nb_init,action);
|
||||
}
|
||||
|
||||
time_baseline=time_baseline/(double(nb_init));
|
||||
|
||||
double time_action=time_calculate(nb_calc,action);
|
||||
|
||||
while (time_action < MIN_TIME) {
|
||||
|
||||
nb_calc*=2;
|
||||
time_action=time_calculate(nb_calc,action);
|
||||
}
|
||||
|
||||
INFOS("nb_init="<<nb_init);
|
||||
INFOS("nb_calc="<<nb_calc);
|
||||
|
||||
|
||||
time_action=time_action/(double(nb_calc));
|
||||
|
||||
action.check_result();
|
||||
|
||||
time_action=time_action-time_baseline;
|
||||
|
||||
return action.nb_op_base()/(time_action*1000000.0);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
56
bench/btl/generic_bench/static/static_size_generator.hh
Normal file
56
bench/btl/generic_bench/static/static_size_generator.hh
Normal file
@@ -0,0 +1,56 @@
|
||||
//=====================================================
|
||||
// File : static_size_generator.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar déc 3 18:59:36 CET 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef _STATIC_SIZE_GENERATOR_HH
|
||||
#define _STATIC_SIZE_GENERATOR_HH
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//recursive generation of statically defined matrix and vector sizes
|
||||
|
||||
template <int SIZE,template<class> class Perf_Analyzer, template<class> class Action, template<class,int> class Interface>
|
||||
struct static_size_generator{
|
||||
static void go(vector<double> & tab_sizes, vector<double> & tab_mflops)
|
||||
{
|
||||
tab_sizes.push_back(SIZE);
|
||||
|
||||
Perf_Analyzer<Action<Interface<REAL_TYPE,SIZE> > > perf_action;
|
||||
tab_mflops.push_back(perf_action.eval_mflops(SIZE));
|
||||
static_size_generator<SIZE-1,Perf_Analyzer,Action,Interface>::go(tab_sizes,tab_mflops);
|
||||
};
|
||||
};
|
||||
|
||||
//recursion end
|
||||
|
||||
template <template<class> class Perf_Analyzer, template<class> class Action, template<class,int> class Interface>
|
||||
struct static_size_generator<1,Perf_Analyzer,Action,Interface>{
|
||||
static void go(vector<double> & tab_sizes, vector<double> & tab_mflops)
|
||||
{
|
||||
tab_sizes.push_back(1);
|
||||
Perf_Analyzer<Action<Interface<REAL_TYPE,1> > > perf_action;
|
||||
tab_mflops.push_back(perf_action.eval_mflops(1));
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
82
bench/btl/generic_bench/timers/STL_perf_analyzer.hh
Normal file
82
bench/btl/generic_bench/timers/STL_perf_analyzer.hh
Normal file
@@ -0,0 +1,82 @@
|
||||
//=====================================================
|
||||
// File : STL_perf_analyzer.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar déc 3 18:59:35 CET 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef _STL_PERF_ANALYSER_HH
|
||||
#define _STL_PERF_ANALYSER_HH
|
||||
|
||||
#include "STL_timer.hh"
|
||||
#include "bench_parameter.hh"
|
||||
|
||||
template<class ACTION>
|
||||
class STL_Perf_Analyzer{
|
||||
public:
|
||||
STL_Perf_Analyzer(unsigned long long nb_sample=DEFAULT_NB_SAMPLE):_nb_sample(nb_sample),_chronos()
|
||||
{
|
||||
MESSAGE("STL_Perf_Analyzer Ctor");
|
||||
};
|
||||
STL_Perf_Analyzer( const STL_Perf_Analyzer & ){
|
||||
INFOS("Copy Ctor not implemented");
|
||||
exit(0);
|
||||
};
|
||||
~STL_Perf_Analyzer( void ){
|
||||
MESSAGE("STL_Perf_Analyzer Dtor");
|
||||
};
|
||||
|
||||
|
||||
inline double eval_mflops(int size)
|
||||
{
|
||||
|
||||
ACTION action(size);
|
||||
|
||||
_chronos.start_baseline(_nb_sample);
|
||||
|
||||
do {
|
||||
|
||||
action.initialize();
|
||||
} while (_chronos.check());
|
||||
|
||||
double baseline_time=_chronos.get_time();
|
||||
|
||||
_chronos.start(_nb_sample);
|
||||
do {
|
||||
action.initialize();
|
||||
action.calculate();
|
||||
} while (_chronos.check());
|
||||
|
||||
double calculate_time=_chronos.get_time();
|
||||
|
||||
double corrected_time=calculate_time-baseline_time;
|
||||
|
||||
// cout << size <<" "<<baseline_time<<" "<<calculate_time<<" "<<corrected_time<<" "<<action.nb_op_base() << endl;
|
||||
|
||||
return action.nb_op_base()/(corrected_time*1000000.0);
|
||||
//return action.nb_op_base()/(calculate_time*1000000.0);
|
||||
|
||||
}
|
||||
private:
|
||||
|
||||
STL_Timer _chronos;
|
||||
unsigned long long _nb_sample;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
78
bench/btl/generic_bench/timers/STL_timer.hh
Normal file
78
bench/btl/generic_bench/timers/STL_timer.hh
Normal file
@@ -0,0 +1,78 @@
|
||||
//=====================================================
|
||||
// File : STL_Timer.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar déc 3 18:59:35 CET 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// STL Timer Class. Adapted (L.P.) from the timer class by Musser et Al
|
||||
// described int the Book : STL Tutorial and reference guide.
|
||||
// Define a timer class for analyzing algorithm performance.
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
class STL_Timer {
|
||||
public:
|
||||
STL_Timer(){ baseline = false; }; // Default constructor
|
||||
// Start a series of r trials:
|
||||
void start(unsigned int r){
|
||||
reps = r;
|
||||
count = 0;
|
||||
iterations.clear();
|
||||
iterations.reserve(reps);
|
||||
initial = time(0);
|
||||
};
|
||||
// Start a series of r trials to determine baseline time:
|
||||
void start_baseline(unsigned int r)
|
||||
{
|
||||
baseline = true;
|
||||
start(r);
|
||||
}
|
||||
// Returns true if the trials have been completed, else false
|
||||
bool check()
|
||||
{
|
||||
++count;
|
||||
final = time(0);
|
||||
if (initial < final) {
|
||||
iterations.push_back(count);
|
||||
initial = final;
|
||||
count = 0;
|
||||
}
|
||||
return (iterations.size() < reps);
|
||||
};
|
||||
// Returns the results for external use
|
||||
double get_time( void )
|
||||
{
|
||||
sort(iterations.begin(), iterations.end());
|
||||
return 1.0/iterations[reps/2];
|
||||
};
|
||||
private:
|
||||
unsigned int reps; // Number of trials
|
||||
// For storing loop iterations of a trial
|
||||
vector<long> iterations;
|
||||
// For saving initial and final times of a trial
|
||||
time_t initial, final;
|
||||
// For counting loop iterations of a trial
|
||||
unsigned long count;
|
||||
// true if this is a baseline computation, false otherwise
|
||||
bool baseline;
|
||||
// For recording the baseline time
|
||||
double baseline_time;
|
||||
};
|
||||
|
||||
73
bench/btl/generic_bench/timers/mixed_perf_analyzer.hh
Normal file
73
bench/btl/generic_bench/timers/mixed_perf_analyzer.hh
Normal file
@@ -0,0 +1,73 @@
|
||||
//=====================================================
|
||||
// File : mixed_perf_analyzer.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar déc 3 18:59:36 CET 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef _MIXED_PERF_ANALYSER_HH
|
||||
#define _MIXED_PERF_ANALYSER_HH
|
||||
|
||||
#include "x86_perf_analyzer.hh"
|
||||
#include "portable_perf_analyzer.hh"
|
||||
|
||||
// choose portable perf analyzer for long calculations and x86 analyser for short ones
|
||||
|
||||
|
||||
template<class Action>
|
||||
class Mixed_Perf_Analyzer{
|
||||
|
||||
public:
|
||||
Mixed_Perf_Analyzer( void ):_x86pa(),_ppa(),_use_ppa(true)
|
||||
{
|
||||
MESSAGE("Mixed_Perf_Analyzer Ctor");
|
||||
};
|
||||
Mixed_Perf_Analyzer( const Mixed_Perf_Analyzer & ){
|
||||
INFOS("Copy Ctor not implemented");
|
||||
exit(0);
|
||||
};
|
||||
~Mixed_Perf_Analyzer( void ){
|
||||
MESSAGE("Mixed_Perf_Analyzer Dtor");
|
||||
};
|
||||
|
||||
|
||||
inline double eval_mflops(int size)
|
||||
{
|
||||
|
||||
double result=0.0;
|
||||
if (_use_ppa){
|
||||
result=_ppa.eval_mflops(size);
|
||||
if (_ppa.get_nb_calc()>DEFAULT_NB_SAMPLE){_use_ppa=false;}
|
||||
}
|
||||
else{
|
||||
result=_x86pa.eval_mflops(size);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Portable_Perf_Analyzer<Action> _ppa;
|
||||
X86_Perf_Analyzer<Action> _x86pa;
|
||||
bool _use_ppa;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
98
bench/btl/generic_bench/timers/portable_perf_analyzer.hh
Normal file
98
bench/btl/generic_bench/timers/portable_perf_analyzer.hh
Normal file
@@ -0,0 +1,98 @@
|
||||
//=====================================================
|
||||
// File : portable_perf_analyzer.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar d<>c 3 18:59:35 CET 2002
|
||||
// Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef _PORTABLE_PERF_ANALYZER_HH
|
||||
#define _PORTABLE_PERF_ANALYZER_HH
|
||||
|
||||
#include "utilities.h"
|
||||
#include "timers/portable_timer.hh"
|
||||
|
||||
template <class Action>
|
||||
class Portable_Perf_Analyzer{
|
||||
public:
|
||||
Portable_Perf_Analyzer( void ):_nb_calc(1),_chronos(){
|
||||
MESSAGE("Portable_Perf_Analyzer Ctor");
|
||||
};
|
||||
Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){
|
||||
INFOS("Copy Ctor not implemented");
|
||||
exit(0);
|
||||
};
|
||||
~Portable_Perf_Analyzer( void ){
|
||||
MESSAGE("Portable_Perf_Analyzer Dtor");
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline double eval_mflops(int size)
|
||||
{
|
||||
Action action(size);
|
||||
|
||||
|
||||
double time_action = time_calculate(action);
|
||||
while (time_action < MIN_TIME)
|
||||
{
|
||||
_nb_calc *= 2;
|
||||
action.initialize();
|
||||
time_action = time_calculate(action);
|
||||
}
|
||||
|
||||
// optimize
|
||||
for (int i=1; i<NB_TRIES; ++i)
|
||||
{
|
||||
action.initialize();
|
||||
time_action = std::min(time_action, time_calculate(action));
|
||||
}
|
||||
|
||||
time_action = time_action / (double(_nb_calc));
|
||||
|
||||
// check
|
||||
action.initialize();
|
||||
action.calculate();
|
||||
action.check_result();
|
||||
|
||||
return action.nb_op_base()/(time_action*1000000.0);
|
||||
}
|
||||
|
||||
double time_calculate(Action & action)
|
||||
{
|
||||
// time measurement
|
||||
_chronos.start();
|
||||
for (int ii=0;ii<_nb_calc;ii++)
|
||||
{
|
||||
action.calculate();
|
||||
}
|
||||
_chronos.stop();
|
||||
return _chronos.user_time();
|
||||
}
|
||||
|
||||
unsigned long long get_nb_calc( void )
|
||||
{
|
||||
return _nb_calc;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
unsigned long long _nb_calc;
|
||||
Portable_Timer _chronos;
|
||||
|
||||
};
|
||||
|
||||
#endif //_PORTABLE_PERF_ANALYZER_HH
|
||||
|
||||
134
bench/btl/generic_bench/timers/portable_perf_analyzer_old.hh
Normal file
134
bench/btl/generic_bench/timers/portable_perf_analyzer_old.hh
Normal file
@@ -0,0 +1,134 @@
|
||||
//=====================================================
|
||||
// File : portable_perf_analyzer.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar d<>c 3 18:59:35 CET 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef _PORTABLE_PERF_ANALYZER_HH
|
||||
#define _PORTABLE_PERF_ANALYZER_HH
|
||||
|
||||
#include "utilities.h"
|
||||
#include "timers/portable_timer.hh"
|
||||
|
||||
template <class Action>
|
||||
class Portable_Perf_Analyzer{
|
||||
public:
|
||||
Portable_Perf_Analyzer( void ):_nb_calc(1),_nb_init(1),_chronos(){
|
||||
MESSAGE("Portable_Perf_Analyzer Ctor");
|
||||
};
|
||||
Portable_Perf_Analyzer( const Portable_Perf_Analyzer & ){
|
||||
INFOS("Copy Ctor not implemented");
|
||||
exit(0);
|
||||
};
|
||||
~Portable_Perf_Analyzer( void ){
|
||||
MESSAGE("Portable_Perf_Analyzer Dtor");
|
||||
};
|
||||
|
||||
|
||||
|
||||
inline double eval_mflops(int size)
|
||||
{
|
||||
|
||||
Action action(size);
|
||||
|
||||
// double time_baseline = time_init(action);
|
||||
// while (time_baseline < MIN_TIME_INIT)
|
||||
// {
|
||||
// _nb_init *= 2;
|
||||
// time_baseline = time_init(action);
|
||||
// }
|
||||
//
|
||||
// // optimize
|
||||
// for (int i=1; i<NB_TRIES; ++i)
|
||||
// time_baseline = std::min(time_baseline, time_init(action));
|
||||
//
|
||||
// time_baseline = time_baseline/(double(_nb_init));
|
||||
|
||||
double time_action = time_calculate(action);
|
||||
while (time_action < MIN_TIME)
|
||||
{
|
||||
_nb_calc *= 2;
|
||||
time_action = time_calculate(action);
|
||||
}
|
||||
|
||||
// optimize
|
||||
for (int i=1; i<NB_TRIES; ++i)
|
||||
time_action = std::min(time_action, time_calculate(action));
|
||||
|
||||
// INFOS("size="<<size);
|
||||
// INFOS("_nb_init="<<_nb_init);
|
||||
// INFOS("_nb_calc="<<_nb_calc);
|
||||
|
||||
time_action = time_action / (double(_nb_calc));
|
||||
|
||||
action.check_result();
|
||||
|
||||
|
||||
double time_baseline = time_init(action);
|
||||
for (int i=1; i<NB_TRIES; ++i)
|
||||
time_baseline = std::min(time_baseline, time_init(action));
|
||||
time_baseline = time_baseline/(double(_nb_init));
|
||||
|
||||
|
||||
|
||||
// INFOS("time_baseline="<<time_baseline);
|
||||
// INFOS("time_action="<<time_action);
|
||||
|
||||
time_action = time_action - time_baseline;
|
||||
|
||||
// INFOS("time_corrected="<<time_action);
|
||||
|
||||
return action.nb_op_base()/(time_action*1000000.0);
|
||||
}
|
||||
|
||||
inline double time_init(Action & action)
|
||||
{
|
||||
// time measurement
|
||||
_chronos.start();
|
||||
for (int ii=0; ii<_nb_init; ii++)
|
||||
action.initialize();
|
||||
_chronos.stop();
|
||||
return _chronos.user_time();
|
||||
}
|
||||
|
||||
|
||||
inline double time_calculate(Action & action)
|
||||
{
|
||||
// time measurement
|
||||
_chronos.start();
|
||||
for (int ii=0;ii<_nb_calc;ii++)
|
||||
{
|
||||
action.initialize();
|
||||
action.calculate();
|
||||
}
|
||||
_chronos.stop();
|
||||
return _chronos.user_time();
|
||||
}
|
||||
|
||||
unsigned long long get_nb_calc( void )
|
||||
{
|
||||
return _nb_calc;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
unsigned long long _nb_calc;
|
||||
unsigned long long _nb_init;
|
||||
Portable_Timer _chronos;
|
||||
|
||||
};
|
||||
|
||||
#endif //_PORTABLE_PERF_ANALYZER_HH
|
||||
103
bench/btl/generic_bench/timers/portable_timer.hh
Executable file
103
bench/btl/generic_bench/timers/portable_timer.hh
Executable file
@@ -0,0 +1,103 @@
|
||||
//=====================================================
|
||||
// File : portable_timer.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)> from boost lib
|
||||
// Copyright (C) EDF R&D, lun sep 30 14:23:17 CEST 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
// simple_time extracted from the boost library
|
||||
//
|
||||
#ifndef _PORTABLE_TIMER_HH
|
||||
#define _PORTABLE_TIMER_HH
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
#define USEC_IN_SEC 1000000
|
||||
|
||||
|
||||
// timer -------------------------------------------------------------------//
|
||||
|
||||
// A timer object measures CPU time.
|
||||
|
||||
class Portable_Timer
|
||||
{
|
||||
public:
|
||||
|
||||
Portable_Timer( void ):_utime_sec_start(-1),
|
||||
_utime_usec_start(-1),
|
||||
_utime_sec_stop(-1),
|
||||
_utime_usec_stop(-1)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void start()
|
||||
{
|
||||
|
||||
int status=getrusage(RUSAGE_SELF, &resourcesUsage) ;
|
||||
|
||||
_start_time = std::clock();
|
||||
|
||||
_utime_sec_start = resourcesUsage.ru_utime.tv_sec ;
|
||||
_utime_usec_start = resourcesUsage.ru_utime.tv_usec ;
|
||||
|
||||
}
|
||||
|
||||
void stop()
|
||||
{
|
||||
|
||||
int status=getrusage(RUSAGE_SELF, &resourcesUsage) ;
|
||||
|
||||
_stop_time = std::clock();
|
||||
|
||||
_utime_sec_stop = resourcesUsage.ru_utime.tv_sec ;
|
||||
_utime_usec_stop = resourcesUsage.ru_utime.tv_usec ;
|
||||
|
||||
}
|
||||
|
||||
double elapsed()
|
||||
{
|
||||
return double(_stop_time - _start_time) / CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
double user_time()
|
||||
{
|
||||
long tot_utime_sec=_utime_sec_stop-_utime_sec_start;
|
||||
long tot_utime_usec=_utime_usec_stop-_utime_usec_start;
|
||||
return double(tot_utime_sec)+ double(tot_utime_usec)/double(USEC_IN_SEC) ;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
struct rusage resourcesUsage ;
|
||||
|
||||
long _utime_sec_start ;
|
||||
long _utime_usec_start ;
|
||||
|
||||
long _utime_sec_stop ;
|
||||
long _utime_usec_stop ;
|
||||
|
||||
std::clock_t _start_time;
|
||||
std::clock_t _stop_time;
|
||||
|
||||
}; // Portable_Timer
|
||||
|
||||
|
||||
#endif // PORTABLE_TIMER_HPP
|
||||
108
bench/btl/generic_bench/timers/x86_perf_analyzer.hh
Normal file
108
bench/btl/generic_bench/timers/x86_perf_analyzer.hh
Normal file
@@ -0,0 +1,108 @@
|
||||
//=====================================================
|
||||
// File : x86_perf_analyzer.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar d<>c 3 18:59:35 CET 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef _X86_PERF_ANALYSER_HH
|
||||
#define _X86_PERF_ANALYSER_HH
|
||||
|
||||
#include "x86_timer.hh"
|
||||
#include "bench_parameter.hh"
|
||||
|
||||
template<class ACTION>
|
||||
class X86_Perf_Analyzer{
|
||||
public:
|
||||
X86_Perf_Analyzer( unsigned long long nb_sample=DEFAULT_NB_SAMPLE):_nb_sample(nb_sample),_chronos()
|
||||
{
|
||||
MESSAGE("X86_Perf_Analyzer Ctor");
|
||||
_chronos.find_frequency();
|
||||
};
|
||||
X86_Perf_Analyzer( const X86_Perf_Analyzer & ){
|
||||
INFOS("Copy Ctor not implemented");
|
||||
exit(0);
|
||||
};
|
||||
~X86_Perf_Analyzer( void ){
|
||||
MESSAGE("X86_Perf_Analyzer Dtor");
|
||||
};
|
||||
|
||||
|
||||
inline double eval_mflops(int size)
|
||||
{
|
||||
|
||||
ACTION action(size);
|
||||
|
||||
int nb_loop=5;
|
||||
double calculate_time=0.0;
|
||||
double baseline_time=0.0;
|
||||
|
||||
for (int j=0 ; j < nb_loop ; j++){
|
||||
|
||||
_chronos.clear();
|
||||
|
||||
for(int i=0 ; i < _nb_sample ; i++)
|
||||
{
|
||||
_chronos.start();
|
||||
action.initialize();
|
||||
action.calculate();
|
||||
_chronos.stop();
|
||||
_chronos.add_get_click();
|
||||
}
|
||||
|
||||
calculate_time += double(_chronos.get_shortest_clicks())/_chronos.frequency();
|
||||
|
||||
if (j==0) action.check_result();
|
||||
|
||||
_chronos.clear();
|
||||
|
||||
for(int i=0 ; i < _nb_sample ; i++)
|
||||
{
|
||||
_chronos.start();
|
||||
action.initialize();
|
||||
_chronos.stop();
|
||||
_chronos.add_get_click();
|
||||
|
||||
}
|
||||
|
||||
baseline_time+=double(_chronos.get_shortest_clicks())/_chronos.frequency();
|
||||
|
||||
}
|
||||
|
||||
double corrected_time = (calculate_time-baseline_time)/double(nb_loop);
|
||||
|
||||
|
||||
// INFOS("_nb_sample="<<_nb_sample);
|
||||
// INFOS("baseline_time="<<baseline_time);
|
||||
// INFOS("calculate_time="<<calculate_time);
|
||||
// INFOS("corrected_time="<<corrected_time);
|
||||
|
||||
// cout << size <<" "<<baseline_time<<" "<<calculate_time<<" "<<corrected_time<<" "<<action.nb_op_base() << endl;
|
||||
|
||||
return action.nb_op_base()/(corrected_time*1000000.0);
|
||||
//return action.nb_op_base()/(calculate_time*1000000.0);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
X86_Timer _chronos;
|
||||
unsigned long long _nb_sample;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
246
bench/btl/generic_bench/timers/x86_timer.hh
Normal file
246
bench/btl/generic_bench/timers/x86_timer.hh
Normal file
@@ -0,0 +1,246 @@
|
||||
//=====================================================
|
||||
// File : x86_timer.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar d<>c 3 18:59:35 CET 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef _X86_TIMER_HH
|
||||
#define _X86_TIMER_HH
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/times.h>
|
||||
//#include "system_time.h"
|
||||
#define u32 unsigned int
|
||||
#include <asm/msr.h>
|
||||
#include "utilities.h"
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
// frequence de la becanne en Hz
|
||||
//#define FREQUENCY 648000000
|
||||
//#define FREQUENCY 1400000000
|
||||
#define FREQUENCY 1695000000
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
class X86_Timer {
|
||||
|
||||
public :
|
||||
|
||||
X86_Timer( void ):_frequency(FREQUENCY),_nb_sample(0)
|
||||
{
|
||||
MESSAGE("X86_Timer Default Ctor");
|
||||
}
|
||||
|
||||
inline void start( void ){
|
||||
|
||||
rdtsc(_click_start.n32[0],_click_start.n32[1]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline void stop( void ){
|
||||
|
||||
rdtsc(_click_stop.n32[0],_click_stop.n32[1]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline double frequency( void ){
|
||||
return _frequency;
|
||||
}
|
||||
|
||||
double get_elapsed_time_in_second( void ){
|
||||
|
||||
return (_click_stop.n64-_click_start.n64)/double(FREQUENCY);
|
||||
|
||||
|
||||
}
|
||||
|
||||
unsigned long long get_click( void ){
|
||||
|
||||
return (_click_stop.n64-_click_start.n64);
|
||||
|
||||
}
|
||||
|
||||
inline void find_frequency( void ){
|
||||
|
||||
time_t initial, final;
|
||||
int dummy=2;
|
||||
|
||||
initial = time(0);
|
||||
start();
|
||||
do {
|
||||
dummy+=2;
|
||||
}
|
||||
while(time(0)==initial);
|
||||
// On est au debut d'un cycle d'une seconde !!!
|
||||
initial = time(0);
|
||||
start();
|
||||
do {
|
||||
dummy+=2;
|
||||
}
|
||||
while(time(0)==initial);
|
||||
final=time(0);
|
||||
stop();
|
||||
// INFOS("fine grained time : "<< get_elapsed_time_in_second());
|
||||
// INFOS("coarse grained time : "<< final-initial);
|
||||
_frequency=_frequency*get_elapsed_time_in_second()/double(final-initial);
|
||||
/// INFOS("CPU frequency : "<< _frequency);
|
||||
|
||||
}
|
||||
|
||||
void add_get_click( void ){
|
||||
|
||||
_nb_sample++;
|
||||
_counted_clicks[get_click()]++;
|
||||
fill_history_clicks();
|
||||
|
||||
}
|
||||
|
||||
void dump_statistics(string filemane){
|
||||
|
||||
ofstream outfile (filemane.c_str(),ios::out) ;
|
||||
|
||||
std::map<unsigned long long , unsigned long long>::iterator itr;
|
||||
for(itr=_counted_clicks.begin() ; itr!=_counted_clicks.end() ; itr++)
|
||||
{
|
||||
outfile << (*itr).first << " " << (*itr).second << endl ;
|
||||
}
|
||||
|
||||
outfile.close();
|
||||
|
||||
}
|
||||
|
||||
void dump_history(string filemane){
|
||||
|
||||
ofstream outfile (filemane.c_str(),ios::out) ;
|
||||
|
||||
|
||||
|
||||
for(int i=0 ; i<_history_mean_clicks.size() ; i++)
|
||||
{
|
||||
outfile << i << " "
|
||||
<< _history_mean_clicks[i] << " "
|
||||
<< _history_shortest_clicks[i] << " "
|
||||
<< _history_most_occured_clicks[i] << endl ;
|
||||
}
|
||||
|
||||
outfile.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
double get_mean_clicks( void ){
|
||||
|
||||
std::map<unsigned long long,unsigned long long>::iterator itr;
|
||||
|
||||
unsigned long long mean_clicks=0;
|
||||
|
||||
for(itr=_counted_clicks.begin() ; itr!=_counted_clicks.end() ; itr++)
|
||||
{
|
||||
|
||||
mean_clicks+=(*itr).second*(*itr).first;
|
||||
}
|
||||
|
||||
return mean_clicks/double(_nb_sample);
|
||||
|
||||
}
|
||||
|
||||
double get_shortest_clicks( void ){
|
||||
|
||||
return double((*_counted_clicks.begin()).first);
|
||||
|
||||
}
|
||||
|
||||
void fill_history_clicks( void ){
|
||||
|
||||
_history_mean_clicks.push_back(get_mean_clicks());
|
||||
_history_shortest_clicks.push_back(get_shortest_clicks());
|
||||
_history_most_occured_clicks.push_back(get_most_occured_clicks());
|
||||
|
||||
}
|
||||
|
||||
|
||||
double get_most_occured_clicks( void ){
|
||||
|
||||
unsigned long long moc=0;
|
||||
unsigned long long max_occurence=0;
|
||||
|
||||
std::map<unsigned long long,unsigned long long>::iterator itr;
|
||||
|
||||
for(itr=_counted_clicks.begin() ; itr!=_counted_clicks.end() ; itr++)
|
||||
{
|
||||
|
||||
if (max_occurence<=(*itr).second){
|
||||
max_occurence=(*itr).second;
|
||||
moc=(*itr).first;
|
||||
}
|
||||
}
|
||||
|
||||
return double(moc);
|
||||
|
||||
}
|
||||
|
||||
void clear( void )
|
||||
{
|
||||
_counted_clicks.clear();
|
||||
|
||||
_history_mean_clicks.clear();
|
||||
_history_shortest_clicks.clear();
|
||||
_history_most_occured_clicks.clear();
|
||||
|
||||
_nb_sample=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private :
|
||||
|
||||
union
|
||||
{
|
||||
unsigned long int n32[2] ;
|
||||
unsigned long long n64 ;
|
||||
} _click_start;
|
||||
|
||||
union
|
||||
{
|
||||
unsigned long int n32[2] ;
|
||||
unsigned long long n64 ;
|
||||
} _click_stop;
|
||||
|
||||
double _frequency ;
|
||||
|
||||
map<unsigned long long,unsigned long long> _counted_clicks;
|
||||
|
||||
vector<double> _history_mean_clicks;
|
||||
vector<double> _history_shortest_clicks;
|
||||
vector<double> _history_most_occured_clicks;
|
||||
|
||||
unsigned long long _nb_sample;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
47
bench/btl/generic_bench/utils/dump_file_x_y.hh
Normal file
47
bench/btl/generic_bench/utils/dump_file_x_y.hh
Normal file
@@ -0,0 +1,47 @@
|
||||
//=====================================================
|
||||
// File : dump_file_x_y.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, lun sep 30 14:23:20 CEST 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef DUMP_FILE_X_Y_HH
|
||||
#define DUMP_FILE_X_Y_HH
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
// The Vector class must satisfy the following part of STL vector concept :
|
||||
// resize() method
|
||||
// [] operator for seting element
|
||||
// the vector element must have the << operator define
|
||||
|
||||
using namespace std;
|
||||
|
||||
template<class Vector_A, class Vector_B>
|
||||
void dump_file_x_y(const Vector_A & X, const Vector_B & Y, const std::string & filename){
|
||||
|
||||
ofstream outfile (filename.c_str(),ios::out) ;
|
||||
int size=X.size();
|
||||
|
||||
for (int i=0;i<size;i++){
|
||||
|
||||
outfile << X[i] << " " << Y[i] << endl ;
|
||||
|
||||
}
|
||||
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
#endif
|
||||
70
bench/btl/generic_bench/utils/size_lin_log.hh
Normal file
70
bench/btl/generic_bench/utils/size_lin_log.hh
Normal file
@@ -0,0 +1,70 @@
|
||||
//=====================================================
|
||||
// File : size_lin_log.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, mar déc 3 18:59:37 CET 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef SIZE_LIN_LOG
|
||||
#define SIZE_LIN_LOG
|
||||
|
||||
#include "size_log.hh"
|
||||
|
||||
template<class Vector>
|
||||
void size_lin_log(const int nb_point, const int size_min, const int size_max, Vector & X)
|
||||
{
|
||||
int ten=10;
|
||||
int nine=9;
|
||||
|
||||
X.resize(nb_point);
|
||||
|
||||
if (nb_point>ten){
|
||||
|
||||
for (int i=0;i<nine;i++){
|
||||
|
||||
X[i]=i+1;
|
||||
|
||||
}
|
||||
|
||||
Vector log_size;
|
||||
size_log(nb_point-nine,ten,size_max,log_size);
|
||||
|
||||
for (int i=0;i<nb_point-nine;i++){
|
||||
|
||||
X[i+nine]=log_size[i];
|
||||
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
for (int i=0;i<nb_point;i++){
|
||||
|
||||
X[i]=i+1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// for (int i=0;i<nb_point;i++){
|
||||
|
||||
// INFOS("computed sizes : X["<<i<<"]="<<X[i]);
|
||||
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
54
bench/btl/generic_bench/utils/size_log.hh
Normal file
54
bench/btl/generic_bench/utils/size_log.hh
Normal file
@@ -0,0 +1,54 @@
|
||||
//=====================================================
|
||||
// File : size_log.hh
|
||||
// Author : L. Plagne <laurent.plagne@edf.fr)>
|
||||
// Copyright (C) EDF R&D, lun sep 30 14:23:17 CEST 2002
|
||||
//=====================================================
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
//
|
||||
#ifndef SIZE_LOG
|
||||
#define SIZE_LOG
|
||||
|
||||
#include "math.h"
|
||||
// The Vector class must satisfy the following part of STL vector concept :
|
||||
// resize() method
|
||||
// [] operator for seting element
|
||||
// the vector element are int compatible.
|
||||
template<class Vector>
|
||||
void size_log(const int nb_point, const int size_min, const int size_max, Vector & X)
|
||||
{
|
||||
X.resize(nb_point);
|
||||
|
||||
float ls_min=log(float(size_min));
|
||||
float ls_max=log(float(size_max));
|
||||
|
||||
float ls=0.0;
|
||||
|
||||
float delta_ls=(ls_max-ls_min)/(float(nb_point-1));
|
||||
|
||||
int size=0;
|
||||
|
||||
for (int i=0;i<nb_point;i++){
|
||||
|
||||
ls = ls_min + float(i)*delta_ls ;
|
||||
|
||||
size=int(exp(ls));
|
||||
|
||||
X[i]=size;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
90
bench/btl/generic_bench/utils/utilities.h
Normal file
90
bench/btl/generic_bench/utils/utilities.h
Normal file
@@ -0,0 +1,90 @@
|
||||
//=============================================================================
|
||||
// File : utilities.h
|
||||
// Created : mar jun 19 13:18:14 CEST 2001
|
||||
// Author : Antoine YESSAYAN, Paul RASCLE, EDF
|
||||
// Project : SALOME
|
||||
// Copyright : EDF 2001
|
||||
// $Header$
|
||||
//=============================================================================
|
||||
|
||||
/* --- Definition macros file to print informations if _DEBUG_ is defined --- */
|
||||
|
||||
# ifndef UTILITIES_H
|
||||
# define UTILITIES_H
|
||||
|
||||
# include <stdlib.h>
|
||||
//# include <iostream> ok for gcc3.01
|
||||
# include <iostream>
|
||||
|
||||
/* --- INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */
|
||||
|
||||
# define HEREWEARE cout<<flush ; cerr << __FILE__ << " [" << __LINE__ << "] : " << flush ;
|
||||
# define INFOS(chain) {HEREWEARE ; cerr << chain << endl ;}
|
||||
# define PYSCRIPT(chain) {cout<<flush ; cerr << "---PYSCRIPT--- " << chain << endl ;}
|
||||
|
||||
/* --- To print date and time of compilation of current source on stdout --- */
|
||||
|
||||
# if defined ( __GNUC__ )
|
||||
# define COMPILER "g++" ;
|
||||
# elif defined ( __sun )
|
||||
# define COMPILER "CC" ;
|
||||
# elif defined ( __KCC )
|
||||
# define COMPILER "KCC" ;
|
||||
# elif defined ( __PGI )
|
||||
# define COMPILER "pgCC" ;
|
||||
# else
|
||||
# define COMPILER "undefined" ;
|
||||
# endif
|
||||
|
||||
# ifdef INFOS_COMPILATION
|
||||
# error INFOS_COMPILATION already defined
|
||||
# endif
|
||||
# define INFOS_COMPILATION {\
|
||||
cerr << flush;\
|
||||
cout << __FILE__ ;\
|
||||
cout << " [" << __LINE__ << "] : " ;\
|
||||
cout << "COMPILED with " << COMPILER ;\
|
||||
cout << ", " << __DATE__ ; \
|
||||
cout << " at " << __TIME__ << endl ;\
|
||||
cout << "\n\n" ;\
|
||||
cout << flush ;\
|
||||
}
|
||||
|
||||
# ifdef _DEBUG_
|
||||
|
||||
/* --- the following MACROS are useful at debug time --- */
|
||||
|
||||
# define HERE cout<<flush ; cerr << "- Trace " << __FILE__ << " [" << __LINE__ << "] : " << flush ;
|
||||
# define SCRUTE(var) HERE ; cerr << #var << "=" << var << endl ;
|
||||
# define MESSAGE(chain) {HERE ; cerr << chain << endl ;}
|
||||
# define INTERRUPTION(code) HERE ; cerr << "INTERRUPTION return code= " << code << endl ; exit(code) ;
|
||||
|
||||
# ifndef ASSERT
|
||||
# define ASSERT(condition) if (!(condition)){ HERE ; cerr << "CONDITION " << #condition << " NOT VERIFIED"<< endl ; INTERRUPTION(1) ;}
|
||||
# endif /* ASSERT */
|
||||
|
||||
#define REPERE cout<<flush ; cerr << " --------------" << endl << flush ;
|
||||
#define BEGIN_OF(chain) {REPERE ; HERE ; cerr << "Begin of: " << chain << endl ; REPERE ; }
|
||||
#define END_OF(chain) {REPERE ; HERE ; cerr << "Normal end of: " << chain << endl ; REPERE ; }
|
||||
|
||||
|
||||
|
||||
# else /* ifdef _DEBUG_*/
|
||||
|
||||
# define HERE
|
||||
# define SCRUTE(var)
|
||||
# define MESSAGE(chain)
|
||||
# define INTERRUPTION(code)
|
||||
|
||||
# ifndef ASSERT
|
||||
# define ASSERT(condition)
|
||||
# endif /* ASSERT */
|
||||
|
||||
#define REPERE
|
||||
#define BEGIN_OF(chain)
|
||||
#define END_OF(chain)
|
||||
|
||||
|
||||
# endif /* ifdef _DEBUG_*/
|
||||
|
||||
# endif /* ifndef UTILITIES_H */
|
||||
Reference in New Issue
Block a user