initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
//=====================================================
|
||||
// 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
|
||||
@@ -0,0 +1,75 @@
|
||||
//=====================================================
|
||||
// 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;
|
||||
};
|
||||
@@ -0,0 +1,58 @@
|
||||
//=====================================================
|
||||
// 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
|
||||
@@ -0,0 +1,89 @@
|
||||
//=====================================================
|
||||
// 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 <gael.guennebaud@inria.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() : _nb_calc(0), m_time_action(0), _chronos() { MESSAGE("Portable_Perf_Analyzer Ctor"); };
|
||||
Portable_Perf_Analyzer(const Portable_Perf_Analyzer&) {
|
||||
INFOS("Copy Ctor not implemented");
|
||||
exit(0);
|
||||
};
|
||||
~Portable_Perf_Analyzer() { MESSAGE("Portable_Perf_Analyzer Dtor"); };
|
||||
|
||||
BTL_DONT_INLINE double eval_mflops(int size) {
|
||||
Action action(size);
|
||||
|
||||
// action.initialize();
|
||||
// time_action = time_calculate(action);
|
||||
while (m_time_action < MIN_TIME) {
|
||||
if (_nb_calc == 0)
|
||||
_nb_calc = 1;
|
||||
else
|
||||
_nb_calc *= 2;
|
||||
action.initialize();
|
||||
m_time_action = time_calculate(action);
|
||||
}
|
||||
|
||||
// optimize
|
||||
for (int i = 1; i < BtlConfig::Instance.tries; ++i) {
|
||||
Action _action(size);
|
||||
std::cout << " " << _action.nb_op_base() * _nb_calc / (m_time_action * 1e6) << " ";
|
||||
_action.initialize();
|
||||
m_time_action = std::min(m_time_action, time_calculate(_action));
|
||||
}
|
||||
|
||||
double time_action = m_time_action / (double(_nb_calc));
|
||||
|
||||
// check
|
||||
if (BtlConfig::Instance.checkResults && size < 128) {
|
||||
action.initialize();
|
||||
action.calculate();
|
||||
action.check_result();
|
||||
}
|
||||
return action.nb_op_base() / (time_action * 1e6);
|
||||
}
|
||||
|
||||
BTL_DONT_INLINE double time_calculate(Action& action) {
|
||||
// time measurement
|
||||
action.calculate();
|
||||
_chronos.start();
|
||||
for (unsigned int ii = 0; ii < _nb_calc; ii++) {
|
||||
action.calculate();
|
||||
}
|
||||
_chronos.stop();
|
||||
return _chronos.user_time();
|
||||
}
|
||||
|
||||
unsigned long long get_nb_calc() { return _nb_calc; }
|
||||
|
||||
private:
|
||||
unsigned long long _nb_calc;
|
||||
double m_time_action;
|
||||
Portable_Timer _chronos;
|
||||
};
|
||||
|
||||
#endif //_PORTABLE_PERF_ANALYZER_HH
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
//=====================================================
|
||||
// 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
|
||||
@@ -0,0 +1,143 @@
|
||||
//=====================================================
|
||||
// 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 <ctime>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define USEC_IN_SEC 1000000
|
||||
|
||||
// timer -------------------------------------------------------------------//
|
||||
|
||||
// A timer object measures CPU time.
|
||||
#if defined(_MSC_VER)
|
||||
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
|
||||
/*#ifndef hr_timer
|
||||
#include "hr_time.h"
|
||||
#define hr_timer
|
||||
#endif*/
|
||||
|
||||
class Portable_Timer {
|
||||
public:
|
||||
typedef struct {
|
||||
LARGE_INTEGER start;
|
||||
LARGE_INTEGER stop;
|
||||
} stopWatch;
|
||||
|
||||
Portable_Timer() {
|
||||
startVal.QuadPart = 0;
|
||||
stopVal.QuadPart = 0;
|
||||
QueryPerformanceFrequency(&frequency);
|
||||
}
|
||||
|
||||
void start() { QueryPerformanceCounter(&startVal); }
|
||||
|
||||
void stop() { QueryPerformanceCounter(&stopVal); }
|
||||
|
||||
double elapsed() {
|
||||
LARGE_INTEGER time;
|
||||
time.QuadPart = stopVal.QuadPart - startVal.QuadPart;
|
||||
return LIToSecs(time);
|
||||
}
|
||||
|
||||
double user_time() { return elapsed(); }
|
||||
|
||||
private:
|
||||
double LIToSecs(LARGE_INTEGER& L) { return ((double)L.QuadPart / (double)frequency.QuadPart); }
|
||||
|
||||
LARGE_INTEGER startVal;
|
||||
LARGE_INTEGER stopVal;
|
||||
LARGE_INTEGER frequency;
|
||||
|
||||
}; // Portable_Timer
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <mach/mach_time.h>
|
||||
|
||||
class Portable_Timer {
|
||||
public:
|
||||
Portable_Timer() {}
|
||||
|
||||
void start() {
|
||||
m_start_time = double(mach_absolute_time()) * 1e-9;
|
||||
;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
m_stop_time = double(mach_absolute_time()) * 1e-9;
|
||||
;
|
||||
}
|
||||
|
||||
double elapsed() { return user_time(); }
|
||||
|
||||
double user_time() { return m_stop_time - m_start_time; }
|
||||
|
||||
private:
|
||||
double m_stop_time, m_start_time;
|
||||
|
||||
}; // Portable_Timer (Apple)
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
class Portable_Timer {
|
||||
public:
|
||||
Portable_Timer() { m_clkid = BtlConfig::Instance.realclock ? CLOCK_REALTIME : CLOCK_PROCESS_CPUTIME_ID; }
|
||||
|
||||
Portable_Timer(int clkid) : m_clkid(clkid) {}
|
||||
|
||||
void start() {
|
||||
timespec ts;
|
||||
clock_gettime(m_clkid, &ts);
|
||||
m_start_time = double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
|
||||
}
|
||||
|
||||
void stop() {
|
||||
timespec ts;
|
||||
clock_gettime(m_clkid, &ts);
|
||||
m_stop_time = double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
|
||||
}
|
||||
|
||||
double elapsed() { return user_time(); }
|
||||
|
||||
double user_time() { return m_stop_time - m_start_time; }
|
||||
|
||||
private:
|
||||
int m_clkid;
|
||||
double m_stop_time, m_start_time;
|
||||
|
||||
}; // Portable_Timer (Linux)
|
||||
|
||||
#endif
|
||||
|
||||
#endif // PORTABLE_TIMER_HPP
|
||||
@@ -0,0 +1,91 @@
|
||||
//=====================================================
|
||||
// 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
|
||||
@@ -0,0 +1,176 @@
|
||||
//=====================================================
|
||||
// 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
|
||||
Reference in New Issue
Block a user