21 const uint32_t
SIZE= 16777216;
49 uint64_t ia = fp2uint<T>(
a);
50 uint64_t ib = fp2uint<T>(
b);
51 uint64_t
c = ia>ib? ia-ib : ib-ia;
59 template <
typename T,
typename F>
61 const std::vector<T>& inputVector,
62 std::vector<T>& outputVector)
65 const uint32_t size = inputVector.size();
67 for (
unsigned int i=0;i<size;++i){
68 outputVector[i]=mathFunc(inputVector[i]);
77 const std::vector<T>& inputVector2,
78 std::vector<uint32_t>& outputVector)
80 assert(inputVector1.size()==inputVector2.size() &&
81 inputVector1.size()==outputVector.size());
83 const uint32_t size = inputVector1.size();
85 for (
unsigned int i=0;i<size;++i)
86 outputVector[i]=
diffbit(inputVector1[i],inputVector2[i]);
103 const uint32_t size=randomV.size();
105 T* arr = &(randomV[0]);
107 if (
kReal == theRangeType )
for (uint32_t i=0;i<size;++i) randomV[i]=(randomV[i]-0.5)*2*
RANGE;
108 if (
kExp == theRangeType )
for (uint32_t i=0;i<size;++i) randomV[i]=(randomV[i]-0.5)*2*705.;
109 if (
kExpf == theRangeType )
for (uint32_t i=0;i<size;++i) randomV[i]=(randomV[i]-0.5)*2*85.;
110 if (
kRealPlus == theRangeType )
for (uint32_t i=0;i<size;++i) randomV[i]=randomV[i]*
RANGE+0.000001;
111 if (
km1p1 == theRangeType )
for (uint32_t i=0;i<size;++i) randomV[i]=(randomV[i]-0.5)*2;
119 const std::vector<T>& VDTVals,
120 const std::vector<T>& SystemVals)
122 const uint32_t size = VDTVals.size();
123 std::vector<uint32_t> diff(size);
126 for (uint32_t i =0;i<size;++i){
134 template <
typename T,
typename F>
136 const std::vector<T>& inputVector,
137 std::vector<T>& outputVector)
141 calculateValues<T>(mathFunc,inputVector,outputVector);
173 struct staticInitHelper{
174 std::map<std::string, std::pair<float,uint32_t> > referenceValues;
179 const int sincosTolerance = 4;
180 const int tanTolerance = 5;
182 const int sincosTolerance = 19;
183 const int tanTolerance = 19;
185 referenceValues[
"Expf"] = std::make_pair(1.
f,8);
186 referenceValues[
"Sinf"] = std::make_pair(1.
f,11);
187 referenceValues[
"Cosf"] = std::make_pair(1.
f,10);
188 referenceValues[
"Tanf"] = std::make_pair(1.
f,11);
189 referenceValues[
"Atanf"] = std::make_pair(1.
f,4);
190 referenceValues[
"Logf"] = std::make_pair(1.
f,4);
191 referenceValues[
"Isqrtf"]= std::make_pair(1.
f,9);
192 referenceValues[
"Asinf"] = std::make_pair(1.
f,5);
193 referenceValues[
"Acosf"] = std::make_pair(1.
f,12);
194 referenceValues[
"Exp"] = std::make_pair(1.
f,4);
195 referenceValues[
"Sin"] = std::make_pair(1.
f,sincosTolerance);
196 referenceValues[
"Cos"] = std::make_pair(1.
f,sincosTolerance);
197 referenceValues[
"Tan"] = std::make_pair(1.
f,tanTolerance);
198 referenceValues[
"Atan"] = std::make_pair(1.
f,4);
199 referenceValues[
"Log"] = std::make_pair(1.
f,4);
200 referenceValues[
"Isqrt"] = std::make_pair(.4
f,4);
201 referenceValues[
"Asin"] = std::make_pair(1.
f,4);
202 referenceValues[
"Acos"] = std::make_pair(1.
f,13);
206 template <
typename T,
typename F1,
typename F2>
210 const std::vector<T>& inputVector,
211 std::vector<T>& outputVectorVDT,
212 std::vector<T>& outputVectorSystem,
214 uint32_t& maxdiffBit,
217 double timeVdt = measureTiming<T>(vdtFunc,inputVector,outputVectorVDT);
218 double timeSystem = measureTiming<T>(systemFunc,inputVector,outputVectorSystem);
219 std::string
name(label);
220 std::string title(label);
221 title+=
";Diff. Bit;#";
226 double meandiffBit = histo.
GetMean();
230 for (uint32_t i=1;i<=
xmax;i++){
235 speedup = timeSystem/timeVdt ;
237 std::cout << std::setw(8)
238 << label << std::setw(10)
239 << timeVdt << std::setw(10)
240 << timeSystem << std::setw(15)
241 << speedup << std::setw(15)
242 << meandiffBit << std::setw(15)
243 << maxdiffBit << std::endl;
255 c.
Print(name.c_str());
266 if (
gbl.referenceValues[label].second < maxdiffBit)
267 std::cerr <<
"WARNING " << label <<
" is too inaccurate!\n";
282 std::vector<float> VDTVals(
SIZE);
283 std::vector<float> SystemVals(
SIZE);
284 std::vector<float> realNumbers(
SIZE);
285 TH1F histo(
"bitDiffHisto",
"willbechanged",32,0,32);
291 compareFunctions<float>(
"Expf",
vdt::fast_expf, expf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
295 compareFunctions<float>(
"Sinf",
vdt::fast_sinf, sinf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
297 compareFunctions<float>(
"Cosf",
vdt::fast_cosf, cosf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
299 compareFunctions<float>(
"Tanf",
vdt::fast_tanf, tanf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
301 compareFunctions<float>(
"Atanf",
vdt::fast_atanf, atanf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
307 std::vector<float> VDTVals(
SIZE);
308 std::vector<float> SystemVals(
SIZE);
309 std::vector<float> realNumbers(
SIZE);
310 TH1F histo(
"bitDiffHisto",
"willbechanged",32,0,32);
316 compareFunctions<float>(
"Logf",
vdt::fast_logf, logf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
318 compareFunctions<float>(
"Isqrtf",
vdt::fast_isqrtf,
isqrtf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
324 std::vector<float> VDTVals(
SIZE);
325 std::vector<float> SystemVals(
SIZE);
326 std::vector<float> realNumbers(
SIZE);
327 TH1F histo(
"bitDiffHisto",
"willbechanged",32,0,32);
333 compareFunctions<float>(
"Asinf",
vdt::fast_asinf, asinf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
335 compareFunctions<float>(
"Acosf",
vdt::fast_acosf, acosf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
341 std::vector<double> VDTVals(
SIZE);
342 std::vector<double> SystemVals(
SIZE);
343 std::vector<double> realNumbers(
SIZE);
344 TH1F histo(
"bitDiffHisto",
"willbechanged",64,0,64);
350 compareFunctions<double>(
"Exp",
vdt::fast_exp,
exp, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
353 compareFunctions<double>(
"Sin",
vdt::fast_sin,
sin, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
355 compareFunctions<double>(
"Cos",
vdt::fast_cos,
cos, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
357 compareFunctions<double>(
"Tan",
vdt::fast_tan,
tan, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
359 compareFunctions<double>(
"Atan",
vdt::fast_atan,
atan, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
365 std::vector<double> VDTVals(
SIZE);
366 std::vector<double> SystemVals(
SIZE);
367 std::vector<double> realNumbers(
SIZE);
368 TH1F histo(
"bitDiffHisto",
"willbechanged",64,0,64);
374 compareFunctions<double>(
"Log",
vdt::fast_log,
log, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
376 compareFunctions<double>(
"Isqrt",
vdt::fast_isqrt,
isqrt, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
382 std::vector<double> VDTVals(
SIZE);
383 std::vector<double> SystemVals(
SIZE);
384 std::vector<double> realNumbers(
SIZE);
385 TH1F histo(
"bitDiffHisto",
"willbechanged",64,0,64);
391 compareFunctions<double>(
"Asin",
vdt::fast_asin,
asin, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
393 compareFunctions<double>(
"Acos",
vdt::fast_acos,
acos, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
400 std::cout <<
"Test performed on " <<
SIZE <<
" random numbers\n" 402 <<
"Name" << std::setw(10)
403 <<
"VDT (s)" << std::setw(10)
404 <<
"Sys (s)" << std::setw(15)
405 <<
"Speedup" << std::setw(15)
406 <<
"<diff Bit>" << std::setw(15)
407 <<
"max(diff Bit)" << std::endl;
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
float fast_expf(float initial_x)
Exponential Function single precision.
float fast_asinf(float x)
Single Precision asin.
Random number generator class based on M.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
R__EXTERN Int_t gErrorIgnoreLevel
double fast_exp(double initial_x)
Exponential Function double precision.
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
uint32_t sp2uint32(float x)
Converts a float to an int.
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
const double RANGE
Simple program to benchmark vdt accuracy and cpu performance.
tomato 1-D histogram with a float per channel (see TH1 documentation)}
double measureTiming(F mathFunc, const std::vector< T > &inputVector, std::vector< T > &outputVector)
struct staticInitHelper gbl
double fast_asin(double x)
Double Precision asin.
uint32_t diffbit(const T a, const T b)
Returns most significative different bit.
void treatBinDiffHisto(TH1F &histo, const std::vector< T > &VDTVals, const std::vector< T > &SystemVals)
virtual void Reset(Option_t *option="")
Reset.
double fast_acos(double x)
void Stop()
Stop the stopwatch.
double fast_atan(double x)
Fast Atan implementation double precision.
double fast_cos(double x)
Double precision cosine: just call sincos.
void compareFunctions(const std::string &label, F1 vdtFunc, F2 systemFunc, const std::vector< T > &inputVector, std::vector< T > &outputVectorVDT, std::vector< T > &outputVectorSystem, float &speedup, uint32_t &maxdiffBit, TH1F &histo)
void checkFunction(const std::string &label, float, uint32_t maxdiffBit)
uint64_t fp2uint< double >(double x)
double fast_log(double x)
virtual void SetLineColor(Color_t lcolor)
Set the line color.
double fast_sin(double x)
Double precision sine: just call sincos.
virtual void Draw(Option_t *option="")
Draw this histogram with options.
float fast_isqrtf(float x)
Two iterations.
uint64_t dp2uint64(double x)
Converts a double to an unsigned long long.
virtual void Print(const char *filename="") const
Save Pad contents in a file in one of various formats.
virtual void RndmArray(Int_t n, Float_t *array)
Return an array of n random numbers uniformly distributed in ]0,1].
virtual void SetName(const char *name)
Change the name of this histogram.
void fillRandom(std::vector< T > &randomV, const rangeType theRangeType)
uint64_t fp2uint< float >(float x)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
virtual void SetTitle(const char *title)
Change (i.e.
void compareOutputs(const std::vector< T > &inputVector1, const std::vector< T > &inputVector2, std::vector< uint32_t > &outputVector)
double fast_tan(double x)
Double precision tangent implementation.
void calculateValues(F mathFunc, const std::vector< T > &inputVector, std::vector< T > &outputVector)
float fast_atanf(float xx)
Fast Atan implementation single precision.
double fast_isqrt(double x)
Four iterations.
float fast_acosf(float x)
virtual void SetLogy(Int_t value=1)
Set Lin/Log scale for Y.