Clang-format tests, examples, libraries, benchmarks, etc.

This commit is contained in:
Antonio Sánchez
2023-12-05 21:22:55 +00:00
committed by Rasmus Munk Larsen
parent 3252ecc7a4
commit 46e9cdb7fe
876 changed files with 33453 additions and 37795 deletions

View File

@@ -33,19 +33,17 @@
// #include "timers/x86_perf_analyzer.hh"
// #include "timers/STL_perf_analyzer.hh"
#ifdef HAVE_MKL
extern "C" void cblas_saxpy(const int, const float, const float*, const int, float *, const int);
extern "C" void cblas_saxpy(const int, const float, const float *, const int, float *, const int);
#endif
using namespace std;
template <template<class> class Perf_Analyzer, class Action>
BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point )
{
if (BtlConfig::skipAction(Action::name()))
return;
template <template <class> class Perf_Analyzer, class Action>
BTL_DONT_INLINE void bench(int size_min, int size_max, int nb_point) {
if (BtlConfig::skipAction(Action::name())) return;
string filename="bench_"+Action::name()+".dat";
string filename = "bench_" + Action::name() + ".dat";
INFOS("starting " <<filename);
INFOS("starting " << filename);
// utilities
@@ -53,7 +51,7 @@ BTL_DONT_INLINE void bench( int size_min, int size_max, int 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);
size_lin_log(nb_point, size_min, size_max, tab_sizes);
std::vector<int> oldSizes;
std::vector<double> oldFlops;
@@ -62,29 +60,26 @@ BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point )
// 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;
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;
BTL_DISABLE_SSE_EXCEPTIONS();
#ifdef HAVE_MKL
#ifdef HAVE_MKL
{
float dummy;
cblas_saxpy(1,0,&dummy,1,&dummy,1);
cblas_saxpy(1, 0, &dummy, 1, &dummy, 1);
}
#endif
#endif
tab_mflops[i] = perf_action.eval_mflops(tab_sizes[i]);
std::cout << tab_mflops[i];
if (hasOldResults)
{
while (oldi>=0 && oldSizes[oldi]>tab_sizes[i])
--oldi;
if (oldi>=0 && oldSizes[oldi]==tab_sizes[i])
{
if (oldFlops[oldi]<tab_mflops[i])
if (hasOldResults) {
while (oldi >= 0 && oldSizes[oldi] > tab_sizes[i]) --oldi;
if (oldi >= 0 && oldSizes[oldi] == tab_sizes[i]) {
if (oldFlops[oldi] < tab_mflops[i])
std::cout << "\t > ";
else
std::cout << "\t < ";
@@ -92,48 +87,38 @@ BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point )
}
--oldi;
}
std::cout << " MFlops (" << nb_point-i << "/" << nb_point << ")" << std::endl;
std::cout << " MFlops (" << nb_point - i << "/" << nb_point << ")" << std::endl;
}
if (!BtlConfig::Instance.overwriteResults)
{
if (hasOldResults)
{
if (!BtlConfig::Instance.overwriteResults) {
if (hasOldResults) {
// merge the two data
std::vector<int> newSizes;
std::vector<double> newFlops;
unsigned int i=0;
unsigned int j=0;
while (i<tab_sizes.size() && j<oldSizes.size())
{
if (tab_sizes[i] == oldSizes[j])
{
unsigned int i = 0;
unsigned int j = 0;
while (i < tab_sizes.size() && j < oldSizes.size()) {
if (tab_sizes[i] == oldSizes[j]) {
newSizes.push_back(tab_sizes[i]);
newFlops.push_back(std::max(tab_mflops[i], oldFlops[j]));
++i;
++j;
}
else if (tab_sizes[i] < oldSizes[j])
{
} else if (tab_sizes[i] < oldSizes[j]) {
newSizes.push_back(tab_sizes[i]);
newFlops.push_back(tab_mflops[i]);
++i;
}
else
{
} else {
newSizes.push_back(oldSizes[j]);
newFlops.push_back(oldFlops[j]);
++j;
}
}
while (i<tab_sizes.size())
{
while (i < tab_sizes.size()) {
newSizes.push_back(tab_sizes[i]);
newFlops.push_back(tab_mflops[i]);
++i;
}
while (j<oldSizes.size())
{
while (j < oldSizes.size()) {
newSizes.push_back(oldSizes[j]);
newFlops.push_back(oldFlops[j]);
++j;
@@ -144,25 +129,21 @@ BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point )
}
// dump the result in a file :
dump_xy_file(tab_sizes,tab_mflops,filename);
dump_xy_file(tab_sizes, tab_mflops, filename);
}
// default Perf Analyzer
template <class Action>
BTL_DONT_INLINE void bench( int size_min, int size_max, int nb_point ){
BTL_DONT_INLINE 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);
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);
// bench<Mixed_Perf_Analyzer,Action>(size_min,size_max,nb_point);
// Only for small problem size. Otherwise 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);
// bench<X86_Perf_Analyzer,Action>(size_min,size_max,nb_point);
// bench<STL_Perf_Analyzer,Action>(size_min,size_max,nb_point);
}
#endif

View File

@@ -39,7 +39,7 @@
#endif
#if (defined __GNUC__)
#define BTL_ASM_COMMENT(X) asm("#" X)
#define BTL_ASM_COMMENT(X) asm("#" X)
#else
#define BTL_ASM_COMMENT(X)
#endif
@@ -47,164 +47,131 @@
#ifdef __SSE__
#include "xmmintrin.h"
// This enables flush to zero (FTZ) and denormals are zero (DAZ) modes:
#define BTL_DISABLE_SSE_EXCEPTIONS() { _mm_setcsr(_mm_getcsr() | 0x8040); }
#define BTL_DISABLE_SSE_EXCEPTIONS() \
{ _mm_setcsr(_mm_getcsr() | 0x8040); }
#else
#define BTL_DISABLE_SSE_EXCEPTIONS()
#endif
/** Enhanced std::string
*/
class BtlString : public std::string
{
public:
BtlString() : std::string() {}
BtlString(const BtlString& str) : std::string(static_cast<const std::string&>(str)) {}
BtlString(const std::string& str) : std::string(str) {}
BtlString(const char* str) : std::string(str) {}
*/
class BtlString : public std::string {
public:
BtlString() : std::string() {}
BtlString(const BtlString& str) : std::string(static_cast<const std::string&>(str)) {}
BtlString(const std::string& str) : std::string(str) {}
BtlString(const char* str) : std::string(str) {}
operator const char* () const { return c_str(); }
operator const char*() const { return c_str(); }
void trim( bool left = true, bool right = true )
{
int lspaces, rspaces, len = length(), i;
lspaces = rspaces = 0;
void trim(bool left = true, bool right = true) {
int lspaces, rspaces, len = length(), i;
lspaces = rspaces = 0;
if ( left )
for (i=0; i<len && (at(i)==' '||at(i)=='\t'||at(i)=='\r'||at(i)=='\n'); ++lspaces,++i);
if (left)
for (i = 0; i < len && (at(i) == ' ' || at(i) == '\t' || at(i) == '\r' || at(i) == '\n'); ++lspaces, ++i)
;
if ( right && lspaces < len )
for(i=len-1; i>=0 && (at(i)==' '||at(i)=='\t'||at(i)=='\r'||at(i)=='\n'); rspaces++,i--);
if (right && lspaces < len)
for (i = len - 1; i >= 0 && (at(i) == ' ' || at(i) == '\t' || at(i) == '\r' || at(i) == '\n'); rspaces++, i--)
;
*this = substr(lspaces, len-lspaces-rspaces);
}
*this = substr(lspaces, len - lspaces - rspaces);
}
std::vector<BtlString> split( const BtlString& delims = "\t\n ") const
{
std::vector<BtlString> ret;
unsigned int numSplits = 0;
size_t start, pos;
start = 0;
do
{
pos = find_first_of(delims, start);
if (pos == start)
{
ret.push_back("");
start = pos + 1;
}
else if (pos == npos)
ret.push_back( substr(start) );
else
{
ret.push_back( substr(start, pos - start) );
start = pos + 1;
}
//start = find_first_not_of(delims, start);
++numSplits;
} while (pos != npos);
return ret;
}
std::vector<BtlString> split(const BtlString& delims = "\t\n ") const {
std::vector<BtlString> ret;
unsigned int numSplits = 0;
size_t start, pos;
start = 0;
do {
pos = find_first_of(delims, start);
if (pos == start) {
ret.push_back("");
start = pos + 1;
} else if (pos == npos)
ret.push_back(substr(start));
else {
ret.push_back(substr(start, pos - start));
start = pos + 1;
}
// start = find_first_not_of(delims, start);
++numSplits;
} while (pos != npos);
return ret;
}
bool endsWith(const BtlString& str) const
{
if(str.size()>this->size())
return false;
return this->substr(this->size()-str.size(),str.size()) == str;
}
bool contains(const BtlString& str) const
{
return this->find(str)<this->size();
}
bool beginsWith(const BtlString& str) const
{
if(str.size()>this->size())
return false;
return this->substr(0,str.size()) == str;
}
bool endsWith(const BtlString& str) const {
if (str.size() > this->size()) return false;
return this->substr(this->size() - str.size(), str.size()) == str;
}
bool contains(const BtlString& str) const { return this->find(str) < this->size(); }
bool beginsWith(const BtlString& str) const {
if (str.size() > this->size()) return false;
return this->substr(0, str.size()) == str;
}
BtlString toLowerCase( void )
{
std::transform(begin(), end(), begin(), static_cast<int(*)(int)>(::tolower) );
return *this;
}
BtlString toUpperCase( void )
{
std::transform(begin(), end(), begin(), static_cast<int(*)(int)>(::toupper) );
return *this;
}
BtlString toLowerCase(void) {
std::transform(begin(), end(), begin(), static_cast<int (*)(int)>(::tolower));
return *this;
}
BtlString toUpperCase(void) {
std::transform(begin(), end(), begin(), static_cast<int (*)(int)>(::toupper));
return *this;
}
/** Case insensitive comparison.
*/
bool isEquiv(const BtlString& str) const
{
BtlString str0 = *this;
str0.toLowerCase();
BtlString str1 = str;
str1.toLowerCase();
return str0 == str1;
}
/** Case insensitive comparison.
*/
bool isEquiv(const BtlString& str) const {
BtlString str0 = *this;
str0.toLowerCase();
BtlString str1 = str;
str1.toLowerCase();
return str0 == str1;
}
/** Decompose the current string as a path and a file.
For instance: "dir1/dir2/file.ext" leads to path="dir1/dir2/" and filename="file.ext"
*/
void decomposePathAndFile(BtlString& path, BtlString& filename) const
{
std::vector<BtlString> elements = this->split("/\\");
path = "";
filename = elements.back();
elements.pop_back();
if (this->at(0)=='/')
path = "/";
for (unsigned int i=0 ; i<elements.size() ; ++i)
path += elements[i] + "/";
}
/** Decompose the current string as a path and a file.
For instance: "dir1/dir2/file.ext" leads to path="dir1/dir2/" and filename="file.ext"
*/
void decomposePathAndFile(BtlString& path, BtlString& filename) const {
std::vector<BtlString> elements = this->split("/\\");
path = "";
filename = elements.back();
elements.pop_back();
if (this->at(0) == '/') path = "/";
for (unsigned int i = 0; i < elements.size(); ++i) path += elements[i] + "/";
}
};
class BtlConfig
{
public:
BtlConfig()
: overwriteResults(false), checkResults(true), realclock(false), tries(DEFAULT_NB_TRIES)
{
char * _config;
_config = getenv ("BTL_CONFIG");
if (_config!=NULL)
{
class BtlConfig {
public:
BtlConfig() : overwriteResults(false), checkResults(true), realclock(false), tries(DEFAULT_NB_TRIES) {
char* _config;
_config = getenv("BTL_CONFIG");
if (_config != NULL) {
std::vector<BtlString> config = BtlString(_config).split(" \t\n");
for (unsigned int i = 0; i<config.size(); i++)
{
if (config[i].beginsWith("-a"))
{
if (i+1==config.size())
{
for (unsigned int i = 0; i < config.size(); i++) {
if (config[i].beginsWith("-a")) {
if (i + 1 == config.size()) {
std::cerr << "error processing option: " << config[i] << "\n";
exit(2);
}
Instance.m_selectedActionNames = config[i+1].split(":");
Instance.m_selectedActionNames = config[i + 1].split(":");
i += 1;
}
else if (config[i].beginsWith("-t"))
{
if (i+1==config.size())
{
} else if (config[i].beginsWith("-t")) {
if (i + 1 == config.size()) {
std::cerr << "error processing option: " << config[i] << "\n";
exit(2);
}
Instance.tries = atoi(config[i+1].c_str());
Instance.tries = atoi(config[i + 1].c_str());
i += 1;
}
else if (config[i].beginsWith("--overwrite"))
{
} else if (config[i].beginsWith("--overwrite")) {
Instance.overwriteResults = true;
}
else if (config[i].beginsWith("--nocheck"))
{
} else if (config[i].beginsWith("--nocheck")) {
Instance.checkResults = false;
}
else if (config[i].beginsWith("--real"))
{
} else if (config[i].beginsWith("--real")) {
Instance.realclock = true;
}
}
@@ -213,15 +180,12 @@ public:
BTL_DISABLE_SSE_EXCEPTIONS();
}
BTL_DONT_INLINE static bool skipAction(const std::string& _name)
{
if (Instance.m_selectedActionNames.empty())
return false;
BTL_DONT_INLINE static bool skipAction(const std::string& _name) {
if (Instance.m_selectedActionNames.empty()) return false;
BtlString name(_name);
for (unsigned int i=0; i<Instance.m_selectedActionNames.size(); ++i)
if (name.contains(Instance.m_selectedActionNames[i]))
return false;
for (unsigned int i = 0; i < Instance.m_selectedActionNames.size(); ++i)
if (name.contains(Instance.m_selectedActionNames[i])) return false;
return true;
}
@@ -232,11 +196,10 @@ public:
bool realclock;
int tries;
protected:
protected:
std::vector<BtlString> m_selectedActionNames;
};
#define BTL_MAIN \
BtlConfig BtlConfig::Instance
#define BTL_MAIN BtlConfig BtlConfig::Instance
#endif // BTL_HH
#endif // BTL_HH

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : init_function.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,39 +16,20 @@
// 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) { return index; }
double simple_function(int index_i, int index_j)
{
return index_i+index_j;
}
double simple_function(int index_i, int index_j) { return index_i + index_j; }
double pseudo_random(int /*index*/)
{
return std::rand()/double(RAND_MAX);
}
double pseudo_random(int /*index*/) { return std::rand() / double(RAND_MAX); }
double pseudo_random(int /*index_i*/, int /*index_j*/)
{
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*/)
{
return 0.0;
}
double null_function(int /*index_i*/, int /*index_j*/)
{
return 0.0;
}
double null_function(int /*index_i*/, int /*index_j*/) { return 0.0; }
#endif

View File

@@ -24,38 +24,35 @@
// resize() method
// [] operator for setting element
// value_type defined
template<double init_function(int,int), class Vector>
BTL_DONT_INLINE void init_row(Vector & X, int size, int row){
template <double init_function(int, int), class Vector>
BTL_DONT_INLINE void init_row(Vector& X, int size, int row) {
X.resize(size);
for (unsigned int j=0;j<X.size();j++){
X[j]=typename Vector::value_type(init_function(row,j));
for (unsigned 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>
BTL_DONT_INLINE void init_matrix(Vector & A, int size){
template <double init_function(int, int), class Vector>
BTL_DONT_INLINE void init_matrix(Vector& A, int size) {
A.resize(size);
for (unsigned int row=0; row<A.size() ; row++){
init_row<init_function>(A[row],size,row);
for (unsigned int row = 0; row < A.size(); row++) {
init_row<init_function>(A[row], size, row);
}
}
template<double init_function(int,int),class Matrix>
BTL_DONT_INLINE void init_matrix_symm(Matrix& A, int size){
template <double init_function(int, int), class Matrix>
BTL_DONT_INLINE void init_matrix_symm(Matrix& A, int size) {
A.resize(size);
for (unsigned int row=0; row<A.size() ; row++)
A[row].resize(size);
for (unsigned int row=0; row<A.size() ; row++){
A[row][row] = init_function(row,row);
for (unsigned int col=0; col<row ; col++){
double x = init_function(row,col);
for (unsigned int row = 0; row < A.size(); row++) A[row].resize(size);
for (unsigned int row = 0; row < A.size(); row++) {
A[row][row] = init_function(row, row);
for (unsigned int col = 0; col < row; col++) {
double x = init_function(row, col);
A[row][col] = A[col][row] = x;
}
}

View File

@@ -24,13 +24,12 @@
// resize() method
// [] operator for setting element
// value_type defined
template<double init_function(int), class Vector>
void init_vector(Vector & X, int size){
template <double init_function(int), class Vector>
void init_vector(Vector& X, int size) {
X.resize(size);
for (unsigned int i=0;i<X.size();i++){
X[i]=typename Vector::value_type(init_function(i));
for (unsigned int i = 0; i < X.size(); i++) {
X[i] = typename Vector::value_type(init_function(i));
}
}

View File

@@ -32,14 +32,11 @@
using namespace std;
template <template <class> class Perf_Analyzer, template <class> class Action, template <class, int> class Interface>
BTL_DONT_INLINE void bench_static(void) {
if (BtlConfig::skipAction(Action<Interface<REAL_TYPE, 10> >::name())) return;
template <template<class> class Perf_Analyzer, template<class> class Action, template<class,int> class Interface>
BTL_DONT_INLINE void bench_static(void)
{
if (BtlConfig::skipAction(Action<Interface<REAL_TYPE,10> >::name()))
return;
string filename = "bench_" + Action<Interface<REAL_TYPE,10> >::name() + ".dat";
string filename = "bench_" + Action<Interface<REAL_TYPE, 10> >::name() + ".dat";
INFOS("starting " << filename);
@@ -48,33 +45,17 @@ BTL_DONT_INLINE void bench_static(void)
std::vector<double> tab_mflops;
std::vector<double> tab_sizes;
static_size_generator<max_size,Perf_Analyzer,Action,Interface>::go(tab_sizes,tab_mflops);
static_size_generator<max_size, Perf_Analyzer, Action, Interface>::go(tab_sizes, tab_mflops);
dump_xy_file(tab_sizes,tab_mflops,filename);
dump_xy_file(tab_sizes, tab_mflops, filename);
}
// default Perf Analyzer
template <template<class> class Action, template<class,int> class Interface>
BTL_DONT_INLINE 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>();
template <template <class> class Action, template <class, int> class Interface>
BTL_DONT_INLINE 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

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : intel_bench_fixed_size.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,7 +16,7 @@
// 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_
@@ -24,43 +24,37 @@
#include "function_time.hh"
template <class Action>
double bench_fixed_size(int size, unsigned long long & nb_calc,unsigned long long & nb_init)
{
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);
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);
// 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);
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);
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));
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);
time_action = time_action - time_baseline;
return action.nb_op_base() / (time_action * 1000000.0);
}
#endif

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : static_size_generator.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,42 +16,37 @@
// 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
// 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)
{
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);
std::cout << tab_sizes.back() << " \t" << std::flush;
Perf_Analyzer<Action<Interface<REAL_TYPE,SIZE> > > perf_action;
Perf_Analyzer<Action<Interface<REAL_TYPE, SIZE> > > perf_action;
tab_mflops.push_back(perf_action.eval_mflops(SIZE));
std::cout << tab_mflops.back() << " MFlops" << std::endl;
static_size_generator<SIZE-1,Perf_Analyzer,Action,Interface>::go(tab_sizes,tab_mflops);
static_size_generator<SIZE - 1, Perf_Analyzer, Action, Interface>::go(tab_sizes, tab_mflops);
};
};
//recursion end
// 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)
{
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;
Perf_Analyzer<Action<Interface<REAL_TYPE, 1> > > perf_action;
tab_mflops.push_back(perf_action.eval_mflops(1));
};
};
#endif

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : STL_perf_analyzer.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,42 +16,35 @@
// 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()
{
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 & ){
};
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)
{
~STL_Perf_Analyzer(void) { MESSAGE("STL_Perf_Analyzer Dtor"); };
inline double eval_mflops(int size) {
ACTION action(size);
_chronos.start_baseline(_nb_sample);
do {
do {
action.initialize();
} while (_chronos.check());
double baseline_time=_chronos.get_time();
double baseline_time = _chronos.get_time();
_chronos.start(_nb_sample);
do {
@@ -59,24 +52,19 @@ public:
action.calculate();
} while (_chronos.check());
double calculate_time=_chronos.get_time();
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);
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:
private:
STL_Timer _chronos;
unsigned long long _nb_sample;
};
#endif

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : STL_Timer.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,7 +16,7 @@
// 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.
@@ -28,10 +28,10 @@
using namespace std;
class STL_Timer {
public:
STL_Timer(){ baseline = false; }; // Default constructor
public:
STL_Timer() { baseline = false; }; // Default constructor
// Start a series of r trials:
void start(unsigned int r){
void start(unsigned int r) {
reps = r;
count = 0;
iterations.clear();
@@ -39,30 +39,28 @@ public:
initial = time(0);
};
// Start a series of r trials to determine baseline time:
void start_baseline(unsigned int r)
{
void start_baseline(unsigned int r) {
baseline = true;
start(r);
}
// Returns true if the trials have been completed, else false
bool check()
{
bool check() {
++count;
final = time(0);
if (initial < final) {
iterations.push_back(count);
iterations.push_back(count);
initial = final;
count = 0;
}
return (iterations.size() < reps);
};
// Returns the results for external use
double get_time( void )
{
double get_time(void) {
sort(iterations.begin(), iterations.end());
return 1.0/iterations[reps/2];
return 1.0 / iterations[reps / 2];
};
private:
private:
unsigned int reps; // Number of trials
// For storing loop iterations of a trial
vector<long> iterations;
@@ -72,7 +70,6 @@ private:
unsigned long count;
// true if this is a baseline computation, false otherwise
bool baseline;
// For recording the baseline time
// For recording the baseline time
double baseline_time;
};

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : mixed_perf_analyzer.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,7 +16,7 @@
// 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
@@ -25,49 +25,34 @@
// 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 & ){
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)
{
~Mixed_Perf_Analyzer(void) { MESSAGE("Mixed_Perf_Analyzer Dtor"); };
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);
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:
private:
Portable_Perf_Analyzer<Action> _ppa;
X86_Perf_Analyzer<Action> _x86pa;
bool _use_ppa;
};
#endif

View File

@@ -25,38 +25,33 @@
#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 & ){
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");
};
~Portable_Perf_Analyzer() { MESSAGE("Portable_Perf_Analyzer Dtor"); };
BTL_DONT_INLINE double eval_mflops(int size)
{
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();
// 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)
{
for (int i = 1; i < BtlConfig::Instance.tries; ++i) {
Action _action(size);
std::cout << " " << _action.nb_op_base()*_nb_calc/(m_time_action*1e6) << " ";
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));
}
@@ -64,40 +59,31 @@ public:
double time_action = m_time_action / (double(_nb_calc));
// check
if (BtlConfig::Instance.checkResults && size<128)
{
if (BtlConfig::Instance.checkResults && size < 128) {
action.initialize();
action.calculate();
action.check_result();
}
return action.nb_op_base()/(time_action*1e6);
return action.nb_op_base() / (time_action * 1e6);
}
BTL_DONT_INLINE double time_calculate(Action & action)
{
BTL_DONT_INLINE double time_calculate(Action& action) {
// time measurement
action.calculate();
_chronos.start();
for (unsigned int ii=0;ii<_nb_calc;ii++)
{
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;
}
unsigned long long get_nb_calc() { return _nb_calc; }
private:
private:
unsigned long long _nb_calc;
double m_time_action;
Portable_Timer _chronos;
};
#endif //_PORTABLE_PERF_ANALYZER_HH
#endif //_PORTABLE_PERF_ANALYZER_HH

View File

@@ -24,93 +24,74 @@
#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 & ){
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)
{
~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_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)
{
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));
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);
// 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));
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);
// INFOS("time_baseline="<<time_baseline);
// INFOS("time_action="<<time_action);
time_action = time_action - time_baseline;
// INFOS("time_corrected="<<time_action);
// INFOS("time_corrected="<<time_action);
return action.nb_op_base()/(time_action*1000000.0);
return action.nb_op_base() / (time_action * 1000000.0);
}
inline double time_init(Action & action)
{
inline double time_init(Action& action) {
// time measurement
_chronos.start();
for (int ii=0; ii<_nb_init; ii++)
action.initialize();
for (int ii = 0; ii < _nb_init; ii++) action.initialize();
_chronos.stop();
return _chronos.user_time();
}
inline double time_calculate(Action & action)
{
inline double time_calculate(Action& action) {
// time measurement
_chronos.start();
for (int ii=0;ii<_nb_calc;ii++)
{
for (int ii = 0; ii < _nb_calc; ii++) {
action.initialize();
action.calculate();
}
@@ -118,17 +99,12 @@ public:
return _chronos.user_time();
}
unsigned long long get_nb_calc( void )
{
return _nb_calc;
}
unsigned long long get_nb_calc(void) { return _nb_calc; }
private:
private:
unsigned long long _nb_calc;
unsigned long long _nb_init;
Portable_Timer _chronos;
};
#endif //_PORTABLE_PERF_ANALYZER_HH
#endif //_PORTABLE_PERF_ANALYZER_HH

View File

@@ -27,10 +27,8 @@
#include <time.h>
#define USEC_IN_SEC 1000000
// timer -------------------------------------------------------------------//
// A timer object measures CPU time.
@@ -44,90 +42,66 @@
#define hr_timer
#endif*/
class Portable_Timer
{
public:
typedef struct {
class Portable_Timer {
public:
typedef struct {
LARGE_INTEGER start;
LARGE_INTEGER stop;
} stopWatch;
} stopWatch;
Portable_Timer() {
startVal.QuadPart = 0;
stopVal.QuadPart = 0;
QueryPerformanceFrequency(&frequency);
}
Portable_Timer()
{
startVal.QuadPart = 0;
stopVal.QuadPart = 0;
QueryPerformanceFrequency(&frequency);
}
void start() { QueryPerformanceCounter(&startVal); }
void start() { QueryPerformanceCounter(&startVal); }
void stop() { QueryPerformanceCounter(&stopVal); }
void stop() { QueryPerformanceCounter(&stopVal); }
double elapsed() {
LARGE_INTEGER time;
time.QuadPart = stopVal.QuadPart - startVal.QuadPart;
return LIToSecs(time);
}
double user_time() { return elapsed(); }
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); }
double LIToSecs(LARGE_INTEGER& L) {
return ((double)L.QuadPart /(double)frequency.QuadPart) ;
}
LARGE_INTEGER startVal;
LARGE_INTEGER stopVal;
LARGE_INTEGER frequency;
LARGE_INTEGER startVal;
LARGE_INTEGER stopVal;
LARGE_INTEGER frequency;
}; // Portable_Timer
}; // Portable_Timer
#elif defined(__APPLE__)
#include <CoreServices/CoreServices.h>
#include <mach/mach_time.h>
class Portable_Timer
{
class Portable_Timer {
public:
Portable_Timer() {}
Portable_Timer()
{
void start() {
m_start_time = double(mach_absolute_time()) * 1e-9;
;
}
void start()
{
m_start_time = double(mach_absolute_time())*1e-9;;
void stop() {
m_stop_time = double(mach_absolute_time()) * 1e-9;
;
}
void stop()
{
m_stop_time = double(mach_absolute_time())*1e-9;;
double elapsed() { return user_time(); }
}
double elapsed()
{
return user_time();
}
double user_time()
{
return m_stop_time - m_start_time;
}
private:
double user_time() { return m_stop_time - m_start_time; }
private:
double m_stop_time, m_start_time;
}; // Portable_Timer (Apple)
}; // Portable_Timer (Apple)
#else
@@ -136,51 +110,33 @@ private:
#include <unistd.h>
#include <sys/times.h>
class Portable_Timer
{
class Portable_Timer {
public:
Portable_Timer() { m_clkid = BtlConfig::Instance.realclock ? CLOCK_REALTIME : CLOCK_PROCESS_CPUTIME_ID; }
Portable_Timer()
{
m_clkid = BtlConfig::Instance.realclock ? CLOCK_REALTIME : CLOCK_PROCESS_CPUTIME_ID;
}
Portable_Timer(int clkid) : m_clkid(clkid) {}
Portable_Timer(int clkid) : m_clkid(clkid)
{}
void start()
{
void start() {
timespec ts;
clock_gettime(m_clkid, &ts);
m_start_time = double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
}
void stop()
{
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 elapsed() { return user_time(); }
double user_time()
{
return m_stop_time - m_start_time;
}
private:
double user_time() { return m_stop_time - m_start_time; }
private:
int m_clkid;
double m_stop_time, m_start_time;
}; // Portable_Timer (Linux)
}; // Portable_Timer (Linux)
#endif

View File

@@ -23,38 +23,30 @@
#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()
{
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 & ){
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)
{
~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++){
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++)
{
for (int i = 0; i < _nb_sample; i++) {
_chronos.start();
action.initialize();
action.calculate();
@@ -62,47 +54,38 @@ public:
_chronos.add_get_click();
}
calculate_time += double(_chronos.get_shortest_clicks())/_chronos.frequency();
calculate_time += double(_chronos.get_shortest_clicks()) / _chronos.frequency();
if (j==0) action.check_result();
if (j == 0) action.check_result();
_chronos.clear();
for(int i=0 ; i < _nb_sample ; i++)
{
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();
baseline_time += double(_chronos.get_shortest_clicks()) / _chronos.frequency();
}
double corrected_time = (calculate_time-baseline_time)/double(nb_loop);
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);
// 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;
// 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);
return action.nb_op_base() / (corrected_time * 1000000.0);
// return action.nb_op_base()/(calculate_time*1000000.0);
}
private:
private:
X86_Timer _chronos;
unsigned long long _nb_sample;
};
#endif

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : x86_timer.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,7 +16,7 @@
// 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
@@ -24,7 +24,7 @@
#include <sys/resource.h>
#include <unistd.h>
#include <sys/times.h>
//#include "system_time.h"
// #include "system_time.h"
#define u32 unsigned int
#include <asm/msr.h>
#include "utilities.h"
@@ -34,213 +34,143 @@
#include <iostream>
// frequence de la becanne en Hz
//#define FREQUENCY 648000000
//#define FREQUENCY 1400000000
// #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"); }
public :
inline void start(void) { rdtsc(_click_start.n32[0], _click_start.n32[1]); }
X86_Timer( void ):_frequency(FREQUENCY),_nb_sample(0)
{
MESSAGE("X86_Timer Default Ctor");
}
inline void stop(void) { rdtsc(_click_stop.n32[0], _click_stop.n32[1]); }
inline void start( void ){
inline double frequency(void) { return _frequency; }
rdtsc(_click_start.n32[0],_click_start.n32[1]);
double get_elapsed_time_in_second(void) { return (_click_stop.n64 - _click_start.n64) / double(FREQUENCY); }
}
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 ){
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;
int dummy = 2;
initial = time(0);
start();
do {
dummy+=2;
}
while(time(0)==initial);
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);
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);
_frequency = _frequency * get_elapsed_time_in_second() / double(final - initial);
/// INFOS("CPU frequency : "<< _frequency);
}
void add_get_click( void ){
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);
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;
}
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) ;
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;
}
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);
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);
}
void fill_history_clicks( void ){
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;
double get_most_occured_clicks( void ){
std::map<unsigned long long, unsigned long long>::iterator itr;
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);
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 )
{
void clear(void) {
_counted_clicks.clear();
_history_mean_clicks.clear();
_history_shortest_clicks.clear();
_history_most_occured_clicks.clear();
_nb_sample=0;
_nb_sample = 0;
}
private :
union
{
unsigned long int n32[2] ;
unsigned long long n64 ;
private:
union {
unsigned long int n32[2];
unsigned long long n64;
} _click_start;
union
{
unsigned long int n32[2] ;
unsigned long long n64 ;
union {
unsigned long int n32[2];
unsigned long long n64;
} _click_stop;
double _frequency ;
double _frequency;
map<unsigned long long,unsigned long long> _counted_clicks;
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

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : size_lin_log.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,55 +16,41 @@
// 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;
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;
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];
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;
} 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]);
// }
// for (int i=0;i<nb_point;i++){
// INFOS("computed sizes : X["<<i<<"]="<<X[i]);
// }
}
#endif

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : size_log.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,7 +16,7 @@
// 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
@@ -25,30 +25,26 @@
// resize() method
// [] operator for setting 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)
{
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_min = log(float(size_min));
float ls_max = log(float(size_max));
float ls=0.0;
float ls = 0.0;
float delta_ls=(ls_max-ls_min)/(float(nb_point-1));
float delta_ls = (ls_max - ls_min) / (float(nb_point - 1));
int size=0;
int size = 0;
for (int i=0;i<nb_point;i++){
for (int i = 0; i < nb_point; i++) {
ls = ls_min + float(i) * delta_ls;
ls = ls_min + float(i)*delta_ls ;
size=int(exp(ls));
size = int(exp(ls));
X[i]=size;
X[i] = size;
}
}
#endif

View File

@@ -9,82 +9,120 @@
/* --- Definition macros file to print information if _DEBUG_ is defined --- */
# ifndef UTILITIES_H
# define UTILITIES_H
#ifndef UTILITIES_H
#define UTILITIES_H
# include <stdlib.h>
//# include <iostream> ok for gcc3.01
# include <iostream>
#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 ;}
#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
#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 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_
#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) ;
#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 */
#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 ; }
#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)
# else /* ifdef _DEBUG_*/
# define HERE
# define SCRUTE(var)
# define MESSAGE(chain)
# define INTERRUPTION(code)
# ifndef ASSERT
# define ASSERT(condition)
# endif /* ASSERT */
#ifndef ASSERT
#define ASSERT(condition)
#endif /* ASSERT */
#define REPERE
#define BEGIN_OF(chain)
#define END_OF(chain)
#endif /* ifdef _DEBUG_*/
# endif /* ifdef _DEBUG_*/
# endif /* ifndef UTILITIES_H */
#endif /* ifndef UTILITIES_H */

View File

@@ -1,14 +1,14 @@
//=====================================================
// File : dump_file_x_y.hh
// Author : L. Plagne <laurent.plagne@edf.fr)>
// 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
@@ -16,7 +16,7 @@
// 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 XY_FILE_HH
#define XY_FILE_HH
#include <fstream>
@@ -25,24 +25,22 @@
#include <vector>
using namespace std;
bool read_xy_file(const std::string & filename, std::vector<int> & tab_sizes,
std::vector<double> & tab_mflops, bool quiet = false)
{
bool read_xy_file(const std::string& filename, std::vector<int>& tab_sizes, std::vector<double>& tab_mflops,
bool quiet = false) {
std::ifstream input_file(filename.c_str(), std::ios::in);
std::ifstream input_file (filename.c_str(),std::ios::in);
if (!input_file){
if (!input_file) {
if (!quiet) {
INFOS("!!! Error opening "<<filename);
INFOS("!!! Error opening " << filename);
}
return false;
}
int nb_point=0;
int size=0;
double mflops=0;
int nb_point = 0;
int size = 0;
double mflops = 0;
while (input_file >> size >> mflops ){
while (input_file >> size >> mflops) {
nb_point++;
tab_sizes.push_back(size);
tab_mflops.push_back(mflops);
@@ -60,16 +58,14 @@ bool read_xy_file(const std::string & filename, std::vector<int> & tab_sizes,
using namespace std;
template<class Vector_A, class Vector_B>
void dump_xy_file(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;
template <class Vector_A, class Vector_B>
void dump_xy_file(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