Loading benchmark/benchmarker.cpp +32 −130 Original line number Diff line number Diff line Loading @@ -7,26 +7,8 @@ #include <cmath> using namespace std; #include "../src/util/timer.h" #include "generators.cpp" //--------------------------- /** * important! to make use of this benchmarker, it is needed to define SORTERFUNCTION * then include this file * */ //--------------------------- #ifdef HAVE_CUDA #include <TNL/Containers/Array.h> #include "../src/util/algorithm.h" using namespace TNL; using namespace TNL::Containers; #endif static int notCorrectCounters = 0; #include "measure.h" #ifndef LOW_POW #define LOW_POW 10 Loading @@ -40,88 +22,7 @@ static int notCorrectCounters = 0; #define TRIES 20 #endif double measure(const vector<int>&vec); #ifndef MY_OWN_MEASURE double measure(const vector<int>&vec) { vector<double> resAcc; for(int i = 0; i < TRIES; i++) { #ifdef HAVE_CUDA Array<int, Devices::Cuda> arr(vec); auto view = arr.getView(); { TIMER t([&](double res){resAcc.push_back(res);}); SORTERFUNCTION(view); } if(!is_sorted(view)) notCorrectCounters++; #else vector<int> tmp = vec; { TIMER t([&](double res){resAcc.push_back(res);}); SORTERFUNCTION(tmp); } if(!std::is_sorted(tmp.begin(), tmp.end())) notCorrectCounters++; #endif } return accumulate(resAcc.begin(), resAcc.end(), 0.0) / resAcc.size(); } #endif double sorted(int size) { return measure(generateSorted(size)); } double random(int size) { return measure(generateRandom(size)); } double shuffle(int size) { return measure(generateShuffle(size)); } double almostSorted(int size) { return measure(generateAlmostSorted(size)); } double decreasing(int size) { return measure(generateDecreasing(size)); } double zero_entropy(int size) { return measure(generateZero_entropy(size)); } double gaussian(int size) { return measure(generateGaussian(size)); } double bucket(int size) { return measure(generateBucket(size)); } double staggared(int size) { return measure(generateStaggered(size)); } //------------------------------------------------------------ void start(ostream & out, string delim) { Loading @@ -137,6 +38,8 @@ void start(ostream & out, string delim) out << "zero_entropy"; out << endl; int wrongAnsCnt = 0; for(int pow = LOW_POW; pow <= HIGH_POW; pow++) { int size =(1<< pow); Loading @@ -145,33 +48,36 @@ void start(ostream & out, string delim) out << "2^" << pow << delim; out << fixed << setprecision(3); out << random(size) << delim; out.flush(); out << measure(generateRandom(size), TRIES, wrongAnsCnt); out << delim; out << shuffle(size) << delim; out.flush(); out << measure(generateShuffle(size), TRIES, wrongAnsCnt); out << delim; out << sorted(size) << delim; out.flush(); out << measure(generateSorted(size), TRIES, wrongAnsCnt); out << delim; out << almostSorted(size) << delim; out.flush(); out << measure(generateAlmostSorted(size), TRIES, wrongAnsCnt); out << delim; out << decreasing(size) << delim; out.flush(); out << measure(generateDecreasing(size), TRIES, wrongAnsCnt); out << delim; out << gaussian(size) << delim; out.flush(); out << measure(generateGaussian(size), TRIES, wrongAnsCnt) ; out << delim; out << bucket(size) << delim; out.flush(); out << measure(generateBucket(size), TRIES, wrongAnsCnt); out << delim; out << staggared(size) << delim; out.flush(); out << measure(generateStaggered(size), TRIES, wrongAnsCnt); out << delim; out << zero_entropy(size); out << measure(generateZero_entropy(size), TRIES, wrongAnsCnt); out << endl; } if(wrongAnsCnt > 0) std::cerr << wrongAnsCnt << "tries were sorted incorrectly" << std::endl; } int main(int argc, char *argv[]) Loading @@ -185,9 +91,5 @@ int main(int argc, char *argv[]) std::ofstream out(argv[1]); start(out, ","); } if(notCorrectCounters > 0) { std::cerr << notCorrectCounters << "tries were sorted incorrectly" << std::endl; } return 0; } No newline at end of file benchmark/bitonic_benchmark/benchmark.cu +9 −3 Original line number Diff line number Diff line #include "../../src/bitonicSort/bitonicSort.h" #define SORTERFUNCTION bitonicSort //--------------------------- #include "../benchmarker.cpp" #include "../measure.cu" template<typename Value> void sorter(ArrayView<Value, Devices::Cuda> arr) { bitonicSort(arr); } No newline at end of file benchmark/measure.cpp 0 → 100644 +31 −0 Original line number Diff line number Diff line #pragma once #include "measure.h" #include "../src/util/timer.h" //-------------------------------------------------------- template<typename Value> void sorter(std::vector<Value>&vec); //-------------------------------------------------------- template<typename Value> double measure(const std::vector<Value>&vec, int tries, int & wrongAnsCnt) { vector<double> resAcc; for(int i = 0; i < tries; i++) { vector<Value> tmp = vec; { TIMER t([&](double res){resAcc.push_back(res);}); sorter(tmp); } if(!std::is_sorted(tmp.begin(), tmp.end())) wrongAnsCnt++; } return accumulate(resAcc.begin(), resAcc.end(), 0.0) / resAcc.size(); } No newline at end of file benchmark/measure.cu 0 → 100644 +39 −0 Original line number Diff line number Diff line #pragma once #include <vector> #include "measure.h" #include "../src/util/timer.h" #include <TNL/Containers/Array.h> #include "../src/util/algorithm.h" using namespace TNL; using namespace TNL::Containers; //-------------------------------------------------------- template<typename Value> void sorter(ArrayView<Value, Devices::Cuda> arr); //-------------------------------------------------------- template<typename Value> double measure(const std::vector<Value>&vec, int tries, int & wrongAnsCnt) { vector<double> resAcc; for(int i = 0; i < tries; i++) { Array<Value, Devices::Cuda> arr(vec); auto view = arr.getView(); { TIMER t([&](double res){resAcc.push_back(res);}); sorter(view); } if(!is_sorted(view)) wrongAnsCnt++; } return accumulate(resAcc.begin(), resAcc.end(), 0.0) / resAcc.size(); } No newline at end of file benchmark/measure.h 0 → 100644 +6 −0 Original line number Diff line number Diff line #pragma once #include <vector> template<typename Value> double measure(const std::vector<Value>&vec, int tries, int & wrongAnsCnt); No newline at end of file Loading
benchmark/benchmarker.cpp +32 −130 Original line number Diff line number Diff line Loading @@ -7,26 +7,8 @@ #include <cmath> using namespace std; #include "../src/util/timer.h" #include "generators.cpp" //--------------------------- /** * important! to make use of this benchmarker, it is needed to define SORTERFUNCTION * then include this file * */ //--------------------------- #ifdef HAVE_CUDA #include <TNL/Containers/Array.h> #include "../src/util/algorithm.h" using namespace TNL; using namespace TNL::Containers; #endif static int notCorrectCounters = 0; #include "measure.h" #ifndef LOW_POW #define LOW_POW 10 Loading @@ -40,88 +22,7 @@ static int notCorrectCounters = 0; #define TRIES 20 #endif double measure(const vector<int>&vec); #ifndef MY_OWN_MEASURE double measure(const vector<int>&vec) { vector<double> resAcc; for(int i = 0; i < TRIES; i++) { #ifdef HAVE_CUDA Array<int, Devices::Cuda> arr(vec); auto view = arr.getView(); { TIMER t([&](double res){resAcc.push_back(res);}); SORTERFUNCTION(view); } if(!is_sorted(view)) notCorrectCounters++; #else vector<int> tmp = vec; { TIMER t([&](double res){resAcc.push_back(res);}); SORTERFUNCTION(tmp); } if(!std::is_sorted(tmp.begin(), tmp.end())) notCorrectCounters++; #endif } return accumulate(resAcc.begin(), resAcc.end(), 0.0) / resAcc.size(); } #endif double sorted(int size) { return measure(generateSorted(size)); } double random(int size) { return measure(generateRandom(size)); } double shuffle(int size) { return measure(generateShuffle(size)); } double almostSorted(int size) { return measure(generateAlmostSorted(size)); } double decreasing(int size) { return measure(generateDecreasing(size)); } double zero_entropy(int size) { return measure(generateZero_entropy(size)); } double gaussian(int size) { return measure(generateGaussian(size)); } double bucket(int size) { return measure(generateBucket(size)); } double staggared(int size) { return measure(generateStaggered(size)); } //------------------------------------------------------------ void start(ostream & out, string delim) { Loading @@ -137,6 +38,8 @@ void start(ostream & out, string delim) out << "zero_entropy"; out << endl; int wrongAnsCnt = 0; for(int pow = LOW_POW; pow <= HIGH_POW; pow++) { int size =(1<< pow); Loading @@ -145,33 +48,36 @@ void start(ostream & out, string delim) out << "2^" << pow << delim; out << fixed << setprecision(3); out << random(size) << delim; out.flush(); out << measure(generateRandom(size), TRIES, wrongAnsCnt); out << delim; out << shuffle(size) << delim; out.flush(); out << measure(generateShuffle(size), TRIES, wrongAnsCnt); out << delim; out << sorted(size) << delim; out.flush(); out << measure(generateSorted(size), TRIES, wrongAnsCnt); out << delim; out << almostSorted(size) << delim; out.flush(); out << measure(generateAlmostSorted(size), TRIES, wrongAnsCnt); out << delim; out << decreasing(size) << delim; out.flush(); out << measure(generateDecreasing(size), TRIES, wrongAnsCnt); out << delim; out << gaussian(size) << delim; out.flush(); out << measure(generateGaussian(size), TRIES, wrongAnsCnt) ; out << delim; out << bucket(size) << delim; out.flush(); out << measure(generateBucket(size), TRIES, wrongAnsCnt); out << delim; out << staggared(size) << delim; out.flush(); out << measure(generateStaggered(size), TRIES, wrongAnsCnt); out << delim; out << zero_entropy(size); out << measure(generateZero_entropy(size), TRIES, wrongAnsCnt); out << endl; } if(wrongAnsCnt > 0) std::cerr << wrongAnsCnt << "tries were sorted incorrectly" << std::endl; } int main(int argc, char *argv[]) Loading @@ -185,9 +91,5 @@ int main(int argc, char *argv[]) std::ofstream out(argv[1]); start(out, ","); } if(notCorrectCounters > 0) { std::cerr << notCorrectCounters << "tries were sorted incorrectly" << std::endl; } return 0; } No newline at end of file
benchmark/bitonic_benchmark/benchmark.cu +9 −3 Original line number Diff line number Diff line #include "../../src/bitonicSort/bitonicSort.h" #define SORTERFUNCTION bitonicSort //--------------------------- #include "../benchmarker.cpp" #include "../measure.cu" template<typename Value> void sorter(ArrayView<Value, Devices::Cuda> arr) { bitonicSort(arr); } No newline at end of file
benchmark/measure.cpp 0 → 100644 +31 −0 Original line number Diff line number Diff line #pragma once #include "measure.h" #include "../src/util/timer.h" //-------------------------------------------------------- template<typename Value> void sorter(std::vector<Value>&vec); //-------------------------------------------------------- template<typename Value> double measure(const std::vector<Value>&vec, int tries, int & wrongAnsCnt) { vector<double> resAcc; for(int i = 0; i < tries; i++) { vector<Value> tmp = vec; { TIMER t([&](double res){resAcc.push_back(res);}); sorter(tmp); } if(!std::is_sorted(tmp.begin(), tmp.end())) wrongAnsCnt++; } return accumulate(resAcc.begin(), resAcc.end(), 0.0) / resAcc.size(); } No newline at end of file
benchmark/measure.cu 0 → 100644 +39 −0 Original line number Diff line number Diff line #pragma once #include <vector> #include "measure.h" #include "../src/util/timer.h" #include <TNL/Containers/Array.h> #include "../src/util/algorithm.h" using namespace TNL; using namespace TNL::Containers; //-------------------------------------------------------- template<typename Value> void sorter(ArrayView<Value, Devices::Cuda> arr); //-------------------------------------------------------- template<typename Value> double measure(const std::vector<Value>&vec, int tries, int & wrongAnsCnt) { vector<double> resAcc; for(int i = 0; i < tries; i++) { Array<Value, Devices::Cuda> arr(vec); auto view = arr.getView(); { TIMER t([&](double res){resAcc.push_back(res);}); sorter(view); } if(!is_sorted(view)) wrongAnsCnt++; } return accumulate(resAcc.begin(), resAcc.end(), 0.0) / resAcc.size(); } No newline at end of file
benchmark/measure.h 0 → 100644 +6 −0 Original line number Diff line number Diff line #pragma once #include <vector> template<typename Value> double measure(const std::vector<Value>&vec, int tries, int & wrongAnsCnt); No newline at end of file