Commit e2f347f2 authored by Lukas Renelt's avatar Lukas Renelt

[vectorclass][test] add scalability tests

parent 90e84dbc
Pipeline #10143 passed with stage
in 17 minutes and 7 seconds
......@@ -53,3 +53,48 @@ foreach(iset IN ITEMS sse2 avx avx2 avx512)
CMAKE_GUARD dune-istl_FOUND
)
endforeach(iset)
set(RUNS 10)
dune_add_test(NAME multirhsperftest-scalar
SOURCES multirhsperftest-scalar.cc
COMPILE_DEFINITIONS -DRUNS=${RUNS}
LINK_LIBRARIES dunecommon
CMAKE_GUARD dune-istl_FOUND
)
foreach(LANES IN ITEMS 2 4 8)
dune_add_test(NAME multirhsperftest-loop-${LANES}
SOURCES multirhsperftest-loop.cc
COMPILE_DEFINITIONS -DLANES=${LANES} -DRUNS=${RUNS}
LINK_LIBRARIES dunecommon
CMAKE_GUARD dune-istl_FOUND
)
endforeach(LANES)
dune_add_test(NAME multirhsperftest-vectorclass-2
SOURCES multirhsperftest-vectorclass.cc
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_DEFINITIONS -DTYPE=Vec2d -DRUNS=${RUNS}
COMPILE_FLAGS -msse2
LINK_LIBRARIES dunecommon
CMAKE_GUARD dune-istl_FOUND
)
dune_add_test(NAME multirhsperftest-vectorclass-4
SOURCES multirhsperftest-vectorclass.cc
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_DEFINITIONS -DTYPE=Vec4d -DRUNS=${RUNS}
COMPILE_FLAGS -mavx2 -mfma
LINK_LIBRARIES dunecommon
CMAKE_GUARD dune-istl_FOUND
)
dune_add_test(NAME multirhsperftest-vectorclass-8
SOURCES multirhsperftest-vectorclass.cc
COMPILE_DEFINITIONS -DMAX_VECTOR_SIZE=${MAX_VECTOR_SIZE}
COMPILE_DEFINITIONS -DTYPE=Vec8d -DRUNS=${RUNS}
COMPILE_FLAGS -mavx512f -mfma
LINK_LIBRARIES dunecommon
CMAKE_GUARD dune-istl_FOUND
)
#include "config.h"
#include <dune/common/simd/loop.hh>
#include "multirhsperftest.hh"
int main(int argc, char ** argv)
{
runInformation times;
times = runJacobiCGTest<Dune::LoopSIMD<double, LANES>>(RUNS);
printRunInformation(times);
return 0;
}
#include "config.h"
#include "multirhsperftest.hh"
int main(int argc, char ** argv)
{
runInformation times;
times = runJacobiCGTest<double>(RUNS);
printRunInformation(times);
return 0;
}
#include "config.h"
#include <dune/vectorclass/vectorclass.hh>
#include "multirhsperftest.hh"
int main(int argc, char ** argv)
{
runInformation times;
times = runJacobiCGTest< TYPE >(RUNS);
printRunInformation(times);
return 0;
}
#ifndef DUNE_VECTORCLASS_TEST_MULTIRHSPERFTEST
#define DUNE_VECTORCLASS_TEST_MULTIRHSPERFTEST
#include "config.h"
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <dune/common/classname.hh>
#include <dune/common/simd/simd.hh>
#include <dune/istl/test/multirhstest.hh>
struct runInformation {
std::vector<double> timestamps;
int runs;
std::string className;
};
template<class T>
runInformation runJacobiCGTest(unsigned int Runs) {
runInformation out;
out.className = Dune::className<T>();
out.runs = Runs;
// define Types
typedef typename Dune::Simd::Scalar<T> MT;
typedef Dune::FieldVector<T,1> VB;
typedef Dune::FieldMatrix<MT,1,1> MB;
typedef Dune::AlignedAllocator<VB> AllocV;
typedef Dune::BlockVector<VB,AllocV> Vector;
typedef Dune::BCRSMatrix<MB> Matrix;
// size
unsigned int size = 100;
unsigned int N = size*size;
// make a compressed row matrix with five point stencil
Matrix A;
setupLaplacian(A,size);
typedef Dune::MatrixAdapter<Matrix,Vector,Vector> Operator;
Operator op(A); // make linear operator from A
Dune::SeqJac<Matrix,Vector,Vector> jac(A,1,0.1);
using VectorType = decltype(detectVectorType(op));
double reduction = 1e-1;
int verb = 1;
Dune::CGSolver<VectorType> cg(op,jac,reduction,8000,verb);
std::vector<double> measuredTime = run_test("Jacobi","CG",op,cg,N,Runs);
out.timestamps = measuredTime;
return out;
}
void printRunInformation(runInformation info, bool verbose = false){
std::cout << "========================================" << std::endl;
std::cout << "type: " << info.className << std::endl;
if(verbose)
for(int i=0; i<info.runs; ++i)
std::cout << "Run " << i+1 << " took " << info.timestamps[i] << std::endl;
std::cout << "----------------------------------------" << std::endl;
if(info.runs > 1){
info.timestamps.erase(info.timestamps.begin());
--info.runs;
double totalTime = 0.0;
for(auto t : info.timestamps)
totalTime += t;
std::cout << "total time(" << info.runs << " runs): " << totalTime << std::endl;
double median = totalTime/(double)info.runs;
std::cout << "median: " << median << std::endl;
double variance = 0.0;
for(auto t : info.timestamps)
variance += (t-median)*(t-median);
variance /= (double)info.runs;
std::cout << "variance: " << variance << std::endl;
}
std::cout << "========================================" << std::endl;
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment