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;
178 referenceValues[
"Expf"] = std::make_pair(1.
f,8);
179 referenceValues[
"Sinf"] = std::make_pair(1.
f,11);
180 referenceValues[
"Cosf"] = std::make_pair(1.
f,10);
181 referenceValues[
"Tanf"] = std::make_pair(1.
f,11);
182 referenceValues[
"Atanf"] = std::make_pair(1.
f,4);
183 referenceValues[
"Logf"] = std::make_pair(1.
f,4);
184 referenceValues[
"Isqrtf"]= std::make_pair(1.
f,9);
185 referenceValues[
"Asinf"] = std::make_pair(1.
f,5);
186 referenceValues[
"Acosf"] = std::make_pair(1.
f,12);
187 referenceValues[
"Exp"] = std::make_pair(1.
f,4);
188 referenceValues[
"Sin"] = std::make_pair(1.
f,4);
189 referenceValues[
"Cos"] = std::make_pair(1.
f,4);
190 referenceValues[
"Tan"] = std::make_pair(1.
f,7);
191 referenceValues[
"Atan"] = std::make_pair(1.
f,4);
192 referenceValues[
"Log"] = std::make_pair(1.
f,4);
193 referenceValues[
"Isqrt"] = std::make_pair(.4
f,4);
194 referenceValues[
"Asin"] = std::make_pair(1.
f,4);
195 referenceValues[
"Acos"] = std::make_pair(1.
f,13);
199 template <
typename T,
typename F1,
typename F2>
203 const std::vector<T>& inputVector,
204 std::vector<T>& outputVectorVDT,
205 std::vector<T>& outputVectorSystem,
207 uint32_t& maxdiffBit,
210 double timeVdt = measureTiming<T>(vdtFunc,inputVector,outputVectorVDT);
211 double timeSystem = measureTiming<T>(systemFunc,inputVector,outputVectorSystem);
212 std::string
name(label);
213 std::string title(label);
214 title+=
";Diff. Bit;#";
219 double meandiffBit = histo.
GetMean();
223 for (uint32_t i=1;i<=
xmax;i++){
228 speedup = timeSystem/timeVdt ;
230 std::cout << std::setw(8)
231 << label << std::setw(10)
232 << timeVdt << std::setw(10)
233 << timeSystem << std::setw(15)
234 << speedup << std::setw(15)
235 << meandiffBit << std::setw(15)
236 << maxdiffBit << std::endl;
248 c.
Print(name.c_str());
259 if (
gbl.referenceValues[label].second < maxdiffBit)
260 std::cerr <<
"WARNING " << label <<
" is too inaccurate!\n";
275 std::vector<float> VDTVals(
SIZE);
276 std::vector<float> SystemVals(
SIZE);
277 std::vector<float> realNumbers(
SIZE);
278 TH1F histo(
"bitDiffHisto",
"willbechanged",32,0,32);
284 compareFunctions<float>(
"Expf",
vdt::fast_expf, expf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
288 compareFunctions<float>(
"Sinf",
vdt::fast_sinf, sinf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
290 compareFunctions<float>(
"Cosf",
vdt::fast_cosf, cosf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
292 compareFunctions<float>(
"Tanf",
vdt::fast_tanf, tanf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
294 compareFunctions<float>(
"Atanf",
vdt::fast_atanf, atanf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
300 std::vector<float> VDTVals(
SIZE);
301 std::vector<float> SystemVals(
SIZE);
302 std::vector<float> realNumbers(
SIZE);
303 TH1F histo(
"bitDiffHisto",
"willbechanged",32,0,32);
309 compareFunctions<float>(
"Logf",
vdt::fast_logf, logf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
311 compareFunctions<float>(
"Isqrtf",
vdt::fast_isqrtf,
isqrtf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
317 std::vector<float> VDTVals(
SIZE);
318 std::vector<float> SystemVals(
SIZE);
319 std::vector<float> realNumbers(
SIZE);
320 TH1F histo(
"bitDiffHisto",
"willbechanged",32,0,32);
326 compareFunctions<float>(
"Asinf",
vdt::fast_asinf, asinf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
328 compareFunctions<float>(
"Acosf",
vdt::fast_acosf, acosf, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
334 std::vector<double> VDTVals(
SIZE);
335 std::vector<double> SystemVals(
SIZE);
336 std::vector<double> realNumbers(
SIZE);
337 TH1F histo(
"bitDiffHisto",
"willbechanged",64,0,64);
343 compareFunctions<double>(
"Exp",
vdt::fast_exp,
exp, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
346 compareFunctions<double>(
"Sin",
vdt::fast_sin,
sin, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
348 compareFunctions<double>(
"Cos",
vdt::fast_cos,
cos, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
350 compareFunctions<double>(
"Tan",
vdt::fast_tan,
tan, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
352 compareFunctions<double>(
"Atan",
vdt::fast_atan,
atan, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
358 std::vector<double> VDTVals(
SIZE);
359 std::vector<double> SystemVals(
SIZE);
360 std::vector<double> realNumbers(
SIZE);
361 TH1F histo(
"bitDiffHisto",
"willbechanged",64,0,64);
367 compareFunctions<double>(
"Log",
vdt::fast_log,
log, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
369 compareFunctions<double>(
"Isqrt",
vdt::fast_isqrt,
isqrt, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
375 std::vector<double> VDTVals(
SIZE);
376 std::vector<double> SystemVals(
SIZE);
377 std::vector<double> realNumbers(
SIZE);
378 TH1F histo(
"bitDiffHisto",
"willbechanged",64,0,64);
384 compareFunctions<double>(
"Asin",
vdt::fast_asin,
asin, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
386 compareFunctions<double>(
"Acos",
vdt::fast_acos,
acos, realNumbers, VDTVals, SystemVals, speedup, maxdiffBit, histo);
393 std::cout <<
"Test performed on " <<
SIZE <<
" random numbers\n"
395 <<
"Name" << std::setw(10)
396 <<
"VDT (s)" << std::setw(10)
397 <<
"Sys (s)" << std::setw(15)
398 <<
"Speedup" << std::setw(15)
399 <<
"<diff Bit>" << std::setw(15)
400 <<
"max(diff Bit)" << std::endl;
virtual void SetLineWidth(Width_t lwidth)
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...
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
R__EXTERN Int_t gErrorIgnoreLevel
double fast_exp(double initial_x)
Exponential Function double precision.
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
uint32_t sp2uint32(float x)
Converts a float to an int.
const double RANGE
Simple program to benchmark vdt accuracy and cpu performance.
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.
virtual void Print(const char *filename="") const
Save Pad contents in a file in one of various formats.
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)
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.
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 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)
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.