1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
|
/*
* vdtPerfBenchmark.cpp
*
* Created on: Jun 23, 2012
* Author: danilopiparo
*/
#include "vdtdiag_random.h"
#include "vdtMath.h"
#include "vdtdiag_helper.h"
#include "vdtdiag_fcnPerformance.h"
#include "vdtdiag_fcnTuples.h"
#include "vdtdiag_simpleCmd.h"
#include <iostream>
#include <fstream>
#include <string>
#include <regex>
/**
* Loop on the functions, and measure performance
**/
/*
- log
- exp
- sin
- cos
- tan
- asin
- acos
- atan
- inverse sqrt
- inverse (faster than division, based on isqrt)
*/
template <class T,class TUPLE>
void print_avg(const TUPLE& dpfcntuple, std::ofstream& ofile,uint32_t repetitions){
fcnPerformance<T> dpExpPerf(std::get<0>(dpfcntuple),
std::get<2>(dpfcntuple),
std::get<1>(dpfcntuple),
repetitions);
dpExpPerf.print();
dpExpPerf.print(ofile);
}
template <class T,class TUPLE>
void print_avg2D(const TUPLE& dpfcntuple, std::ofstream& ofile,uint32_t repetitions){
fcnPerformance<T> dpExpPerf(std::get<0>(dpfcntuple),
std::get<2>(dpfcntuple),
std::get<3>(dpfcntuple),
std::get<1>(dpfcntuple),
repetitions);
dpExpPerf.print();
dpExpPerf.print(ofile);
}
int main(int argc, char **argv){
//set cmd options
CmdOptions opt;
opt.addOption("-n","--nick","Nickname to distinguish different runs/libraries used (required)");
opt.addOption("-s","--size","# of numbers to be tested (default 50000)");
opt.addOption("-r","--repetitions","# of repetitions from which statistics are calculated (default 150)");
opt.addOption("-M","--pool_max","Upper limit of the pool interval");
opt.addOption("-m","--pool_min","Lower limit of the pool interval");
opt.addOption("-p","--pattern","Regular expression to be matched in function name");
double POOL_MAX=5000;
double POOL_MIN=-POOL_MAX;
uint32_t SIZE = 50000;
uint32_t REPETITIONS = 150;
std::string nick = "";
std::string pattern_s=".*";
if(!opt.parseCmd(argc,argv)){
std::cout << "Something is wrong with cmd options, try --help\n"
<<"usage: vdtPerfBenchmark -n=<run88libmVSvdt>\n";
return 0;
}
// if help was printed, exit
if(opt.isSet("-h"))
return 1;
// process cmd options
nick = opt.getArgument("-n");
if(nick == ""){
std::cout << "Error: Nickname was not specified!\n";
opt.printHelp("-n");
return 0;
}
//getArgument() contains isSet check
if(opt.getArgument("-s") != "")
SIZE = std::stoi(opt.getArgument("-s").c_str());
if(opt.getArgument("-r") != "")
REPETITIONS = std::stoi(opt.getArgument("-r").c_str());
if(opt.getArgument("-m") != "")
POOL_MIN = std::stod(opt.getArgument("-m").c_str());
if(opt.getArgument("-M") != "")
POOL_MAX = std::stod(opt.getArgument("-M").c_str());
if (opt.getArgument("-p")!= "")
pattern_s = opt.getArgument("-p");
std::regex pattern (pattern_s);
// Control print
std::cout << "Running with nick: " << nick << ", size: " << SIZE << ", repetitions: "<< REPETITIONS
<< ", the pool max:" << POOL_MAX << ", the pool min:" << POOL_MIN
<< " and the pattern " << pattern_s << "\n";
// setup filename
std::string fname = nick + "__performance_benchmark.txt";
std::ofstream ofile(fname);
std::cout << "Double Precision\n";
randomPool<double> symmrpool (POOL_MIN,POOL_MAX,SIZE);
randomPool<double> asymmrpool (.00001,POOL_MAX,SIZE);
randomPool<double> mone2onerpool (-1,1,SIZE);
randomPool<double> expPool (-705,705,SIZE);
randomPool2D<double> mone2onerpool2D (-1,-1,1,1,SIZE);
// simple
std::vector<genfpfcn_tuple<double>> dp_fcns;
getFunctionTuples(&dp_fcns,symmrpool,asymmrpool,mone2onerpool,expPool);
std::string funcname;
for (const auto& dpfcntuple : dp_fcns){
funcname = std::get<0>(dpfcntuple);
if (std::regex_match(funcname.begin(), funcname.end(), pattern))
print_avg<double,genfpfcn_tuple<double>>(dpfcntuple,ofile,REPETITIONS);
}
// double precision vectorised -----------------------------------------------
// Simple
std::vector<genfpfcnv_tuple<double>> dp_fcnsv;
getFunctionTuplesvect(&dp_fcnsv,symmrpool,asymmrpool,mone2onerpool,expPool);
for (const auto& dpfcntuple : dp_fcnsv){
funcname = std::get<0>(dpfcntuple);
if (std::regex_match(funcname.begin(), funcname.end(), pattern))
print_avg<double,genfpfcnv_tuple<double>>(dpfcntuple,ofile,REPETITIONS);
}
//------------------------------------------------------------------------------
// NOW SINGLE PRECISION
std::cout << "Single Precision\n";
randomPool<float> symmrpoolf (POOL_MIN,POOL_MAX,SIZE);
randomPool<float> asymmrpoolf (.00001,POOL_MAX,SIZE);
randomPool<float> mone2onerpoolf (-1,1,SIZE);
randomPool<float> expPoolf (-80,80,SIZE);
randomPool2D<float> mone2onerpool2Df (-1.f,-1.f,1.f,1.f,SIZE);
// simple
std::vector<genfpfcn_tuple<float>> sp_fcns;
getFunctionTuples(&sp_fcns,symmrpoolf,asymmrpoolf,mone2onerpoolf,expPoolf);
for (const auto& spfcntuple : sp_fcns){
funcname = std::get<0>(spfcntuple);
if (std::regex_match(funcname.begin(), funcname.end(), pattern))
print_avg<float,genfpfcn_tuple<float>>(spfcntuple,ofile,REPETITIONS);
}
// single precision vectorised
// Simple
std::vector<genfpfcnv_tuple<float>> sp_fcnsv;
getFunctionTuplesvect(&sp_fcnsv,symmrpoolf,asymmrpoolf,mone2onerpoolf,expPoolf);
for (const auto& spfcntuple : sp_fcnsv){
funcname = std::get<0>(spfcntuple);
if (std::regex_match(funcname.begin(), funcname.end(), pattern))
print_avg<float,genfpfcnv_tuple<float>>(spfcntuple,ofile,REPETITIONS);
}
// 2D
std::cout << "\n\n Functions with Two Arguments \n";
// Double Precision
std::cout << "Double Precision\n";
std::vector<genfpfcn2D_tuple<double>> dp_fcns2D;
getFunctionTuples(&dp_fcns2D,mone2onerpool2D);
for (const auto& dpfcntuple : dp_fcns2D){
funcname = std::get<0>(dpfcntuple);
if (std::regex_match(funcname.begin(), funcname.end(), pattern))
print_avg2D<double,genfpfcn2D_tuple<double>>(dpfcntuple,ofile,REPETITIONS);
}
// Double Precision Array
std::vector<genfpfcn2Dv_tuple<double>> dp_fcns2Dv;
getFunctionTuplesvect(&dp_fcns2Dv,mone2onerpool2D);
for (const auto& dpfcntuple : dp_fcns2Dv){
funcname = std::get<0>(dpfcntuple);
if (std::regex_match(funcname.begin(), funcname.end(), pattern))
print_avg2D<double,genfpfcn2Dv_tuple<double>>(dpfcntuple,ofile,REPETITIONS);
}
// Single Precision
std::cout << "Single Precision\n";
std::vector<genfpfcn2D_tuple<float>> sp_fcns2D;
getFunctionTuples(&sp_fcns2D,mone2onerpool2Df);
for (const auto& spfcntuple : sp_fcns2D){
funcname = std::get<0>(spfcntuple);
if (std::regex_match(funcname.begin(), funcname.end(), pattern))
print_avg2D<float,genfpfcn2D_tuple<float>>(spfcntuple,ofile,REPETITIONS);
}
// Single Precision Array
std::vector<genfpfcn2Dv_tuple<float>> sp_fcns2Dv;
getFunctionTuplesvect(&sp_fcns2Dv,mone2onerpool2Df);
for (const auto& spfcntuple : sp_fcns2Dv){
funcname = std::get<0>(spfcntuple);
if (std::regex_match(funcname.begin(), funcname.end(), pattern))
print_avg2D<float,genfpfcn2Dv_tuple<float>>(spfcntuple,ofile,REPETITIONS);
}
ofile.close();
}
|